Skip to content

Commit 6f05b68

Browse files
committed
pre-commit check
1 parent 3337626 commit 6f05b68

File tree

6 files changed

+91
-72
lines changed

6 files changed

+91
-72
lines changed

pcmdi_metrics/mjo/lib/post_process_plot_ensemble_mean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def main():
1111
# mip = "cmip5"
12-
mip = 'cmip6'
12+
mip = "cmip6"
1313
exp = "historical"
1414
version = "v20230924"
1515
period = "1985-2004"

pcmdi_metrics/variability_mode/lib/plot_map.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
import faulthandler
12
import sys
23

3-
#import cartopy
4+
# import cartopy
45
import cartopy.crs as ccrs
56
import matplotlib.path as mpath
67
import matplotlib.pyplot as plt
78
import matplotlib.ticker as mticker
89
import numpy as np
9-
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER
10-
from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter
11-
from pcmdi_metrics.variability_mode.lib import debug_print
1210
from cartopy.feature import LAND as cartopy_land
1311
from cartopy.feature import OCEAN as cartopy_ocean
12+
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER
13+
from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter
1414

15-
import faulthandler
15+
from pcmdi_metrics.variability_mode.lib import debug_print
1616

1717
faulthandler.enable()
1818

1919

20-
def plot_map(mode, model, syear, eyear, season, eof_Nth, frac_Nth, output_file_name, debug=False):
20+
def plot_map(
21+
mode, model, syear, eyear, season, eof_Nth, frac_Nth, output_file_name, debug=False
22+
):
2123
"""Plot dive down map and save
2224
2325
Parameters
@@ -74,7 +76,9 @@ def plot_map(mode, model, syear, eyear, season, eof_Nth, frac_Nth, output_file_n
7476
+ percentage
7577
)
7678

77-
debug_print('plot_map: projection, plot_title:' + projection +', '+ plot_title, debug)
79+
debug_print(
80+
"plot_map: projection, plot_title:" + projection + ", " + plot_title, debug
81+
)
7882

7983
gridline = True
8084

@@ -148,7 +152,7 @@ def plot_map_cartopy(
148152
Switch for debugging print statements (default is False)
149153
"""
150154

151-
debug_print('plot_map_cartopy starts', debug)
155+
debug_print("plot_map_cartopy starts", debug)
152156

153157
lons = data.getLongitude()
154158
lats = data.getLatitude()
@@ -160,8 +164,8 @@ def plot_map_cartopy(
160164
if debug:
161165
print(min_lon, max_lon, min_lat, max_lat)
162166

163-
debug_print('Central longitude setup starts', debug)
164-
debug_print('proj: '+proj, debug)
167+
debug_print("Central longitude setup starts", debug)
168+
debug_print("proj: " + proj, debug)
165169
# map types example:
166170
# https://github.com/SciTools/cartopy-tutorial/blob/master/tutorial/projections_crs_and_terms.ipynb
167171

@@ -185,19 +189,19 @@ def plot_map_cartopy(
185189
standard_parallels=(20, max_lat),
186190
)
187191
else:
188-
print('Error: projection not defined!')
192+
print("Error: projection not defined!")
189193

190194
if debug:
191-
debug_print('Central longitude setup completes', debug)
192-
print('projection:', projection)
195+
debug_print("Central longitude setup completes", debug)
196+
print("projection:", projection)
193197

194198
# Generate plot
195-
debug_print('Generate plot starts', debug)
196-
#fig = plt.figure(figsize=(8, 6))
197-
debug_print('fig done', debug)
198-
#ax = plt.axes(projection=projection)
199+
debug_print("Generate plot starts", debug)
200+
fig = plt.figure(figsize=(8, 6))
201+
debug_print("fig done", debug)
202+
# ax = plt.axes(projection=projection)
199203
ax = plt.axes(projection=ccrs.NorthPolarStereo())
200-
debug_print('ax done', debug)
204+
debug_print("ax done", debug)
201205
im = ax.contourf(
202206
lons,
203207
lats,
@@ -207,12 +211,12 @@ def plot_map_cartopy(
207211
levels=levels,
208212
extend="both",
209213
)
210-
debug_print('contourf done', debug)
214+
debug_print("contourf done", debug)
211215
ax.coastlines()
212-
debug_print('Generate plot completed', debug)
216+
debug_print("Generate plot completed", debug)
213217

214218
# Grid Lines and tick labels
215-
debug_print('projection starts', debug)
219+
debug_print("projection starts", debug)
216220
if proj == "PlateCarree":
217221
if data_area == "global":
218222
if gridline:
@@ -230,7 +234,7 @@ def plot_map_cartopy(
230234
if gridline:
231235
gl = ax.gridlines(alpha=0.5, linestyle="--")
232236
elif "Stereo" in proj:
233-
debug_print(proj + ' start', debug)
237+
debug_print(proj + " start", debug)
234238
if gridline:
235239
gl = ax.gridlines(draw_labels=True, alpha=0.5, linestyle="--")
236240
gl.xlocator = mticker.FixedLocator(
@@ -254,7 +258,7 @@ def plot_map_cartopy(
254258
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
255259
circle = mpath.Path(verts * radius + center)
256260
ax.set_boundary(circle, transform=ax.transAxes)
257-
debug_print(proj + ' plotted', debug)
261+
debug_print(proj + " plotted", debug)
258262
elif proj == "Lambert":
259263
# Make a boundary path in PlateCarree projection, I choose to start in
260264
# the bottom left and go round anticlockwise, creating a boundary point
@@ -271,7 +275,7 @@ def plot_map_cartopy(
271275
draw_labels=True,
272276
alpha=0.8,
273277
linestyle="--",
274-
crs=cartopy.crs.PlateCarree(),
278+
crs=ccrs.PlateCarree(),
275279
)
276280
gl.xformatter = LONGITUDE_FORMATTER
277281
gl.yformatter = LATITUDE_FORMATTER
@@ -284,7 +288,7 @@ def plot_map_cartopy(
284288
right_label = ea.get_position()[0] > 0
285289
if right_label:
286290
ea.set_visible(False)
287-
debug_print('projection completed', debug)
291+
debug_print("projection completed", debug)
288292

289293
# Add title
290294
plt.title(title, pad=15, fontsize=15)
@@ -311,6 +315,6 @@ def plot_map_cartopy(
311315
)
312316

313317
# Done, save figure
314-
debug_print('plot done, save figure as ' + filename, debug)
318+
debug_print("plot done, save figure as " + filename, debug)
315319
fig.savefig(filename)
316320
plt.close("all")

pcmdi_metrics/variability_mode/param/myParam_demo_NAM.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
# Analysis Options
1414
# -------------------------------------------------
1515
variability_mode = "NAM" # Available domains: NAM, NAO, SAM, PNA, PDO
16-
seasons = ["DJF", "MAM", "JJA", "SON"] # Available seasons: DJF, MAM, JJA, SON, monthly, yearly
16+
seasons = [
17+
"DJF",
18+
"MAM",
19+
"JJA",
20+
"SON",
21+
] # Available seasons: DJF, MAM, JJA, SON, monthly, yearly
1722

1823
ConvEOF = True # Calculate conventioanl EOF for model
1924
CBF = True # Calculate Common Basis Function (CBF) for model
@@ -31,8 +36,8 @@
3136
reference_data_path = os.path.join(
3237
"/p/user_pub/PCMDIobs/obs4MIPs/NOAA-ESRL-PSD/20CR/mon/psl/gn/latest",
3338
"psl_mon_20CR_PCMDI_gn_187101-201212.nc"
34-
#"/p/user_pub/PCMDIobs/PCMDIobs2/atmos/mon/psl/20CR/gn/v20200707",
35-
#"psl_mon_20CR_BE_gn_v20200707_187101-201212.nc",
39+
# "/p/user_pub/PCMDIobs/PCMDIobs2/atmos/mon/psl/20CR/gn/v20200707",
40+
# "psl_mon_20CR_BE_gn_v20200707_187101-201212.nc",
3641
)
3742

3843
varOBS = "psl"
@@ -88,4 +93,3 @@
8893
# Output for models
8994
nc_out = True
9095
plot = True
91-

pcmdi_metrics/variability_mode/param/myParam_demo_PDO.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@
9494

9595
# Output for models
9696
nc_out = True
97-
plot = True
97+
plot = True

pcmdi_metrics/variability_mode/scripts_pcmdi/parallel_submitter_all_modes_models.py

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ def find_latest(path):
1010
dir_list = [p for p in glob.glob(path + "/v????????")]
1111
return sorted(dir_list)[-1]
1212

13+
1314
# ---------------------------------------------------------------
1415

1516
mip = "cmip6"
1617
exp = "historical"
1718

18-
datadir = '/p/user_pub/pmp/pmp_results/pmp_v1.1.2/additional_xmls/latest'
19+
datadir = "/p/user_pub/pmp/pmp_results/pmp_v1.1.2/additional_xmls/latest"
1920
param_dir = "../param"
2021

2122
modes = ["NAM", "SAM", "NAO", "PNA", "NPO", "PDO", "NPGO"]
2223

2324
case_id = "{:v%Y%m%d}".format(datetime.datetime.now())
2425

2526
num_workers = 40
26-
debug = True
27+
debug = True
2728

2829
# ---------------------------------------------------------------
2930

@@ -49,64 +50,72 @@ def find_latest(path):
4950
else:
5051
eofn_obs = 1
5152
eofn_mod = 1
52-
53+
5354
datadir_ver = find_latest(datadir)
54-
datadir_final = os.path.join(datadir_ver, mip, exp, 'atmos', 'mon', var)
55-
56-
xml_list = glob.glob(os.path.join(datadir_final, '*.xml'))
57-
55+
datadir_final = os.path.join(datadir_ver, mip, exp, "atmos", "mon", var)
56+
57+
xml_list = glob.glob(os.path.join(datadir_final, "*.xml"))
58+
5859
# get list of models
59-
models_list = sort_human(
60-
[r.split("/")[-1].split(".")[2] for r in xml_list]
61-
)
60+
models_list = sort_human([r.split("/")[-1].split(".")[2] for r in xml_list])
6261
# remove repeat
6362
models_list = sort_human(list(dict.fromkeys(models_list)))
6463

6564
if debug:
6665
models_list = models_list[0:3]
67-
66+
6867
print(models_list)
6968
print(len(models_list))
70-
69+
7170
for model in models_list:
72-
file_list_model = glob.glob(os.path.join(datadir_final, '*.' + model + '.*.xml'))
71+
file_list_model = glob.glob(
72+
os.path.join(datadir_final, "*." + model + ".*.xml")
73+
)
7374
runs_list = sort_human(
74-
[
75-
r.split("/")[-1].split(".")[3]
76-
for r in file_list_model
77-
]
75+
[r.split("/")[-1].split(".")[3] for r in file_list_model]
7876
)
7977

8078
if debug:
8179
runs_list = runs_list[0:1]
82-
80+
8381
print(model, runs_list)
8482

8583
for run in runs_list:
86-
8784
cmd_content = [
88-
'variability_modes_driver.py',
89-
'-p', os.path.join(param_dir, param_file),
90-
'--variability_mode', mode,
91-
'--osyear', str(osyear),
92-
'--eofn_obs', str(eofn_obs),
93-
'--eofn_mod', str(eofn_mod),
94-
'--mip', mip, '--exp', exp,
95-
'--modnames', model,
96-
'--realization', run,
85+
"variability_modes_driver.py",
86+
"-p",
87+
os.path.join(param_dir, param_file),
88+
"--variability_mode",
89+
mode,
90+
"--osyear",
91+
str(osyear),
92+
"--eofn_obs",
93+
str(eofn_obs),
94+
"--eofn_mod",
95+
str(eofn_mod),
96+
"--mip",
97+
mip,
98+
"--exp",
99+
exp,
100+
"--modnames",
101+
model,
102+
"--realization",
103+
run,
97104
]
98105

99106
if model != models_list[0] or run != runs_list[0]:
100107
cmd_content.extend(["--no_plot_obs", "--no_nc_out_obs"])
101108

102109
if debug:
103-
cmd_content.append('--debug True')
110+
cmd_content.append("--debug True")
111+
112+
cmd = " ".join(cmd_content)
104113

105-
cmd = ' '.join(cmd_content)
114+
log_file = (
115+
"_".join(["variability_modes", mode, mip, exp, model, run]) + ".txt"
116+
)
106117

107-
log_file = '_'.join(['variability_modes', mode, mip, exp, model, run]) + '.txt'
108-
109-
print(cmd)
118+
print(cmd)
110119
cmds_list.append(cmd)
111120
logfilename_list.append(log_file)
112121

@@ -118,8 +127,11 @@ def find_latest(path):
118127
"/p/user_pub/pmp/pmp_results/pmp_v1.1.2",
119128
"log",
120129
"variability_modes",
121-
mip, exp, case_id)
122-
130+
mip,
131+
exp,
132+
case_id,
133+
)
134+
123135
os.makedirs(log_dir, exist_ok=True)
124136

125137
parallel_submitter(
@@ -128,4 +140,3 @@ def find_latest(path):
128140
logfilename_list=logfilename_list,
129141
num_workers=num_workers,
130142
)
131-

pcmdi_metrics/variability_mode/variability_modes_driver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@
451451
eof_lr_obs[season](region_subdomain),
452452
frac_obs[season],
453453
output_img_file_obs,
454-
debug=debug
454+
debug=debug,
455455
)
456456
plot_map(
457457
mode + "_teleconnection",
@@ -462,7 +462,7 @@
462462
eof_lr_obs[season](longitude=(lon1g, lon2g)),
463463
frac_obs[season],
464464
output_img_file_obs + "_teleconnection",
465-
debug=debug
465+
debug=debug,
466466
)
467467
debug_print("obs plotting end", debug)
468468

@@ -757,7 +757,7 @@
757757
eof_lr_cbf(region_subdomain),
758758
frac_cbf,
759759
output_img_file + "_cbf",
760-
debug=debug
760+
debug=debug,
761761
)
762762
plot_map(
763763
mode + "_teleconnection",
@@ -768,7 +768,7 @@
768768
eof_lr_cbf(longitude=(lon1g, lon2g)),
769769
frac_cbf,
770770
output_img_file + "_cbf_teleconnection",
771-
debug=debug
771+
debug=debug,
772772
)
773773

774774
debug_print("cbf pcs end", debug)

0 commit comments

Comments
 (0)