def get_array_properties(self, array_name, keytype="A"): """Return a Struct defining the properties of the FITS array in extension named `array_name`.""" with fits_open(self.filepath) as hdulist: try: array_name = self._array_name_to_hdu_index(array_name) hdu = hdulist[array_name[1]] except Exception: return 'UNDEFINED' generic_class = { "IMAGEHDU" : "IMAGE", "BINTABLEHDU" : "TABLE", }.get(hdu.__class__.__name__.upper(), "UNKNOWN") if generic_class in ["IMAGE","UNKNOWN"]: typespec = hdu.data.dtype.name column_names = None else: # TABLE dtype = hdu.data.dtype typespec = {name.upper():str(dtype.fields[name][0]) for name in dtype.names} column_names = [name.upper() for name in hdu.data.dtype.names] return utils.Struct( SHAPE = hdu.data.shape, KIND = generic_class, DATA_TYPE = typespec, COLUMN_NAMES = column_names, NAME = array_name[0], EXTENSION = array_name[1], DATA = hdu.data if (keytype == "D") else None )
def __init__(self, context, refpath, crdscfg): self._context = context self._refpath = refpath self._crdscfg = utils.Struct(crdscfg) self.pipeline_exceptions = self._crdscfg.get("pipeline_exceptions", {}) self.pipeline_cfgs_to_steps = self._crdscfg.get("pipeline_cfgs_to_steps", {}) self.steps_to_reftypes = self._crdscfg.get("steps_to_reftypes", {})
def jpoll_pull_messages(key, since_id=None): """Return a list of jpoll json message objects from the channel associated with `key` sent after datetime string `since` or since the last pull if since is not specified. """ messages = [] for msg in S.jpoll_pull_messages(key, since_id): decoded = utils.Struct(msg) decoded.data = html.unescape(decoded.data) messages.append(decoded) return messages
def fail_if_existing_lock(self): """Issue a warning if self.locked_instrument is already locked.""" response = self.get("/lock_status/" + self.username + "/") log.verbose("lock_status:", response) json_dict = utils.Struct(response.json()) if (json_dict.name and (not json_dict.is_expired) and (json_dict.type == "instrument") and (json_dict.user == self.username)): log.fatal_error( "User", repr(self.username), "has already locked", repr(json_dict.name), ". Failing to avert collisions. User --logout or logout on the website to bypass." )
def create_submission(self): """Create a Submission object based on script / command-line parameters.""" return utils.Struct( uploaded_files={ os.path.basename(filepath): filepath for filepath in self.files } if self.args.files else {}, description=self.args.description, username=self.username, creator_name=self.args.creator, change_level=self.args.change_level, auto_rename=not self.args.dont_auto_rename, compare_old_reference=not self.args.dont_compare_old_reference, submission_kind=self.args.submission_kind, observatory=self.observatory, pmap_mode=self.pmap_mode, pmap_name=self.pmap_name, agent="command-line-script")
def __init__(self, header): """Initialize this TypeSpec from dict `header`, enforcing requirments and creating suitable defaults for missing fields. """ header = utils.Struct(header) assert "suffix" in header assert "text_descr" in header or header.filetype == "all" if "tpn" not in header: header.tpn = header.instrument.lower() + "_" + header.suffix + ".tpn" if "ld_tpn" not in header: header.ld_tpn = header.instrument.lower() + "_" + header.suffix + "_ld.tpn" if "file_ext" not in header: header.file_ext = ".fits" if "unique_rowkeys" not in header: header.unique_rowkeys = None if "extra_keys" not in header: header.extra_keys = None super(TypeSpec, self).__init__(header.items())
def get_system_versions(master_version, context=None): """Return the versions Struct associated with cal s/w master_version as defined by `context` which can be defined as "null", "none", or None to use the default context, or with any other valid date based context specifier. """ return utils.Struct(S.get_system_versions(master_version, str(context)))
def get_submission_info(observatory, username): """Return configuration parameters needed for command line file submission relative to the current server, observatory, and username. """ return utils.Struct(S.get_submission_info(observatory, username))
def get_affected_datasets(observatory, old_context=None, new_context=None): """Return a structure describing the ids affected by the last context change.""" return utils.Struct(S.get_affected_datasets(observatory, old_context, new_context))
def get_body(self): """Load the input_yaml as a CRDS Struct and return it.""" return utils.Struct(yaml.safe_load(self.input_yaml))
def __init__(self, context, refpath, crdscfg): self._context = context self._refpath = refpath self._crdscfg = utils.Struct(crdscfg)