def __init__(self, filename, distance): fits = pyfits.open(filename) # compress all images into one image by average all the pixels if len(fits[0].data.shape) == 3: print("Found {0} exposures. Averaging...".format( fits[0].data.shape[0])) data = np.average(fits[0].data, axis=0) else: data = fits[0].data # create the wcs information w = WCS(naxis=2) w.wcs.crpix = [0, 0] plate_scale = foxsi_optics_calib.plate_scale(distance).to('arcsec') w.wcs.cdelt = plate_scale.value * np.ones(2) w.wcs.crval = [0, 0] w.wcs.ctype = ["TAN", "TAN"] CCDData.__init__(self, data, wcs=w, unit='adu', header=deepcopy(fits[0].header)) # save the name of the filename self.filename = os.path.basename(filename) x, y = np.meshgrid(*[np.arange(v) for v in self.data.shape]) * u.pixel self.xaxis, self.yaxis = self.wcs.wcs_pix2world(x, y, 1) * u.arcsec self.xlim = np.floor( [np.min(self.xaxis).value, np.max(self.xaxis).value]) self.ylim = np.floor( [np.min(self.yaxis).value, np.max(self.yaxis).value])
def __init__(self, *args, **kwargs): debug = kwargs.pop('debug', False) if debug: print("args=", *args) print("kwargs=", *kwargs) self._identifier = kwargs.pop('identifier', 'unknown') _beam = dict() _beam["BMAJ"] = self._beam_convert(kwargs.pop('bmaj', None)) _beam["BMIN"] = self._beam_convert(kwargs.pop('bmin', None)) _beam["BPA"] = self._beam_convert(kwargs.pop('bpa', None)) self._restfreq = kwargs.pop('restfreq', None) self._filename = None #This won't work: On arithmetic operations, this raises the exception. #if self._identifier is None: # raise ValueError("an identifier for Measurement must be specified.") #On arithmetic operations, this causes an annoying # log.info() message from CCDData about overwriting Quantity # This workaround is needed because CCDData raises an exception if unit # not given. Whereas having BUNIT in the image header instead would be # perfectly reasonable... # The side-effect of this is that Measurement not instantiated from # an image and with no unit given gets "adu" as the unit. self._defunit = "adu" _unit = kwargs.pop('unit', self._defunit) # Also works: super().__init__(*args, **kwargs, unit=_unit) CCDData.__init__(self, *args, **kwargs, unit=_unit) # If user provided restfreq, insert it into header # FITS standard is Hz if self._restfreq is not None: rf = u.Unit(self._restfreq).to("Hz") #print("new restfreq: %s Hz"%rf) self.header["RESTFREQ"] = rf # Set unit to header BUNIT or put BUNIT into header if it # wasn't present if "BUNIT" in self.header: self._unit = u.Unit(self.header["BUNIT"]) if self.uncertainty is not None: self.uncertainty._unit = u.Unit(self.header["BUNIT"]) else: # use str in case a astropy.Unit was given self.header["BUNIT"] = str(_unit) # Ditto beam parameters if "BMAJ" not in self.header: #print("setting BMAJ to ",_beam["BMAJ"]) self.header["BMAJ"] = _beam["BMAJ"] if "BMIN" not in self.header: self.header["BMIN"] = _beam["BMIN"] if "BPA" not in self.header: self.header["BPA"] = _beam["BPA"]
def __init__(self, *args, **kwargs): debug = kwargs.pop('debug', False) if debug: print("args=", *args) print("kwargs=", *kwargs) self._identifier = kwargs.pop('identifier', 'unknown') self._title = kwargs.pop('title', None) _beam = dict() _beam["BMAJ"] = self._beam_convert(kwargs.pop('bmaj', None)) _beam["BMIN"] = self._beam_convert(kwargs.pop('bmin', None)) _beam["BPA"] = self._beam_convert(kwargs.pop('bpa', None)) self._restfreq = kwargs.pop('restfreq', None) self._filename = None #This won't work: On arithmetic operations, this raises the exception. #if self._identifier is None: # raise ValueError("an identifier for Measurement must be specified.") #On arithmetic operations, this causes an annoying # log.info() message from CCDData about overwriting Quantity # This workaround is needed because CCDData raises an exception if unit # not given. Whereas having BUNIT in the image header instead would be # perfectly reasonable... # The side-effect of this is that Measurement not instantiated from # an image and with no unit given gets "adu" as the unit. self._defunit = "adu" unitpresent = 'unit' in kwargs _unit = kwargs.pop('unit', self._defunit) # Also works: super().__init__(*args, **kwargs, unit=_unit) CCDData.__init__(self, *args, **kwargs, unit=_unit) # force single pixel data to be interable arrays. # I consider this a bug in CCDData, StdDevUncertainty that they don't do this. # also StdDevUncertainty does not convert float to np.float! #print("DU",np.shape(self.data),np.shape(self.uncertainty.array)) #print(type(self.data)) if np.shape(self.data) == (): self.data = np.array([self.data]) if self.error is not None and np.shape(self.error) == (): self.uncertainty.array = np.array([self.uncertainty.array]) # If user provided restfreq, insert it into header # FITS standard is Hz if self._restfreq is not None: rf = u.Unit(self._restfreq).to("Hz") self.header["RESTFREQ"] = rf # Set unit to header BUNIT or put BUNIT into header if it # wasn't present AND if unit wasn't given in the constructor if not unitpresent and "BUNIT" in self.header: self._unit = u.Unit(self.header["BUNIT"]) if self.uncertainty is not None: self.uncertainty._unit = u.Unit(self.header["BUNIT"]) else: # use str in case a astropy.Unit was given self.header["BUNIT"] = str(_unit) # Ditto beam parameters if "BMAJ" not in self.header: self.header["BMAJ"] = _beam["BMAJ"] if "BMIN" not in self.header: self.header["BMIN"] = _beam["BMIN"] if "BPA" not in self.header: self.header["BPA"] = _beam["BPA"] if self.wcs is not None: self._set_up_for_interp()