static PyObject* PyMangleMask_weight(struct PyMangleMask* self, PyObject* args) { int status=1; struct Point pt; PyObject* ra_obj=NULL; PyObject* dec_obj=NULL; PyObject* weight_obj=NULL; double* ra_ptr=NULL; double* dec_ptr=NULL; double* weight_ptr=NULL; npy_intp poly_id=0; npy_intp nra=0, ndec=0, i=0; if (!PyArg_ParseTuple(args, (char*)"OO", &ra_obj, &dec_obj)) { return NULL; } if (!check_ra_dec_arrays(ra_obj,dec_obj,&ra_ptr,&nra,&dec_ptr,&ndec)) { return NULL; } if (!(weight_obj=make_double_array(nra, "weight", &weight_ptr))) { return NULL; } for (i=0; i<nra; i++) { point_set_from_radec(&pt, *ra_ptr, *dec_ptr); //status=mangle_polyid_and_weight(self->mask, status=MANGLE_POLYID_AND_WEIGHT(self->mask, &pt, &poly_id, weight_ptr); if (status != 1) { goto _weight_cleanup; } ra_ptr++; dec_ptr++; weight_ptr++; } _weight_cleanup: if (status != 1) { Py_XDECREF(weight_obj); return NULL; } return weight_obj; }
static PyObject* PyMangleMask_genrand_range(struct PyMangleMask* self, PyObject* args) { int status=1; PY_LONG_LONG nrand=0; double ramin=0,ramax=0,decmin=0,decmax=0; double cthmin=0,cthmax=0,phimin=0,phimax=0; struct Point pt; PyObject* ra_obj=NULL; PyObject* dec_obj=NULL; PyObject* tuple=NULL; double* ra_ptr=NULL; double* dec_ptr=NULL; double weight=0; npy_intp poly_id=0; npy_intp ngood=0; double theta=0, phi=0; if (!PyArg_ParseTuple(args, (char*)"Ldddd", &nrand, &ramin, &ramax, &decmin, &decmax)) { return NULL; } if (nrand <= 0) { PyErr_Format(PyExc_ValueError, "nrand should be > 0, got (%ld)",(npy_intp)nrand); status=0; goto _genrand_range_cleanup; } if (!radec_range_to_costhetaphi(ramin,ramax,decmin,decmax, &cthmin,&cthmax,&phimin,&phimax)) { status=0; goto _genrand_range_cleanup; } if (!(ra_obj=make_double_array(nrand, "ra", &ra_ptr))) { status=0; goto _genrand_range_cleanup; } if (!(dec_obj=make_double_array(nrand, "dec", &dec_ptr))) { status=0; goto _genrand_range_cleanup; } seed_random(); while (ngood < nrand) { genrand_theta_phi(cthmin,cthmax,phimin,phimax,&theta, &phi); point_set_from_thetaphi(&pt, theta, phi); //status=mangle_polyid_and_weight(self->mask, &pt, &poly_id, &weight); status=MANGLE_POLYID_AND_WEIGHT(self->mask, &pt, &poly_id, &weight); if (status != 1) { goto _genrand_range_cleanup; } if (poly_id >= 0) { // rely on short circuiting if (weight < 1.0 || drand48() < weight) { ngood++; radec_from_point(&pt, ra_ptr, dec_ptr); ra_ptr++; dec_ptr++; } } } _genrand_range_cleanup: if (status != 1) { Py_XDECREF(ra_obj); Py_XDECREF(dec_obj); Py_XDECREF(tuple); return NULL; } tuple=PyTuple_New(2); PyTuple_SetItem(tuple, 0, ra_obj); PyTuple_SetItem(tuple, 1, dec_obj); return tuple; }
static PyObject* PyMangleMask_polyid_and_weight(struct PyMangleMask* self, PyObject* args) { int status=1; struct Point pt; PyObject* ra_obj=NULL; PyObject* dec_obj=NULL; PyObject* poly_id_obj=NULL; PyObject* weight_obj=NULL; double* ra_ptr=NULL; double* dec_ptr=NULL; double* weight_ptr=NULL; npy_intp* poly_id_ptr=NULL; npy_intp nra=0, ndec=0, i=0; PyObject* tuple=NULL; if (!PyArg_ParseTuple(args, (char*)"OO", &ra_obj, &dec_obj)) { return NULL; } if (!check_ra_dec_arrays(ra_obj,dec_obj,&ra_ptr,&nra,&dec_ptr,&ndec)) { return NULL; } if (!(poly_id_obj=make_intp_array(nra, "polyid", &poly_id_ptr))) { status=0; goto _poly_id_and_weight_cleanup; } if (!(weight_obj=make_double_array(nra, "weight", &weight_ptr))) { status=0; goto _poly_id_and_weight_cleanup; } for (i=0; i<nra; i++) { point_set_from_radec(&pt, *ra_ptr, *dec_ptr); status=mangle_polyid_and_weight_nopix(self->mask, &pt, poly_id_ptr, weight_ptr); if (status != 1) { goto _poly_id_and_weight_cleanup; } ra_ptr++; dec_ptr++; poly_id_ptr++; weight_ptr++; } _poly_id_and_weight_cleanup: if (status != 1) { Py_XDECREF(poly_id_obj); Py_XDECREF(weight_obj); Py_XDECREF(tuple); return NULL; } tuple=PyTuple_New(2); PyTuple_SetItem(tuple, 0, poly_id_obj); PyTuple_SetItem(tuple, 1, weight_obj); return tuple; }
static PyObject* PyMangleMask_genrand(struct PyMangleMask* self, PyObject* args) { int status=1; PY_LONG_LONG nrand=0; struct Point pt; PyObject* ra_obj=NULL; PyObject* dec_obj=NULL; PyObject* tuple=NULL; double* ra_ptr=NULL; double* dec_ptr=NULL; double weight=0; npy_intp poly_id=0; npy_intp ngood=0; double theta=0, phi=0; if (!PyArg_ParseTuple(args, (char*)"L", &nrand)) { return NULL; } if (nrand <= 0) { PyErr_Format(PyExc_ValueError, "nrand should be > 0, got (%ld)",(npy_intp)nrand); status=0; goto _genrand_cleanup; } if (!(ra_obj=make_double_array(nrand, "ra", &ra_ptr))) { status=0; goto _genrand_cleanup; } if (!(dec_obj=make_double_array(nrand, "dec", &dec_ptr))) { status=0; goto _genrand_cleanup; } seed_random(); while (ngood < nrand) { genrand_theta_phi_allsky(&theta, &phi); point_set_from_thetaphi(&pt, theta, phi); if (self->pixelres == -1) { status=polyid_and_weight(self, &pt, &poly_id, &weight); } else { status=polyid_and_weight_pixelized(self, &pt, &poly_id, &weight); } if (status != 1) { goto _genrand_cleanup; } if (poly_id >= 0) { // rely on short circuiting if (weight < 1.0 || drand48() < weight) { ngood++; radec_from_point(&pt, ra_ptr, dec_ptr); ra_ptr++; dec_ptr++; } } } _genrand_cleanup: if (status != 1) { Py_XDECREF(ra_obj); Py_XDECREF(dec_obj); Py_XDECREF(tuple); return NULL; } tuple=PyTuple_New(2); PyTuple_SetItem(tuple, 0, ra_obj); PyTuple_SetItem(tuple, 1, dec_obj); return tuple; }