Skip to content

Commit

Permalink
Merge pull request #792 from EC-Earth/co2box
Browse files Browse the repository at this point in the history
add new component co2box
  • Loading branch information
treerink authored Feb 16, 2024
2 parents e0cf5d7 + ef79450 commit a8b96c0
Show file tree
Hide file tree
Showing 12 changed files with 640 additions and 12 deletions.
16 changes: 16 additions & 0 deletions ece2cmor3/cmor_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def create_cmor_source(attributes, component):
if src is None:
log.error("Could not find a TM5 source variable within attributes %s" % (str(attributes.__dict__)))
result = tm5_source(src)
if component == "co2box":
if src is None:
log.error("Could not find a co2box source variable within attributes %s" % (str(attributes.__dict__)))
result = co2box_source(src)
# if component == NEWCOMPONENT:
# create some source here, if NEWCOMPONENT has nc files as output, the NEMO case can be copied
return result
Expand Down Expand Up @@ -273,3 +277,15 @@ def model_component(self):

def variable(self):
return self.colname_

class co2box_source(cmor_source):

def __init__(self, colname):
super(co2box_source, self).__init__()
self.colname_ = colname

def model_component(self):
return "co2box"

def variable(self):
return self.colname_
22 changes: 22 additions & 0 deletions ece2cmor3/cmor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,28 @@ def get_tm5_interval(filepath):
log.error("Date string in filename %s not supported." % fname)
return start, end

def find_co2box_output(path, expname, varname=None, freq=None):
"""
Finds co2box outputfiles, which consist of varname_freq_expname_date.nc
inputs:
Path (mandatory)
expname (mandatory)
varname (optional)
freq (optional)
output:
list of full paths to files
"""
if expname is None:
expname = "[a-zA-Z0-9]*"
if varname is None:
varname = "[a-zA-Z0-9]*"
if freq is None:
freq = "[a-zA-Z0-9]*"
date = "[0-9]{8}-[0-9]{8}"
rexp = "^%s_%s_%s_%s\.nc$"%(varname,freq,expname,date)
expr = re.compile(rexp)
a = [os.path.join(path, f) for f in os.listdir(path) if re.match(expr, f)]
return [os.path.join(path, f) for f in os.listdir(path) if re.match(expr, f)]

# Writes the ncvar (numpy array or netcdf variable) to CMOR variable with id varid
def netcdf2cmor(varid, ncvar, timdim=0, factor=1.0, term=0.0, psvarid=None, ncpsvar=None, swaplatlon=False,
Expand Down
Loading

0 comments on commit a8b96c0

Please sign in to comment.