Skip to content

Commit

Permalink
Merge pull request #102 from valeriupredoi/dev_report_only
Browse files Browse the repository at this point in the history
New boolean in analysis_compare to run report maker only
  • Loading branch information
valeriupredoi authored Aug 14, 2023
2 parents 4e98cdd + db4b9f1 commit a775ec0
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 120 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ These values are:
- `do_analysis_timeseries`:
- A Boolean value to run or skip the single model timeseries.
- Set to False if the single model analysis has already completed.
- This value is overwritten by the `analysis_compare -s` which skips new timeseries analyses.
- `do_mass_download`:
- A boolean value to run the mass download.
- This is not currently possible as we can only download mass file from mass-cli1 on jasmin.
Expand Down Expand Up @@ -293,6 +294,15 @@ These values are:
A sample yaml exists in `input_yml/comparison_analysis_template.yml`,
which can be adapted to additional analyses.

In order to only run the report making part of the comparison analysis
(skip the `analysis_timeseries` part),
either set the `do_analysis_timeseries` key to `False` in the `input_yml` file,
or run `analysis_compare` with the command line argument: `-s` or `--skip-timeseries`.
To skip the analysis timeseries command, use `--no-skip-timeseries`.
Though without without either of these command line arguments,
bgcval2 will default to the value in your `input_yml` file.
Also, the command line argument overwrites the value in `input_yml`.

Once the comparison suite has been run, members of the esmeval group workspace on JASMIN
can copy the html report to a web-visible directory, using the script:

Expand Down
49 changes: 26 additions & 23 deletions bgcval2/analysis_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ def timeseries_compare(jobs,
lineThicknesses=defaultdict(lambda: 1),
linestyles=defaultdict(lambda: '-'),
ensembles={},
config_user=None):
config_user=None,
):
"""
timeseries_compare:
Suite of tools to take pre-analyses time series model data
Expand Down Expand Up @@ -336,15 +337,13 @@ def timeseries_compare(jobs,
if strictFileCheck:
raise FileError('Model Files are not found jobID: %s, name: %s', jobID, name)


if 'dataFile' in av[name] and not os.path.exists(av[name]['dataFile']):
print(
"analysis-Timeseries.py:\tWARNING:\tdata file is not found:",
av[name]['dataFile'])
if strictFileCheck:
raise FileError('Data Files are not found jobID: %s, name: %s', jobID, name)


#####
# time series and traffic lights.
tsa = timeseriesAnalysis(
Expand All @@ -368,6 +367,8 @@ def timeseries_compare(jobs,
clean=False,
noNewFiles=True,
)


#dataD[(jobID,name )] = tsa.dataD
modeldataD[(jobID, name)] = tsa.modeldataD

Expand All @@ -378,12 +379,6 @@ def timeseries_compare(jobs,

####
for name in av.keys():
# for name in [
# 'Temperature', 'Salinity', 'MLD', 'FreshwaterFlux',
# 'AirSeaFluxCO2', 'AirSeaFlux', 'Chlorophyll', 'Nitrate',
# 'Alkalinity', 'pH'
# ]:
# if name not in list(av.keys()): continue
regions = av[name]['regions']
layers = av[name]['layers']
metrics = av[name]['metrics']
Expand All @@ -397,14 +392,11 @@ def timeseries_compare(jobs,
continue
title = titleify([region, layer, metric, name])

#timesD[jobID] = sorted(mdata.keys())
#arrD[jobID] = [mdata[t] for t in timesD[jobID]]

times, datas = apply_shifttimes(mdata, jobID, shifttimes)
print('post apply_shifttimes:', len(times), len(datas))
times, datas = apply_timerange(times, datas, jobID, timeranges)
timesD[jobID] = times #mdata.keys())
arrD[jobID] = datas #t] for t in timesD[jobID]]
timesD[jobID] = times
arrD[jobID] = datas
print(jobID, region, layer, metric, len(times), len(datas))
timesD, arrD = build_ensemble(timesD, arrD, ensembles)

Expand All @@ -413,7 +405,7 @@ def timeseries_compare(jobs,
units = av[name]['modeldetails']['units']

ts = 'Together'
for ls in ['DataOnly', ]: # 'movingav30years']
for ls in ['DataOnly', ]:
tsp.multitimeseries(
timesD, # model times (in floats)
arrD, # model time series
Expand Down Expand Up @@ -444,17 +436,18 @@ def timeseries_compare(jobs,
if ensembles != {}:
jobs = list(ensembles.keys())

# Senmd everything to the comparison maker:
# Send everything to the comparison maker:
comparehtml5Maker(
jobIDs=jobs,
reportdir=bvt.folder('CompareReports2/' + analysisname),
files=AllImages,
clean=False,
doZip=False,
jobDescriptions=jobDescriptions,
jobColours=colours,
paths=paths,
analysisKeys=analysisKeys,
)
print('End of timeseries_compare')


def flatten(lats, lons, dataA, dataB):
Expand Down Expand Up @@ -546,12 +539,10 @@ def load_comparison_yml(master_compare_yml_fn):
details['timeranges'] = timeranges
details['suites'] = suites
details['auto_download'] = auto_download_dict
# print(details)
# assert 0
return details


def load_yml_and_run(compare_yml, config_user):
def load_yml_and_run(compare_yml, config_user, skip_timeseries):
"""
Loads the comparison yaml file and run compare_yml.
Expand All @@ -565,6 +556,11 @@ def load_yml_and_run(compare_yml, config_user):
do_mass_download = details['do_mass_download']
master_suites = details['master_suites']

if skip_timeseries is None:
pass
else:
do_analysis_timeseries = not skip_timeseries

colours = details['colours']
thicknesses = details['thicknesses']
linestyles = details['linestyles']
Expand Down Expand Up @@ -624,7 +620,7 @@ def load_yml_and_run(compare_yml, config_user):
analysisname=analysis_name,
lineThicknesses=thicknesses,
linestyles=linestyles,
config_user=config_user
config_user=config_user,
)


Expand All @@ -649,6 +645,13 @@ def get_args():
help='User configuration file (for paths).',
required=False)

parser.add_argument('--skip_timeseries',
'-s',
default=None,
help='When True: skip the new timeseries analyses and make the html report. Overwrites the do_analysis_timeseries flag in input_yml.',
action=argparse.BooleanOptionalAction,
required=False)

args = parser.parse_args()

return args
Expand All @@ -670,8 +673,8 @@ def main():
if not os.path.isfile(compare_yml):
print(f"analysis_timeseries: Could not find comparison config file {compare_yml}")
sys.exit(1)

load_yml_and_run(compare_yml, config_user)
skip_timeseries = args.skip_timeseries
load_yml_and_run(compare_yml, config_user, skip_timeseries)

print("Finished... ")

Expand Down
98 changes: 22 additions & 76 deletions bgcval2/bgcval2_make_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def html5Maker(
reportdir='reports/tmp',
year='*',
clean=False,
doZip=False,
physicsOnly=False,
paths=None,
config_user=None,
Expand Down Expand Up @@ -1358,22 +1357,30 @@ def newImageLocation(fn):

print("-------------\nSuccess\ntest with:\nfirefox", indexhtmlfn)
print("To zip it up:\n", tar)
if doZip:
import subprocess
subprocess.Popen(tar.split())


def comparehtml5Maker(
jobIDs=[],
reportdir='reports/tmp',
files=[],
clean=False,
doZip=False,
jobDescriptions={},
jobColours={},
paths = {}
paths = {},
analysisKeys=[]
):

"""
Generates the multi-job comparison report.
jobIDs: list of job IDs
reportdir: output job direction
files: a list of paths to images
clean: bool to remove old report.
jobDescriptions: dict to describe eahc job
jobColours: dict for each jobs colour in the legend.
paths: bgcval.paths
analysisKeys: list of analysis keys (generated from the input_yml).
"""
if clean:
#####
# Delete old files
Expand Down Expand Up @@ -1452,6 +1459,8 @@ def newImageLocation(fn):
Caption=Caption,
tablehtml=htmltable)

# A curated list of specific plots to include in the headlines
# of the comparison report
physicsKM = [
'AMOC_26N',
'ADRC_26N',
Expand All @@ -1469,7 +1478,6 @@ def newImageLocation(fn):
'MA_Drake',
'MA_AMOC_26N',
'MA_AEU',

]

bgcKM = [
Expand All @@ -1493,13 +1501,14 @@ def newImageLocation(fn):
'MA_TotalPhytoC_Global_Surface',
'MA_TotalZooC_Global_Surface',
]

categories = {
'Physics Key Metrics': [],
'BGC Key Metrics': [],
'Other Plots': [],
}
extrafolds = []


for fn in files:
found = False
for key in physicsKM:
Expand All @@ -1525,17 +1534,6 @@ def newImageLocation(fn):
]
found = True
if found: continue
for extracat in extrafolds:
if found: continue
if fn.find('/' + extracat + '/') > -1:
try:
categories[extracat].append(fn)
except:
categories[extracat] = [
fn,
]

if found: continue
try:
categories['Other Plots'].append(fn)
except:
Expand All @@ -1548,9 +1546,6 @@ def newImageLocation(fn):
categoryOrder.append('Physics Key Metrics')
if len(categories['BGC Key Metrics']):
categoryOrder.append('BGC Key Metrics')
for exf in extrafolds:
if exf not in list(categories.keys()): continue
if len(categories[exf]): categoryOrder.append(exf)

if len(categories['Other Plots']): categoryOrder.append('Other Plots')
categories['Other Plots'] = sorted(categories['Other Plots'])
Expand Down Expand Up @@ -1588,7 +1583,7 @@ def newImageLocation(fn):
Files=relativeFiles)

if len(categories['Other Plots']):
otherFilenames = files[:] #categories['Other Plots'][:]
otherFilenames = files[:]
SectionTitle = 'All Plots'

hrefs = []
Expand All @@ -1598,57 +1593,7 @@ def newImageLocation(fn):
FileLists = {}
FileOrder = {}

names = [
'Chlorophyll',
'MLD',
'Nitrate',
'Phosphate',
'Salinity',
'Temperature',
'Current',
#'so',
'Ice',
'DIC',
'pH',
'DMS',
'DiaFrac',
'Dust',
'Iron',
'Silicate',
'Alkalinity',
'AMOC',
'ADRC',
'DrakePassage',
'AirSeaFlux',
'DTC',
'Oxygen',
'OMZ',
'Production',
'Export',
'FreshwaterFlux',
'HeatFlux',
'soga',
'scvoltot',
'thetaoga',
'scalarHeatContent',
]
# Add the rest of the names from key_lists directory.
key_lists_dir = os.path.join(paths.bgcval2_repo, 'key_lists')
for suite_yml in glob(os.path.join(key_lists_dir, '*.yml')):
# look for a list in keys_list directory:
# Open yml file:
with open(suite_yml, 'r') as openfile:
suite_dict = yaml.safe_load(openfile)

keys_dict = suite_dict.get('keys', {})
for key, key_bool in keys_dict.items():
if not key_bool:
continue
if key in names:
continue
names.append(key)

for key in sorted(names):
for key in sorted(analysisKeys):
#####
# Determine the list of files:
vfiles = []
Expand Down Expand Up @@ -1690,6 +1635,8 @@ def newImageLocation(fn):
print("Adding ", relfn, "to script")

if len(otherFilenames):
# I think this is never happens anymore.
assert 0
href = 'OtherPlots-others'

hrefs.append(href)
Expand Down Expand Up @@ -1724,7 +1671,6 @@ def newImageLocation(fn):
print(Descriptions)
print(FileLists)
print(FileOrder)
# hrefs=[]
if len(hrefs):
html5Tools.AddSubSections(indexhtmlfn,
hrefs,
Expand Down
Loading

0 comments on commit a775ec0

Please sign in to comment.