As for Gridder2D, a SetResolution() function would be nice.
Thanks.
Patrick
class Gridder1D(Gridder):
def __init__(self, nx):
Gridder.__init__(self)
if nx <= 0:
raise InputError("nx must be a positiv integer!")
self.nx = nx
self.xmin = 0
self.xmax = 0
- self._gdata = numpy.zeros(nx, dtype=numpy.double)
- self._gnorm = numpy.zeros(nx, dtype=numpy.double)
+
+ self._allocate_memory()
+
+ def _allocate_memory(self):
+ """
+ Class method to allocate memory for the gridder based on the nx
+ class attribute.
+ """
+
+ self._gdata = numpy.zeros(self.nx, dtype=numpy.double)
+ self._gnorm = numpy.zeros(self.nx, dtype=numpy.double)
def savetxt(self, filename, header=""):
"""
save gridded data to a txt file with two columns. The first column is
the data coordinate and the second the corresponding data value
Parameters
----------
filename : str
output filename
header : str, optional
optional header for the data file.
"""
numpy.savetxt(
filename,
numpy.vstack((self.xaxis, self.data)).T,
header=header,
fmt="%.6g %.4g",
)
+
+ def SetResolution(self, nx):
+ """
+ Reset the resolution of the gridder. In this case the original data
+ stored in the object will be deleted.
+
+ Parameters
+ ----------
+ nx : int
+ number of points in x-direction
+ """
+ self.nx = nx
+
+ self._allocate_memory()
As for Gridder2D, a SetResolution() function would be nice.
Thanks.
Patrick
class Gridder1D(Gridder): def __init__(self, nx): Gridder.__init__(self) if nx <= 0: raise InputError("nx must be a positiv integer!") self.nx = nx self.xmin = 0 self.xmax = 0 - self._gdata = numpy.zeros(nx, dtype=numpy.double) - self._gnorm = numpy.zeros(nx, dtype=numpy.double) + + self._allocate_memory() + + def _allocate_memory(self): + """ + Class method to allocate memory for the gridder based on the nx + class attribute. + """ + + self._gdata = numpy.zeros(self.nx, dtype=numpy.double) + self._gnorm = numpy.zeros(self.nx, dtype=numpy.double) def savetxt(self, filename, header=""): """ save gridded data to a txt file with two columns. The first column is the data coordinate and the second the corresponding data value Parameters ---------- filename : str output filename header : str, optional optional header for the data file. """ numpy.savetxt( filename, numpy.vstack((self.xaxis, self.data)).T, header=header, fmt="%.6g %.4g", ) + + def SetResolution(self, nx): + """ + Reset the resolution of the gridder. In this case the original data + stored in the object will be deleted. + + Parameters + ---------- + nx : int + number of points in x-direction + """ + self.nx = nx + + self._allocate_memory()