Example #1
0
/*@null@*/ static PyObject*
Wcs_pix2foc(
    Wcs* self,
    PyObject* args,
    PyObject* kwds) {

    PyObject*      pixcrd_obj = NULL;
    int            origin     = 1;
    PyArrayObject* pixcrd     = NULL;
    PyArrayObject* foccrd     = NULL;
    int            status     = -1;
    const char*    keywords[] = {
        "pixcrd", "origin", NULL
    };

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oi:pix2foc", (char **)keywords,
                                     &pixcrd_obj, &origin)) {
        return NULL;
    }

    pixcrd = (PyArrayObject*)PyArray_ContiguousFromAny(pixcrd_obj, PyArray_DOUBLE, 2, 2);
    if (pixcrd == NULL) {
        return NULL;
    }

    if (PyArray_DIM(pixcrd, 1) != NAXES) {
        PyErr_SetString(PyExc_ValueError, "Pixel array must be an Nx2 array");
        goto _exit;
    }

    foccrd = (PyArrayObject*)PyArray_SimpleNew(2, PyArray_DIMS(pixcrd), PyArray_DOUBLE);
    if (foccrd == NULL) {
        goto _exit;
    }

    Py_BEGIN_ALLOW_THREADS
    preoffset_array(pixcrd, origin);
    status = pipeline_pix2foc(&self->x,
                              (unsigned int)PyArray_DIM(pixcrd, 0),
                              (unsigned int)PyArray_DIM(pixcrd, 1),
                              (double*)PyArray_DATA(pixcrd),
                              (double*)PyArray_DATA(foccrd));
    unoffset_array(pixcrd, origin);
    unoffset_array(foccrd, origin);
    Py_END_ALLOW_THREADS

_exit:

    Py_XDECREF(pixcrd);

    if (status == 0) {
        return (PyObject*)foccrd;
    } else {
        Py_XDECREF(foccrd);
        if (status == -1) {
            /* Exception already set */
            return NULL;
        } else {
            wcserr_to_python_exc(self->x.err);
            return NULL;
        }
    }
}
Example #2
0
static int
PySip_init(
    PySip* self,
    PyObject* args,
    /*@unused@*/ PyObject* kwds) {

  PyObject*      py_a     = NULL;
  PyObject*      py_b     = NULL;
  PyObject*      py_ap    = NULL;
  PyObject*      py_bp    = NULL;
  PyObject*      py_crpix = NULL;
  PyArrayObject* a        = NULL;
  PyArrayObject* b        = NULL;
  PyArrayObject* ap       = NULL;
  PyArrayObject* bp       = NULL;
  PyArrayObject* crpix    = NULL;
  double*        a_data   = NULL;
  double*        b_data   = NULL;
  double*        ap_data  = NULL;
  double*        bp_data  = NULL;
  unsigned int   a_order  = 0;
  unsigned int   b_order  = 0;
  unsigned int   ap_order = 0;
  unsigned int   bp_order = 0;
  int            status   = -1;

  if (!PyArg_ParseTuple(args, "OOOOO:Sip.__init__",
                        &py_a, &py_b, &py_ap, &py_bp, &py_crpix)) {
    return -1;
  }

  if (convert_matrix(py_a, &a, &a_data, &a_order) ||
      convert_matrix(py_b, &b, &b_data, &b_order) ||
      convert_matrix(py_ap, &ap, &ap_data, &ap_order) ||
      convert_matrix(py_bp, &bp, &bp_data, &bp_order)) {
    goto exit;
  }

  crpix = (PyArrayObject*)PyArray_ContiguousFromAny(py_crpix, PyArray_DOUBLE,
                                                    1, 1);
  if (crpix == NULL) {
    goto exit;
  }

  if (PyArray_DIM(crpix, 0) != 2) {
    PyErr_SetString(PyExc_ValueError, "CRPIX wrong length");
    goto exit;
  }

  status = sip_init(&self->x,
                    a_order, a_data,
                    b_order, b_data,
                    ap_order, ap_data,
                    bp_order, bp_data,
                    PyArray_DATA(crpix));

 exit:
  Py_XDECREF(a);
  Py_XDECREF(b);
  Py_XDECREF(ap);
  Py_XDECREF(bp);
  Py_XDECREF(crpix);

  if (status == 0) {
    return 0;
  } else if (status == -1) {
    /* Exception already set */
    return -1;
  } else {
    wcserr_to_python_exc(self->x.err);
    return -1;
  }
}
Example #3
0
/*@null@*/ static PyObject*
Wcs_all_pix2world(
    Wcs* self,
    PyObject* args,
    PyObject* kwds) {

    int            naxis      = 2;
    PyObject*      pixcrd_obj = NULL;
    int            origin     = 1;
    PyArrayObject* pixcrd     = NULL;
    PyArrayObject* world      = NULL;
    int            status     = -1;
    const char*    keywords[] = {
        "pixcrd", "origin", NULL
    };

    if (!PyArg_ParseTupleAndKeywords(
                args, kwds, "Oi:all_pix2world", (char **)keywords,
                &pixcrd_obj, &origin)) {
        return NULL;
    }

    naxis = self->x.wcs->naxis;

    pixcrd = (PyArrayObject*)PyArray_ContiguousFromAny(pixcrd_obj, PyArray_DOUBLE, 2, 2);
    if (pixcrd == NULL) {
        return NULL;
    }

    if (PyArray_DIM(pixcrd, 1) < naxis) {
        PyErr_Format(
            PyExc_RuntimeError,
            "Input array must be 2-dimensional, where the second dimension >= %d",
            naxis);
        goto exit;
    }

    world = (PyArrayObject*)PyArray_SimpleNew(2, PyArray_DIMS(pixcrd), PyArray_DOUBLE);
    if (world == NULL) {
        goto exit;
    }

    /* Make the call */
    Py_BEGIN_ALLOW_THREADS
    preoffset_array(pixcrd, origin);
    wcsprm_python2c(self->x.wcs);
    status = pipeline_all_pixel2world(&self->x,
                                      (unsigned int)PyArray_DIM(pixcrd, 0),
                                      (unsigned int)PyArray_DIM(pixcrd, 1),
                                      (double*)PyArray_DATA(pixcrd),
                                      (double*)PyArray_DATA(world));
    wcsprm_c2python(self->x.wcs);
    unoffset_array(pixcrd, origin);
    Py_END_ALLOW_THREADS
    /* unoffset_array(world, origin); */

exit:
    Py_XDECREF(pixcrd);

    if (status == 0 || status == 8) {
        return (PyObject*)world;
    } else if (status == -1) {
        PyErr_SetString(
            PyExc_ValueError,
            "Wrong number of dimensions in input array.  Expected 2.");
        return NULL;
    } else {
        Py_DECREF(world);
        if (status == -1) {
            /* exception already set */
            return NULL;
        } else {
            wcserr_to_python_exc(self->x.err);
            return NULL;
        }
    }
}
Example #4
0
/*@null@*/ static PyObject*
PySip_foc2pix(
    PySip* self,
    PyObject* args,
    PyObject* kwds) {

  PyObject*      foccrd_obj = NULL;
  int            origin     = 1;
  PyArrayObject* foccrd     = NULL;
  PyArrayObject* pixcrd     = NULL;
  int            status     = -1;
  const char*    keywords[] = {
    "foccrd", "origin", NULL };

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oi:foc2pix", (char **)keywords,
                                   &foccrd_obj, &origin)) {
    return NULL;
  }

  if (self->x.ap == NULL || self->x.bp == NULL) {
    PyErr_SetString(
        PyExc_ValueError,
        "SIP object does not have coefficients for foc2pix transformation (AP and BP)");
    return NULL;
  }

  foccrd = (PyArrayObject*)PyArray_ContiguousFromAny(foccrd_obj, PyArray_DOUBLE, 2, 2);
  if (foccrd == NULL) {
    goto exit;
  }

  if (PyArray_DIM(foccrd, 1) != 2) {
    PyErr_SetString(PyExc_ValueError, "Pixel array must be an Nx2 array");
    goto exit;
  }

  pixcrd = (PyArrayObject*)PyArray_SimpleNew(2, PyArray_DIMS(foccrd),
                                             PyArray_DOUBLE);
  if (pixcrd == NULL) {
    status = 2;
    goto exit;
  }

  Py_BEGIN_ALLOW_THREADS
  preoffset_array(foccrd, origin);
  status = sip_foc2pix(&self->x,
                       (unsigned int)PyArray_DIM(pixcrd, 1),
                       (unsigned int)PyArray_DIM(pixcrd, 0),
                       (double*)PyArray_DATA(foccrd),
                       (double*)PyArray_DATA(pixcrd));
  unoffset_array(foccrd, origin);
  unoffset_array(pixcrd, origin);
  Py_END_ALLOW_THREADS

 exit:
  Py_XDECREF(foccrd);

  if (status == 0) {
    return (PyObject*)pixcrd;
  } else {
    Py_XDECREF(pixcrd);
    if (status == -1) {
      /* Exception already set */
      return NULL;
    } else {
      wcserr_to_python_exc(self->x.err);
      return NULL;
    }
  }
}