From 1e4ee5e057469227dc9e8eff44f19eba72be91f8 Mon Sep 17 00:00:00 2001 From: jan Date: Sun, 3 Jul 2016 03:13:20 -0700 Subject: [PATCH] add autoshift_dxyz and copy() --- gridlock/grid.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gridlock/grid.py b/gridlock/grid.py index 1a41b7e..f64c740 100644 --- a/gridlock/grid.py +++ b/gridlock/grid.py @@ -5,6 +5,7 @@ from numpy import diff, floor, ceil, zeros, hstack, newaxis import pickle import warnings +import copy from float_raster import raster @@ -169,6 +170,16 @@ class Grid(object): dxyz = self.shifted_dxyz(which_shifts) 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, ind: numpy.ndarray or List, which_shifts: int = None, @@ -346,6 +357,14 @@ class Grid(object): with open(filename, 'wb') as f: 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, surface_normal: Direction or int, center: List or numpy.ndarray,