diff --git a/src/compo/mopitt_co_nc2ioda.py b/src/compo/mopitt_co_nc2ioda.py index c247d4df5..bb1374d92 100755 --- a/src/compo/mopitt_co_nc2ioda.py +++ b/src/compo/mopitt_co_nc2ioda.py @@ -54,8 +54,9 @@ class mopitt(object): - def __init__(self, filenames): + def __init__(self, filenames, time_range): self.filenames = filenames + self.time_range = time_range self.varDict = defaultdict(lambda: defaultdict(dict)) self.outdata = defaultdict(lambda: DefaultOrderedDict(OrderedDict)) self.varAttrs = DefaultOrderedDict(lambda: DefaultOrderedDict(dict)) @@ -151,7 +152,15 @@ def _read(self): ap_tc = ap_tc.astype('float32') # set flag: rule out all anomalous data - flg = qa == 0 + qaf = qa == 0 + + # date range to fit DA window + date_start = datetime.strptime(self.time_range[0], "%Y%m%d%H") + date_end = datetime.strptime(self.time_range[1], "%Y%m%d%H") + date_list = [datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ") for date in times] + tsf = [(date_i >= date_start) & (date_i < date_end) for date_i in date_list] + + flg = np.logical_and(qaf, tsf) if first: # add metadata variables @@ -230,10 +239,18 @@ def main(): help="path of IODA output file", type=str, required=True) + optional = parser.add_argument_group(title='optional arguments') + optional.add_argument( + '-r', '--time_range', + help="extract a date range to fit the data assimilation window" + "format -r YYYYMMDDHH YYYYMMDDHH", + type=str, metavar=('begindate', 'enddate'), nargs=2, + default=('1970010100', '2170010100')) + args = parser.parse_args() # Read in the MOPITT CO data - co = mopitt(args.input) + co = mopitt(args.input, args.time_range) # setup the IODA writer writer = iconv.IodaWriter(args.output, locationKeyList, DimDict) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8bbc060ba..5ad87193b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -893,7 +893,8 @@ ecbuild_add_test( TARGET test_${PROJECT_NAME}_mopitt_co netcdf "${Python3_EXECUTABLE} ${CMAKE_BINARY_DIR}/bin/mopitt_co_nc2ioda.py -i testinput/mopitt_co.he5 - -o testrun/mopitt_co.nc" + -o testrun/mopitt_co.nc + -r 2021092903 2021092921" mopitt_co.nc ${IODA_CONV_COMP_TOL_ZERO}) ecbuild_add_test( TARGET test_${PROJECT_NAME}_modis_aod diff --git a/test/testoutput/mopitt_co.nc b/test/testoutput/mopitt_co.nc index 4a4b12dab..33cccafeb 100644 --- a/test/testoutput/mopitt_co.nc +++ b/test/testoutput/mopitt_co.nc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3a6c239fbb5b72df4ba40a0f3fd534e485569b60f5d4e2e84bc239cd90bd230a -size 210375 +oid sha256:5a5703deff298e440fb7f4349a4d8585335d16b3d9b9e0e141f4927ac3f42ab4 +size 171846