Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve help messages and interface for single job #40

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bgcval2/UKESMpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def folder(name):
It also accepts lists of strings.
"""
if type(name) == type(['a', 'b', 'c']):
name = join(name, '/')
name = os.path.join(name)
if name[-1] != '/':
name = name + '/'
if exists(name) is False:
Expand Down
8 changes: 4 additions & 4 deletions bgcval2/analysis_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4245,7 +4245,7 @@ def load_yml_and_run(compare_yml, config_user):
print(jobID, 'suite:', suites[jobID])

for jobID in jobs:
# even if you don't want to download, we run this
# even if you don't want to download, we run this
# as it clears up the path and ensures recently downloed data is
# correctly symlinked.
download_from_mass(jobID, doMoo=do_mass_download)
Expand Down Expand Up @@ -4338,15 +4338,15 @@ def main():
compare_ymls = args.compare_yml

for compare_yml in compare_ymls:
print(f"analysis_timeseries: Comparison config file {compare_yml}")
print(f"analysis_compare: Comparison config file {compare_yml}")

if not os.path.isfile(compare_yml):
print(f"analysis_timeseries: Could not find comparison config file {compare_yml}")
print(f"analysis_compare: Could not find comparison config file {compare_yml}")
sys.exit(1)

load_yml_and_run(compare_yml, config_user)

print("Finished... ")
print("Finished analysis_compare... ")


if __name__ == "__main__":
Expand Down
143 changes: 100 additions & 43 deletions bgcval2/analysis_p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@

#####
#Standard Python modules:
from sys import argv, exit
from os.path import exists
from calendar import month_name
from socket import gethostname
from getpass import getuser
from glob import glob
from netCDF4 import Dataset
import numpy as np
import sys
import os
import argparse
import itertools

#####
#Specific local code:
Expand All @@ -50,6 +51,7 @@
from .p2p.patternAnalyses import InterAnnualPatterns, BGCvsPhysics
from .bgcvaltools.pftnames import months
from .p2p.shelveToDictionary import shelveToDictionary
from .download_from_mass import findLastFinishedYear

#####
# User defined set of paths pointing towards the datasets.
Expand Down Expand Up @@ -85,7 +87,7 @@

p2pKeys_annual = [
'T',
'S', #'MLD',
'S', #'MLD',
'Chl_CCI',
'N',
'Si',
Expand Down Expand Up @@ -113,7 +115,7 @@

p2pKeys_physics = [
'T',
'S', #'MLD',
'S', #'MLD',
'ZonalCurrent',
'MeridionalCurrent',
'VerticalCurrent'
Expand All @@ -139,7 +141,7 @@ def analysis_p2p(
noTargets=True,
):
"""

"""
#####
# Switches:
Expand Down Expand Up @@ -1499,44 +1501,99 @@ def single_p2p(jobID, key, year):
print("Error: %s" % sys.exc_info()[0])


def run():
def get_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
accepted_keys = ['debug', 'physics', 'leve2', 'annual']

parser.add_argument('-j',
'--jobID',
nargs='+',
type=str,
default=None,
help='One or more UKESM Job IDs (automatically generated by cycl/rose suite).',
required=True,
)
parser.add_argument('-k',
'--keys',
default=['level2', ],
nargs='+',
type=str,
help=''.join(['Runtime keys - each key links to a pre-determined list of variables to analyse. ',
'Keys are: ', ', '.join( accepted_keys)]),
required=False,
)
parser.add_argument('-y',
'--years',
default=['best',],
nargs='+',
type=str,
help=''.join(['Years to analysis. Default is "best". ']),
required=False,
)

parser.add_argument('-c',
'--config-file',
default=os.path.join(os.path.dirname(os.path.realpath(__file__)),
'default-bgcval2-config.yml'),
help='User configuration file (for paths).',
required=False)

args = parser.parse_args()

return args



def main():
from ._version import __version__
print(f'BGCVal2: {__version__}')
if "--help" in argv or len(argv) == 1:
print("Running with no arguments. Exiting.")
if "--help" in argv:
print("Read the documentation.")
sys.exit(0)
try:
jobID = argv[1]
except:
jobID = 'u-ab749'
args = get_args()

jobIDs = args.jobID
keys = args.keys
years = args.years

accepted_keys = ['debug', 'physics', 'leve2', 'annual']
for jobID, year, suite in itertools.product(jobIDs, years, keys):
print('p2p:', jobID, year, suite)
if year == 'best':
best_year = False
for divby in [100, 50, 25, 10, 5, 1]:
if best_year:
continue
print("analysis_p2p:\t find best year", divby, year,best_year )
best_year = findLastFinishedYear(jobID,
dividby=divby, debug= False) # numberfiles=numberfiles)
if best_year == False:
continue
else:
year = best_year

try:
year = argv[2]
except:
year = '2007'

if 'debug' in argv[1:]:
analysisSuite = 'debug'
elif 'level2' in argv[1:]:
analysisSuite = 'level2'
elif 'physics' in argv[1:]:
analysisSuite = 'physics'
else:
analysisSuite = 'annual'

analysis_p2p(
models=[
'NEMO',
'MEDUSA',
],
jobID=jobID,
years=[
year,
], #'2075','2076',
modelGrid='eORCA1',
annual=True,
noPlots=False,
analysisSuite=analysisSuite,
)
analysis_p2p(
models=[
'NEMO',
'MEDUSA',
],
jobID=jobID,
years=[
year,
], #'2075','2076',
modelGrid='eORCA1',
annual=True,
noPlots=False,
analysisSuite=[suite,
],
)


print('analysis_p2p:', jobID, year, suite)
single_p2p(jobID, suite, year)

print("Finished p2p... ")


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion bgcval2/analysis_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4991,7 +4991,7 @@ def main():
"Will proceed with defaults.")
config_user = None

for jobID, suite in itertools.product(keys, jobIDs):
for jobID, suite in itertools.product(jobIDs, keys):
analysis_timeseries(
jobID=jobID,
analysisSuite=suite,
Expand Down
Loading