ppcpy.misc.json2nc_mapping#
Functions
Adds a new variable to the 'variables' section of the given dictionary. |
|
Creates a NetCDF file from a structured dictionary. |
|
Reads in an existing json-file and outputs a dict-structure |
|
Removes a specific variable from the 'variables' section of the given dictionary. |
|
Updates the value of a specific attribute for a specified variable in the data dictionary. |
- ppcpy.misc.json2nc_mapping.read_json_to_dict(file_path)[source]#
Reads in an existing json-file and outputs a dict-structure
- ppcpy.misc.json2nc_mapping.create_netcdf_from_dict(nc_file_path, data_dict, compression_level=1)[source]#
Creates a NetCDF file from a structured dictionary.
- Parameters:
nc_file_path (str) – Path to the NetCDF file to create.
data_dict (dict) – Dictionary with keys ‘global_attributes’, ‘dimensions’, and ‘variables’.
Example of data_dict structure: {
- “global_attributes”: {
“title”: “Example NetCDF File”, “institution”: “My Organization”
}, “dimensions”: {
“time”: None, # Unlimited dimension “lat”: 10, “lon”: 20
}, “variables”: {
- “temperature”: {
“dimensions”: (“time”, “lat”, “lon”), “dtype”: “float32”, “attributes”: {
“units”: “K”, “long_name”: “Surface temperature”
}, “data”: np.random.rand(5, 10, 20) # Example data
}, “pressure”: {
“dimensions”: (“time”, “lat”, “lon”), “dtype”: “float32”, “attributes”: {
“units”: “Pa”, “long_name”: “Surface pressure”
}, “data”: np.random.rand(5, 10, 20) # Example data
}
}
}
- ppcpy.misc.json2nc_mapping.add_variable_2_json_dict_mapper(data_dict, new_key, reference_key, new_data=None, new_attributes=None)[source]#
Adds a new variable to the ‘variables’ section of the given dictionary.
- Parameters:
data_dict (dict) – The original dictionary structure.
reference_key (str) – The name of the existing variable to reference to (template for new key/variable)
new_key (str) – The name of the new variable to add.
new_data (np.ndarray, optional) – The data for the new variable.
new_attributes (dict, optional) – Additional or updated attributes for the new variable.
- ppcpy.misc.json2nc_mapping.remove_variable_from_json_dict_mapper(data_dict, key_to_remove)[source]#
Removes a specific variable from the ‘variables’ section of the given dictionary.
- Parameters:
data_dict (dict) – The original dictionary structure.
key_to_remove (str) – The name of the variable to remove.
- ppcpy.misc.json2nc_mapping.update_variable_attribute_of_json_dict_mapper(data_dict, variable_key, attribute_key, new_value)[source]#
Updates the value of a specific attribute for a specified variable in the data dictionary.
- Parameters:
data_dict (dict) – The dictionary containing the variables and attributes.
variable_key (str) – The key of the variable to update.
attribute_key (str) – The key of the attribute to update.
new_value (any) – The new value to set for the attribute.