예제 #1
0
파일: locate.py 프로젝트: ddkauffman/crds
def locate_dir(instrument, mode=None):
    """Locate the instrument specific directory for a reference file."""
    if mode is  None:
        mode = config.get_crds_ref_subdir_mode(observatory="hst")
    else:
        config.check_crds_ref_subdir_mode(mode)
    crds_refpath = config.get_crds_refpath("hst")
    prefix = get_env_prefix(instrument)
    if mode == "legacy":   # Locate cached files at the appropriate CDBS-style  iref$ locations
        try:
            rootdir = os.environ[prefix]
        except KeyError:
            try:
                rootdir = os.environ[prefix[:-1]]
            except KeyError:
                raise KeyError("Reference location not defined for " + repr(instrument) +
                               ".  Did you configure " + repr(prefix) + "?")
    elif mode == "instrument" and instrument != "synphot":   # use simple names inside CRDS cache.
        rootdir = os.path.join(crds_refpath, instrument)
        refdir = os.path.join(crds_refpath, prefix[:-1])
        if not os.path.exists(refdir):
            if config.writable_cache_or_verbose("Skipping making instrument directory link for", repr(instrument)):
                log.verbose("Creating legacy cache link", repr(refdir), "-->", repr(rootdir))
                with log.verbose_warning_on_exception("Failed creating legacy symlink:", refdir, "-->", rootdir):
                    utils.ensure_dir_exists(rootdir + "/locate_dir.fits")
                    os.symlink(rootdir, refdir)
    elif mode == "instrument" and instrument == "synphot":
        rootdir = os.path.join(crds_refpath, instrument)
    elif mode == "flat":    # use original flat cache structure,  all instruments in same directory.
        rootdir = crds_refpath
    else:
        raise ValueError("Unhandled reference file location mode " + repr(mode))
    return rootdir
예제 #2
0
파일: locate.py 프로젝트: jaytmiller/crds
def locate_dir(instrument, mode=None):
    """Locate the instrument specific directory for a reference file."""
    if mode is  None:
        mode = config.get_crds_ref_subdir_mode(observatory="hst")
    else:
        config.check_crds_ref_subdir_mode(mode)
    crds_refpath = config.get_crds_refpath("hst")
    prefix = get_env_prefix(instrument)
    if mode == "legacy":   # Locate cached files at the appropriate CDBS-style  iref$ locations
        try:
            rootdir = os.environ[prefix]
        except KeyError:
            try:
                rootdir = os.environ[prefix[:-1]]
            except KeyError:
                raise KeyError("Reference location not defined for " + repr(instrument) + 
                               ".  Did you configure " + repr(prefix) + "?")
    elif mode == "instrument" and instrument != "synphot":   # use simple names inside CRDS cache.
        rootdir = os.path.join(crds_refpath, instrument)
        refdir = os.path.join(crds_refpath, prefix[:-1])
        if not os.path.exists(refdir):
            if config.writable_cache_or_verbose("Skipping making instrument directory link for", repr(instrument)):
                log.verbose("Creating legacy cache link", repr(refdir), "-->", repr(rootdir))
                with log.verbose_warning_on_exception("Failed creating legacy symlink:", refdir, "-->", rootdir):
                    utils.ensure_dir_exists(rootdir + "/locate_dir.fits")
                    os.symlink(rootdir, refdir)
    elif mode == "instrument" and instrument == "synphot":
        rootdir = os.path.join(crds_refpath, instrument)        
    elif mode == "flat":    # use original flat cache structure,  all instruments in same directory.
        rootdir = crds_refpath
    else:
        raise ValueError("Unhandled reference file location mode " + repr(mode))
    return rootdir
예제 #3
0
    def rmdir(self, subdir):
        """If it exists, remove `subdir` of the <synphot_dir> specified.

        subdir    string    subdirectory of <synphot_dir> to remove.
        """
        path = os.path.join(self.args.synphot_dir, subdir)
        log.verbose("rmdir: ", repr(path))
        with log.verbose_warning_on_exception("Failed removing", repr(path)):
            shutil.rmtree(path)
예제 #4
0
    def rmdir(self, subdir):
        """If it exists, remove `subdir` of the <synphot_dir> specified.

        subdir    string    subdirectory of <synphot_dir> to remove.
        """
        path = os.path.join(self.args.synphot_dir, subdir)
        log.verbose("rmdir: ", repr(path))
        with log.verbose_warning_on_exception("Failed removing", repr(path)):
            shutil.rmtree(path)        
예제 #5
0
def refpath_to_parkeys(refpath):
    """Given a key for a TpnInfo's list, return the associated required parkeys."""
    from . import locate
    keys = []
    with log.verbose_warning_on_exception("Can't determine parkeys for",
                                          repr(refpath)):
        context = heavy_client.get_context_name("roman")
        p = crds.get_pickled_mapping(context)  # reviewed
        instrument, filekind = locate.get_file_properties(refpath)
        keys = p.get_imap(instrument).get_rmap(filekind).get_required_parkeys()
    return sorted(keys)
예제 #6
0
파일: reftypes.py 프로젝트: oirlab/tmt-crds
 def reference_name_to_tpn_text(self, filename, field="tpn"):
     """Given reference `filename`,  return the text of the corresponding .tpn"""
     instrument, filekind = self.locator.get_file_properties(filename)
     lines = []
     for tpn in reversed(self.get_all_tpn_paths(instrument, filekind,
                                                field)):
         with log.verbose_warning_on_exception("Failed loading tpn",
                                               repr(tpn)):
             label = "From TPN: " + os.path.basename(tpn)
             underline = len(label) * "-"
             lines += [label, underline]
             lines += generic_tpn.load_tpn_lines(tpn)
             lines += [""]
     return "\n".join(lines) + "\n"
예제 #7
0
def _get_fits_datamodel_pairs(header):
    """Return the (FITS, DM) and (DM, FITS) cross strap pairs associated with
    every keyword in `header` as defined by the datamodels interface functions
    defined by the CRDS JWST schema module.
    """
    pairs = []
    from . import schema
    for key in header:
        with log.verbose_warning_on_exception("Failed cross strapping keyword", repr(key)):
            fitskey = schema.dm_to_fits(key) or key
            dmkey = schema.fits_to_dm(key) or key
            pairs.append((fitskey, dmkey))
            pairs.append((dmkey, fitskey))
    log.verbose("Cal code datamodels keyword equivalencies:\n", log.PP(pairs), verbosity=90)
    return pairs
예제 #8
0
def refpath_to_parkeys(refpath):
    """Given a key for a TpnInfo's list, return the associated required parkeys."""
    from . import locate
    keys = []
    with log.verbose_warning_on_exception("Can't determine parkeys for", repr(refpath)):
        context  = heavy_client.get_context_name("jwst")
        p = crds.get_pickled_mapping(context)   # reviewed
        instrument, filekind = locate.get_file_properties(refpath)
        keys = p.get_imap(instrument).get_rmap(filekind).get_required_parkeys()
        # The below turned out to be bad because CRDS-only values aren't in datamodels
        # so in this case the datamodels schema are too narrow for these and will reject
        # e.g. SYSTEM or it's types.
        #         keys.append("META.INSTRUMENT.NAME")
        #         keys.append("META.REFTYPE")
    return sorted(keys)
예제 #9
0
파일: schema.py 프로젝트: jaytmiller/crds
def refpath_to_parkeys(refpath):
    """Given a key for a TpnInfo's list, return the associated required parkeys."""
    from . import locate
    keys = []
    with log.verbose_warning_on_exception("Can't determine parkeys for", repr(refpath)):
        context  = heavy_client.get_context_name("jwst")
        p = crds.get_pickled_mapping(context)   # reviewed
        instrument, filekind = locate.get_file_properties(refpath)
        keys = p.get_imap(instrument).get_rmap(filekind).get_required_parkeys()
        # The below turned out to be bad because CRDS-only values aren't in datamodels
        # so in this case the datamodels schema are too narrow for these and will reject
        # e.g. SYSTEM or it's types.
        #         keys.append("META.INSTRUMENT.NAME")
        #         keys.append("META.REFTYPE")
    return sorted(keys)
예제 #10
0
    def difference(self):
        """Run UNIX diff on two json files named `old_file` and `new_file`.
        If self.pretty_print is True,  reformat the files as temporaries

        Returns:
        0 no differences
        1 some differences
        2 errors
        """
        result, out_err = super(JsonDifferencer, self).diff()
        out_err = out_err.replace(self.remove_files[0], self.old_file)
        out_err = out_err.replace(self.remove_files[1], self.new_file)
        print(out_err, end="")
        if self.pretty_print:
            for fname in self.remove_files:
                with log.verbose_warning_on_exception("Failed removing", repr(fname)):
                    os.remove(fname)
        return result
예제 #11
0
파일: diff.py 프로젝트: jaytmiller/crds
 def difference(self):
     """Run UNIX diff on two json files named `old_file` and `new_file`.
     If self.pretty_print is True,  reformat the files as temporaries
     
     Returns:
     0 no differences
     1 some differences
     2 errors
     """
     result, out_err = super(JsonDifferencer, self).diff()
     out_err = out_err.replace(self.remove_files[0], self.old_file)
     out_err = out_err.replace(self.remove_files[1], self.new_file)
     print(out_err, end="")
     if self.pretty_print:
         for fname in self.remove_files:
             with log.verbose_warning_on_exception("Failed removing", repr(fname)):
                 os.remove(fname)
     return result