Skip to content

Commit

Permalink
Merge pull request #911 from PCMDI/910_pjg_computeclimopts
Browse files Browse the repository at this point in the history
910 pjg computeclimopts
  • Loading branch information
lee1043 committed Mar 29, 2023
2 parents e0605b8 + 233959b commit 4a4f63e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
23 changes: 18 additions & 5 deletions pcmdi_metrics/mean_climate/lib/calculate_climatology.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def calculate_climatology(
var, infile,
outfile=None, outpath=None, outfilename=None,
start=None, end=None, ver=None):
start=None, end=None, ver=None, periodinname=None, climlist=None):

if ver is None:
ver=datetime.datetime.now().strftime("v%Y%m%d")
Expand Down Expand Up @@ -84,8 +84,14 @@ def calculate_climatology(
d_clim_dict['SON'] = d_clim.isel(time=3)
d_clim_dict['AC'] = d_ac

for s in ["AC", "DJF", "MAM", "JJA", "SON"]:
addf = (
if climlist is None:
clims = ["AC", "DJF", "MAM", "JJA", "SON"]
else:
clims = climlist

for s in clims:
if periodinname is None:
addf = (
"."
+ start_yr_str
+ start_mo_str
Expand All @@ -96,8 +102,15 @@ def calculate_climatology(
+ s
+ "."
+ ver
+ ".nc"
)
+ ".nc")
if periodinname is not None:
addf = (
"."
+ s
+ "."
+ ver
+ ".nc")

if outfilename is not None:
out = os.path.join(outdir, outfilename)
out_season = out.replace(".nc", addf)
Expand Down
8 changes: 7 additions & 1 deletion pcmdi_metrics/mean_climate/pcmdi_compute_climatologies.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
)
P.add_argument("--end", dest="end", help="Defines end year and month", required=False)

P.add_argument("--periodinname", dest="periodinname", help="Include clim period in name (default yes) or not", required=False)

P.add_argument("--climlist", dest="climlist", help="Defines list of clim seasons to output (default='all')", required=False)

args = P.get_parameter()

infile_template = args.infile
Expand All @@ -40,6 +44,8 @@
varlist = args.vars
start = args.start
end = args.end
periodinname = args.periodinname
climlist = args.climlist

print("start and end are ", start, " ", end)
print("variable list: ", varlist)
Expand Down Expand Up @@ -68,4 +74,4 @@
print('outpath:', outpath)

# calculate climatologies for this variable
calculate_climatology(var, infile, outfile, outpath, outfilename, start, end, ver)
calculate_climatology(var, infile, outfile, outpath, outfilename, start, end, ver, periodinname, climlist)

0 comments on commit 4a4f63e

Please sign in to comment.