Skip to content

Commit 126fd01

Browse files
authored
Merge pull request #1266 from PCMDI/turn_off_conda_use_in_code
Option to turn off conda use in the code
2 parents c8c06b6 + 74fb36a commit 126fd01

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
# General file formatters
1010
# =======================
1111
- repo: https://github.com/pre-commit/pre-commit-hooks
12-
rev: v4.4.0
12+
rev: v5.0.0
1313
hooks:
1414
- id: trailing-whitespace
1515
args: [--markdown-linebreak-ext=md]
@@ -25,7 +25,7 @@ repos:
2525
- id: black
2626

2727
- repo: https://github.com/timothycrosley/isort
28-
rev: 5.13.2
28+
rev: 6.0.1
2929
hooks:
3030
- id: isort
3131
args: ["--honor-noqa"]

pcmdi_metrics/io/base.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def write(
352352
include_YAML=False,
353353
include_history=False,
354354
include_script=False,
355+
include_provenance=True,
355356
*args,
356357
**kwargs,
357358
):
@@ -389,20 +390,26 @@ def write(
389390
f = open(file_name)
390391
out_dict = json.load(f)
391392
else:
392-
out_dict = OrderedDict({"provenance": generateProvenance()})
393+
if include_provenance:
394+
out_dict = OrderedDict({"provenance": generateProvenance()})
395+
else:
396+
out_dict = OrderedDict({"provenance": dict()})
393397
f = open(file_name, "w")
394398
update_dict(out_dict, data)
395-
if "yaml" in out_dict["provenance"]["conda"]:
396-
if include_YAML:
397-
out_dict["YAML"] = out_dict["provenance"]["conda"]["yaml"]
398-
del out_dict["provenance"]["conda"]["yaml"]
399+
if "conda" in out_dict["provenance"]:
400+
if "yaml" in out_dict["provenance"]["conda"]:
401+
if include_YAML:
402+
out_dict["YAML"] = out_dict["provenance"]["conda"]["yaml"]
403+
del out_dict["provenance"]["conda"]["yaml"]
399404

400405
if not include_script:
401406
if "script" in out_dict["provenance"].keys():
402407
del out_dict["provenance"]["script"]
408+
403409
if not include_history:
404410
if "history" in out_dict["provenance"].keys():
405411
del out_dict["provenance"]["history"]
412+
406413
json.dump(out_dict, f, cls=CDMSDomainsEncoder, *args, **kwargs)
407414
f.close()
408415

pcmdi_metrics/variability_mode/lib/argparse_functions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ def AddParserArgument(P):
200200
default=True,
201201
help="Option for update existing JSON file: True (i.e., update) (default) / False (i.e., overwrite)",
202202
)
203+
P.add_argument(
204+
"--provenance",
205+
dest="provenance",
206+
action="store_true",
207+
default=True,
208+
help="Save provenance in output JSON",
209+
)
210+
P.add_argument(
211+
"--no_provenance",
212+
dest="provenance",
213+
action="store_false",
214+
default=False,
215+
help="Option to not save provenance in output JSON",
216+
)
203217
P.add_argument(
204218
"--cmec",
205219
dest="cmec",

pcmdi_metrics/variability_mode/lib/lib_variability_mode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def variability_metrics_to_json(
315315
model: str = None,
316316
run: str = None,
317317
cmec_flag: bool = False,
318+
include_provenance: bool = True,
318319
):
319320
# Open JSON
320321
JSON = pcmdi_metrics.io.base.Base(outdir, json_filename)
@@ -346,6 +347,7 @@ def variability_metrics_to_json(
346347
sort_keys=True,
347348
indent=4,
348349
separators=(",", ": "),
350+
include_provenance=include_provenance,
349351
)
350352
if cmec_flag:
351353
print("Writing cmec file")

pcmdi_metrics/variability_mode/variability_modes_driver.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@
8989
EofScaling = param.EofScaling # If True, consider EOF with unit variance
9090
RmDomainMean = param.RemoveDomainMean # If True, remove Domain Mean of each time step
9191
LandMask = param.landmask # If True, maskout land region thus consider only over ocean
92+
provenance = param.provenance
9293

9394
print("EofScaling:", EofScaling)
9495
print("RmDomainMean:", RmDomainMean)
9596
print("LandMask:", LandMask)
97+
print("provenance:", provenance)
9698

9799
nc_out_obs = param.nc_out_obs # Record NetCDF output
98100
plot_obs = param.plot_obs # Generate plots
@@ -1075,6 +1077,7 @@
10751077
# =================================================================
10761078
# Dictionary to JSON: individual JSON during model_realization loop
10771079
# -----------------------------------------------------------------
1080+
debug_print("json (individual) writing start", debug)
10781081
json_filename_tmp = f"var_mode_{mode}_EOF{eofn_mod}_stat_{mip}_{exp}_{fq}_{realm}_{model}_{run}_{msyear}-{meyear}"
10791082

10801083
variability_metrics_to_json(
@@ -1084,7 +1087,9 @@
10841087
model=model,
10851088
run=run,
10861089
cmec_flag=cmec,
1090+
include_provenance=provenance,
10871091
)
1092+
debug_print("json (individual) writing done", debug)
10881093

10891094
except Exception as err:
10901095
if debug:
@@ -1096,10 +1101,12 @@
10961101
# Dictionary to JSON: collective JSON at the end of model_realization loop
10971102
# ------------------------------------------------------------------------
10981103
if not parallel and (len(models) > 1):
1104+
debug_print("json (collective) writing start", debug)
10991105
json_filename_all = f"var_mode_{mode}_EOF{eofn_mod}_stat_{mip}_{exp}_{fq}_{realm}_allModels_allRuns_{msyear}-{meyear}"
11001106
variability_metrics_to_json(
11011107
dir_paths["metrics_results"], json_filename_all, result_dict, cmec_flag=cmec
11021108
)
1109+
debug_print("json (collective) writing done", debug)
11031110

11041111
if not debug:
11051112
sys.exit(0)

0 commit comments

Comments
 (0)