This method creates a new grid with the data from the current grid resampled to a regular grid specified by *edges*. _update () def resample ( self, edges ): """Resample data to a new grid with edges *edges*. setter def interpolation_spline_order ( self, x ): """Setting the ``interpolation_spline_order`` updates :func:`interpolated` Because we cache the interpolation function, we need to rebuild the cache whenever the interpolation order changes: this is handled by :meth:`_update` """ self. 3 = cubic 4 & 5 are also supported Only choose values that are acceptable to :func:`_filter`! See Also - interpolated """ return self. format ( grid, edges, origin, delta )) def interpolation_spline_order ( self ): """Order of the B-spline interpolation of the data. """ default_format = 'DX' def _init_ ( self, grid = None, edges = None, origin = None, delta = None, metadata = ". The attribute tadata holds a user-defined dictionary that can be used to annotate the data.
The grid (id) can be manipulated as a standard numpy array. The export(format='dx') method always exports a 3D object, the rest should work for an array of any dimension. grid except AttributeError : return x class Grid ( object ): """Class to manage a multidimensional grid object. import CCP4 def _grid ( x ): """Access the underlying ndarray of a Grid object or return the object itself""" try : return x.
from _future_ import absolute_import, division import six from six.moves import cPickle, range, zip import os import errno import numpy # For interpolated grids: need scipy.ndimage but we import it only when needed: # import scipy from.
In particular this module contains the :class:`Grid` class that acts as a universal constructor for specific formats:: g = Grid(**kwargs) # construct g.export(filename, format) # export to the desired format Some formats can also be read:: g = Grid() # make an empty Grid g.load(filename) # populate with data from filename Classes and functions - """ # Having consistent truedivision in this module is essential so that # its behavior is fully consistent in Python 2 and Python 3. """ :mod:`re` - Core functionality for storing n-D grids = The :mod:`core` module contains classes and functions that are independent of the grid data format. While this solves the problem, I did not answer yet why this issue of the griddata function only appears for a cubic interpolation.# gridDataFormats - python modules to read and write gridded data # Copyright (c) 2009-2014 Oliver Beckstein # Released under the GNU Lesser General Public License, version 3 or later. Grid_z2 = riddata(np.stack((points,points),axis=1), values, (grid_x, grid_y), method='cubic') The result will have nan only on the edges of the array Nonanindex=np.invert(np.isnan(points))*np.invert(np.isnan(points))*np.invert(np.isnan(values)) #Find all the indexes where there is no nan neither in values nor in points. numpy can be used efficiently for doing so: import numpy as np Grid_z2 = griddata(points, values, (grid_x, grid_y), method='cubic') # this is filled only with nans.Ī solution is to remove all nan from the points and values input arrays prior to interpolating the data. Grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear') # this has nans on the edges (as expected) Grid_z0 = griddata(points, values, (grid_x, grid_y), method='nearest') # no nans here Values=np.nan # now add a single nan value to the array This is a minimal working example, adapted from griddata scipy interpolation not working (giving nan): import numpy as np What is the reason for this behavior and is there a simple way to ignore nans in the values input? This is not the case when using the 'nearest' or the 'linear' interpolation methods. However, as soon as a single nan is present in the values parameter, the returned interpolation is filled with only nan. I want to perform cubic interpolation of an array that contains some nan values using iddata.