mf6rtm.utils package
Submodules
mf6rtm.utils.utils module
- mf6rtm.utils.utils.add_charge_flag_to_species_in_solution(script, species=['pH'])
Add ‘charge’ to species lines inside SOLUTION blocks in a PHREEQC input string.
- Return type:
str
- mf6rtm.utils.utils.concentration_l_to_m3(x)
Convert M/L to M/m3
- mf6rtm.utils.utils.concentration_m3_to_l(x)
Convert M/L to M/m3
- mf6rtm.utils.utils.concentration_to_massrate(q, conc)
Calculate mass rate from rate (L3/T) and concentration (M/L3)
- mf6rtm.utils.utils.concentration_volbulk_to_volwater(conc_volbulk, porosity)
Calculate concentrations as volume of pore water from bulk volume and porosity
- mf6rtm.utils.utils.fill_missing_minerals(data_dict)
Fill missing minerals in all zones with zero parameters.
- Parameters:
data_dict (dict) – Dictionary with zone indices as keys and mineral dictionaries as values. Each mineral dictionary contains parameter names and values.
- Returns:
Updated dictionary with all minerals present in all zones.
- Return type:
dict
Examples
>>> data_dict = { ... 0: {'Goethite': {'m0': 1.0, 'si': 0.9}}, ... 1: {'Pyrite': {'m0': 2.0, 'si': 1.8}} ... } >>> filled = fill_missing_minerals(data_dict) >>> filled[0]['Pyrite'] # Now exists with zeros {'m0': 0.0, 'si': 0.0}
- mf6rtm.utils.utils.flatten_list(xss)
Flatten a list of lists
- mf6rtm.utils.utils.generate_equ_phases_block(phases_dict, i)
Generate an EQUILIBRIUM_PHASES block for PHREEQC input script :type phases_dict: dict :param phases_dict: A dictionary with phase names as keys and lists of saturation indices and amounts as values. :type phases_dict: dict :type i: int :param i: The block number. :type i: int
- Returns:
script – The EQUILIBRIUM_PHASES block as a string.
- Return type:
str
- mf6rtm.utils.utils.generate_exchange_block(phases_dict, i, equilibrate_solutions=1)
Generate an EXCHANGE block for PHREEQC input script :param exchange_dict: A dictionary with species names as keys and exchange concentrations as values. :type exchange_dict: dict :type i: int :param i: The block number. :type i: int
- Returns:
script – The EXCHANGE block as a string.
- Return type:
str
- mf6rtm.utils.utils.generate_kinetics_block(kinetics_dict, i)
Generate a KINETICS block for PHREEQC input script.
- Parameters:
kinetics_dict (dict) –
Dictionary structured like: {
- ”Pyrite”: {
“m0”: [0.04], “parms”: [3.42, 0.0, 0.5, 0.0], “formula”: “Pyrite -1.0 Fe 1.0 S -1.0”
}
i (int) – The block number.
- Returns:
script – The KINETICS block as a string.
- Return type:
str
- mf6rtm.utils.utils.generate_solution_block(species_dict, i, temp=25.0, water=1.0)
Generate a SOLUTION block for PHREEQC input script :type species_dict: dict :param species_dict: A dictionary with species names as keys and concentrations as values. :type species_dict: dict :type i: int :param i: The solution number. :type i: int :type temp: float, optional :param temp: The temperature of the solution in degrees Celsius. The default is 25.0. :type temp: float, optional :type water: float, optional :param water: The mass of water in kg. The default is 1.0. :type water: float, optional
- Returns:
script – The SOLUTION block as a string.
- Return type:
str
- mf6rtm.utils.utils.generate_surface_block(surface_dict, i, options=[])
Generate a SURFACE block for PHREEQC input script :type surface_dict: dict :param surface_dict: A dictionary with surface names as keys and lists of site densities and site densities as values. :type surface_dict: dict :type i: int :param i: The block number. :type i: int
- Returns:
script – The SURFACE block as a string.
- Return type:
str
- mf6rtm.utils.utils.get_compound_names(database_file, block='SOLUTION_MASTER_SPECIES')
Get a list of compound names from a PHREEQC database file :type database_file: str :param database_file: The path to the PHREEQC database file. :type database_file: str :type block: str, optional :param block: The keyword for the block containing the compound names. The default is ‘SOLUTION_MASTER_SPECIES’. :type block: str, optional
- Returns:
compound_names – A list of compound names.
- Return type:
list
- mf6rtm.utils.utils.get_indices(element, lst)
- mf6rtm.utils.utils.handle_block(current_items, block_generator, i, *args, **kwargs)
Generate a block for a PHREEQC input script if the current items are not empty :type current_items: list :param current_items: A list of items to include in the block. :type current_items: list :type block_generator: function :param block_generator: A function that generates the block. :type block_generator: function :type i: int :param i: The block number. :type i: int
- Returns:
script – The block as a string.
- Return type:
str
- mf6rtm.utils.utils.map_species_property_to_grid(data_dict, ic_array, species, property_key)
Create an array matching ic_array shape with a selected property (e.g., ‘moles’, ‘si’) of a given species from a zone-indexed dictionary.
- Parameters:
data_dict (dict) – Format: {zone_idx (int): {species_name (str): {key: value, …}}}
ic_array (np.ndarray) – 1-indexed zone allocation array of shape (nlay, nrow, ncol).
species (str) – Species name to extract (e.g., ‘Goethite’).
property_key (str) – Property to extract for the species (e.g., ‘moles’, ‘si’).
- Returns:
Array of same shape as ic_array filled with the extracted property values.
- Return type:
np.ndarray
- Raises:
KeyError – If the species or property_key is missing in any zone where it’s expected.
- mf6rtm.utils.utils.parse_equilibriums_dataframe(df, columns=None)
Convert a DataFrame of equilibrium phases into a nested dictionary.
- Parameters:
df (pandas.DataFrame) – The input DataFrame.
columns (list of str, optional) – List of column names in the following order: [phase, sat_index, conc_mol_lb, num]. Default: [‘phase’, ‘sat_index’, ‘conc_mol_lb’, ‘num’] num corresponds to the block number
- Returns:
Dictionary structured as {zone: {phase: {‘si’: val, ‘m0’: val}}}
- Return type:
dict
- mf6rtm.utils.utils.parse_kinetics_dataframe(df, optional_fields=['formula', 'steps'])
Convert a DataFrame of kinetic phase data into a nested dictionary to import into mup3d.
- Parameters:
df (pandas.DataFrame) – Must include ‘m0’, ‘parm1’-‘parm4’, ‘num’, and either ‘phase’ or ‘name’.
optional_fields (list of str, optional) – List of optional columns to include if present and non-NaN.
- Returns:
Nested dictionary like: {
- 1: {
- “Calcite”: {
“m0”: 4.0, “parms”: [100.0, 0.6], “formula”: “Calcite -1.0 Ca 1.0 C -1.0”, …
}
}
- Return type:
dict
- mf6rtm.utils.utils.prep_bins(dest_path, src_path='bin', get_only=[], add_platform=True)
Copy executables from the source path to the destination path
- mf6rtm.utils.utils.rearrange_copy_blocks(script)
- mf6rtm.utils.utils.solution_csv_to_dict(csv_file, header=True)
Read a solution CSV file and convert it to a dictionary :type csv_file: str :param csv_file: The path to the solution CSV file. :type csv_file: str :type header: bool, optional :param header: Whether the CSV file has a header. The default is True. :type header: bool, optional
- Returns:
data – A dictionary with the first column as keys and the remaining columns as values.
- Return type:
dict
- mf6rtm.utils.utils.solution_df_to_dict(data, header=True)
Convert a pandas DataFrame to a dictionary :type data: pandas.DataFrame :param data: The DataFrame to convert. :type data: pandas.DataFrame :type header: bool, optional :param header: Whether the DataFrame has a header. The default is True. :type header: bool, optional
- Returns:
data – A dictionary with the first column as keys and the remaining columns as values.
- Return type:
dict
- mf6rtm.utils.utils.surfaces_csv_to_dict(csv_file, header=True)
Read an equilibrium phases CSV file and convert it to a dictionary :type csv_file: str :param csv_file: The path to the equilibrium phases CSV file. :type csv_file: str :type header: bool, optional :param header: Whether the CSV file has a header. The default is True. :type header: bool, optional
- Returns:
data – A dictionary with phase names as keys and lists of saturation indices and amounts as values.
- Return type:
dict
Module contents
Main utilities