Exemplo n.º 1
0
static PyObject *
busdaycalendar_holidays_get(NpyBusDayCalendar *self)
{
    PyArrayObject *ret;
    PyArray_Descr *date_dtype;
    npy_intp size = self->holidays.end - self->holidays.begin;

    /* Create a date dtype */
    date_dtype = create_datetime_dtype_with_unit(NPY_DATETIME, NPY_FR_D);
    if (date_dtype == NULL) {
        return NULL;
    }

    /* Allocate a date array (this steals the date_dtype reference) */
    ret = (PyArrayObject *)PyArray_SimpleNewFromDescr(1, &size, date_dtype);
    if (ret == NULL) {
        return NULL;
    }

    /* Copy the holidays */
    if (size > 0) {
        memcpy(PyArray_DATA(ret), self->holidays.begin,
                    size * sizeof(npy_datetime));
    }

    return (PyObject *)ret;
}
Exemplo n.º 2
0
PyObject *punwrap2D_Unwrap2D(PyObject *self, PyObject *args) {
  PyObject *op1, *op2;
  PyArrayObject *phsArray, *mskArray, *retArray;
  float *wr_phs, *uw_phs;
  BYTE *bmask;
  int typenum_phs, typenum_msk, ndim;
  npy_intp *dims;
  PyArray_Descr *dtype_phs;

  if(!PyArg_ParseTuple(args, "OO", &op1, &op2)) {
    PyErr_SetString(PyExc_Exception,"Unwrap2D: Couldn't parse the arguments");
    return NULL;
  }
  if(op1==NULL || op2==NULL) {
    PyErr_SetString(PyExc_Exception,"Unwrap2D: Arguments not read correctly");
    return NULL;
  }
  
  typenum_phs = PyArray_TYPE(op1);
  typenum_msk = PyArray_TYPE(op2);
  ndim = PyArray_NDIM(op1);
  dims = PyArray_DIMS(op2);
  /* This stuff is technically enforced in punwrap/__init__.py */
  if(typenum_phs != PyArray_FLOAT) {
    PyErr_SetString(PyExc_Exception, "Unwrap2D: I can only handle single-precision floating point numbers");
    return NULL;
  }
  if(typenum_msk != PyArray_UBYTE) {
    PyErr_SetString(PyExc_Exception, "Unwrap2D: The mask should be type uint8");
    return NULL;
  }
  if(ndim != 2) {
    PyErr_SetString(PyExc_Exception, "Unwrap2D: I can only unwrap 2D arrays");
    return NULL;
  }

  dtype_phs = PyArray_DescrFromType(typenum_phs);
  /* increasing references here */
  phsArray = (PyArrayObject *)PyArray_FROM_OTF(op1, typenum_phs, NPY_IN_ARRAY);
  mskArray = (PyArrayObject *)PyArray_FROM_OTF(op2, typenum_msk, NPY_IN_ARRAY);
  /* create a new, empty ndarray with floats */
  retArray = (PyArrayObject *)PyArray_SimpleNewFromDescr(ndim, dims, dtype_phs);
  wr_phs = (float *)PyArray_DATA(phsArray);
  uw_phs = (float *)PyArray_DATA(retArray);
  bmask = (BYTE *)PyArray_DATA(mskArray);

  phase_unwrap_2D(wr_phs, uw_phs, bmask, (int) dims[0], (int) dims[1]);

  Py_DECREF(phsArray);
  Py_DECREF(mskArray);
  return PyArray_Return(retArray);
    
}
Exemplo n.º 3
0
PyObject *punwrap3D_Unwrap3D(PyObject *self, PyObject *args) {
  PyObject *op;
  PyArrayObject *phsArray, *retArray;
  float *wr_phs, *uw_phs;
  npy_intp *dims;
  int typenum_phs, ndim;
  PyArray_Descr *dtype_phs;
    
  if(!PyArg_ParseTuple(args, "O", &op)) {
    PyErr_SetString(PyExc_Exception, "Unwrap3D: Couldn't parse any args");
    return NULL;
  }
  if(op==NULL) {
    PyErr_SetString(PyExc_Exception, "Unwrap3D: Arguments not read correctly");
    return NULL;
  }

  typenum_phs = PyArray_TYPE(op);
  ndim = PyArray_NDIM(op);
  dims = PyArray_DIMS(op);
  if(typenum_phs != PyArray_FLOAT) {
    PyErr_SetString(PyExc_Exception, "Unwrap3D: I can only handle single-precision floating point numbers");
    return NULL;
  }
  if(ndim < 3) {
    PyErr_SetString(PyExc_Exception, "Unwrap3D: I can only unwrap 3D arrays");
    return NULL;
  }

  dtype_phs = PyArray_DescrFromType(typenum_phs);
  /* increasing reference here */
  phsArray = (PyArrayObject *)PyArray_FROM_OTF(op, typenum_phs, NPY_IN_ARRAY);
  /* create a new, empty ndarray with floats */
  retArray = (PyArrayObject *)PyArray_SimpleNewFromDescr(ndim, dims, dtype_phs);
  
  wr_phs = (float *)PyArray_DATA(phsArray);
  uw_phs = (float *)PyArray_DATA(retArray);

  unwrap_phs(wr_phs, uw_phs, (int) dims[0], (int) dims[1], (int) dims[2]);
  
  Py_DECREF(phsArray);
  return PyArray_Return(retArray);
    
}