add autoshift_dxyz and copy()

This commit is contained in:
jan 2016-07-03 03:13:20 -07:00
parent 7cc578cac4
commit 1e4ee5e057

View File

@ -5,6 +5,7 @@ from numpy import diff, floor, ceil, zeros, hstack, newaxis
import pickle import pickle
import warnings import warnings
import copy
from float_raster import raster from float_raster import raster
@ -169,6 +170,16 @@ class Grid(object):
dxyz = self.shifted_dxyz(which_shifts) dxyz = self.shifted_dxyz(which_shifts)
return [exyz[a][:-1] + dxyz[a] / 2.0 for a in range(3)] return [exyz[a][:-1] + dxyz[a] / 2.0 for a in range(3)]
def autoshifted_dxyz(self):
"""
Return cell widths, with each dimension shifted by the corresponding shifts.
:return: [grid.shifted_dxyz(which_shifts=a)[a] for a in range(3)]
"""
if len(self.grids) != 3:
raise GridError('autoshifting requires exactly 3 grids')
return [self.shifted_dxyz(which_shifts=a)[a] for a in range(3)]
def ind2pos(self, def ind2pos(self,
ind: numpy.ndarray or List, ind: numpy.ndarray or List,
which_shifts: int = None, which_shifts: int = None,
@ -346,6 +357,14 @@ class Grid(object):
with open(filename, 'wb') as f: with open(filename, 'wb') as f:
pickle.dump(self.__dict__, f, protocol=2) pickle.dump(self.__dict__, f, protocol=2)
def copy(self):
"""
Return a deep copy of the grid.
:return: Deep copy of the grid.
"""
return copy.deepcopy(self)
def draw_polygons(self, def draw_polygons(self,
surface_normal: Direction or int, surface_normal: Direction or int,
center: List or numpy.ndarray, center: List or numpy.ndarray,