8.5.1. Parflow Module
parflow module
Export Run() object
- parflow.read_pfb(file: str, keys: dict = None, mode: str = 'full', z_first: bool = True, read_sg_info: bool = True)
Read a single pfb file, and return the data therein
- Parameters:
file – The file to read.
keys –
A set of keys for indexing subarrays of the full pfb. Optional. This is mainly a trick for interfacing with xarray, but the format of the keys is:
:: {‘x’: {‘start’: start_x, ‘stop’: end_x},
’y’: {‘start’: start_y, ‘stop’: end_y}, ‘z’: {‘start’: start_z, ‘stop’: end_z}}
mode – The mode for the reader. See
ParflowBinaryReader::read_all_subgridsfor more information about what modes are available.read_sg_info – Precalculating subgrid information does not always work correctly for some files, especially velocity files. If
True, read subgrid info directly from the pfb file (slower, but more robust)
- Returns:
An nd array containing the data from the pfb file.
- parflow.read_pfb_sequence(file_seq: Iterable[str], keys=None, z_first: bool = True, z_is: str = 'z', read_sg_info: bool = False)
An efficient wrapper to read a sequence of pfb files. This approach is faster than looping over the
read_pfbfunction because it caches the subgrid information from the first pfb file and then uses that to initialize all other readers.- Parameters:
file_seq – An iterable sequence of file names to be read.
keys –
A set of keys for indexing subarrays of the full pfb. Optional. This is mainly a trick for interfacing with xarray, but the format of the keys is:
:: {‘x’: {‘start’: start_x, ‘stop’: end_x},
’y’: {‘start’: start_y, ‘stop’: end_y}, ‘z’: {‘start’: start_z, ‘stop’: end_z}}
z_first – Whether the z dimension should be first. If true returned arrays have dimensions (‘z’, ‘y’, ‘x’) else (‘x’, ‘y’, ‘z’)
z_is – A descriptor of what the z axis represents. Can be one of ‘z’, ‘time’, ‘variable’. Default is ‘z’.
read_sg_info – Precalculating subgrid information does not always work correctly for some files, especially velocity files. If
True, read subgrid info directly from the pfb file (slower, but more robust)
- Returns:
An nd array containing the data from the files.
- parflow.write_pfb(file, array, p=1, q=1, r=1, x=0.0, y=0.0, z=0.0, dx=1.0, dy=1.0, dz=1.0, z_first=True, dist=True, **kwargs)
Write a single pfb file. The data must be a 3D numpy array with float64 values. The number of subgrids in the saved file will be p * q * r. This is regardless of the number of subgrids in the PFB file loaded by the ParflowBinaryReader into the numpy array. Therefore, loading a file with ParflowBinaryReader and saving it with this method may restructure the file into a different number of subgrids if you change these values.
If dist is True then also write a file with the .dist extension added to the file_name. The .dist file will contain one line per subgrid with the offset of the subgrid in the .pfb file.
- Parameters:
file – The name of the file to write the array to.
array – The array to write.
p – Number of subgrids in the x direction.
q – Number of subgrids in the y direction.
r – Number of subgrids in the z direction.
x – The length of the x-axis
y – The length of the y-axis
z – The length of the z-axis
dx – The spacing between cells in the x direction
dy – The spacing between cells in the y direction
dz – The spacing between cells in the z direction
z_first – Whether the z-axis should be first or last.
dist – Whether to write the distfile in addition to the pfb.
kwargs – Extra keyword arguments, primarily to eat unnecessary args by passing in a dictionary with **dict.