def test_instrument_keyword(map_data, hpc_coord):
    header = make_fitswcs_header(map_data, hpc_coord, instrument='test name')
    assert header['instrume'] == 'test name'

    # Check returned MetaDict will make a `sunpy.map.Map`
    map_test = sunpy.map.Map(map_data, header)
    assert isinstance(map_test, sunpy.map.mapbase.GenericMap)
def synop_header(shape_out, dtime):
    frame_out = SkyCoord(0,
                         0,
                         unit=u.deg,
                         frame="heliographic_carrington",
                         obstime=dtime)
    ref_pix = [(shape_out[1] - 1) // 2, (shape_out[0] - 1) // 2] * u.pix
    header = make_fitswcs_header(
        shape_out,
        frame_out,
        reference_pixel=ref_pix,
        scale=[360 / shape_out[1], 180 / shape_out[0]] * u.deg / u.pix,
        projection_code="CAR")
    return header
Exemple #3
0
 def get_header(self, channel, coordinates):
     """
     Create the FITS header for a given channel and set of loop coordinates
     that define the needed FOV.
     """
     bins, bin_range = self.get_detector_array(coordinates)
     header = make_fitswcs_header(
         (bins[1], bins[0]),  # swap order because it expects (row,column)
         bin_range[
             0],  # align with the lower left corner of the lower left pixel
         reference_pixel=(-0.5, -0.5) *
         u.pixel,  # center of the lower left pixel is (0,0)
         scale=self.resolution,
         instrument=f'{self.detector}_{channel.telescope_number}',
         telescope=self.telescope,
         wavelength=channel.channel,
     )
     return header
Exemple #4
0
def synthetic_magnetogram(bottom_left_coord,
                          top_right_coord,
                          shape: u.pixel,
                          centers,
                          sigmas: u.arcsec,
                          amplitudes: u.Gauss,
                          observer=None):
    """
    Compute synthetic magnetogram using 2D guassian "sunspots"

    Parameters
    ----------
    bottom_left_coord : `~astropy.coordinates.SkyCoord`
        Bottom left corner
    top_right_coord : `~astropy.coordinates.SkyCoord`
        Top right corner
    shape : `~astropy.units.Quantity`
        Dimensionality of the magnetogram
    centers : `~astropy.coordinates.SkyCoord`
        Center coordinates of flux concentration
    sigmas : `~astropy.units.Quantity`
        Standard deviation of flux concentration with shape `(N,2)`, with `N` the
        number of flux concentrations
    amplitudes : `~astropy.units.Quantity`
        Amplitude of flux concentration with shape `(N,)`
    observer : `~astropy.coordinates.SkyCoord`, optional
        Defaults to Earth observer at current time
    """
    time_now = astropy.time.Time.now()
    if observer is None:
        observer = sunpy.coordinates.ephemeris.get_earth(time=time_now)
    # Transform to HPC frame
    hpc_frame = sunpy.coordinates.Helioprojective(observer=observer,
                                                  obstime=observer.obstime)
    bottom_left_coord = bottom_left_coord.transform_to(hpc_frame)
    top_right_coord = top_right_coord.transform_to(hpc_frame)
    # Setup array
    delta_x = (top_right_coord.Tx - bottom_left_coord.Tx).to(u.arcsec)
    delta_y = (top_right_coord.Ty - bottom_left_coord.Ty).to(u.arcsec)
    dx = delta_x / shape[0]
    dy = delta_y / shape[1]
    data = np.zeros((int(shape[1].value), int(shape[0].value)))
    xphysical, yphysical = np.meshgrid(
        np.arange(shape[0].value) * shape.unit * dx,
        np.arange(shape[1].value) * shape.unit * dy)
    # Add sunspots
    centers = centers.transform_to(hpc_frame)
    for c, s, a in zip(centers, sigmas, amplitudes):
        xc_2 = (xphysical - (c.Tx - bottom_left_coord.Tx)).to(
            u.arcsec).value**2.0
        yc_2 = (yphysical - (c.Ty - bottom_left_coord.Ty)).to(
            u.arcsec).value**2.0
        data += a.to(
            u.Gauss).value * np.exp(-xc_2 /
                                    (2 * s[0].to(u.arcsec).value**2) - yc_2 /
                                    (2 * s[1].to(u.arcsec).value**2))
    # Build metadata
    meta = make_fitswcs_header(
        data,
        bottom_left_coord,
        reference_pixel=(0, 0) * u.pixel,
        scale=u.Quantity((dx, dy)),
        instrument='synthetic_magnetic_imager',
        telescope='synthetic_magnetic_imager',
    )
    meta['bunit'] = 'gauss'
    return GenericMap(data, meta)
def test_rotation_matrix(map_data, hpc_coord):
    header = make_fitswcs_header(map_data,
                                 hpc_coord,
                                 rotation_matrix=np.array([[1, 0], [0, 1]]))
    wcs = WCS(header)
    np.testing.assert_allclose(wcs.wcs.pc, [[1, 0], [0, 1]], atol=1e-5)
def test_rotation_angle(map_data, hpc_coord):
    header = make_fitswcs_header(map_data,
                                 hpc_coord,
                                 rotation_angle=90 * u.deg)
    wcs = WCS(header)
    np.testing.assert_allclose(wcs.wcs.pc, [[0, -1], [1, 0]], atol=1e-5)
def test_deafult_rotation(map_data, hpc_coord):
    header = make_fitswcs_header(map_data, hpc_coord)
    wcs = WCS(header)
    np.testing.assert_allclose(wcs.wcs.pc, [[1, 0], [0, 1]], atol=1e-5)
def hgs_header(map_data, hgs_coord):
    return make_fitswcs_header(map_data, hgs_coord, projection_code='CAR')
def hpc_header(map_data, hpc_coord):
    return make_fitswcs_header(map_data, hpc_coord)
Exemple #10
0
def test_invalid_inputs(map_data, hcc_coord, hpc_coord_notime, hpc_coord):
    # Raise the HCC error
    with pytest.raises(ValueError):
        make_fitswcs_header(map_data, hcc_coord)

    # Check for when coordinate argument isn't given as an `astropy.coordinate.SkyCoord`
    with pytest.raises(ValueError):
        make_fitswcs_header(map_data, map_data)

    # Check for when an observation time isn't given
    with pytest.raises(ValueError):
        make_fitswcs_header(map_data, hpc_coord_notime)

    # Check arguments not given as astropy Quantities
    with pytest.raises(TypeError):
        header = make_fitswcs_header(map_data,
                                     hpc_coord,
                                     reference_pixel=[0, 0])
        header = make_fitswcs_header(map_data, hpc_coord, scale=[0, 0])

    # Check arguments of reference_pixel and scale have to be given in astropy units of pix, and arcsec/pix
    with pytest.raises(u.UnitsError):
        header = make_fitswcs_header(map_data,
                                     hpc_coord,
                                     reference_pixel=u.Quantity([0, 0]))
        header = make_fitswcs_header(map_data,
                                     hpc_coord,
                                     scale=u.Quantity([0, 0]))
        header = make_fitswcs_header(map_data,
                                     hpc_coord,
                                     scale=u.Quantity([0, 0] * u.arcsec))