def load_from_template(cls):
     """
     extension: create a ModelInputData from the template files
     input: None
     output: ModelInputData
     """
     filedict = get_filedict(cls.__name__)
     for record in filedict.values():
         source = record['template']
         dest = record['actual']
         ncf.copy_compress(source, dest)
     return cls()
 def load_from_archive(cls, dirname):
     """
     extension: create a SensitivityData from previous archived files.
     input: string (path/to/file)
     output: SensitivityData
     """
     pathname = os.path.realpath(dirname)
     assert os.path.isdir(pathname), 'dirname must be an existing directory'
     filedict = get_filedict(cls.__name__)
     for record in filedict.values():
         source = os.path.join(pathname, record['archive'])
         dest = record['actual']
         ncf.copy_compress(source, dest)
     return cls()
 def load_from_archive(cls, dirname):
     """
     extension: create a ModelOutputData from previous archived files
     input: string (path/to/file)
     output: ModelOutputData
     
     notes: this function assumes the filenames match archive default names
     """
     pathname = os.path.realpath(dirname)
     assert os.path.isdir(pathname), 'dirname must be an existing directory'
     filedict = get_filedict(cls.__name__)
     for record in filedict.values():
         source = os.path.join(pathname, record['archive'])
         dest = record['actual']
         ncf.copy_compress(source, dest)
     return cls()
 def archive(self, dirname=None):
     """
     extension: save copy of files to archive/experiment directory
     input: string or None
     output: None
     
     notes: this will overwrite any clash of namespace.
     if input is None file will write to experiment directory
     else it will create dirname in experiment directory and save there.
     """
     save_path = get_archive_path()
     if dirname is not None:
         save_path = os.path.join(save_path, dirname)
     ensure_path(save_path, inc_file=False)
     for record in self.file_data.values():
         source = record['actual']
         dest = os.path.join(save_path, record['archive'])
         ncf.copy_compress(source, dest)
     return None
Exemple #5
0
    sense_lay = int(ncf.get_attr(icon_file, 'NLAYS'))
    cmaq_config.sense_emis_lays = str(sense_lay)

# generate sample files by running 1 day of cmaq (fwd & bwd)
cmaq_handle.wipeout_fwd()
cmaq_handle.run_fwd_single(dt.start_date, is_first=True)
# make force file with same attr as conc and all data zeroed
conc_spcs = ncf.get_attr(conc_file, 'VAR-LIST').split()
conc_data = ncf.get_variable(conc_file, conc_spcs)
force_data = {k: np.zeros(v.shape) for k, v in conc_data.items()}
ncf.create_from_template(conc_file, force_file, force_data)
cmaq_handle.run_bwd_single(dt.start_date, is_first=True)

# create record for icon & emis files
fh.ensure_path(os.path.dirname(template.icon))
ncf.copy_compress(icon_file, template.icon)
for date in dt.get_datelist():
    emis_src = dt.replace_date(cmaq_config.emis_file, date)
    emis_dst = dt.replace_date(template.emis, date)
    fh.ensure_path(os.path.dirname(emis_dst))
    ncf.copy_compress(emis_src, emis_dst)

# create template for conc, force & sense files
fh.ensure_path(os.path.dirname(template.conc))
fh.ensure_path(os.path.dirname(template.force))
fh.ensure_path(os.path.dirname(template.sense_emis))
fh.ensure_path(os.path.dirname(template.sense_conc))
ncf.copy_compress(conc_file, template.conc)
ncf.copy_compress(force_file, template.force)
ncf.copy_compress(sense_emis_file, template.sense_emis)
ncf.copy_compress(sense_conc_file, template.sense_conc)