Skip to content

Commit

Permalink
added capability to choose moving average and labels in the yml files
Browse files Browse the repository at this point in the history
  • Loading branch information
ledm committed Nov 2, 2023
1 parent 7dbe814 commit 841f073
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
19 changes: 15 additions & 4 deletions bgcval2/analysis_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def timeseries_compare(jobs,
jobDescriptions={},
lineThicknesses=defaultdict(lambda: 1),
linestyles=defaultdict(lambda: '-'),
labels = {},
ensembles={},
config_user=None,
):
Expand Down Expand Up @@ -382,6 +383,7 @@ def timeseries_compare(jobs,
regions = av[name]['regions']
layers = av[name]['layers']
metrics = av[name]['metrics']
smoothings = av[name]['smoothings']
for region, layer, metric in itertools.product(regions, layers, metrics):
timesD = {}
arrD = {}
Expand All @@ -405,20 +407,22 @@ def timeseries_compare(jobs,
units = av[name]['modeldetails']['units']

ts = 'Together'
for ls in ['DataOnly', ]:
for smoothing in smoothings:
#or ls in ['DataOnly', ]:
tsp.multitimeseries(
timesD, # model times (in floats)
arrD, # model time series
data=-999, # in situ data distribution
title=title,
filename=bvt.folder(imageFolder) +
'_'.join([name, region, layer, ts, ls + '.png']),
'_'.join([name, region, layer, ts, smoothing + '.png']),
units=units,
plotStyle=ts,
lineStyle=ls,
smoothing=smoothing,
colours=colours,
thicknesses=lineThicknesses,
linestyles=linestyles,
labels=labels,
)

# Generate a list of comparison images:
Expand Down Expand Up @@ -515,7 +519,8 @@ def load_comparison_yml(master_compare_yml_fn):
descriptions = {}
shifttimes = {} # number of years to shift time axis.
timeranges = {}

labels = {}

for jobID, job_dict in details['jobs'].items():
if job_dict.get('colour', False):
colours[jobID] = job_dict['colour']
Expand All @@ -530,13 +535,16 @@ def load_comparison_yml(master_compare_yml_fn):
timeranges[jobID] = job_dict.get('timerange', None)
suites[jobID] = job_dict.get('suite', default_suite)
auto_download_dict[jobID] = job_dict.get('auto_download', auto_download_dict[jobID])
labels[jobID] = job_dict.get('label', jobID)


details['colours'] = colours
details['descriptions'] = descriptions
details['thicknesses'] = thicknesses
details['linestyles'] = linestyles
details['shifttimes'] = shifttimes
details['timeranges'] = timeranges
details['labels'] = labels
details['suites'] = suites
details['auto_download'] = auto_download_dict
return details
Expand Down Expand Up @@ -567,6 +575,7 @@ def load_yml_and_run(compare_yml, config_user, skip_timeseries):
descriptions = details['descriptions']
shifttimes = details['shifttimes']
timeranges = details['timeranges']
labels = details['labels']
suites = details['suites']
auto_download = details['auto_download']
strictFileCheck = details.get('strictFileCheck', True)
Expand All @@ -578,6 +587,7 @@ def load_yml_and_run(compare_yml, config_user, skip_timeseries):
print(jobID, 'colour:',colours[jobID])
print(jobID, 'line thickness & style:',thicknesses[jobID], linestyles[jobID])
print(jobID, 'Shift time by', shifttimes[jobID])
print(jobID, 'Label: ', labels[jobID])
print(jobID, 'Time range (None means all):', timeranges.get(jobID, None))
print(jobID, 'suite:', suites[jobID])
print(jobID, 'auto_download', auto_download[jobID])
Expand Down Expand Up @@ -620,6 +630,7 @@ def load_yml_and_run(compare_yml, config_user, skip_timeseries):
analysisname=analysis_name,
lineThicknesses=thicknesses,
linestyles=linestyles,
labels=labels,
config_user=config_user,
)

Expand Down
5 changes: 5 additions & 0 deletions bgcval2/analysis_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ def load_key_file(key, paths, jobID, strictFileCheck=True):
output_dict['metrics'] = key_dict.get('metrics', metricList)
output_dict['metrics'] = parse_list_from_string(output_dict['metrics'])

# Smoothings:
default_smoothings = ['DataOnly', ]
output_dict['smoothings'] = key_dict.get('smoothings', default_smoothings)
output_dict['smoothings'] = parse_list_from_string(output_dict['smoothings'])

# Load Grid:
gridFile = key_dict.get('gridFile', paths.orcaGridfn)
output_dict['gridFile'] = list_input_files(gridFile, key_dict, paths)[0]
Expand Down
53 changes: 28 additions & 25 deletions bgcval2/timeseries/timeseriesPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,10 @@ def multitimeseries(
'lime',
],
plotStyle='Together',
lineStyle='',
smoothing='',
thicknesses=defaultdict(lambda: 1),
linestyles=defaultdict(lambda: '-'),
labels={},
):

if 0 in [len(timesD), len(list(timesD.keys()))]: return
Expand Down Expand Up @@ -783,7 +784,8 @@ def multitimeseries(
if np.min(arr) < ylims[0]: ylims[0] = np.min(arr)
if np.max(arr) > ylims[1]: ylims[1] = np.max(arr)

if lineStyle.lower() in ['spline', 'all']:
label = labels.get(jobID, jobID)
if smoothing.lower() in ['spline', 'all']:
tnew = np.linspace(times[0], times[-1], 60)
arr_smooth = interpolate.spline(times, arr, tnew)
pyplot.plot(
Expand All @@ -792,10 +794,10 @@ def multitimeseries(
c=colours[jobID],
ls=linestyles[jobID],
lw=thicknesses[jobID],
label=jobID + ' spline',
label=label + ' spline',
)

if lineStyle.lower() in ['movingaverage', 'both', 'all']:
if smoothing.lower() in ['movingaverage', 'both', 'all']:
if len(times) > 100.: window = 30
elif len(times) > 30.: window = 15
elif len(times) > 10.: window = 4
Expand All @@ -810,10 +812,10 @@ def multitimeseries(
c=colours[jobID],
ls=linestyles[jobID],
lw=thicknesses[jobID],
label=jobID,
label=label,
)

if lineStyle.lower() in [
if smoothing.lower() in [
'movingaverage5',
]:
window = 5
Expand All @@ -827,11 +829,11 @@ def multitimeseries(
arr_new,
c=colours[jobID],
ls=linestyles[jobID],
label=jobID,
label=label,
lw=thicknesses[jobID],
)

if lineStyle.lower() in [
if smoothing.lower() in [
'movingav1year',
]:
arr_new = movingaverage_DT(arr,
Expand All @@ -844,10 +846,10 @@ def multitimeseries(
c=colours[jobID],
ls=linestyles[jobID],
lw=thicknesses[jobID],
label=jobID,
label=label,
)
if lineStyle.lower() in [
'movingav5years',
if smoothing.lower() in [
'movingav5years', 'both5'
]:
arr_new = movingaverage_DT(arr,
times,
Expand All @@ -859,11 +861,11 @@ def multitimeseries(
c=colours[jobID],
ls=linestyles[jobID],
lw=thicknesses[jobID],
label=jobID,
label=label,
)

if lineStyle.lower() in [
'movingav30years',
if smoothing.lower() in [
'movingav30years', 'both30'
]:
pyplot.plot(times,
arr,
Expand All @@ -881,11 +883,11 @@ def multitimeseries(
c=colours[jobID],
ls=linestyles[jobID],
lw=thicknesses[jobID],
label=jobID,
label=label,
)

if lineStyle.lower() in [
'movingav100years',
if smoothing.lower() in [
'movingav100years', 'both100',
]:
pyplot.plot(times,
arr,
Expand All @@ -903,10 +905,10 @@ def multitimeseries(
c=colours[jobID],
ls=linestyles[jobID],
lw=thicknesses[jobID],
label=jobID,
label=label,
)

if lineStyle.lower() in [
if smoothing.lower() in [
'movingaverage12',
]:
window = 12
Expand All @@ -921,10 +923,10 @@ def multitimeseries(
c=colours[jobID],
ls=linestyles[jobID],
lw=2.,
label=jobID,
label=label,
)

if lineStyle.lower() in [
if smoothing.lower() in [
'movingaverage60',
]:
window = 60
Expand All @@ -939,28 +941,29 @@ def multitimeseries(
c=colours[jobID],
ls=linestyles[jobID],
lw=2.,
label=jobID,
label=label,
)

if lineStyle.lower() in [
if smoothing.lower() in [
'',
'both',
'all',
'both5', 'both30', 'both100',
]:
pyplot.plot(times,
arr,
c=colours[jobID],
ls=linestyles[jobID],
lw=0.25)

if lineStyle.lower() in ['dataonly']:
if smoothing.lower() in ['dataonly']:
pyplot.plot(
times,
arr,
c=colours[jobID],
ls=linestyles[jobID],
lw=thicknesses[jobID],
label=jobID,
label=label,
)

if type(data) == type(10.):
Expand Down
1 change: 1 addition & 0 deletions key_files/amoc_26n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ model_convert:
altmaskfile: $PATHS_BGCVAL2/bgcval2/data/basinlandmask_eORCA1.nc
layers: layerless
regions: regionless
smoothings: DataOnly both5 both30 movingav30years

0 comments on commit 841f073

Please sign in to comment.