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 ui for neon script #1467

Merged
merged 73 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
6b35998
improve ui for neon script
jedwards4b Aug 18, 2021
73a4164
fix run_length issues
jedwards4b Aug 19, 2021
eaa0e0e
do not use mpi-serial
jedwards4b Aug 19, 2021
231658f
update surface files
jedwards4b Aug 20, 2021
0010273
more run_neon improvements
jedwards4b Aug 23, 2021
9c67f30
changes prompeted by code review
jedwards4b Aug 24, 2021
68b0059
initialize base_case_root
jedwards4b Aug 24, 2021
e5ecb46
add --setup-only and --no-batch options
jedwards4b Aug 24, 2021
39d46e7
rename neon upload script and add history file upload to it
jedwards4b Aug 24, 2021
4d0b046
sort available site list
jedwards4b Aug 25, 2021
8e145cd
dont use UNSET for data downloads
jedwards4b Aug 25, 2021
234bf61
update with corrected start dates and new surface files
jedwards4b Aug 26, 2021
d28115c
update cdeps and comments
jedwards4b Aug 26, 2021
098501d
add user_nl_datm_streams to neon defaults
jedwards4b Aug 31, 2021
8d90743
interpolate missing values, fix organic calculations.
negin513 Aug 31, 2021
cdc3a5e
clean ups and adding comments.
negin513 Aug 31, 2021
11cb158
clean up formattings.
negin513 Aug 31, 2021
955afec
more cleanups
negin513 Aug 31, 2021
d8d9af8
update surfdata files
jedwards4b Aug 31, 2021
1770da5
update cdeps external
jedwards4b Sep 1, 2021
f8bfd17
add a rerun option
jedwards4b Sep 2, 2021
235f524
explicitly check_input_data in script
jedwards4b Sep 7, 2021
4a0373f
Update cime to a hash on Jim's branch
ekluzek Sep 7, 2021
3af0b34
Merge commit '4a0373ff5' into jedwards/neon_updates
ekluzek Sep 7, 2021
b5661af
Update cime to latest tag with the needed update in it
ekluzek Sep 9, 2021
a82688c
Correct CIME org
ekluzek Sep 13, 2021
93dd98d
Merge tag 'ctsm5.1.dev057' into jedwards/neon_updates
ekluzek Sep 20, 2021
7527f6d
Merge tag 'ctsm5.1.dev057' into neon_modify_dev_0831
ekluzek Sep 20, 2021
b53c809
Merge branch 'neon_modify_dev_0831' into jedwards/neon_updates
ekluzek Sep 20, 2021
25ab14f
update ndep file for NEON
jedwards4b Sep 30, 2021
aa95f0d
Merge branch 'jedwards/neon_updates' of github.com:jedwards4b/ctsm in…
jedwards4b Sep 30, 2021
99f7812
reduce stdout volume by changing default to --silent
jedwards4b Oct 5, 2021
7b352c6
improve overwrite logic
jedwards4b Oct 12, 2021
157a2ef
clean up debug statements
jedwards4b Oct 12, 2021
5afa96c
updates regarding organic and other changes
negin513 Nov 2, 2021
bd92fd4
updates for the ag sites
negin513 Nov 2, 2021
99a85fe
quick changes that should be done for this PR to work.
negin513 Nov 2, 2021
b807e8e
very simple wrapper for creating and modifying all neon sites at once.
negin513 Nov 2, 2021
91edfeb
just a quick change for estimated_oc round up issue.
negin513 Nov 2, 2021
c9a99ec
Merge tag 'ctsm5.1.dev063' into jedwards/neon_updates
ekluzek Nov 23, 2021
a0349e3
Merge tag 'ctsm5.1.dev064' into jedwards/neon_updates
ekluzek Nov 30, 2021
8b514dc
Merge tag 'ctsm5.1.dev064' into neon_modify_surf
ekluzek Nov 30, 2021
5444c1d
Merge tag 'ctsm5.1.dev065' into neon_modify_dev_0831
ekluzek Dec 2, 2021
fb2a152
Merge remote-tracking branch 'jed/jedwards/neon_updates' into neon_mo…
negin513 Dec 2, 2021
0d69139
Small update with running through black
ekluzek Dec 3, 2021
7178ea3
Merge remote-tracking branch 'negin513/neon_modify_dev_0831' into jed…
ekluzek Dec 3, 2021
405ccbb
Merge remote-tracking branch 'negin513/neon_modify_dev_0831' into neo…
ekluzek Dec 3, 2021
a106275
Run modify_singlept_site_neon.py through black
ekluzek Dec 3, 2021
2b5bc4c
LILAC build: change --esmf-lib-path to --esmf-mkfile-path
billsacks Dec 6, 2021
bb2181c
Merge remote-tracking branch 'escomp/master' into lilac_fix_userdefined
billsacks Dec 6, 2021
06c99c6
Get lilac user-defined machine build working with latest cime
billsacks Dec 7, 2021
b917e02
Merge branch 'neon_modify_surf' into jedwards/neon_updates
ekluzek Dec 7, 2021
9963e46
Update to cesm2_3_alpha07c externals
ekluzek Dec 9, 2021
4c1b355
Switch out glob for bsd_glog because it's being removed in newer perl…
ekluzek Dec 9, 2021
9f767fa
Add one to the number of skip steps as required by the new CAM config…
ekluzek Dec 9, 2021
fda1569
Merge tag 'ctsm5.1.dev066' into jedwards/neon_updates
ekluzek Dec 9, 2021
9c4c0d6
Merge remote-tracking branch 'billsacks/lilac_fix_userdefined' into j…
ekluzek Dec 9, 2021
3d16070
Add a target to the makefile to run the python code through black
ekluzek Dec 9, 2021
5f00876
Update cmeps to version which allows channel depths to be passed
ekluzek Dec 9, 2021
a06a059
Get balance check unit test on skip steps working with change in skip…
ekluzek Dec 10, 2021
abb3b30
Change the call of black from a reformat to a check, incldue the main…
ekluzek Dec 10, 2021
b407a37
updated neon surface dataset
negin513 Dec 11, 2021
411c321
Update last year to 2020 as we have data through the end of 2020 now
ekluzek Dec 11, 2021
bee0da5
Merge remote-tracking branch 'negin513/neon_modify_surf' into jedward…
ekluzek Dec 11, 2021
304990b
Merge branch 'jedwards/neon_updates' of github.com:jedwards4b/CTSM in…
ekluzek Dec 11, 2021
abe76e9
Remove tests from the test lists that were removed from the master list
ekluzek Dec 11, 2021
e9953fc
Remove smf tests from tests lists as they have been removed from the …
ekluzek Dec 11, 2021
e043f53
Add note about running a baseline compare case
ekluzek Dec 11, 2021
9afbad8
Move explicit settings for black and list of includes and excludes to…
ekluzek Dec 11, 2021
07214b4
Change stop statements into calls to abort() so that they will pass a…
ekluzek Dec 12, 2021
6ef9999
Replace SCRIP grid file and mapping files for 1x1_brazil as they had …
ekluzek Dec 12, 2021
a5b873a
Start updating the Change files
ekluzek Dec 13, 2021
ae1a023
Update of Change files
ekluzek Dec 13, 2021
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 bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4254,7 +4254,7 @@ sub check_input_files {
my $pathname = $nl->get_variable_value($group, $var);
# Need to strip the quotes
$pathname =~ s/['"]//g;

next if ($pathname =~ /UNSET$/);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekluzek The change here is to prevent variables marked as UNSET being listed in the ctsm.input_data_list - this should avoid the problem in #1198 wrt fatmlndfrc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a good start. I'd also like it to not show up in the namelist, as having a file set to "$DIN_LOC_DIR/UNSET" is confusing and looks wrong. I'll likely work on this in addition to what you are doing here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also did work in 017a7ed to prevent blank files being listed. I think @jedwards4b is also a good protection although I think it really should trigger an error because something is screwy if you have a namelist item set to UNSET.

The comment that generated this was...

#1198 (comment)

if ($input_pathname_type eq 'abs') {
if ($inputdata_rootdir) {
#MV $pathname =~ s:$inputdata_rootdir::;
Expand Down
2 changes: 1 addition & 1 deletion cime_config/usermods_dirs/NEON/defaults/user_nl_clm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
!----------------------------------------------------------------------------------

flanduse_timeseries = ' ' ! This isn't needed for a non transient case, but will be once we start using transient compsets
fsurdat = "$DIN_LOC_ROOT/lnd/clm2/surfdata_map/NEON/surfdata_hist_78pfts_CMIP6_simyr2000_${NEONSITE}_c210720.nc"
fsurdat = "$DIN_LOC_ROOT/lnd/clm2/surfdata_map/NEON/surfdata_hist_78pfts_CMIP6_simyr2000_${NEONSITE}_c210805.nc"
model_year_align_urbantv = 2018
stream_year_first_urbantv = 2018
stream_year_last_urbantv = 2019
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want ndep and popdens to update to the last year of the simulation (or at least the spinup)? this would be 2020 for spinup and 2021 for transient cases. How do we keep updating this moving forward?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedwards4b do these get updated somehow below?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wwieder these don't get autoupdated by any means. Right now the only way to change it is to keep changing the last year in this file (or in each case run). The last year update could also be handedl in run_neon.py though. I don't know that's any better though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now, but as we move to making more of the real-time hindcasts they should be updated for new years of data? Updating urban likely ins't too important and for short runs the deposition files shouldn't changethat much?

Expand Down
173 changes: 173 additions & 0 deletions tools/site_and_regional/neon_s3_upload
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#! /usr/bin/env python3
"""
Script to rename and upload NEON site finidat files for use in transient startup cases

"""

import os, sys
# Get the ctsm util tools and then the cime tools.
_CTSM_PYTHON = os.path.abspath(os.path.join(os.path.dirname(__file__), "..","..",'python'))
sys.path.insert(1, _CTSM_PYTHON)

import boto3
from botocore.exceptions import ClientError
import glob
import datetime
from ctsm import add_cime_to_path
from ctsm.path_utils import path_to_ctsm_root
from standard_script_setup import *
from CIME.case import Case
from CIME.utils import expect, safe_copy

logger = logging.getLogger(__name__)

def get_parser(args, description, valid_neon_sites):
"""
Get Parser object for this script
"""
parser = argparse.ArgumentParser(description=description,
formatter_class=argparse.RawDescriptionHelpFormatter)

CIME.utils.setup_standard_logging_options(parser)

parser.print_usage = parser.print_help

parser.add_argument('--neon-sites',
help='4-letter neon site code.',
action="store",
required=False,
choices=valid_neon_sites + ['all'],
dest="neon_sites",
default=["OSBS"],
nargs='+')

parser.add_argument('--output-root',
help='''
Root Directory of case results
[default: %(default)s]
''',
action="store",
dest="output_root",
type =str,
required=False,
default=os.getcwd())

parser.add_argument('--file-date',
help='''
Date of ctsm restart file(s) to upload
''',
action="store",
dest="file_date",
required = False,
type = datetime.date.fromisoformat,
default = datetime.datetime.strptime("0268-01-01",'%Y-%m-%d'))


parser.add_argument('--upload-finidat',
help='''
Upload the final restart files from the end of the postad run for each site.
''',
action="store_true",
dest="upload_finidat",
required = False,
default = False)

parser.add_argument('--upload-history',
help='''
Upload the transient run h1 history files for each site.
''',
action="store_true",
dest="upload_history",
required = False,
default = False)



args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)

if 'all' in args.neon_sites:
neon_sites = valid_neon_sites
else:
neon_sites = args.neon_sites
for site in neon_sites:
if site not in valid_neon_sites:
raise ValueError("Invalid site name {}".format(site))

expect(args.upload_finidat or args.upload_history,"Must specify at least one of --upload-finidat or --upload-history")

return neon_sites, args.output_root, args.file_date, args.upload_finidat, args.upload_history

def upload_file(file_name, bucket, object_name=None):
"""Upload a file to an S3 bucket

:param file_name: File to upload
:param bucket: Bucket to upload to
:param object_name: S3 object name. If not specified then file_name is used
:return: True if file was uploaded, else False
"""

# If S3 object_name was not specified, use file_name
if object_name is None:
object_name = os.path.basename(file_name)

# Upload the file
s3_client = boto3.client('s3')
try:
logger.info("Uploading file {} to {}".format(file_name, object_name))
response = s3_client.upload_file(file_name, bucket, object_name)
except ClientError as e:
logger.error(e)
return False
return True

def main(description):
"""
For each site in the site_list find the site.postad run directory and grab the latest clm restart file
from there,
"""

if not os.path.isfile(os.path.join(os.getenv("HOME"),".aws","credentials")):
raise FileNotFoundError("User account must have valid aws credentials to run this script.")

cesmroot = path_to_ctsm_root()
# Get the list of supported neon sites from usermods
valid_neon_sites = glob.glob(os.path.join(cesmroot,"cime_config","usermods_dirs","NEON","[!d]*"))
valid_neon_sites = [v.split('/')[-1] for v in valid_neon_sites]
filedatestamp = datetime.datetime.now().date()
site_list, output_root, file_date, upload_finidat, upload_history = get_parser(sys.argv, description, valid_neon_sites)
for site in site_list:
rundir = None
if upload_finidat:
logger.info("Upload finidat for {}".format(site))
case_path = os.path.join(output_root, site+".postad")
if os.path.isdir(case_path):
with Case(case_path) as case:
rundir = case.get_value("RUNDIR")
basefile = site+".postad.clm2.r.{}-00000.nc".format(file_date.strftime("%4Y-%m-%d"))
finidat_file = os.path.join(rundir,basefile)
if not os.path.isfile(finidat_file):
logger.warning("Could not find file {}".format(finidat_file))
continue
newfile = basefile.replace(".postad.",".{}.".format(filedatestamp))

upload_file(finidat_file, 'neon-ncar-transfer', os.path.join("NEON","lnd","ctsm","initdata",newfile))
if upload_history:
logger.info("Upload history for {}".format(site))
case_path = os.path.join(output_root, site+".transient")
if not os.path.isdir(case_path):
logger.warning("No case found in {}".format(case_path))
continue
with Case(case_path) as case:
archive_dir = os.path.join(case.get_value("DOUT_S_ROOT"),"lnd","hist")
for histfile in glob.iglob(archive_dir + "/*.h1.*"):
newfile = os.path.basename(histfile)
upload_file(histfile, 'neon-ncar-transfer', os.path.join("NEON","archive",site,"lnd","hist",newfile))






if __name__ == "__main__":
main(__doc__)

Loading