crunchflow.output.spatial.SpatialProfile
- class crunchflow.output.spatial.SpatialProfile(fileprefix, folder='.', output_times=None, suffix='.tec', warnings=True)
The SpatialProfile class for working with spatial_profile (.tec, .out and .dat) files.
- Parameters:
- fileprefixstr
file prefix of the tec file to read in, without the timestep number or “.tec” file ending. For example, if your files are “volume1.tec”, “volume2.tec”, etc., then fileprefix should be “volume”.
- folderstr, optional
folder in which the .tec files are located. The default is the current directory
- output_timeslist of float, optional
list of the actual output times at which the .tec files were output, in CrunchFlow time units
- suffixstr, optional
file ending of the tec files to read in. This can vary depending on the version of CrunchTope used. The default is ‘.tec’, but ‘.out’ is also tried if ‘.tec’ files are not found.
- Attributes:
- timeslist of int
relative times at which .tec files were output, sorted
- fileslist of str
ordered list of all files matching fileprefix
- columnslist of str
list of all vars included within each .tec file
- nxint
# of grid cells in the x direction. Typically only defined for 2D and 3D output
- nyint
# of grid cells in the y direction. Typically only defined for 2D and 3D output
- nzint
# of grid cells in the z direction. Typically only defined for 2D and 3D output
- coordsndarray of float
(nx*ny*nz, 2) array of x, y coordinates of each node. Typically only defined for 2D and 3D output
- griddedXndarray of float
(ny, nx) array of x coordinates; used for plotting. Typically only defined for 2D and 3D output
- griddedYndarray of float
(ny, nx) array of y coordinates; used for plotting. Typically only defined for 2D and 3D output
Methods
__init__(fileprefix, folder, output_times, suffix)
Read in and get basic info about all .tec files matching fileprefix. For example, tec(‘volume’) will read in all files matching ‘volume[0-9]+.tec’
extract(variable, time)
Return the spatial profile of var at the given time.
plot(variable, time)
Plot .tec output from a single time step.
plot_series(variable)
Plot .tec output for a series of time steps.
outline(variable, value, time)
Get line segments that outline all the regions equal to the provided value.
Examples
>>> vol = SpatialProfile('volume') >>> print(vol.columns) >>> vol.plot('Calcite') >>> calcite = vol.extract('Calcite', time=2)
- extract(var, time=None, output_time=None)
Return the spatial profile of var at the given time.
- Parameters:
- varstr
variable to return (e.g., ‘Porosity’)
- timeint
time slice at which to return the profile. By default, returns the first time slice.
- output_timefloat
output time at which to return the profile. If provided, this will override the time parameter. If both time and output_time are provided, time will be ignored.
- Returns:
- datandarray of float
(ny, nx) numpy array of var
- plot(var, time=None, output_time=None, plot_type='image', figsize=(12, 3), **kwargs)
Plot .tec output from a single time step.
- Parameters:
- varstr
variable to plot (e.g., ‘H+’)
- timeint
which time slice to show. Refers to the file number, not the output time. By default, plots the first time slice.
- output_timefloat
which output time to show. If provided, this will override the time parameter. If both time and output_time are provided, time will be ignored.
- figsizetuple of int
figure size; default (12, 3)
- plot_typestr
whether to display an image (‘image’) or a color-filled contour plot (‘contourf’)
- **kwargsdict
args passed on to matplotlib plot function (either contourf or imshow)
- Returns:
- figpyplot object
matplotlib fig handle for the plot
- axpyplot object
matplotlib ax handle for the plot
- plot_series(var, times=None, output_times=None, plot_type='image', figsize=None, **kwargs)
Plot .tec output for a series of time steps.
- Parameters:
- varstr
variable to plot (e.g., ‘H+’)
- timeslist
time steps to plot, must be either components of self.times or self.output_times; defaults to all time steps
- plot_typestr
whether to display an image (‘image’) or a contour-filled contour plot (‘contourf’)
- output_timeslist of float, optional
list of the actual output times at which the .tec files were output, in CrunchFlow time units. If provided, this will override the times parameter. If both times and output_times are provided, times will be ignored.
- figsizetuple of int
figure size; default (12, 1.5 * # of timesteps)
- **kwargsdict
args passed on to matplotlib’s imshow
- Returns:
- figpyplot object
matplotlib fig handle for the plot
- axeslist of pyplot objects
list of matplotlib axes handles for each subplot
- outline(var, value=None, time=None, output_time=None)
For a given .tec file, get line segments that outline all the regions equal to the provided value. Useful for generating outlines of areas of a model domain sharing a single attribute (e.g., permeability) and later adding the outlines to a plot of a different variable.
- Parameters:
- varstr
variable to outline (e.g., ‘Porosity’)
- valuefloat
value to outline. The default is least-frequent value in array
- timeint
time slice at which to create an outline. By default, outlines the first time slice.
- output_timefloat
output time at which to create an outline. If provided, this will override the time parameter. If both time and output_time are provided, time will be ignored.
- Returns:
- segmentsndarray of float
array of (x,y) coordinate pairs for each line segment that comprises the outline
Examples
>>> # Get stratigraphy from permeability map >>> perm = SpatialProfile('permeability') >>> segments = perm.outline('X-Perm') >>> >>> # Plot stratigraphy outlines on O2 map >>> conc = SpatialProfile('conc') >>> fig, ax = conc.plot('O2(aq)') >>> ax.plot(segments[:,0], segments[:,1])