def __init__(self, filename, *, template="./labels/m3/l2_template.xml", clean=False, **pdr_kwargs): # default values for known attributes populated later self.RFL_IMAGE = np.array([]) self.SUPPL_IMAGE = np.array([]) self.filename = None self.LABEL = None self.rfl_file = None self.sup_file = None # read the label with PDR super().__init__(filename, **pdr_kwargs) # roll images into HDULists of appropriate types self.fits_rfl_image = fitsify(self.RFL_IMAGE.astype("float32")) self.fits_sup_image = fitsify(self.SUPPL_IMAGE.astype("float32")) if clean: del self.RFL_IMAGE del self.SUPPL_IMAGE self.template = template self.pds4_root = ( interpret_m3_basename(self.filename)["basename"].lower() + "_l2")
def __init__(self, filename, *, template="./labels/m3/l1b_template.xml", clean=False, **pdr_kwargs): # default values for known attributes populated later self.OBS_IMAGE = np.array([]) self.RDN_IMAGE = np.array([]) self.LOC_IMAGE = np.array([]) self.UTC_TIME_TABLE = None self.filename = None self.LABEL = None self.rdn_file = None self.loc_file = None self.obs_file = None self.tim_file = None # read the label with PDR super().__init__(filename, **pdr_kwargs) # roll images into HDULists of appropriate types self.fits_loc_image = fitsify(self.LOC_IMAGE.astype("float64")) self.fits_rdn_image = fitsify(self.RDN_IMAGE.astype("float32")) self.fits_obs_image = fitsify(self.OBS_IMAGE.astype("float32")) if clean: # LOC_IMAGE doesn't get deleted here because it's used in tag # mapping. # we may change that later. del self.RDN_IMAGE del self.OBS_IMAGE self.template = template self.pds4_root = ( interpret_m3_basename(self.filename)["basename"].lower() + "_l1b")
def write_pds4( self, output_directory, write_product_files=True, write_label_file=True, ): """ output file objects and label for a PDS4 product corresponding to this object. (string containing output directory -> None) """ print("Converting " + self.filename + " to PDS4.") # all of the images we need to convert in this way seem to have ENVI # headers that are handled well by rasterio; moreover, since they # don't have PDS3 # labels, we can't assemble a struct format specification without # referencing # the ENVI headers _anyway_, so just using rasterio. self.fits_image_file = output_directory + self.pds4_root + ".fits" if write_product_files: # these are 2D images; they have a single 'band' to rasterio envi_img = rasterio.open(self.filename).read(1) self.FITS_IMAGE = fitsify(envi_img) print("Writing image to " + self.fits_image_file) self.FITS_IMAGE.writeto(self.fits_image_file, overwrite=True) self.write_label(output_directory, write_label_file, label_name=self.pds4_root)
def __init__(self, filename, *, template="./labels/m3/l0_template.xml", clean=False, **pdr_kwargs): # default values for known attributes populated later self.LABEL = None self.L0_LINE_PREFIX_TABLE = None self.L0_IMAGE = np.array([]) self.filename = None self.fits_image_file = None self.clock_file = None super().__init__(filename, **pdr_kwargs) # stymie numpy's enthusiasm for 64-bit integers and roll into an # HDUList self.FITS_IMAGE = fitsify(self.L0_IMAGE.astype("int16")) self.PREFIX_DATAFRAME = pd.DataFrame(self.L0_LINE_PREFIX_TABLE) # replace missing-byte strings (which are present in most of the files, # and _supposed_ to be present in all) with 'n/a' and put that info # at the end (so that order of most of the fields corresponds to # 1-indexed # byte order rather than 2-indexed) self.PREFIX_DATAFRAME[23] = self.PREFIX_DATAFRAME[0].apply( null_bytes_to_na) self.PREFIX_DATAFRAME.drop(0, axis=1, inplace=True) if clean: del self.L0_IMAGE self.template = template self.pds4_root = ( interpret_m3_basename(self.filename)["basename"].lower() + "_l0")
def __init__(self, filename, *, template="./labels/m3/bad_detector_element_template.xml"): self.filename = None self.template = template self.fits_image_file = None super().__init__(filename) envi_img = rasterio.open(self.filename).read(1) self.FITS_IMAGE = fitsify(envi_img) self.pds4_root = ( interpret_m3_basename(self.filename)["basename"].lower() + "_bde")
def __init__( self, filename, *, template_directory="./labels/clementine/", image_index=None, template_override=None, **pdr_kwargs ): # default values for known attributes populated later self.LABEL = {} self.IMAGE = np.array([]) self.IMAGE_HISTOGRAM = np.array([]) self.filename = None self.fits_image_file = None self.histogram_file = None self.image_index = image_index super().__init__(filename, **pdr_kwargs) # stymie numpy's enthusiasm for 64-bit integers and roll into an # HDUList self.FITS_IMAGE = fitsify(self.IMAGE.astype("uint8")) if template_override is None: self.template = template_directory + 'edr_template.xml' else: self.template = template_override # 'basename' of the PDS4 product self.pds4_root = format_edr_time(self.LABEL["START_TIME"]) \ + "_" + self.LABEL["INSTRUMENT_ID"].lower() \ + "_" + self.LABEL["TARGET_NAME"].lower() if self.LABEL["FILTER_NAME"] != "N/A": self.pds4_root += "_" + self.LABEL["FILTER_NAME"].lower() if self.LABEL["CENTER_FILTER_WAVELENGTH"] != "N/A": self.pds4_root += "_" + str( self.LABEL["CENTER_FILTER_WAVELENGTH"].value)