예제 #1
0
def update_file_bestrefs(context, dataset, updates):
    """Update the header of `dataset` with best reference recommendations
    `bestrefs` determined by context named `pmap`.
    """
    if not updates:
        return

    version_info = heavy_client.version_info()
    instrument = updates[0].instrument
    locator = utils.instrument_to_locator(instrument)
    prefix = locator.get_env_prefix(instrument) 

    with data_file.fits_open(dataset, mode="update", do_not_scale_image_data=True, checksum=False) as hdulist:

        def set_key(keyword, value):
            """Set a single keyword value with logging,  bound to outer-scope hdulist."""
            log.verbose("Setting", repr(dataset), keyword, "=", value)
            hdulist[0].header[keyword] = value

        set_key("CRDS_CTX", context)
        set_key("CRDS_VER", version_info)

        for update in sorted(updates):
            new_ref = update.new_reference.upper()
            if new_ref != "N/A":
                new_ref = (prefix + new_ref).lower()
            keyword = locator.filekind_to_keyword(update.filekind)
            set_key(keyword, new_ref)

        # This is a workaround for a bug in astropy.io.fits handling of 
        # FITS updates that are header-only and extend the header.
        # This statement appears to do nothing but *is not* pointless.
        for hdu in hdulist:
            hdu.data
예제 #2
0
파일: list.py 프로젝트: jaytmiller/crds
 def list_config(self):
     """Print out configuration info about the current environment and server."""
     info = config.get_crds_env_vars()
     real_paths = config.get_crds_actual_paths(self.observatory)
     server = self.server_info
     current_server_url = api.get_crds_server()
     cache_subdir_mode = config.get_crds_ref_subdir_mode(self.observatory)
     pyinfo = _get_python_info()
     _print_dict("CRDS Environment", info)
     _print_dict("CRDS Client Config", { 
             "server_url" : current_server_url, 
             "cache_subdir_mode": cache_subdir_mode,
             "readonly_cache": self.readonly_cache,
             "effective_context": heavy_client.get_context_name(self.observatory),
             "crds" : repr(crds),
             "version": heavy_client.version_info() 
             })
     _print_dict("CRDS Actual Paths", real_paths)
     _print_dict("CRDS Server Info", server, 
                 ["observatory", "status", "connected", "operational_context", "last_synced", 
                  "reference_url", "mapping_url", "effective_mode"])
     if self.observatory == "hst":
         cal_vars = { var : os.environ[var] for var in os.environ
                       if len(var) == 4 and var.lower().endswith("ref") }
         _print_dict("Calibration Environment", cal_vars)
     _print_dict("Python Environment", pyinfo)
예제 #3
0
파일: list.py 프로젝트: jaytmiller/crds
 def list_status(self):
     """Print out *basic* configuration info about the current environment and server."""
     info = config.get_crds_env_vars()
     server = self.server_info
     pyinfo = _get_python_info()
     status = OrderedDict(
         [("CRDS_PATH", info.get("CRDS_PATH", "undefined")),
          ("CRDS_SERVER_URL", info.get("CRDS_SERVER_URL", "undefined")),
          ("CRDS_MODE", info["CRDS_MODE"]),
          ("Readonly Cache", self.readonly_cache),
          ("Cache Locking", crds_cache_locking.status()),
          ("Effective Context", heavy_client.get_context_name(self.observatory)),
          ("Last Synced", server.last_synced),
          ("CRDS Version", heavy_client.version_info()),
          ("Python Version", pyinfo["Python Version"]),
          ("Python Executable", pyinfo["Python Executable"]),
          ])
     _print_dict(None, status)
예제 #4
0
 def list_config(self):
     """Print out configuration info about the current environment and server."""
     info = config.get_crds_env_vars()
     real_paths = config.get_crds_actual_paths(self.observatory)
     server = self.server_info
     current_server_url = api.get_crds_server()
     cache_subdir_mode = config.get_crds_ref_subdir_mode(self.observatory)
     pyinfo = _get_python_info()
     _print_dict("CRDS Environment", info)
     _print_dict(
         "CRDS Client Config", {
             "server_url":
             current_server_url,
             "cache_subdir_mode":
             cache_subdir_mode,
             "readonly_cache":
             self.readonly_cache,
             "effective_context":
             heavy_client.get_context_name(self.observatory),
             "crds":
             repr(crds),
             "version":
             heavy_client.version_info()
         })
     _print_dict("CRDS Actual Paths", real_paths)
     _print_dict("CRDS Server Info", server, [
         "observatory", "status", "connected", "operational_context",
         "last_synced", "reference_url", "mapping_url", "effective_mode"
     ])
     download_uris = dict(
         config_uri=os.path.dirname(api.get_flex_uri("server_config")),
         pickle_uri=os.path.dirname(api.get_flex_uri("xyz.pmap.pkl")),
         mapping_uri=os.path.dirname(api.get_flex_uri("xyz.pmap")),
         reference_uri=os.path.dirname(api.get_flex_uri("xyz.fits")),
     )
     _print_dict("Actual Download URIs", download_uris)
     if self.observatory == "hst":
         cal_vars = {
             var: os.environ[var]
             for var in os.environ
             if len(var) == 4 and var.lower().endswith("ref")
         }
         _print_dict("Calibration Environment", cal_vars)
     _print_dict("Python Environment", pyinfo)
예제 #5
0
파일: list.py 프로젝트: jdavies-st/crds
 def list_status(self):
     """Print out *basic* configuration info about the current environment and server."""
     info = config.get_crds_env_vars()
     server = self.server_info
     pyinfo = _get_python_info()
     status = OrderedDict([
         ("CRDS_PATH", info.get("CRDS_PATH", "undefined")),
         ("CRDS_SERVER_URL", info.get("CRDS_SERVER_URL", "undefined")),
         ("CRDS_MODE", info["CRDS_MODE"]),
         ("Readonly Cache", self.readonly_cache),
         ("Cache Locking", crds_cache_locking.status()),
         ("Effective Context",
          heavy_client.get_context_name(self.observatory)),
         ("Last Synced", server.last_synced),
         ("CRDS Version", heavy_client.version_info()),
         ("Python Version", pyinfo["Python Version"]),
         ("Python Executable", pyinfo["Python Executable"]),
     ])
     _print_dict(None, status)