diff --git a/src/pypromice/process/aws.py b/src/pypromice/process/aws.py index ec872009..0d830f34 100644 --- a/src/pypromice/process/aws.py +++ b/src/pypromice/process/aws.py @@ -118,7 +118,7 @@ def getL3(self): # logger.info('Resampling to hour') # return resampled - def writeArr(self, dataset, outpath): + def writeArr(self, dataset, outpath, t=None): '''Write L3 data to .nc and .csv hourly and daily files Parameters @@ -128,13 +128,19 @@ def writeArr(self, dataset, outpath): outpath : str Output directory t : str - Resampling string + Resampling string. This is automatically defined based + on the data type if not given. The default is None. ''' - f = [l.attrs['format'] for l in self.L0] - if 'raw' in f or 'STM' in f: - write.prepare_and_write(dataset, outpath, self.vars, self.meta, '10min') + if t is not None: + write.prepare_and_write(dataset, outpath, self.vars, self.meta, t) else: - write.prepare_and_write(dataset, outpath, self.vars, self.meta, '60min') + f = [l.attrs['format'] for l in self.L0] + if 'raw' in f or 'STM' in f: + write.prepare_and_write(dataset, outpath, self.vars, + self.meta, '10min') + else: + write.prepare_and_write(dataset, outpath, self.vars, + self.meta, '60min') # def addAttributes(self, dataset): # '''Add variable and attribute metadata diff --git a/src/pypromice/process/get_l2.py b/src/pypromice/process/get_l2.py index a29b2e48..bc63dd9b 100644 --- a/src/pypromice/process/get_l2.py +++ b/src/pypromice/process/get_l2.py @@ -3,8 +3,6 @@ from argparse import ArgumentParser import pypromice from pypromice.process.aws import AWS -from pypromice.process.write import prepare_and_write -from pypromice.process.load import getVars, getMeta def parse_arguments_l2(): parser = ArgumentParser(description="AWS L2 processor") @@ -19,6 +17,8 @@ def parse_arguments_l2(): required=False, help='File path to variables look-up table') parser.add_argument('-m', '--metadata', default=None, type=str, required=False, help='File path to metadata') + parser.add_argument('-t', '--time', default=None, type=str, + required=False, help='Resampling frequency') args = parser.parse_args() return args @@ -59,10 +59,7 @@ def get_l2(): if args.outpath is not None: if not os.path.isdir(args.outpath): os.mkdir(args.outpath) - if aws.L2.attrs['format'] == 'raw': - prepare_and_write(aws.L2, args.outpath, getVars(), getMeta(), '10min') - prepare_and_write(aws.L2, args.outpath, getVars(), getMeta(), '60min') - + aws.writeArr(aws.L2, args.outpath, args.time) if __name__ == "__main__": get_l2() diff --git a/src/pypromice/process/get_l3.py b/src/pypromice/process/get_l3.py index eccdab1a..688ada59 100644 --- a/src/pypromice/process/get_l3.py +++ b/src/pypromice/process/get_l3.py @@ -17,6 +17,8 @@ def parse_arguments_l3(): required=False, help='File path to variables look-up table') parser.add_argument('-m', '--metadata', default=None, type=str, required=False, help='File path to metadata') + parser.add_argument('-t', '--time', default=None, type=str, + required=False, help='Resampling frequency') args = parser.parse_args() return args @@ -54,9 +56,11 @@ def get_l3(): aws.getL2() aws.getL3() - # Write out Level 3 + # Write out level 3 if args.outpath is not None: - aws.writeL3(args.outpath) + if not os.path.isdir(args.outpath): + os.mkdir(args.outpath) + aws.writeArr(aws.L3, args.outpath, args.time) if __name__ == "__main__": get_l3()