Skip to content
Merged
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
49 changes: 28 additions & 21 deletions src/marine/argoClim2ioda.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import ioda_conv_engines as iconv
from orddicts import DefaultOrderedDict


class argoClim(object):

def __init__(self, filename, begindate=None, enddate=None):
Expand Down Expand Up @@ -67,9 +67,12 @@ def _readData(self):
assert self.varname in ['TEMPERATURE', 'SALINITY'],\
"%s is not a valid variable name" % self.varname

self.varname2 = 'waterTemperature'

lon = nc.variables['LONGITUDE'][:]
lat = nc.variables['LATITUDE'][:]
pres = nc.variables['PRESSURE'][:]
pres = nc.variables['PRESSURE'][:] #pressure in decibar
depth = pres #1 decibar = 1 meter, so you can use pressure as depth

# Get absolute time instead of time since epoch
dtime = nc.variables['TIME']
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The input file testinput/argoclim_test.nc already has the variable TIME with an attribute for units set to months since 2004-01-01 00:00:00. IODA cannot really handle the months since yet and would really need seconds since but it could be possible to bypass a lot of date manipulation happening inside this code with some potential manipulations of the Epoch and values in TIME to conform to IODA. Perhaps we can leave this alone right now, but I see potential for beneficial changes in this area.

Expand Down Expand Up @@ -100,9 +103,10 @@ def _readData(self):
time = timeArray[bI:eI]

mean = nc.variables['ARGO_%s_MEAN' % self.varname][:]
meanK = [x+273.15 for x in mean]

# create a full field from mean and anomaly
fullField = anomaly + np.tile(mean, (anomaly.shape[0], 1, 1, 1))
fullField = anomaly + np.tile(meanK, (anomaly.shape[0], 1, 1, 1))

try:
nc.close()
Expand All @@ -115,7 +119,7 @@ def _readData(self):
self.data = {}
self.data['lat'] = lat
self.data['lon'] = lon
self.data['pres'] = pres
self.data['depth'] = depth
self.data['time'] = time
self.data['field'] = fullField.data

Expand All @@ -137,8 +141,8 @@ def __init__(self, filename, date, argo):
self.locKeyList = [
("latitude", "float"),
("longitude", "float"),
("pressure", "float"),
("datetime", "string")
("depthBelowWaterSurface", "float"),
("dateTime", "string")
]

self.GlobalAttrs = {
Expand All @@ -149,17 +153,17 @@ def __init__(self, filename, date, argo):
self.data = DefaultOrderedDict(lambda: DefaultOrderedDict(dict))
self.varAttrs = DefaultOrderedDict(lambda: DefaultOrderedDict(dict))

valKey = argo.varname, iconv.OvalName()
errKey = argo.varname, iconv.OerrName()
qcKey = argo.varname, iconv.OqcName()
valKey = argo.varname2, iconv.OvalName()
errKey = argo.varname2, iconv.OerrName()
qcKey = argo.varname2, iconv.OqcName()

# There has to be a better way than explicitly looping over 4! dimensions
for t, time in enumerate(argo.data['time']):
for y, lat in enumerate(argo.data['lat']):
for x, lon in enumerate(argo.data['lon']):
for z, pres in enumerate(argo.data['pres']):
for z, depth in enumerate(argo.data['depth']):

locKey = lat, lon, pres, time.strftime('%Y-%m-%dT%H:%M:%SZ')
locKey = lat, lon, depth, time.strftime('%Y-%m-%dT%H:%M:%SZ')

val = argo.data['field'][t, z, y, x]
err = 0.
Expand All @@ -169,21 +173,24 @@ def __init__(self, filename, date, argo):
self.data[locKey][errKey] = err
self.data[locKey][qcKey] = qc

self.varAttrs[argo.varname, iconv.OvalName()]['_FillValue'] = -999.
self.varAttrs[argo.varname, iconv.OerrName()]['_FillValue'] = -999.
self.varAttrs[argo.varname, iconv.OqcName()]['_FillValue'] = -999
self.varAttrs[argo.varname, iconv.OvalName()]['units'] = 'degree_C'
self.varAttrs[argo.varname, iconv.OerrName()]['units'] = 'degree_C'
self.varAttrs[argo.varname, iconv.OqcName()]['units'] = 'unitless'
self.varAttrs[argo.varname2, iconv.OvalName()]['_FillValue'] = -999.
self.varAttrs[argo.varname2, iconv.OerrName()]['_FillValue'] = -999.
self.varAttrs[argo.varname2, iconv.OqcName()]['_FillValue'] = -999
self.varAttrs[argo.varname2, iconv.OvalName()]['units'] = 'K'
self.varAttrs[argo.varname2, iconv.OerrName()]['units'] = 'K'
self.varAttrs['depthBelowWaterSurface', 'MetaData']['units'] = 'm'


# Extract obs
ObsVars, nlocs = iconv.ExtractObsData(self.data, self.locKeyList)
DimDict = {'nlocs': nlocs}
ObsVars, Location = iconv.ExtractObsData(self.data, self.locKeyList)
DimDict = {'Location': Location
}
varDims = {
'TEMPERATURE': ['nlocs']
'waterTemperature': ['Location']
}
# Set up IODA writer
self.writer = iconv.IodaWriter(self.filename, self.locKeyList, DimDict)

# Write out observations
self.writer.BuildIoda(ObsVars, varDims, self.varAttrs, self.GlobalAttrs)

Expand Down Expand Up @@ -227,7 +234,7 @@ def main():
}

varDims = {
'TEMPERATURE': ['nlocs']
'waterTemperature': ['Location']
Comment thread
gthompsnJCSDA marked this conversation as resolved.
}

IODA(foutput, fdate, argo)
Expand Down
4 changes: 2 additions & 2 deletions test/testoutput/argoclim.nc
Git LFS file not shown