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_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; }