Welcome to pystrain’s documentation!¶
-
class
grid.
Grid
(x_min, x_max, x_step, y_min, y_max, y_step)¶ A dead simple grid class.
A very simple grid class to be used within the StrainTensor project. A Grid instance has x- and y- axis limits and step sizes (i.e x_min, x_max, x_step, y_min, y_max, y_step). It is iterable; when iterating, the instance will return the center of each cell, starting from the bottom left corner and ending at the top right. The iteration is performed row-wise (i.e. > [x0+xstep/2, y0+ystep/2] > [x0+xstep/2, y0+ystep/2+ystep] > [x0+xstep/2, y0+ystep/2+2*ystep] > … > [x0+xstep/2, ymax-ystep/2] > [x0+xstep/2+xstep, y0+ystep/2] > [x0+xstep/2+xstep, y0+ystep/2+ystep] > [x0+xstep/2+xstep, y0+ystep/2+2*ystep]
-
x_min
¶ minimum value in x-axis.
-
x_max
¶ maximum value in x-axis.
-
x_step
¶ x-axis step size.
-
y_min
¶ minimum value in y-axis.
-
y_max
¶ maximum value in y-axis.
-
y_step
¶ y-axis step size.
-
cxi
¶ current x-axis tick / index
-
cyi
¶ current y-axis tick / index
-
xpts
¶ number of ticks on x-axis
-
ypts
¶ number of ticks on y-axis
-
next
()¶ Return the centre od the next cell.
Return the (centre of the) next cell (aka x,y coordinate pair). Next actually means the cell on the right (if there is one), or else the leftmost cell in the above row.
Raises: StopIteration
– if there are not more cell we can get to.
-
xidx2xval
(idx)¶ Index to value for x-axis.
Given an index (on x-axis), return the value at the centre of this cell. The index represents the number of a cell (starting from zero).
Parameters: idx (int) – the index; should be in range (0, self.xpts]
-
yidx2yval
(idx)¶ Index to value for y-axis.
Given an index (on y-axis), return the value at the centre of this cell. The index represents the number of a cell (starting from zero).
Parameters: idx (int) – the index; should be in range (0, self.ypts]
-
-
grid.
generate_grid
(sta_lst, x_step, y_step)¶ Grid generator.
Given a list of Stations and x- and y-axis step sizes, compute and return a Grid instance. The max/min x and y values (of the Grid) are extracted from the station coordinates; if needed, they are adjusted so that (xmax-xmin) is divisible (without remainder) with xstep. Obsviously, sta_lst coordinates (assesed by .lon and .lat) must match the x_step and y_step values respectively (same units and reference system).
Parameters: - sta_lst (list) – list of Station instances. Coordinates of the stations are used, using the ‘lon’ and ‘lat’ instance variables. Longtitude values are matched to ‘x_step’ and latitude values are matched to ‘ystep’
- x_step (float) – value of step for the x-axis of the grid.
- y_step (float) – value of step for the y-axis of the grid.
Returns: A Grid instance; the min and max values of the Grid are computed from the input coordinates (i.e. the sta_lst input list) and then adjusted so that the range (xmax-xmin) is divisible with x_step (same goes for the y-axis)
Todo
The lines assert divmod(y_max-y_min, y_step)[1] == 0e0 and assert divmod(x_max-x_min, x_step)[1] == 0e0 may throw dues to rounding errors; how can i fix that?