Example #1
0
def test_conv_hpc_hg(angle_unit, dsun, b0, l0):
    coord = [382, 748]
    known_answer = [33.486471, 44.663506]
    result = wcs.convert_hpc_hg(coord[0], coord[1], dsun_meters=dsun,
                                b0_deg=b0,
                                l0_deg=l0, angle_units=angle_unit)
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
Example #2
0
def test_conv_hpc_hg():
    coord = [382, 748]
    known_answer = [34.091299, 45.095130]
    result = wcs.convert_hpc_hg(coord[0], coord[1], dsun_meters=img.dsun,
                                b0_deg=img.heliographic_latitude,
                                l0_deg=img.heliographic_longitude, angle_units=img.units['x'])
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
Example #3
0
def test_hpc_hgs(Tx, Ty):
    hpc = Helioprojective(Tx, Ty)
    hgs = hpc.transform_to(HeliographicStonyhurst)

    lon, lat = wcs.convert_hpc_hg(Tx.value, Ty.value, angle_units='arcsec',
                                  b0_deg=hpc.B0.to(u.deg).value, l0_deg=hpc.L0.to(u.deg).value,
                                  dsun_meters=hpc.D0.to(u.m))

    assert_quantity_allclose(lon*u.deg, hgs.lon)
    assert_quantity_allclose(lat*u.deg, hgs.lat)
Example #4
0
def test_conv_hpc_hg(angle_unit, dsun, b0, l0):
    coord = [382, 748]
    known_answer = [33.486471, 44.663506]
    result = wcs.convert_hpc_hg(coord[0],
                                coord[1],
                                dsun_meters=dsun,
                                b0_deg=b0,
                                l0_deg=l0,
                                angle_units=angle_unit)
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
Example #5
0
def test_convert_back():
    # Make sure transformation followed by inverse transformation returns
    # the original coordinates
    coord = [40.0, 32.0]
    assert_allclose(wcs.convert_hcc_hpc(*wcs.convert_hpc_hcc(*coord)),
                    coord, rtol=1e-2, atol=0)
    coord = [13.0, 58.0]
    assert_allclose(wcs.convert_hg_hcc(*wcs.convert_hcc_hg(*coord)),
                    coord, rtol=1e-2, atol=0)
    coord = [34.0, 45.0]
    assert_allclose(wcs.convert_hpc_hg(*wcs.convert_hg_hpc(*coord)),
                    coord, rtol=1e-2, atol=0)
def test_hpc_hgs(Tx, Ty):
    hpc = Helioprojective(Tx, Ty,
                          observer=HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU))
    hgs = hpc.transform_to(HeliographicStonyhurst)
    l0_deg = hpc.observer.lon
    b0_deg = hpc.observer.lat
    d0 = hpc.observer.radius

    lon, lat = wcs.convert_hpc_hg(Tx.value, Ty.value, angle_units='arcsec',
                                  b0_deg=b0_deg.to(u.deg).value, l0_deg=l0_deg.to(u.deg).value,
                                  dsun_meters=d0.to(u.m))

    assert_quantity_allclose(lon*u.deg, hgs.lon)
    assert_quantity_allclose(lat*u.deg, hgs.lat)
Example #7
0
def test_convert_to_coord(dsun, angle_unit, b0, l0):
    x, y = (34.0, 96.0)
    b0_deg = b0
    l0_deg = l0

    def check_conversion(from_coord, to_coord, expected):
        # Make sure that wcs.convert_to_coord returns the expected value
        assert_allclose(wcs.convert_to_coord(x,
                                             y,
                                             from_coord,
                                             to_coord,
                                             b0_deg=b0_deg,
                                             l0_deg=l0_deg,
                                             dsun_meters=dsun,
                                             angle_units=angle_unit),
                        expected,
                        rtol=1e-2,
                        atol=0)

    check_conversion('hcc', 'hg',
                     wcs.convert_hcc_hg(x, y, b0_deg=b0_deg, l0_deg=l0_deg))
    check_conversion(
        'hpc', 'hg',
        wcs.convert_hpc_hg(x,
                           y,
                           b0_deg=b0_deg,
                           l0_deg=l0_deg,
                           dsun_meters=dsun,
                           angle_units=angle_unit))
    check_conversion('hg', 'hcc',
                     wcs.convert_hg_hcc(x, y, b0_deg=b0_deg, l0_deg=l0_deg))
    check_conversion(
        'hcc', 'hpc',
        wcs.convert_hcc_hpc(x, y, dsun_meters=dsun, angle_units=angle_unit))
    check_conversion(
        'hg', 'hpc',
        wcs.convert_hg_hpc(x,
                           y,
                           b0_deg=b0_deg,
                           l0_deg=l0_deg,
                           dsun_meters=dsun,
                           angle_units=angle_unit))
    check_conversion(
        'hpc', 'hcc',
        wcs.convert_hpc_hcc(x, y, dsun_meters=dsun, angle_units=angle_unit))
Example #8
0
def test_hpc_hgs(Tx, Ty):
    hpc = Helioprojective(Tx,
                          Ty,
                          observer=HeliographicStonyhurst(
                              0 * u.deg, 0 * u.deg, 1 * u.AU))
    hgs = hpc.transform_to(HeliographicStonyhurst)
    l0_deg = hpc.observer.lon
    b0_deg = hpc.observer.lat
    d0 = hpc.observer.radius

    lon, lat = wcs.convert_hpc_hg(Tx.value,
                                  Ty.value,
                                  angle_units='arcsec',
                                  b0_deg=b0_deg.to(u.deg).value,
                                  l0_deg=l0_deg.to(u.deg).value,
                                  dsun_meters=d0.to(u.m))

    assert_quantity_allclose(lon * u.deg, hgs.lon)
    assert_quantity_allclose(lat * u.deg, hgs.lat)
Example #9
0
def test_convert_to_coord(dsun, angle_unit, b0, l0):
    x, y = (34.0, 96.0)
    b0_deg = b0
    l0_deg = l0

    def check_conversion(from_coord, to_coord, expected):
            # Make sure that wcs.convert_to_coord returns the expected value
        assert_allclose(wcs.convert_to_coord(x, y, from_coord, to_coord,
            b0_deg=b0_deg, l0_deg=l0_deg, dsun_meters=dsun, angle_units=angle_unit),
            expected, rtol=1e-2, atol=0)

    check_conversion('hcc', 'hg', wcs.convert_hcc_hg(x, y, b0_deg=b0_deg,
                                                         l0_deg=l0_deg))
    check_conversion('hpc', 'hg', wcs.convert_hpc_hg(x, y, b0_deg=b0_deg,
                            l0_deg=l0_deg, dsun_meters=dsun, angle_units=angle_unit))
    check_conversion('hg', 'hcc', wcs.convert_hg_hcc(x, y, b0_deg=b0_deg,
                                                            l0_deg=l0_deg))
    check_conversion('hcc', 'hpc', wcs.convert_hcc_hpc(x, y, dsun_meters=dsun,
                                                           angle_units=angle_unit))
    check_conversion('hg', 'hpc', wcs.convert_hg_hpc(x, y, b0_deg=b0_deg,
                            l0_deg=l0_deg, dsun_meters=dsun, angle_units=angle_unit))
    check_conversion('hpc', 'hcc', wcs.convert_hpc_hcc(x, y, dsun_meters=dsun,
                                                           angle_units=angle_unit))
Example #10
0
def test_convert_to_coord():
    x, y = (34.0, 96.0)
    b0_deg = img.heliographic_latitude
    l0_deg = img.heliographic_longitude
    units = img.units['x']
    dsun=img.dsun
    def check_conversion(from_coord, to_coord, expected):
        # Make sure that wcs.convert_to_coord returns the expected value
        assert_allclose(wcs.convert_to_coord(x, y, from_coord, to_coord,
            b0_deg=b0_deg, l0_deg=l0_deg, dsun_meters=dsun, angle_units=units),
            expected, rtol=1e-2, atol=0)
    check_conversion('hcc', 'hg', wcs.convert_hcc_hg(x, y, b0_deg=b0_deg,
                                                     l0_deg=l0_deg))
    check_conversion('hpc', 'hg', wcs.convert_hpc_hg(x, y, b0_deg=b0_deg,
                        l0_deg=l0_deg, dsun_meters=dsun, angle_units=units))
    check_conversion('hg', 'hcc', wcs.convert_hg_hcc(x, y, b0_deg=b0_deg,
                                                        l0_deg=l0_deg))
    check_conversion('hcc', 'hpc', wcs.convert_hcc_hpc(x, y, dsun_meters=dsun,
                                                       angle_units=units))
    check_conversion('hg', 'hpc', wcs.convert_hg_hpc(x, y, b0_deg=b0_deg,
                        l0_deg=l0_deg, dsun_meters=dsun, angle_units=units))
    check_conversion('hpc', 'hcc', wcs.convert_hpc_hcc(x, y, dsun_meters=dsun,
                                                       angle_units=units))
Example #11
0
def rot_hpc(x, y, tstart, tend, frame_time='synodic', rot_type='howard', **kwargs):
    """Given a location on the Sun referred to using the Helioprojective
    Cartesian co-ordinate system (typically quoted in the units of arcseconds)
    use the solar rotation profile to find that location at some later or
    earlier time.  Note that this function assumes that the data was observed
    from the Earth or near Earth vicinity.  Specifically, data from SOHO and
    STEREO observatories are not supported.  Note also that the function does
    NOT use solar B0 and L0 values provided in source FITS files - these
    quantities are calculated.

    Parameters
    ----------
    x : `~astropy.units.Quantity`
        Helio-projective x-co-ordinate in arcseconds (can be an array).

    y : `~astropy.units.Quantity`
        Helio-projective y-co-ordinate in arcseconds (can be an array).

    tstart : `sunpy.time.time`
        date/time to which x and y are referred.

    tend : `sunpy.time.time`
    date/time at which x and y will be rotated to.

    rot_type : {'howard' | 'snodgrass' | 'allen'}
        | howard: Use values for small magnetic features from Howard et al.
        | snodgrass: Use Values from Snodgrass et. al
        | allen: Use values from Allen, Astrophysical Quantities, and simpler
          equation.

    frame_time: {'sidereal' | 'synodic'}
        Choose type of day time reference frame.

    Returns
    -------
    x : `~astropy.units.Quantity`
        Rotated helio-projective x-co-ordinate in arcseconds (can be an array).

    y : `~astropy.units.Quantity`
        Rotated helio-projective y-co-ordinate in arcseconds (can be an array).

    Examples
    --------
    >>> import astropy.units as u
    >>> from sunpy.physics.transforms.differential_rotation import rot_hpc
    >>> rot_hpc( -570 * u.arcsec, 120 * u.arcsec, '2010-09-10 12:34:56', '2010-09-10 13:34:56')
    (<Angle -562.9105822671319 arcsec>, <Angle 119.31920621992195 arcsec>)

    Notes
    -----
    SSWIDL code equivalent: http://hesperia.gsfc.nasa.gov/ssw/gen/idl/solar/rot_xy.pro .
    The function rot_xy uses arcmin2hel.pro and hel2arcmin.pro to implement the
    same functionality as this function.  These two functions seem to perform
    inverse operations of each other to a high accuracy.  The corresponding
    equivalent functions here are convert_hpc_hg and convert_hg_hpc
    respectively. These two functions seem to perform inverse
    operations of each other to a high accuracy.  However, the values
    returned by arcmin2hel.pro are slightly different from those provided
    by convert_hpc_hg.  This leads to very slightly different results from
    rot_hpc compared to rot_xy.
    """

    # must have pairs of co-ordinates
    if np.array(x).shape != np.array(y).shape:
        raise ValueError('Input co-ordinates must have the same shape.')

    # Make sure we have enough time information to perform a solar differential
    # rotation
    # Start time
    dstart = parse_time(tstart)
    dend = parse_time(tend)
    interval = (dend - dstart).total_seconds() * u.s

    # Get the Sun's position from the vantage point at the start time
    vstart = kwargs.get("vstart", _calc_P_B0_SD(dstart))
    # Compute heliographic co-ordinates - returns (longitude, latitude). Points
    # off the limb are returned as nan
    longitude, latitude = convert_hpc_hg(x.to(u.arcsec).value,
                                         y.to(u.arcsec).value,
                                         b0_deg=vstart["b0"].to(u.deg).value,
                                         l0_deg=vstart["l0"].to(u.deg).value, 
                                         dsun_meters=(constants.au * sun.sunearth_distance(t=dstart)).value,
                                         angle_units='arcsec')
    longitude = Longitude(longitude, u.deg)
    latitude = Angle(latitude, u.deg)
    # Compute the differential rotation
    drot = diff_rot(interval, latitude, frame_time=frame_time,
                    rot_type=rot_type)

    # Convert back to heliocentric cartesian in units of arcseconds
    vend = kwargs.get("vend", _calc_P_B0_SD(dend))

    # It appears that there is a difference in how the SSWIDL function
    # hel2arcmin and the sunpy function below performs this co-ordinate
    # transform.
    newx, newy = convert_hg_hpc(longitude.to(u.deg).value + drot.to(u.deg).value,
                                latitude.to(u.deg).value,
                                b0_deg=vend["b0"].to(u.deg).value,
                                l0_deg=vend["l0"].to(u.deg).value,
                                dsun_meters=(constants.au * sun.sunearth_distance(t=dend)).value,
                                occultation=False)
    newx = Angle(newx, u.arcsec)
    newy = Angle(newy, u.arcsec)
    return newx.to(u.arcsec), newy.to(u.arcsec)
Example #12
0
    def draw_grid(self, axes=None, grid_spacing=20, **kwargs):
        """Draws a grid over the surface of the Sun

        Parameters
        ----------
        axes: matplotlib.axes object or None
        Axes to plot limb on or None to use current axes.

        grid_spacing: float
            Spacing (in degrees) for longitude and latitude grid.

        Returns
        -------
        matplotlib.axes object

        Notes
        -----
        keyword arguments are passed onto matplotlib.pyplot.plot
        """

        if not axes:
            axes = plt.gca()

        x, y = self.pixel_to_data()
        rsun = self.rsun_meters
        dsun = self.dsun

        b0 = self.heliographic_latitude
        l0 = self.heliographic_longitude
        units = [self.units["x"], self.units["y"]]

        # Prep the plot kwargs
        plot_kw = {"color": "white", "linestyle": "dotted", "zorder": 100}
        plot_kw.update(kwargs)

        # TODO: This function could be optimized. Does not need to convert the entire image
        # coordinates
        # lon_self, lat_self = wcs.convert_hpc_hg(rsun, dsun, angle_units = units[0], b0, l0, x, y)
        lon_self, lat_self = wcs.convert_hpc_hg(x, y, b0_deg=b0, l0_deg=l0, dsun_meters=dsun, angle_units="arcsec")
        # define the number of points for each latitude or longitude line
        num_points = 20

        # TODO: The following code is ugly. Fix it.
        lon_range = [lon_self.min(), lon_self.max()]
        lat_range = [lat_self.min(), lat_self.max()]
        if np.isfinite(lon_range[0]) == False:
            lon_range[0] = -90 + self.heliographic_longitude
        if np.isfinite(lon_range[1]) == False:
            lon_range[1] = 90 + self.heliographic_longitude
        if np.isfinite(lat_range[0]) == False:
            lat_range[0] = -90 + self.heliographic_latitude
        if np.isfinite(lat_range[1]) == False:
            lat_range[1] = 90 + self.heliographic_latitude

        hg_longitude_deg = np.linspace(lon_range[0], lon_range[1], num=num_points)
        hg_latitude_deg = np.arange(lat_range[0], lat_range[1] + grid_spacing, grid_spacing)

        # draw the latitude lines
        for lat in hg_latitude_deg:
            hg_latitude_deg_mesh, hg_longitude_deg_mesh = np.meshgrid(lat * np.ones(num_points), hg_longitude_deg)
            x, y = wcs.convert_hg_hpc(
                hg_longitude_deg_mesh,
                hg_latitude_deg_mesh,
                b0_deg=b0,
                l0_deg=l0,
                dsun_meters=dsun,
                angle_units=units[0],
                occultation=False,
            )

            axes.plot(x, y, **plot_kw)

        hg_longitude_deg = np.arange(lon_range[0], lon_range[1] + grid_spacing, grid_spacing)
        hg_latitude_deg = np.linspace(lat_range[0], lat_range[1], num=num_points)

        # draw the longitude lines
        for lon in hg_longitude_deg:
            hg_longitude_deg_mesh, hg_latitude_deg_mesh = np.meshgrid(lon * np.ones(num_points), hg_latitude_deg)
            x, y = wcs.convert_hg_hpc(
                hg_longitude_deg_mesh,
                hg_latitude_deg_mesh,
                b0_deg=b0,
                l0_deg=l0,
                dsun_meters=dsun,
                angle_units=units[0],
                occultation=False,
            )
            axes.plot(x, y, **plot_kw)

        axes.set_ylim(self.yrange)
        axes.set_xlim(self.xrange)

        return axes
Example #13
0
File: map.py Project: mjm159/sunpy
    def draw_grid(self, axes=None, grid_spacing=20):
        """Draws a grid over the surface of the Sun
        
        Parameters
        ----------
        axes: matplotlib.axes object or None
        Axes to plot limb on or None to use current axes.
        
        grid_spacing: float
            Spacing (in degrees) for longitude and latitude grid.
        
        Returns
        -------
        matplotlib.axes object
        """

        if not axes:
            axes = plt.gca()

        x, y = self.pixel_to_data()
        dsun = self.dsun

        b0 = self.heliographic_latitude
        l0 = self.heliographic_longitude
        units = [self.units.get('x'), self.units.get('y')]

        #TODO: This function could be optimized. Does not need to convert the entire image
        # coordinates
        lon_self, lat_self = wcs.convert_hpc_hg(x, y, b0_deg=b0, l0_deg=l0, dsun_meters=dsun, angle_units=units[0])
        # define the number of points for each latitude or longitude line
        num_points = 20
        
        #TODO: The following code is ugly. Fix it.
        lon_range = [lon_self.min(), lon_self.max()]
        lat_range = [lat_self.min(), lat_self.max()]
        if np.isfinite(lon_range[0]) == False: 
            lon_range[0] = -90 + self.heliographic_longitude
        if np.isfinite(lon_range[1]) == False: 
            lon_range[1] = 90 + self.heliographic_longitude
        if np.isfinite(lat_range[0]) == False: 
            lat_range[0] = -90 + self.heliographic_latitude
        if np.isfinite(lat_range[1]) == False: 
            lat_range[1] = 90 + self.heliographic_latitude

        hg_longitude_deg = np.linspace(lon_range[0], lon_range[1], num=num_points)
        hg_latitude_deg = np.arange(lat_range[0], lat_range[1]+grid_spacing, grid_spacing)

        # draw the latitude lines
        for lat in hg_latitude_deg:
            hg_latitude_deg_mesh, hg_longitude_deg_mesh = np.meshgrid(
                lat * np.ones(num_points), hg_longitude_deg)
            x, y = wcs.convert_hg_hpc(hg_longitude_deg_mesh, hg_latitude_deg_mesh, 
                                      b0_deg=self.heliographic_latitude,
                                      l0_deg=self.heliographic_longitude,
                                      dsun_meters = self.dsun, angle_units='arcsec')
            axes.plot(x, y, color='white', linestyle='dotted',zorder=100)
            
        hg_longitude_deg = np.arange(lon_range[0], lon_range[1]+grid_spacing, grid_spacing)
        hg_latitude_deg = np.linspace(lat_range[0], lat_range[1], num=num_points)

        # draw the longitude lines
        for lon in hg_longitude_deg:
            hg_longitude_deg_mesh, hg_latitude_deg_mesh = np.meshgrid(
                lon * np.ones(num_points), hg_latitude_deg)
            x, y = wcs.convert_hg_hpc(hg_longitude_deg_mesh, hg_latitude_deg_mesh, 
                                      b0_deg=self.heliographic_latitude,
                                      l0_deg=self.heliographic_longitude,
                                      dsun_meters = self.dsun, angle_units='arcsec')
            axes.plot(x, y, color='white', linestyle='dotted',zorder=100)
            
        axes.set_ylim(self.yrange)
        axes.set_xlim(self.xrange)

        return axes
Example #14
0
def map_hpc_to_hg(smap, xbin = 1, ybin = 1):
    """Take a map (like an AIA map) and convert it from HPC to HG."""

    #x,y = wcs.convert_pixel_to_data(map.header)
    x,y = wcs.convert_pixel_to_data(smap.shape[1],
                                    smap.shape[0],
                                    smap.scale['x'], 
                                    smap.scale['y'],
                                    smap.center['x'],
                                    smap.center['y'],   
                                    smap.reference_coordinate['x'],
                                    smap.reference_coordinate['y'],
                                    smap.coordinate_system['x'])
    
    #lon_map, lat_map = wcs.convert_hpc_hg(map.header, x, y)
    lon_map, lat_map = wcs.convert_hpc_hg(smap.rsun_meters,
                                          smap.dsun,
                                          smap.scale['x'],
                                          smap.scale['y'],
                                          smap.heliographic_latitude,
                                          smap.carrington_longitude,
                                          x, y)
    
    lon_bin = xbin
    lat_bin = ybin 
    lon_range = (np.nanmin(lon_map), np.nanmax(lon_map))
    lat_range = (np.nanmin(lat_map), np.nanmax(lat_map))

    lon = np.arange(lon_range[0], lon_range[1], lon_bin)
    lat = np.arange(lat_range[0], lat_range[1], lat_bin)
    newgrid = np.meshgrid(lon, lat)

    # newgrid = wcs.convert_hg_hpc(map.header, lon_grid, lat_grid, units = 'arcsec')
    points = np.vstack((lon_map.ravel(), lat_map.ravel())).T
    values = np.array(smap).ravel()

    # get rid of all of the bad (nan) indices (i.e. those off of the sun)
    index = np.isfinite(points[:,0]) * np.isfinite(points[:,1])
    points = np.vstack((points[index,0], points[index,1])).T
  
    values = values[index]
    
    newdata = griddata(points, values, newgrid, method="linear")

    header = smap.header.copy()
    header['CDELT1'] = lon_bin
    header['NAXIS1'] = len(lon)
    header['CRVAL1'] = lon.min()
    header['CRPIX1'] = 1
    header['CRPIX2'] = 1
    header['CUNIT1'] = "deg"
    header['CTYPE1'] = "HG"
    header['CDELT2'] = lat_bin
    header['NAXIS2'] = len(lat)
    header['CRVAL2'] = lat.min()
    header['CUNIT2'] = "deg"
    header['CTYPE2'] = "HG"

    transformed_map = sunpy.map.BaseMap(newdata, header)

    transformed_map.cmap = map.cmap
    transformed_map.name = map.name
    transformed_map.date = map.date
    transformed_map.center = {
        "x": wcs.get_center(header, axis='x'),
        "y": wcs.get_center(header, axis='y')}

    return transformed_map
Example #15
0
    def draw_grid(self, axes=None, grid_spacing=20, **kwargs):
        """Draws a grid over the surface of the Sun

        Parameters
        ----------
        axes: matplotlib.axes object or None
        Axes to plot limb on or None to use current axes.

        grid_spacing: float
            Spacing (in degrees) for longitude and latitude grid.

        Returns
        -------
        matplotlib.axes object

        Notes
        -----
        keyword arguments are passed onto matplotlib.pyplot.plot
        """

        if not axes:
            axes = plt.gca()

        x, y = self.pixel_to_data()
        rsun = self.rsun_meters
        dsun = self.dsun

        b0 = self.heliographic_latitude
        l0 = self.heliographic_longitude
        units = [self.units['x'], self.units['y']]

        #Prep the plot kwargs
        plot_kw = {'color': 'white', 'linestyle': 'dotted', 'zorder': 100}
        plot_kw.update(kwargs)

        #TODO: This function could be optimized. Does not need to convert the entire image
        # coordinates
        #lon_self, lat_self = wcs.convert_hpc_hg(rsun, dsun, angle_units = units[0], b0, l0, x, y)
        lon_self, lat_self = wcs.convert_hpc_hg(x,
                                                y,
                                                b0_deg=b0,
                                                l0_deg=l0,
                                                dsun_meters=dsun,
                                                angle_units='arcsec')
        # define the number of points for each latitude or longitude line
        num_points = 20

        #TODO: The following code is ugly. Fix it.
        lon_range = [lon_self.min(), lon_self.max()]
        lat_range = [lat_self.min(), lat_self.max()]
        if np.isfinite(lon_range[0]) == False:
            lon_range[0] = -90 + self.heliographic_longitude
        if np.isfinite(lon_range[1]) == False:
            lon_range[1] = 90 + self.heliographic_longitude
        if np.isfinite(lat_range[0]) == False:
            lat_range[0] = -90 + self.heliographic_latitude
        if np.isfinite(lat_range[1]) == False:
            lat_range[1] = 90 + self.heliographic_latitude

        hg_longitude_deg = np.linspace(lon_range[0],
                                       lon_range[1],
                                       num=num_points)
        hg_latitude_deg = np.arange(lat_range[0], lat_range[1] + grid_spacing,
                                    grid_spacing)

        # draw the latitude lines
        for lat in hg_latitude_deg:
            hg_latitude_deg_mesh, hg_longitude_deg_mesh = np.meshgrid(
                lat * np.ones(num_points), hg_longitude_deg)
            x, y = wcs.convert_hg_hpc(hg_longitude_deg_mesh,
                                      hg_latitude_deg_mesh,
                                      b0_deg=b0,
                                      l0_deg=l0,
                                      dsun_meters=dsun,
                                      angle_units=units[0],
                                      occultation=False)

            axes.plot(x, y, **plot_kw)

        hg_longitude_deg = np.arange(lon_range[0], lon_range[1] + grid_spacing,
                                     grid_spacing)
        hg_latitude_deg = np.linspace(lat_range[0],
                                      lat_range[1],
                                      num=num_points)

        # draw the longitude lines
        for lon in hg_longitude_deg:
            hg_longitude_deg_mesh, hg_latitude_deg_mesh = np.meshgrid(
                lon * np.ones(num_points), hg_latitude_deg)
            x, y = wcs.convert_hg_hpc(hg_longitude_deg_mesh,
                                      hg_latitude_deg_mesh,
                                      b0_deg=b0,
                                      l0_deg=l0,
                                      dsun_meters=dsun,
                                      angle_units=units[0],
                                      occultation=False)
            axes.plot(x, y, **plot_kw)

        axes.set_ylim(self.yrange)
        axes.set_xlim(self.xrange)

        return axes
Example #16
0
def params(flare,**kwargs):

    m2deg = 360./(2*3.1415926*6.96e8)
    if flare["event_coordunit"] == "degrees":
        flare_event_coord1 = flare['event_coord1']
        flare_event_coord2 = flare['event_coord2']
    elif flare["event_coordunit"] == "arcsec" or flare["event_coordunit"] == "arcseconds":
        info = pb0r(flare["event_starttime"])
        #Caution: the following conversion does not take dsun into account (i.e., apparent radius)
        flare_coords = convert_hpc_hg(flare['event_coord1'],
                                      flare['event_coord2'],
                                      info["b0"], info["l0"])
        flare_event_coord1 = flare_coords[0]
        flare_event_coord2 = flare_coords[1]

    """ Define the parameters we will use for the unraveling of the maps"""
    params = {"epi_lat": flare_event_coord2, #30., #degrees, HG latitude of wave epicenter
              "epi_lon": flare_event_coord1, #45., #degrees, HG longitude of wave epicenter
              #HG grid, probably would only want to change the bin sizes
              "lat_min": -90.,
              "lat_max": 90.,
              "lat_bin": 0.2,
              "lon_min": -180.,
              "lon_max": 180.,
              "lon_bin": 5.,
              #    #HPC grid, probably would only want to change the bin sizes
              "hpcx_min": -1025.,
              "hpcx_max": 1023.,
              "hpcx_bin": 2.,
              "hpcy_min": -1025.,
              "hpcy_max": 1023.,
              "hpcy_bin": 2.,
              "hglt_obs": 0,
              "rotation": 360. / (27. * 86400.), #degrees/s, rigid solar rotation
              }

    #params = {
    #    "cadence": 12., #seconds
    #    
    #    "hglt_obs": 0., #degrees
    #    "rotation": 360./(27.*86400.), #degrees/s, rigid solar rotation
    #   
    #    #Wave parameters that are initial conditions
    #    "direction": 25., #degrees, measured CCW from HG +latitude
    #    "epi_lat": 30., #degrees, HG latitude of wave epicenter
    #    "epi_lon": 45., #degrees, HG longitude of wave epicenter
    #    
    #    #Wave parameters that can evolve over time
    #    #The first element is constant in time
    #    #The second element (if present) is linear in time
    #    #The third element (if present) is quadratic in time
    #    #Be very careful of non-physical behavior
    #    "width": [90., 1.5], #degrees, full angle in azimuth, centered at 'direction'
    #    "wave_thickness": [6.0e6*m2deg,6.0e4*m2deg], #degrees, sigma of Gaussian profile in longitudinal direction
    #    "wave_normalization": [1.], #integrated value of the 1D Gaussian profile
    #    "speed": [9.33e5*m2deg, -1.495e3*m2deg], #degrees/s, make sure that wave propagates all the way to lat_min for polynomial speed
    #    
    #    #Noise parameters
    #    "noise_type": "Poisson", #can be None, "Normal", or "Poisson"
    #    "noise_scale": 0.3,
    #    "noise_mean": 1.,
    #    "noise_sdev": 1.,
    #    
    #    "max_steps": 20,
    #    
    #    #HG grid, probably would only want to change the bin sizes
    #    "lat_min": -90.,
    #    "lat_max": 90.,
    #    "lat_bin": 0.2,
    #    "lon_min": -180.,
    #    "lon_max": 180.,
    #    "lon_bin": 5.,
    #    
    #    #HPC grid, probably would only want to change the bin sizes
    #    "hpcx_min": -1025.,
    #    "hpcx_max": 1023.,
    #    "hpcx_bin": 2.,
    #    "hpcy_min": -1025.,
    #    "hpcy_max": 1023.,
    #    "hpcy_bin": 2.
    #}

    return params
Example #17
0
def params(flare, **kwargs):

    m2deg = 360. / (2 * 3.1415926 * 6.96e8)
    if flare["event_coordunit"] == "degrees":
        flare_event_coord1 = flare['event_coord1']
        flare_event_coord2 = flare['event_coord2']
    elif flare["event_coordunit"] == "arcsec" or flare[
            "event_coordunit"] == "arcseconds":
        info = pb0r(flare["event_starttime"])
        #Caution: the following conversion does not take dsun into account (i.e., apparent radius)
        flare_coords = convert_hpc_hg(flare['event_coord1'],
                                      flare['event_coord2'], info["b0"],
                                      info["l0"])
        flare_event_coord1 = flare_coords[0]
        flare_event_coord2 = flare_coords[1]
    """ Define the parameters we will use for the unraveling of the maps"""
    params = {
        "epi_lat":
        flare_event_coord2,  #30., #degrees, HG latitude of wave epicenter
        "epi_lon":
        flare_event_coord1,  #45., #degrees, HG longitude of wave epicenter
        #HG grid, probably would only want to change the bin sizes
        "lat_min": -90.,
        "lat_max": 90.,
        "lat_bin": 0.2,
        "lon_min": -180.,
        "lon_max": 180.,
        "lon_bin": 5.,
        #    #HPC grid, probably would only want to change the bin sizes
        "hpcx_min": -1025.,
        "hpcx_max": 1023.,
        "hpcx_bin": 2.,
        "hpcy_min": -1025.,
        "hpcy_max": 1023.,
        "hpcy_bin": 2.,
        "hglt_obs": 0,
        "rotation": 360. / (27. * 86400.),  #degrees/s, rigid solar rotation
    }

    #params = {
    #    "cadence": 12., #seconds
    #
    #    "hglt_obs": 0., #degrees
    #    "rotation": 360./(27.*86400.), #degrees/s, rigid solar rotation
    #
    #    #Wave parameters that are initial conditions
    #    "direction": 25., #degrees, measured CCW from HG +latitude
    #    "epi_lat": 30., #degrees, HG latitude of wave epicenter
    #    "epi_lon": 45., #degrees, HG longitude of wave epicenter
    #
    #    #Wave parameters that can evolve over time
    #    #The first element is constant in time
    #    #The second element (if present) is linear in time
    #    #The third element (if present) is quadratic in time
    #    #Be very careful of non-physical behavior
    #    "width": [90., 1.5], #degrees, full angle in azimuth, centered at 'direction'
    #    "wave_thickness": [6.0e6*m2deg,6.0e4*m2deg], #degrees, sigma of Gaussian profile in longitudinal direction
    #    "wave_normalization": [1.], #integrated value of the 1D Gaussian profile
    #    "speed": [9.33e5*m2deg, -1.495e3*m2deg], #degrees/s, make sure that wave propagates all the way to lat_min for polynomial speed
    #
    #    #Noise parameters
    #    "noise_type": "Poisson", #can be None, "Normal", or "Poisson"
    #    "noise_scale": 0.3,
    #    "noise_mean": 1.,
    #    "noise_sdev": 1.,
    #
    #    "max_steps": 20,
    #
    #    #HG grid, probably would only want to change the bin sizes
    #    "lat_min": -90.,
    #    "lat_max": 90.,
    #    "lat_bin": 0.2,
    #    "lon_min": -180.,
    #    "lon_max": 180.,
    #    "lon_bin": 5.,
    #
    #    #HPC grid, probably would only want to change the bin sizes
    #    "hpcx_min": -1025.,
    #    "hpcx_max": 1023.,
    #    "hpcx_bin": 2.,
    #    "hpcy_min": -1025.,
    #    "hpcy_max": 1023.,
    #    "hpcy_bin": 2.
    #}

    return params
Example #18
0
from sunpy import wcs
print(wcs.convert_hg_hpc(10, 53))
# Convert that position back to heliographic coordinates
print(wcs.convert_hpc_hg(100.49, 767.97))
# Try to convert a position which is not on the Sun to HG
print(wcs.convert_hpc_hg(-1500, 0))
# Convert sky coordinate to a position in HCC
print(wcs.convert_hpc_hcc(-300, 400, z=True))
Example #19
0
File: map.py Project: tdunn19/sunpy
    def draw_grid(self, axes=None, grid_spacing=20):
        """Draws a grid over the surface of the Sun
        
        Parameters
        ----------
        axes: matplotlib.axes object or None
        Axes to plot limb on or None to use current axes.
        
        grid_spacing: float
            Spacing (in degrees) for longitude and latitude grid.
        
        Returns
        -------
        matplotlib.axes object
        """

        if not axes:
            axes = plt.gca()

        x, y = self.pixel_to_data()
        rsun = self.rsun_meters
        dsun = self.dsun

        b0 = self.heliographic_latitude
        l0 = self.heliographic_longitude
        units = [self.units.get('x'), self.units.get('y')]

        #TODO: This function could be optimized. Does not need to convert the entire image
        # coordinates
        lon_self, lat_self = wcs.convert_hpc_hg(rsun, dsun, units[0], units[1],
                                                b0, l0, x, y)
        # define the number of points for each latitude or longitude line
        num_points = 20

        #TODO: The following code is ugly. Fix it.
        lon_range = [lon_self.min(), lon_self.max()]
        lat_range = [lat_self.min(), lat_self.max()]
        if np.isfinite(lon_range[0]) == False:
            lon_range[0] = -90 + self.heliographic_longitude
        if np.isfinite(lon_range[1]) == False:
            lon_range[1] = 90 + self.heliographic_longitude
        if np.isfinite(lat_range[0]) == False:
            lat_range[0] = -90 + self.heliographic_latitude
        if np.isfinite(lat_range[1]) == False:
            lat_range[1] = 90 + self.heliographic_latitude

        hg_longitude_deg = np.linspace(lon_range[0],
                                       lon_range[1],
                                       num=num_points)
        hg_latitude_deg = np.arange(lat_range[0], lat_range[1] + grid_spacing,
                                    grid_spacing)

        # draw the latitude lines
        for lat in hg_latitude_deg:
            hg_latitude_deg_mesh, hg_longitude_deg_mesh = np.meshgrid(
                lat * np.ones(num_points), hg_longitude_deg)
            x, y = wcs.convert_hg_hpc(self.rsun_meters,
                                      self.dsun,
                                      self.heliographic_latitude,
                                      self.heliographic_longitude,
                                      hg_longitude_deg_mesh,
                                      hg_latitude_deg_mesh,
                                      units='arcsec')
            axes.plot(x, y, color='white', linestyle='dotted', zorder=100)

        hg_longitude_deg = np.arange(lon_range[0], lon_range[1] + grid_spacing,
                                     grid_spacing)
        hg_latitude_deg = np.linspace(lat_range[0],
                                      lat_range[1],
                                      num=num_points)

        # draw the longitude lines
        for lon in hg_longitude_deg:
            hg_longitude_deg_mesh, hg_latitude_deg_mesh = np.meshgrid(
                lon * np.ones(num_points), hg_latitude_deg)
            x, y = wcs.convert_hg_hpc(self.rsun_meters,
                                      self.dsun,
                                      self.heliographic_latitude,
                                      self.heliographic_longitude,
                                      hg_longitude_deg_mesh,
                                      hg_latitude_deg_mesh,
                                      units='arcsec')
            axes.plot(x, y, color='white', linestyle='dotted', zorder=100)

        axes.set_ylim(self.yrange)
        axes.set_xlim(self.xrange)

        return axes