GridPostProcessing package
Submodules
GridPostProcessing.r2c_utils
r2c_utils.py
Utility functions to read, process, and write EnSim‐format .r2c ASCII files, reorder MATLAB GRU data arrays, convert to 2D grids, and clean attribute names.
Utility functions to read, process, and write EnSim-format .r2c ASCII files, reorder MATLAB GRU data arrays, convert to 2D grids, clean attribute names, and produce small-multiples georeferenced plots (absolute or difference).
- GridPostProcessing.r2c_utils.clean_attribute_name(name)[source]
Strip parentheses and trailing whitespace from an attribute name.
- Parameters:
name (str) – Raw attribute name, possibly containing “(units)” or similar.
- Returns:
Cleaned name with text in parentheses removed.
- Return type:
str
- GridPostProcessing.r2c_utils.convert_to_2d(gru_data)[source]
Convert a 1D object array of 1D arrays into a 2D float array.
- Parameters:
gru_data (np.ndarray, dtype=object) – Object array where each element is a 1D numeric sequence.
- Returns:
2D array of shape (layers, length) or None on failure.
- Return type:
np.ndarray or None
- GridPostProcessing.r2c_utils.plot_diff_panel_geo(base_mat, scen_mat, header_info, attributes, subset_ids, skip_idxs, panel_title, out_file)[source]
Small-multiples of (scen – base) for each attribute in subset_ids.
- GridPostProcessing.r2c_utils.plot_r2c_panel_geo(mat, header_info, attributes, subset_ids, skip_idxs, panel_title, out_file, cmap='viridis', vmin=None, vmax=None)[source]
Small-multiples of the raw .r2c layers in mat.
- GridPostProcessing.r2c_utils.read_r2c_file(file_path)[source]
Read an EnSim‐format .r2c ASCII file and return header info, attribute metadata, and the 3D data array.
- Parameters:
file_path (str) – Path to the .r2c file.
- Returns:
header_info (dict[str, str]) – Mapping from header keys (e.g. ‘:xCount’, ‘:yOrigin’) to their values.
attributes (dict[int, dict]) – Mapping from attribute ID → {‘name’: str, ‘type’: str|None, ‘units’: str|None}.
data_matrix (np.ndarray, shape (n_attributes, n_rows, n_cols)) – The numeric grid values, reshaped according to header counts.
- GridPostProcessing.r2c_utils.reorder_attributes(attribute_data, new_order_ids, attributes)[source]
Reorder a flat name→2D-array dict according to a list of attribute IDs.
- Parameters:
attribute_data (dict[str, np.ndarray]) – Mapping attribute name → 2D array as read from a .r2c.
new_order_ids (list[int]) – 1-based attribute IDs in the order you want to write them.
attributes (dict[int, dict]) – Original mapping from attribute ID → metadata dict returned by read_r2c_file.
- Returns:
ordered_attributes (dict[int, dict]) – New ID→metadata, where IDs run 1..N in the new sequence.
ordered_attribute_data (dict[str, np.ndarray]) – Mapping attribute name → 2D array, in the same new sequence.
- GridPostProcessing.r2c_utils.reorder_matlab_data(gru_data, order_ids)[source]
Reorder a MATLAB‐loaded GRU struct array into a specified field sequence.
- Parameters:
gru_data (np.ndarray, dtype=object or structured) – A 1×1 struct array from scipy.io.loadmat.
order_ids (list[int]) – 1-based indices indicating the new order of fields.
- Returns:
Each entry is the original gru_data[field][0,0] in the new sequence.
- Return type:
np.ndarray of object, shape (len(order_ids),)
- GridPostProcessing.r2c_utils.write_new_r2c(new_file_path, header_info, ordered_attributes, attribute_data)[source]
Write a new .r2c file from header info, attribute metadata, and grid data.
- Parameters:
new_file_path (str) – Path to write the .r2c file.
header_info (dict[str, str]) – Header key→value mapping (as from read_r2c_file).
ordered_attributes (dict[int, dict]) – Attribute ID→metadata dict specifying write order.
attribute_data (dict[str, np.ndarray]) – Mapping attribute name→2D array of shape (n_rows, n_cols).