Example #1
0
    def carrington_longitude(self):
        """Carrington longitude (crln_obs)"""
        carrington_longitude = self.meta.get('crln_obs', None)

        if carrington_longitude is None:
            warnings.warn_explicit("Missing metadata for Carrington longitude: assuming Earth-based observer",
                                   Warning, __file__, inspect.currentframe().f_back.f_lineno)
            carrington_longitude = (sun.heliographic_solar_center(self.date))[0]

        return carrington_longitude
Example #2
0
    def heliographic_latitude(self):
        """Heliographic latitude in degrees"""
        heliographic_latitude = self.meta.get('hglt_obs',
                                              self.meta.get('crlt_obs',
                                                            self.meta.get('solar_b0', None)))

        if heliographic_latitude is None:
            warnings.warn_explicit("Missing metadata for heliographic latitude: assuming Earth-based observer",
                                   Warning, __file__, inspect.currentframe().f_back.f_lineno)
            heliographic_latitude = (sun.heliographic_solar_center(self.date))[1]

        return heliographic_latitude
Example #3
0
    def heliographic_latitude(self):
        """Heliographic latitude"""
        heliographic_latitude = self.meta.get("hglt_obs", self.meta.get("crlt_obs", self.meta.get("solar_b0", None)))

        if heliographic_latitude is None:
            warnings.warn_explicit(
                "Missing metadata for heliographic latitude: assuming Earth-based observer",
                Warning,
                __file__,
                inspect.currentframe().f_back.f_lineno,
            )
            heliographic_latitude = (sun.heliographic_solar_center(self.date))[1]

        return u.Quantity(heliographic_latitude, "deg")
    def __init__(self, filename, rotate=0):
        """Read a magnetogram as a sunpy.map object.

        Args:
            filename (str): filepath of magnetogram
            rotate (float, optional): amount to rotate the image, defaults to zero

        Raises:
            IOError: if the fits file does not fit one the file specifications or the file does not exist

        """
        self.im_raw = sunpy.map.Map(filename)
        self.fn = filename
        self.im_corr = None
        self.lath = None
        self.lonh = None
        self.mflux_corr = None
        self.mflux_raw = None
        self.area = None
        self.par = {}

        if self.im_raw.detector == '512':
            self.par['X0'] = self.im_raw.meta['CRPIX1A']
            self.par['Y0'] = self.im_raw.meta['CRPIX2A']
            self.par['B0'] = mnp.Measurement(self.im_raw.meta['B0'], np.abs(self.im_raw.meta['B0']) * .01)
            self.par['L0'] = mnp.Measurement(self.im_raw.meta['L0'], np.abs(self.im_raw.meta['L0']) * .01)
            self.par['SL0'] = mnp.Measurement(0, 0)  # Stonyhurst L0
            self.par['xscale'] = mnp.Measurement(self.im_raw.scale[0].value, 0.002)
            self.par['yscale'] = mnp.Measurement(self.im_raw.scale[1].value, 0.002)
            self.par['rsun'] = mnp.Measurement(self.im_raw.rsun_obs.value, 1)
            self.par['dsun'] = self.dsun_meters
            if rotate != 0:
                self.im_raw = self.im_raw.rotate(angle=rotate * u.deg)
        elif self.im_raw.detector == 'SPMG':
            self.par['X0'] = self.im_raw.meta['CRPIX1A']
            self.par['Y0'] = self.im_raw.meta['CRPIX2A']
            self.par['B0'] = mnp.Measurement(self.im_raw.meta['B0'], np.abs(self.im_raw.meta['B0']) * .01)
            self.par['L0'] = mnp.Measurement(self.im_raw.meta['L0'], np.abs(self.im_raw.meta['L0']) * .01)
            self.par['SL0'] = mnp.Measurement(0, 0)  # Stonyhurst L0
            self.par['xscale'] = mnp.Measurement(self.im_raw.scale[0].value, 0)
            self.par['yscale'] = mnp.Measurement(self.im_raw.scale[1].value, 0)
            self.par['rsun'] = mnp.Measurement(self.im_raw.rsun_obs.value, 1)
            self.par['dsun'] = self.dsun_meters
            if rotate != 0:
                self.im_raw.rotate(angle=rotate * u.deg)
        elif self.im_raw.detector == 'MDI':
            self.par['rsun'] = mnp.Measurement(self.im_raw.rsun_obs.value, 1)
            self.par['dsun'] = mnp.Measurement(self.im_raw.dsun.value, 0)
            try:
                self.P0 = self.im_raw.meta['p_angle'] - rotate
            except KeyError:
                self.P0 = self.im_raw.meta['solar_p'] - rotate
            if self.P0 != 0:
                self.im_raw = self.im_raw.rotate(angle=-self.P0 * u.deg)
            self.par['X0'], self.par['Y0'] = (x.value for x in self.im_raw.reference_pixel)
            try:
                self.par['B0'] = mnp.Measurement(self.im_raw.meta['B0'], np.abs(self.im_raw.meta['B0']) * .01)
                self.par['L0'] = mnp.Measurement(self.im_raw.meta['L0'], np.abs(self.im_raw.meta['L0']) * .01)
            except KeyError:
                self.par['B0'] = mnp.Measurement(self.im_raw.meta['OBS_B0'], np.abs(self.im_raw.meta['OBS_B0']) * .01)
                self.par['L0'] = mnp.Measurement(self.im_raw.meta['OBS_L0'], np.abs(self.im_raw.meta['OBS_L0']) * .01)
            self.par['SL0'] = self.par['L0'] - sun.heliographic_solar_center(self.im_raw.date)[0].value
            if self.par['SL0'] < -90:
                self.par['SL0'] += 360
            if self.par['SL0'] > 90:
                self.par['SL0'] -= 360
            self.par['xscale'] = mnp.Measurement(1.982, 0.003)
            self.par['yscale'] = mnp.Measurement(1.982, 0.003)
        elif self.im_raw.detector == 'HMI':
            self.par['rsun'] = mnp.Measurement(self.im_raw.rsun_obs.value, 1)
            self.par['dsun'] = mnp.Measurement(self.im_raw.dsun.value, 0)
            self.P0 = self.im_raw.meta['CROTA2'] - rotate
            if self.P0 != 0:
                self.im_raw = self.im_raw.rotate(angle=-self.P0 * u.deg)
            self.par['X0'], self.par['Y0'] = (x.value for x in self.im_raw.reference_pixel)
            self.par['B0'] = mnp.Measurement(self.im_raw.meta['CRLT_OBS'], np.abs(self.im_raw.meta['CRLT_OBS']) * .01)
            self.par['L0'] = mnp.Measurement(self.im_raw.meta['CRLN_OBS'], np.abs(self.im_raw.meta['CRLN_OBS']) * .01)
            self.par['SL0'] = self.par['L0'] - sun.heliographic_solar_center(self.im_raw.date)[0].value
            if self.par['SL0'] < 0:
                self.par['SL0'] += 360
            self.par['xscale'] = mnp.Measurement(self.im_raw.scale[0].value, 0.001)
            self.par['yscale'] = mnp.Measurement(self.im_raw.scale[1].value, 0.001)
        else:
            print("Not a valid instrument or missing header information regarding instrument.")
            raise IOError

        self.im_raw_u = mnp.Measurement(self.im_raw.data, np.abs(self.im_raw.data) * .10)
        # Fill in last bit of data if reading in cached file.
        if hasattr(self, 'lonh'):
            x, y = self._grid()