climate-ref-pmp 0.6.0__py3-none-any.whl → 0.6.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- climate_ref_pmp/diagnostics/variability_modes.py +64 -0
- {climate_ref_pmp-0.6.0.dist-info → climate_ref_pmp-0.6.2.dist-info}/METADATA +1 -1
- {climate_ref_pmp-0.6.0.dist-info → climate_ref_pmp-0.6.2.dist-info}/RECORD +6 -6
- {climate_ref_pmp-0.6.0.dist-info → climate_ref_pmp-0.6.2.dist-info}/WHEEL +0 -0
- {climate_ref_pmp-0.6.0.dist-info → climate_ref_pmp-0.6.2.dist-info}/licenses/LICENCE +0 -0
- {climate_ref_pmp-0.6.0.dist-info → climate_ref_pmp-0.6.2.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
from collections.abc import Iterable
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Any, Union
|
|
2
4
|
|
|
3
5
|
from loguru import logger
|
|
4
6
|
|
|
@@ -171,6 +173,8 @@ class ExtratropicalModesOfVariability(CommandLineDiagnostic):
|
|
|
171
173
|
logger.warning(f"A single cmec output file not found: {results_files}")
|
|
172
174
|
return ExecutionResult.build_from_failure(definition)
|
|
173
175
|
|
|
176
|
+
clean_up_json(results_files[0])
|
|
177
|
+
|
|
174
178
|
# Find the other outputs
|
|
175
179
|
png_files = [definition.as_relative_path(f) for f in definition.output_directory.glob("*.png")]
|
|
176
180
|
data_files = [definition.as_relative_path(f) for f in definition.output_directory.glob("*.nc")]
|
|
@@ -200,3 +204,63 @@ class ExtratropicalModesOfVariability(CommandLineDiagnostic):
|
|
|
200
204
|
cmec_output_bundle=cmec_output_bundle,
|
|
201
205
|
cmec_metric_bundle=cmec_metric_bundle,
|
|
202
206
|
)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def clean_up_json(json_file: Union[str, Path]) -> None:
|
|
210
|
+
"""
|
|
211
|
+
Clean up the JSON file by removing unnecessary fields.
|
|
212
|
+
|
|
213
|
+
Parameters
|
|
214
|
+
----------
|
|
215
|
+
json_file : str or Path
|
|
216
|
+
Path to the JSON file to clean up.
|
|
217
|
+
"""
|
|
218
|
+
import json
|
|
219
|
+
|
|
220
|
+
with open(str(json_file)) as f:
|
|
221
|
+
data = json.load(f)
|
|
222
|
+
|
|
223
|
+
# Remove null values from the JSON data
|
|
224
|
+
data = remove_null_values(data)
|
|
225
|
+
|
|
226
|
+
with open(str(json_file), "w") as f:
|
|
227
|
+
json.dump(data, f, indent=4)
|
|
228
|
+
|
|
229
|
+
# Log the cleanup action
|
|
230
|
+
logger.debug(f"Cleaned up JSON file: {json_file}")
|
|
231
|
+
logger.info("JSON file cleaned up successfully.")
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def remove_null_values(data: Union[dict[Any, Any], list[Any], Any]) -> Union[dict[Any, Any], list[Any], Any]:
|
|
235
|
+
"""
|
|
236
|
+
Recursively removes keys with null (None) values from a dictionary or list.
|
|
237
|
+
|
|
238
|
+
Parameters
|
|
239
|
+
----------
|
|
240
|
+
data : dict, list, or Any
|
|
241
|
+
The JSON-like data structure to process. It can be a dictionary, a list,
|
|
242
|
+
or any other type of data.
|
|
243
|
+
|
|
244
|
+
Returns
|
|
245
|
+
-------
|
|
246
|
+
dict, list, or Any
|
|
247
|
+
A new data structure with null values removed. If the input is a dictionary,
|
|
248
|
+
keys with `None` values are removed. If the input is a list, items are
|
|
249
|
+
recursively processed to remove `None` values. For other types, the input
|
|
250
|
+
is returned unchanged.
|
|
251
|
+
|
|
252
|
+
Examples
|
|
253
|
+
--------
|
|
254
|
+
>>> data = {
|
|
255
|
+
... "key1": None,
|
|
256
|
+
... "key2": {"subkey1": 123, "subkey2": None},
|
|
257
|
+
... "key3": [None, 456, {"subkey3": None}],
|
|
258
|
+
... }
|
|
259
|
+
>>> remove_null_values(data)
|
|
260
|
+
{'key2': {'subkey1': 123}, 'key3': [456, {}]}
|
|
261
|
+
"""
|
|
262
|
+
if isinstance(data, dict):
|
|
263
|
+
return {key: remove_null_values(value) for key, value in data.items() if value is not None}
|
|
264
|
+
if isinstance(data, list):
|
|
265
|
+
return [remove_null_values(item) for item in data if item is not None]
|
|
266
|
+
return data
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: climate-ref-pmp
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.2
|
|
4
4
|
Summary: PMP diagnostic provider for the Rapid Evaluation Framework
|
|
5
5
|
Author-email: Jiwoo Lee <jwlee@llnl.gov>, Jared Lewis <jared.lewis@climate-resource.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -5,7 +5,7 @@ climate_ref_pmp/dataset_registry/pmp_climatology.txt,sha256=lruldzyr8fS79Tdg5RsI
|
|
|
5
5
|
climate_ref_pmp/diagnostics/__init__.py,sha256=KmfWl_L0aeZE4KC_MhEQU-5n87BmZI40w5uvji8EZ-I,314
|
|
6
6
|
climate_ref_pmp/diagnostics/annual_cycle.py,sha256=HVOg4lHJMsvS0gm6rW86FJOAiW8gZt-5UDzEC_6dbH4,11533
|
|
7
7
|
climate_ref_pmp/diagnostics/enso.py,sha256=vk7w4waMFFfPtuq9BbCxwzGESCUXl_y-wXm38FdyBwM,9695
|
|
8
|
-
climate_ref_pmp/diagnostics/variability_modes.py,sha256=
|
|
8
|
+
climate_ref_pmp/diagnostics/variability_modes.py,sha256=tI6xcSZ57657ecHBOKcRUW_QLYwT3c2DqVeCesx5PI8,9521
|
|
9
9
|
climate_ref_pmp/drivers/enso_driver.py,sha256=i5Wli5GktaH5jtTRMOmtR9ha9_xbJojoc8VoGK7Iueo,16910
|
|
10
10
|
climate_ref_pmp/params/pmp_param_MoV-psl.py,sha256=cpQyro0UdVWxe7jREidEQdirjksIXc7lm3CIfefcz5I,2268
|
|
11
11
|
climate_ref_pmp/params/pmp_param_MoV-ts.py,sha256=yfKs8qgsoaCmdRwDJWSZ3sy0GM_WsQrOde9d__iOo7I,2547
|
|
@@ -13,8 +13,8 @@ climate_ref_pmp/params/pmp_param_annualcycle_1-clims.py,sha256=P7DkL5wdtK9huQ9um
|
|
|
13
13
|
climate_ref_pmp/params/pmp_param_annualcycle_2-metrics.py,sha256=JH9flUE9Ti-2bhCpDkDtmup1aD_7brHPqNSbc2-loF8,1655
|
|
14
14
|
climate_ref_pmp/requirements/conda-lock.yml,sha256=MtIkAaUNMF3ADJvscGCk9GghyfseveFuNla9Zu4euDc,330345
|
|
15
15
|
climate_ref_pmp/requirements/environment.yml,sha256=BNpqu73k6tlRBr92eYw_NfPls5jcAnJDkynvaYz074I,133
|
|
16
|
-
climate_ref_pmp-0.6.
|
|
17
|
-
climate_ref_pmp-0.6.
|
|
18
|
-
climate_ref_pmp-0.6.
|
|
19
|
-
climate_ref_pmp-0.6.
|
|
20
|
-
climate_ref_pmp-0.6.
|
|
16
|
+
climate_ref_pmp-0.6.2.dist-info/METADATA,sha256=LVWuXJMKSZy6GZb2a357dKIYMz_L42UgtaoRUECJEGw,2733
|
|
17
|
+
climate_ref_pmp-0.6.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
18
|
+
climate_ref_pmp-0.6.2.dist-info/licenses/LICENCE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
19
|
+
climate_ref_pmp-0.6.2.dist-info/licenses/NOTICE,sha256=4qTlax9aX2-mswYJuVrLqJ9jK1IkN5kSBqfVvYLF3Ws,128
|
|
20
|
+
climate_ref_pmp-0.6.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|