flopy.utils.flopy_io module¶
Module for input/output utilities
-
flux_to_wel
(cbc_file, text, precision='single', model=None, verbose=False)[source]¶ Convert flux in a binary cell budget file to a wel instance
Parameters: - cbc_file ((str) cell budget file name) –
- text ((str) text string of the desired flux type (e.g. "drains")) –
- precision ((optional str) precision of the cell budget file) –
- model ((optional) BaseModel instance. If passed, a new ModflowWel) – instance will be added to model
- verbose (bool flag passed to CellBudgetFile) –
Returns: Return type: flopy.modflow.ModflowWel instance
-
get_next_line
(f)[source]¶ Get the next line from a file that is not a blank line
Parameters: f (filehandle) – filehandle to a open file Returns: line – next non-empty line in a open file Return type: string
-
line_parse
(line)[source]¶ Convert a line of text into to a list of values. This handles the case where a free formatted MODFLOW input file may have commas in it.
-
line_strip
(line)[source]¶ Remove comments and replace commas from input text for a free formatted modflow input file
Parameters: line (str) – a line of text from a modflow input file Returns: str Return type: line with comments removed and commas replaced
-
loadtxt
(file, delimiter=' ', dtype=None, skiprows=0, use_pandas=True, **kwargs)[source]¶ Use pandas if it is available to load a text file (significantly faster than n.loadtxt or genfromtxt see http://stackoverflow.com/questions/18259393/numpy-loading-csv-too-slow-compared-to-matlab)
Parameters: - file (file or str) – File, filename, or generator to read.
- delimiter (str, optional) – The string used to separate values. By default, this is any whitespace.
- dtype (data-type, optional) – Data-type of the resulting array
- skiprows (int, optional) – Skip the first skiprows lines; default: 0.
- use_pandas (bool) – If true, the much faster pandas.read_csv method is used.
- kwargs (dict) – Keyword arguments passed to numpy.loadtxt or pandas.read_csv.
Returns: ra – Numpy record array of file contents.
Return type: np.recarray
-
multi_line_strip
(fobj)[source]¶ Get next line that is not blank or is not a comment line from a free formatted modflow input file
Parameters: fobj (open file object) – a line of text from an input file Returns: str Return type: line with comments removed and commas replaced
-
read_fixed_var
(line, ncol=1, length=10, ipos=None, free=False)[source]¶ Parse a fixed format line using user provided data
Parameters: - line (str) – text string to parse.
- ncol (int) – number of columns to parse from line. (default is 1)
- length (int) – length of each column for fixed column widths. (default is 10)
- ipos (list, int, or numpy array) – user-provided column widths. (default is None)
- free (bool) – boolean indicating if sting is free format. ncol, length, and ipos are not used if free is True. (default is False)
Returns: out – padded list containing data parsed from the passed text string
Return type: list
-
ulstrd
(f, nlist, ra, model, sfac_columns, ext_unit_dict)[source]¶ Read a list and allow for open/close, binary, external, sfac, etc.
Parameters: - f (file handle) – file handle for where the list is being read from
- nlist (int) – size of the list (number of rows) to read
- ra (np.recarray) – A record array of the correct size that will be filled with the list
- model (model object) – The model object (of type
flopy.modflow.mf.Modflow
) to which this package will be added. - sfac_columns (list) – A list of strings containing the column names to scale by sfac
- ext_unit_dict (dictionary, optional) – If the list in the file is specified using EXTERNAL,
then in this case ext_unit_dict is required, which can be
constructed using the function
flopy.utils.mfreadnam.parsenamefile
.
-
write_fixed_var
(v, length=10, ipos=None, free=False, comment=None)[source]¶ Parameters: - v (list, int, float, bool, or numpy array) – list, int, float, bool, or numpy array containing the data to be written to a string.
- length (int) – length of each column for fixed column widths. (default is 10)
- ipos (list, int, or numpy array) – user-provided column widths. (default is None)
- free (bool) – boolean indicating if a free format string should be generated. length and ipos are not used if free is True. (default is False)
- comment (str) – comment string to add to the end of the string
Returns: out – fixed or free format string generated using user-provided data
Return type: str