Skip to content

Commit e6345a1

Browse files
committed
style fix for pre-commit test
1 parent e643cb5 commit e6345a1

File tree

4 files changed

+76
-69
lines changed

4 files changed

+76
-69
lines changed

pcmdi_metrics/mean_climate/lib/compute_metrics.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ def compute_metrics(Var, dm, do, debug=False):
3535

3636
# unify time and time bounds between observation and model
3737
if debug:
38-
print('before time and time bounds unifying')
39-
print('dm.time: ', dm['time'])
40-
print('do.time: ', do['time'])
38+
print("before time and time bounds unifying")
39+
print("dm.time: ", dm["time"])
40+
print("do.time: ", do["time"])
4141

4242
"""
4343
# Below is temporary...
4444
dm['time'] = do['time']
4545
dm[dm.time.encoding['bounds']] = do[do.time.attrs['bounds']]
4646
"""
47-
47+
4848
if debug:
49-
print('after time and time bounds unifying')
50-
print('dm.time: ', dm['time'])
51-
print('do.time: ', do['time'])
52-
53-
dm.to_netcdf('dm.nc')
54-
do.to_netcdf('do.nc')
49+
print("after time and time bounds unifying")
50+
print("dm.time: ", dm["time"])
51+
print("do.time: ", do["time"])
52+
53+
dm.to_netcdf("dm.nc")
54+
do.to_netcdf("do.nc")
5555

5656
metrics_dictionary = OrderedDict()
5757

@@ -65,15 +65,15 @@ def compute_metrics(Var, dm, do, debug=False):
6565

6666
print("compute_metrics, rms_xyt")
6767
rms_xyt = pcmdi_metrics.mean_climate.lib.rms_xyt(dm, do, var)
68-
print('compute_metrics, rms_xyt:', rms_xyt)
68+
print("compute_metrics, rms_xyt:", rms_xyt)
6969

7070
print("compute_metrics, stdObs_xyt")
7171
stdObs_xyt = pcmdi_metrics.mean_climate.lib.std_xyt(do, var)
72-
print('compute_metrics, stdObs_xyt:', stdObs_xyt)
72+
print("compute_metrics, stdObs_xyt:", stdObs_xyt)
7373

7474
print("compute_metrics, std_xyt")
7575
std_xyt = pcmdi_metrics.mean_climate.lib.std_xyt(dm, var)
76-
print('compute_metrics, std_xyt:', std_xyt)
76+
print("compute_metrics, std_xyt:", std_xyt)
7777

7878
# CALCULATE ANNUAL MEANS
7979
print("compute_metrics-CALCULATE ANNUAL MEANS")
@@ -82,23 +82,23 @@ def compute_metrics(Var, dm, do, debug=False):
8282
# CALCULATE ANNUAL MEAN BIAS
8383
print("compute_metrics-CALCULATE ANNUAL MEAN BIAS")
8484
bias_xy = pcmdi_metrics.mean_climate.lib.bias_xy(dm_am, do_am, var)
85-
print('compute_metrics-CALCULATE ANNUAL MEAN BIAS, bias_xy:', bias_xy)
85+
print("compute_metrics-CALCULATE ANNUAL MEAN BIAS, bias_xy:", bias_xy)
8686

8787
# CALCULATE MEAN ABSOLUTE ERROR
8888
print("compute_metrics-CALCULATE MSE")
8989
mae_xy = pcmdi_metrics.mean_climate.lib.meanabs_xy(dm_am, do_am, var)
90-
print('compute_metrics-CALCULATE MSE, mae_xy:', mae_xy)
90+
print("compute_metrics-CALCULATE MSE, mae_xy:", mae_xy)
9191

9292
# CALCULATE ANNUAL MEAN RMS (centered and uncentered)
9393
print("compute_metrics-CALCULATE MEAN RMS")
9494
rms_xy = pcmdi_metrics.mean_climate.lib.rms_xy(dm_am, do_am, var)
9595
rmsc_xy = pcmdi_metrics.mean_climate.lib.rmsc_xy(dm_am, do_am, var)
96-
print('compute_metrics-CALCULATE MEAN RMS: rms_xy, rmsc_xy: ', rms_xy, rmsc_xy)
96+
print("compute_metrics-CALCULATE MEAN RMS: rms_xy, rmsc_xy: ", rms_xy, rmsc_xy)
9797

9898
# CALCULATE ANNUAL MEAN CORRELATION
9999
print("compute_metrics-CALCULATE MEAN CORR")
100100
cor_xy = pcmdi_metrics.mean_climate.lib.cor_xy(dm_am, do_am, var)
101-
print('compute_metrics-CALCULATE MEAN CORR: cor_xy:', cor_xy)
101+
print("compute_metrics-CALCULATE MEAN CORR: cor_xy:", cor_xy)
102102

103103
# CALCULATE ANNUAL OBS and MOD STD
104104
print("compute_metrics-CALCULATE ANNUAL OBS AND MOD STD")
@@ -166,9 +166,7 @@ def compute_metrics(Var, dm, do, debug=False):
166166
metrics_dictionary["std_xy"]["ann"] = format(std_xy, sig_digits)
167167
metrics_dictionary["std-obs_xyt"]["ann"] = format(stdObs_xyt, sig_digits)
168168
metrics_dictionary["std_xyt"]["ann"] = format(std_xyt, sig_digits)
169-
metrics_dictionary["std-obs_xy_devzm"]["ann"] = format(
170-
stdObs_xy_devzm, sig_digits
171-
)
169+
metrics_dictionary["std-obs_xy_devzm"]["ann"] = format(stdObs_xy_devzm, sig_digits)
172170
metrics_dictionary["std_xy_devzm"]["ann"] = format(std_xy_devzm, sig_digits)
173171
metrics_dictionary["rms_xyt"]["ann"] = format(rms_xyt, sig_digits)
174172
metrics_dictionary["rms_xy"]["ann"] = format(rms_xy, sig_digits)

pcmdi_metrics/mean_climate/lib/load_and_regrid.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ def load_and_regrid(
3434

3535
# load data
3636
ds = xcdat_open(
37-
data_path,
38-
data_var=varname_in_file,
39-
decode_times=decode_times) # NOTE: decode_times=False will be removed once obs4MIP written using xcdat
40-
37+
data_path, data_var=varname_in_file, decode_times=decode_times
38+
) # NOTE: decode_times=False will be removed once obs4MIP written using xcdat
39+
4140
# SET CONDITIONAL ON INPUT VARIABLE
4241
if varname == "pr":
43-
print('Adjust units for pr')
42+
print("Adjust units for pr")
4443
if ds[varname_in_file].units == "kg m-2 s-1":
4544
ds[varname_in_file] = ds[varname_in_file] * 86400
46-
print('pr units adjusted to [mm d-1] from [kg m-2 s-1] by 86400 multiplied')
45+
print("pr units adjusted to [mm d-1] from [kg m-2 s-1] by 86400 multiplied")
4746

4847
"""
4948
# calendar quality check
@@ -64,20 +63,22 @@ def load_and_regrid(
6463
ds.time.attrs["calendar"] = 'standard'
6564
print('[WARNING]: calendar info not found for time axis. ds.time.attrs["calendar"] is adjusted to standard')
6665
"""
67-
66+
6867
# time bound check #1 -- add proper time bound info if cdms-generated annual cycle is loaded
69-
if isinstance(ds.time.values[0], np.float64): # and "units" not in list(ds.time.attrs.keys()):
70-
ds.time.attrs['units'] = "days since 0001-01-01"
68+
if isinstance(
69+
ds.time.values[0], np.float64
70+
): # and "units" not in list(ds.time.attrs.keys()):
71+
ds.time.attrs["units"] = "days since 0001-01-01"
7172
ds = xc.decode_time(ds)
7273
if debug:
73-
print('decode_time done')
74-
74+
print("decode_time done")
75+
7576
# time bound check #2 -- add time bounds itself it it is missing
76-
if 'bounds' in list(ds.time.attrs.keys()):
77-
time_bnds_key = ds.time.attrs['bounds']
77+
if "bounds" in list(ds.time.attrs.keys()):
78+
time_bnds_key = ds.time.attrs["bounds"]
7879
if time_bnds_key not in list(ds.keys()):
79-
ds = ds.bounds.add_missing_bounds(['T'])
80-
print('[WARNING]: bounds.add_missing_bounds conducted for T axis')
80+
ds = ds.bounds.add_missing_bounds(["T"])
81+
print("[WARNING]: bounds.add_missing_bounds conducted for T axis")
8182

8283
# level - extract a specific level if needed
8384
if level is not None:
@@ -143,15 +144,14 @@ def load_and_regrid(
143144

144145
ds_regridded[varname] = ds_regridded[varname].assign_attrs({"units": units})
145146

146-
ds_regridded[varname] = ds_regridded[varname].assign_attrs({'units': units})
147-
147+
ds_regridded[varname] = ds_regridded[varname].assign_attrs({"units": units})
148+
148149
# time bound check #3 -- preserve time bnds in regridded dataset
149-
if 'bounds' in list(ds_regridded.time.attrs.keys()):
150-
time_bnds_key = ds_regridded.time.attrs['bounds']
150+
if "bounds" in list(ds_regridded.time.attrs.keys()):
151+
time_bnds_key = ds_regridded.time.attrs["bounds"]
151152
if time_bnds_key not in list(ds_regridded.keys()):
152-
ds_regridded = ds_regridded.bounds.add_missing_bounds(['T'])
153-
print('[WARNING]: bounds.add_missing_bounds conducted for T axis')
154-
153+
ds_regridded = ds_regridded.bounds.add_missing_bounds(["T"])
154+
print("[WARNING]: bounds.add_missing_bounds conducted for T axis")
155155

156156
if debug:
157157
print("ds_regridded:", ds_regridded)

pcmdi_metrics/mean_climate/lib/mean_climate_metrics_to_json.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,21 @@ def mean_climate_metrics_to_json(
2424
if m == model:
2525
ref_list = list(json_dict["RESULTS"][m].keys())
2626
if debug:
27-
print('debug:: mean_climate_metrics_to_json:: m, ref_list: ', m, ref_list)
28-
if 'units' in ref_list:
29-
ref_list.remove('units')
27+
print(
28+
"debug:: mean_climate_metrics_to_json:: m, ref_list: ",
29+
m,
30+
ref_list,
31+
)
32+
if "units" in ref_list:
33+
ref_list.remove("units")
3034
for ref in ref_list:
3135
if debug:
32-
print('debug:: mean_climate_metrics_to_json:: m, ref, json_dict["RESULTS"][m][ref]: ', m, ref, json_dict["RESULTS"][m][ref])
36+
print(
37+
'debug:: mean_climate_metrics_to_json:: m, ref, json_dict["RESULTS"][m][ref]: ',
38+
m,
39+
ref,
40+
json_dict["RESULTS"][m][ref],
41+
)
3342
runs_in_model_dict = list(json_dict["RESULTS"][m][ref].keys())
3443
for r in runs_in_model_dict:
3544
if (r != run) and (run is not None):

pcmdi_metrics/mean_climate/mean_climate_driver.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -233,32 +233,36 @@
233233
# ----------------
234234
if "all" in reference_data_set:
235235
reference_data_set = [
236-
x for x in list(obs_dict[varname].keys()) if (x == "default" or "alternate" in x)]
236+
x
237+
for x in list(obs_dict[varname].keys())
238+
if (x == "default" or "alternate" in x)
239+
]
237240
print("reference_data_set (all): ", reference_data_set)
238241

239242
for ref in reference_data_set:
240-
print('ref:', ref)
241-
243+
print("ref:", ref)
244+
242245
# identify data to load (annual cycle (AC) data is loading in)
243246
ref_dataset_name = obs_dict[varname][ref]
244247
ref_data_full_path = os.path.join(
245-
reference_data_path,
246-
obs_dict[varname][ref_dataset_name]["template"])
247-
print('ref_data_full_path:', ref_data_full_path)
248-
248+
reference_data_path, obs_dict[varname][ref_dataset_name]["template"]
249+
)
250+
print("ref_data_full_path:", ref_data_full_path)
251+
249252
# load data and regrid
250253
ds_ref = load_and_regrid(
251-
data_path=ref_data_full_path,
252-
varname=varname,
253-
level=level,
254-
t_grid=t_grid,
255-
# decode_times=False,
256-
decode_times=True,
257-
regrid_tool=regrid_tool,
258-
debug=debug)
254+
data_path=ref_data_full_path,
255+
varname=varname,
256+
level=level,
257+
t_grid=t_grid,
258+
# decode_times=False,
259+
decode_times=True,
260+
regrid_tool=regrid_tool,
261+
debug=debug,
262+
)
259263

260264
ds_ref_dict = OrderedDict()
261-
265+
262266
# for record in output json
263267
result_dict["References"][ref] = obs_dict[varname][ref_dataset_name]
264268

@@ -421,7 +425,7 @@
421425
)
422426

423427
# compute metrics
424-
428+
425429
print("compute metrics start")
426430
result_dict["RESULTS"][model][ref][run][
427431
region
@@ -469,11 +473,7 @@
469473
# write collective JSON --- all models / all obs / single variable
470474
json_filename = "_".join([var, target_grid, regrid_tool, "metrics", case_id])
471475
mean_climate_metrics_to_json(
472-
metrics_output_path,
473-
json_filename,
474-
result_dict,
475-
cmec_flag=cmec,
476-
debug=debug
476+
metrics_output_path, json_filename, result_dict, cmec_flag=cmec, debug=debug
477477
)
478478

479-
print("pmp mean clim driver completed")
479+
print("pmp mean clim driver completed")

0 commit comments

Comments
 (0)