Skip to content

Commit

Permalink
Merge pull request #2 from adrifoster/subsetdata_update
Browse files Browse the repository at this point in the history
Subsetdata update
  • Loading branch information
negin513 authored Jan 3, 2022
2 parents 3cc9fb9 + 2e73d8a commit 782c117
Show file tree
Hide file tree
Showing 8 changed files with 659 additions and 645 deletions.
2 changes: 1 addition & 1 deletion Externals.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ local_path = components/cmeps
required = True

[cdeps]
tag = cdeps0.12.32
tag = cdeps0.12.34
protocol = git
repo_url = https://github.com/ESCOMP/CDEPS.git
local_path = components/cdeps
Expand Down
30 changes: 21 additions & 9 deletions cime_config/config_component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@
This is an advanced flag and should only be used by expert users.</desc>
</entry>

<entry id="CLM_USRDAT_DIR">
<type>char</type>
<default_value>UNSET</default_value>
<group>run_component_ctsm</group>
<file>env_run.xml</file>
<desc>Directory name for user-created surface, landuse, and datm datasets.
This is used as an argument in user_mods namelists (e.g. user_nl_clm,
user_nl_datm_streams) generated with the subset_data script. Users
should modify this variable (in shell_commands or elsewhere) to set the
location of user-created data. The default value is UNSET.</desc>
</entry>

<entry id="CLM_FORCE_COLDSTART">
<type>char</type>
<valid_values>on,off</valid_values>
Expand Down Expand Up @@ -271,19 +283,19 @@
<desc>User mods to apply to specific compset matches. </desc>
</entry>

<entry id="NEONSITE">
<entry id="NEONSITE">
<type>char</type>
<valid_values>
<valid_values>
ABBY,BLAN,CPER,DEJU,GRSM,HEAL,KONA,LENO,NIWO,ONAQ,PUUM,SERC,SRER,TALL,TREE,WOOD,
BARR,BONA,DCFS,DELA,GUAN,JERC,KONZ,MLBS,NOGP,ORNL,RMNP,SJER,STEI,TEAK,UKFS,WREF,
BART,CLBJ,DSNY,HARV,JORN,LAJA,MOAB,OAES,OSBS,SCBI,SOAP,STER,TOOL,UNDE,YELL
</valid_values>
<default_value/>
<group>run_component_ctsm</group>
<file>env_run.xml</file>
<desc>Name of site for NEON tower data</desc>
</entry>
</valid_values>
<default_value/>
<group>run_component_ctsm</group>
<file>env_run.xml</file>
<desc>Name of site for NEON tower data</desc>
</entry>

<help>
=========================================
CLM naming conventions
Expand Down
60 changes: 33 additions & 27 deletions python/ctsm/site_and_regional/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# -- standard libraries
import os
import logging
from collections import namedtuple

from datetime import date
from getpass import getuser
Expand All @@ -19,15 +20,20 @@
# -- import local classes for this script
from ctsm.git_utils import get_git_short_hash

USRDAT_DIR = "CLM_USRDAT_DIR"
logger = logging.getLogger(__name__)

# named tuple for datm input/output files and folder names
DatmFiles = namedtuple(
"DatmFiles",
"indir outdir fdomain_in dir_solar dir_prec dir_tpqw tag_solar tag_prec tag_tpqw name_solar "
"name_prec name_tpqw "
)

class BaseCase:
"""
Parent class to SinglePointCase and RegionalCase
...
Attributes
----------
create_domain : bool
Expand All @@ -38,22 +44,22 @@ class BaseCase:
flag for creating landuse file
create_datm : bool
flag for creating DATM files
create_user_mods
flag for creating a user_mods directory
Methods
-------
create_1d_coord(filename, lon_varname , lat_varname,x_dim , y_dim )
create 1d coordinate variables to enable sel() method
add_tag_to_filename(filename, tag)
add a tag and timetag to a filename ending with
[._]cYYMMDD.nc or [._]YYMMDD.nc
update_metadata(nc)
Class method for adding some new attributes (such as date, username) and
remove the old attributes from the netcdf file.
"""

def __init__(self, create_domain, create_surfdata, create_landuse, create_datm):
def __init__(self, create_domain, create_surfdata, create_landuse, create_datm,
create_user_mods):
"""
Initializes BaseCase with the given arguments.
Expand All @@ -67,26 +73,21 @@ def __init__(self, create_domain, create_surfdata, create_landuse, create_datm):
Flag for creating landuse file a region/single point
create_datmdata : bool
Flag for creating datm files a region/single point
create_user_mods : bool
Flag for creating user mods directories and files for running CTSM
"""
self.create_domain = create_domain
self.create_surfdata = create_surfdata
self.create_landuse = create_landuse
self.create_datm = create_datm
self.create_user_mods = create_user_mods

def __str__(self):
"""
Converts ingredients of the BaseCase to string for printing.
"""
return (
str(self.__class__)
+ "\n"
+ "\n".join(
(
str(item) + " = " + str(self.__dict__[item])
for item in sorted(self.__dict__)
)
)
)
return "{}\n{}".format(str(self.__class__), "\n".join(
("{} = {}".format(str(key), str(self.__dict__[key])) for key in sorted(self.__dict__))))

@staticmethod
def create_1d_coord(filename, lon_varname, lat_varname, x_dim, y_dim):
Expand All @@ -110,7 +111,7 @@ def create_1d_coord(filename, lon_varname, lat_varname, x_dim, y_dim):
f_out (xarray Dataset): Xarray Dataset with 1-d coords
"""
logger.debug("Open file: " + filename)
logger.debug("Open file: %s", filename)
f_in = xr.open_dataset(filename)

# create 1d coordinate variables to enable sel() method
Expand All @@ -125,7 +126,8 @@ def create_1d_coord(filename, lon_varname, lat_varname, x_dim, y_dim):
f_in.close()
return f_out

def update_metadata(self, nc):
@staticmethod
def update_metadata(nc_file):
"""
Class method for adding some new attributes (such as date, username) and
remove the old attributes from the netcdf file.
Expand All @@ -151,27 +153,31 @@ def update_metadata(self, nc):
# get git hash
sha = get_git_short_hash()

nc.attrs["Created_on"] = today_string
nc.attrs["Created_by"] = getuser()
nc.attrs["Created_with"] = os.path.abspath(__file__) + " -- " + sha
nc_file.attrs["Created_on"] = today_string
nc_file.attrs["Created_by"] = getuser()
nc_file.attrs["Created_with"] = os.path.abspath(__file__) + " -- " + sha

# delete unrelated attributes if they exist
del_attrs = [
"source_code",
"SVN_url",
"hostname",
"history" "History_Log",
"history History_Log",
"Logname",
"Host",
"Version",
"Compiler_Optimized",
]
attr_list = nc.attrs
attr_list = nc_file.attrs

for attr in del_attrs:
if attr in attr_list:
logger.debug("This attr should be deleted : " + attr)
del nc.attrs[attr]
logger.debug("This attr should be deleted : %s", attr)
del nc_file.attrs[attr]

# for attr, value in attr_list.items():
# print (attr + " = "+str(value))
@staticmethod
def write_to_file(text, file):
"""
Writes text to a file, surrounding text with \n characters
"""
file.write("\n{}\n".format(text))
Loading

0 comments on commit 782c117

Please sign in to comment.