def main(output_path, delta, ncml_file=None, glob_string=None, apply_to_members=None, hard_start=None, hard_end=None): if glob_string is not None: collection = Collection.from_glob(glob_string, ncml=ncml_file) elif ncml_file is not None: collection = Collection.from_ncml_file(ncml_file, apply_to_members=apply_to_members) if delta.years > 0: starting = collection.aggregation.starting.replace(microsecond=0, second=0, minute=0, hour=0, day=1, month=1) elif delta.months > 0: starting = collection.aggregation.starting.replace(microsecond=0, second=0, minute=0, hour=0, day=1) elif delta.days > 0: starting = collection.aggregation.starting.replace(microsecond=0, second=0, minute=0, hour=0) windows = collection.bins(delta=delta, starting=starting, hard_start=hard_start, hard_end=hard_end) # Create output directory if not os.path.exists(output_path): os.makedirs(output_path) for i, window in enumerate(windows): # Create a file name starting = window.starting.strftime("%Y%m%dT%H%M") ending = window.ending.strftime("%Y%m%dT%H%M") if starting == ending: file_name = "{0}.nc".format(starting) else: file_name = "{0}_TO_{1}.nc".format(starting, ending) output_file = os.path.join(output_path, file_name) pyaxiomlogger.info("Combining ({0}/{1}) - {2} files into {3}".format(i+1, len(windows), len(window.members), output_file)) Collection.combine(members=window.members, output_file=output_file) return 0
def test_combine_with_dimension(self): output_file = tempfile.NamedTemporaryFile().name print output_file members = [ m.path for m in self.c.aggregation.members ] Collection.combine(members=members, output_file=output_file, dimension='time') self.assertTrue(os.path.isfile(output_file)) os.remove(output_file)
def test_combine_with_dimension(self): output_file = tempfile.NamedTemporaryFile().name members = [m.path for m in self.c.aggregation.members] Collection.combine(members=members, output_file=output_file, dimension='time') self.assertTrue(os.path.isfile(output_file)) os.remove(output_file)
def main(output_path, delta, ncml_file=None, glob_string=None, apply_to_members=None, hard_start=None, hard_end=None): if glob_string is not None: collection = Collection.from_glob(glob_string, ncml=ncml_file) elif ncml_file is not None: collection = Collection.from_ncml_file( ncml_file, apply_to_members=apply_to_members) if delta.years > 0: starting = collection.aggregation.starting.replace(microsecond=0, second=0, minute=0, hour=0, day=1, month=1) elif delta.months > 0: starting = collection.aggregation.starting.replace(microsecond=0, second=0, minute=0, hour=0, day=1) elif delta.days > 0: starting = collection.aggregation.starting.replace(microsecond=0, second=0, minute=0, hour=0) windows = collection.bins(delta=delta, starting=starting, hard_start=hard_start, hard_end=hard_end) # Create output directory if not os.path.exists(output_path): os.makedirs(output_path) for i, window in enumerate(windows): # Create a file name starting = window.starting.strftime("%Y%m%dT%H%M") ending = window.ending.strftime("%Y%m%dT%H%M") if starting == ending: file_name = "{0}.nc".format(starting) else: file_name = "{0}_TO_{1}.nc".format(starting, ending) output_file = os.path.join(output_path, file_name) pyaxiomlogger.info("Combining ({0}/{1}) - {2} files into {3}".format( i + 1, len(windows), len(window.members), output_file)) Collection.combine(members=window.members, output_file=output_file) return 0
def test_combine_with_dimension_and_stride(self): output_file = tempfile.NamedTemporaryFile().name members = [m.path for m in self.c.aggregation.members] Collection.combine(members=members, output_file=output_file, dimension='time', start_index=1, stop_index=6, stride=2) self.assertTrue(os.path.isfile(output_file)) os.remove(output_file)
def setUp(self): glob_string = os.path.join(os.path.dirname(__file__), "resources/coamps/cencoos_4km/wnd_tru/**/*.nc") ncml = """<?xml version="1.0" encoding="UTF-8"?> <netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2"> <attribute name="title" value="changed" /> </netcdf> """ self.c = Collection.from_glob(glob_string, ncml=ncml)
def setUp(self): glob_string = os.path.join( os.path.dirname(__file__), "resources/coamps/cencoos_4km/wnd_tru/**/*.nc") ncml = """<?xml version="1.0" encoding="UTF-8"?> <netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2"> <attribute name="title" value="changed" /> </netcdf> """ self.c = Collection.from_glob(glob_string, ncml=ncml)
def setUp(self): glob_string = os.path.join( os.path.dirname(__file__), "resources/coamps/cencoos_4km/wnd_tru/10m/*.nc") self.c = Collection.from_glob(glob_string)
def setUp(self): input_folder = os.path.join( os.path.dirname(__file__), "resources/coamps/cencoos_4km/wnd_tru/10m/") self.c = Collection.from_directory(input_folder, apply_to_members=False)
def test_combine_passing_members(self): output_file = tempfile.NamedTemporaryFile().name Collection.combine(members=self.c.aggregation.members, output_file=output_file) self.assertTrue(os.path.isfile(output_file)) os.remove(output_file)
def setUp(self): input_ncml = os.path.join(os.path.dirname(__file__), "resources/coamps_10km_wind.ncml") self.c = Collection.from_ncml_file(input_ncml)
def setUp(self): glob_string = os.path.join(os.path.dirname(__file__), "resources/coamps/cencoos_4km/wnd_tru/10m/*.nc") self.c = Collection.from_glob(glob_string)
def setUp(self): input_folder = os.path.join(os.path.dirname(__file__), "resources/coamps/cencoos_4km/wnd_tru/10m/") self.c = Collection.from_directory(input_folder, apply_to_members=False)
def test_combine_with_dimension_and_stride(self): output_file = tempfile.NamedTemporaryFile().name members = [ m.path for m in self.c.aggregation.members ] Collection.combine(members=members, output_file=output_file, dimension='time', start_index=1, stop_index=6, stride=2) self.assertTrue(os.path.isfile(output_file)) os.remove(output_file)