Ejemplo n.º 1
0
    def DrawGridSource(self, grid_spacing=15 * u.deg, *args, **kwargs):
        """maps the Longitude and Latitude grids to Bokeh DataSource
        """
        XX, YY = np.meshgrid(np.arange(self.smap.data.shape[0]),
                             np.arange(self.smap.data.shape[1]))
        x, y = self.smap.pixel_to_data(XX * u.pix, YY * u.pix)
        dsun = self.smap.dsun

        b0 = self.smap.heliographic_latitude.to(u.deg).value
        l0 = self.smap.heliographic_longitude.to(u.deg).value
        units = self.smap.spatial_units

        xs = []
        ys = []

        hg_longitude_deg = np.linspace(-180, 180, num=361) + l0
        hg_latitude_deg = np.arange(-90, 90, grid_spacing.to(u.deg).value)

        # draw the latitude lines
        for lat in hg_latitude_deg:
            x, y = wcs.convert_hg_hpc(hg_longitude_deg,
                                      lat * np.ones(361),
                                      b0_deg=b0,
                                      l0_deg=l0,
                                      dsun_meters=dsun,
                                      angle_units=units.x,
                                      occultation=True)
            valid = np.logical_and(np.isfinite(x), np.isfinite(y))
            x = x[valid]
            y = y[valid]
            xs.append(x.tolist())
            ys.append(y.tolist())

        hg_longitude_deg = np.arange(-180, 180,
                                     grid_spacing.to(u.deg).value) + l0
        hg_latitude_deg = np.linspace(-90, 90, num=181)

        # draw the longitude lines
        for lon in hg_longitude_deg:
            x, y = wcs.convert_hg_hpc(lon * np.ones(181),
                                      hg_latitude_deg,
                                      b0_deg=b0,
                                      l0_deg=l0,
                                      dsun_meters=dsun,
                                      angle_units=units[0],
                                      occultation=True)
            valid = np.logical_and(np.isfinite(x), np.isfinite(y))
            x = x[valid]
            y = y[valid]
            xs.append(x.tolist())
            ys.append(y.tolist())

        return ColumnDataSource(data={'xs': xs, 'ys': ys})
Ejemplo n.º 2
0
def test_conv_hg_hpc():
    coord = [34.0, 45.0]
    result = wcs.convert_hg_hpc(coord[0], coord[1], dsun_meters=img.dsun, 
                                b0_deg=img.heliographic_latitude,
                                l0_deg=img.heliographic_longitude, angle_units = img.units['x'])
    known_answer = [381.737592, 747.072612]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
Ejemplo n.º 3
0
def test_conv_hg_hpc(angle_unit, dsun, b0, l0):
    coord = [34.0, 45.0]
    result = wcs.convert_hg_hpc(coord[0], coord[1], dsun_meters=dsun,
                                b0_deg=b0, l0_deg=l0, angle_units=angle_unit)
    known_answer = [381.737592, 747.072612]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)

    # Test to make sure occultation parameter works
    coord = [34.0, 96.0]
    coord2 = [55.0, 56.0]
    known_answer = [[np.nan, 441.65710359], [np.nan, 831.30194808]]
    coords = zip(coord, coord2)
    result = wcs.convert_hg_hpc(*coords, dsun_meters=dsun,
                b0_deg=b0, l0_deg=l0,
                angle_units=angle_unit, occultation=True)
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
Ejemplo n.º 4
0
def test_conv_hg_hpc():
    coord = [34.0, 45.0]
    result = wcs.convert_hg_hpc(coord[0], coord[1], dsun_meters=img.dsun,
                                b0_deg=img.heliographic_latitude,
                                l0_deg=img.heliographic_longitude, angle_units=img.units['x'])
    known_answer = [381.737592, 747.072612]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)

    # Test to make sure occultation parameter works
    coord = [34.0, 96.0]
    coord2 = [55.0, 56.0]
    known_answer = [[np.nan, 441.65710359], [np.nan, 831.30194808]]
    coords = zip(coord, coord2)
    result = wcs.convert_hg_hpc(*coords, dsun_meters=img.dsun,
                b0_deg=img.heliographic_latitude, l0_deg=img.heliographic_longitude,
                angle_units=img.units['x'], occultation=True)
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
Ejemplo n.º 5
0
def test_conv_hg_hpc():
    coord = [34.0, 45.0]
    result = wcs.convert_hg_hpc(coord[0],
                                coord[1],
                                dsun_meters=img.dsun,
                                b0_deg=img.heliographic_latitude,
                                l0_deg=img.heliographic_longitude,
                                angle_units=img.units['x'])
    known_answer = [381.737592, 747.072612]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
Ejemplo n.º 6
0
def test_conv_hg_hpc():
    coord = [34.0, 45.0]
    result = wcs.convert_hg_hpc(img.rsun_meters, img.dsun, 
                                img.heliographic_latitude,
                                img.heliographic_longitude,
                                coord[0], coord[1])
    known_answer = [0.10603822, 0.20752017]
    magnitude = np.floor(np.log10(known_answer))
    assert_array_almost_equal(result*10**(-magnitude), 
                              known_answer*10**(-magnitude), decimal=2)
Ejemplo n.º 7
0
def test_hgs_hpc(lon, lat):
    hgs = HeliographicStonyhurst(lon, lat)
    hpc = hgs.transform_to(Helioprojective)

    Tx, Ty = wcs.convert_hg_hpc(lon.value, lat.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(Tx*u.arcsec, hpc.Tx)
    assert_quantity_allclose(Ty*u.arcsec, hpc.Ty)
Ejemplo n.º 8
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_hgs_hpc(lon, lat):
    hgs = HeliographicStonyhurst(lon, lat)
    hpc = hgs.transform_to(Helioprojective(observer=HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU)))
    l0_deg = hpc.observer.lon
    b0_deg = hpc.observer.lat
    d0 = hpc.observer.radius

    Tx, Ty = wcs.convert_hg_hpc(lon.value, lat.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(Tx*u.arcsec, hpc.Tx)
    assert_quantity_allclose(Ty*u.arcsec, hpc.Ty)
Ejemplo n.º 10
0
def map_hg_to_hpc(smap, xbin = 10, ybin = 10):
    """Take a map in heliographic coordinates (HG) and convert it to 
    helioprojective cartesian coordinates (HPC)."""

    lon,lat = wcs.convert_pixel_to_data(smap.header)
    x_map, y_map = wcs.convert_hg_hpc(smap.header, lon, lat, units ='arcsec')
    
    x_range = (np.nanmin(x_map), np.nanmax(x_map))
    y_range = (np.nanmin(y_map), np.nanmax(y_map))
    
    x = np.arange(x_range[0], x_range[1], xbin)
    y = np.arange(y_range[0], y_range[1], ybin)
    newgrid = np.meshgrid(x, y)
    
    # newgrid = wcs.convert_hpc_hg(map.header, xgrid/(3600), ygrid/(3600))
    
    points = np.vstack((x_map.ravel(), y_map.ravel())).T
    values = np.array(smap).ravel()
    newdata = griddata(points, values, newgrid, method="linear")
    
    # now grab the original map header and update it
    header = smap.header.copy()
    header["CDELT1"] = xbin
    header["NAXIS1"] = len(x)
    header["CRVAL1"] = x.min()
    header["CRPIX1"] = 1
    header["CUNIT1"] = "arcsec"
    header["CTYPE1"] = "HPLT-TAN"
    header["CDELT2"] = ybin
    header["NAXIS2"] = len(y)
    header["CRVAL2"] = y.min()
    header["CRPIX2"] = 1
    header["CUNIT2"] = "arcsec"
    header["CTYPE2"] = "HPLT-TAN"
    
    transformed_map = sunpy.map.BaseMap(newdata, header)
    
    transformed_map.cmap = smap.cmap
    transformed_map.name = smap.name
    transformed_map.date = smap.date

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

    return transformed_map
Ejemplo n.º 11
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))
Ejemplo n.º 12
0
def cut_AIA(keys_AIA, keys_HMI, aia_image_data, hmi_image):
    '''
    Identifying which AIA pixels ae included in the CEA-coordinate SHARP
    bounding box.
    
    Parameters:
    ----------------------------    
    keys_AIA: String List
        The AIA data keys, for the data crop
    
    keys_HMI: String List
        The HMI data keys, fot the data crop
    
    aia_image_data: Numpy array (2-dimensional)
        The AIA image data, size 4096*4096, after doing aiaprep

    hmi_image: Astropy fits file object
        The fits file object of the HMI data

    Returns:
    ----------------------------
    cropped_aia_image_data: Numpy array (2-dimensional)
        The cropped AIA data
    '''
    XDIM_CEA = hmi_image[1].data.shape[1]
    YDIM_CEA = hmi_image[1].data.shape[0]
    aia_mask = np.full([4096, 4096], np.nan)

    for j in range(int(YDIM_CEA)):
        for i in range(int(XDIM_CEA)):
            x_hg = keys_HMI.CRVAL1[0] - 0.5*XDIM_CEA*keys_HMI.CDELT1[0]\
                + i*keys_HMI.CDELT1[0]
            y_hg = keys_HMI.CRVAL2[0] - 0.5*YDIM_CEA*keys_HMI.CDELT1[0]\
                + j*keys_HMI.CDELT1[0]
            HPC_out = wcs.convert_hg_hpc(x_hg,
                                         y_hg,
                                         b0_deg=keys_HMI.CRLT_OBS[0],
                                         l0_deg=keys_HMI.CRLN_OBS[0])
            x_aia = int(((HPC_out[0]) / keys_AIA.CDELT1) + keys_AIA.CRPIX1)
            y_aia = int(((HPC_out[1]) / keys_AIA.CDELT1) + keys_AIA.CRPIX2)
            aia_mask[y_aia, x_aia] = 1.0

    cropped_aia_image_data = aia_image_data * aia_mask

    return cropped_aia_image_data
Ejemplo n.º 13
0
def test_hgs_hpc(lon, lat):
    hgs = HeliographicStonyhurst(lon, lat)
    hpc = hgs.transform_to(
        Helioprojective(
            observer=HeliographicStonyhurst(0 * u.deg, 0 * u.deg, 1 * u.AU)))
    l0_deg = hpc.observer.lon
    b0_deg = hpc.observer.lat
    d0 = hpc.observer.radius

    Tx, Ty = wcs.convert_hg_hpc(lon.value,
                                lat.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(Tx * u.arcsec, hpc.Tx)
    assert_quantity_allclose(Ty * u.arcsec, hpc.Ty)
Ejemplo n.º 14
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))
Ejemplo n.º 15
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))
Ejemplo n.º 16
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)
    #runningdiffT = []
    for time in times:
        # Load/calculate temperature map data
        print time
        try:
            if time not in [times[0], times[-11], times[-2], times[-1]]:
                means.append(np.nan)
                continue
            data_dir = join(data_root, "{:%Y/%m/%d/}".format(time))
            maps_dir = join(maps_root, "{:%Y/%m/%d/}".format(time))
            thismap = tmap(time, data_dir=data_dir, maps_dir=maps_dir)#, verbose=True)
            thismap.save()
        
            # Crop temperature map to active region
            x, y = wcs.convert_hg_hpc(region['hgc_x'], region['hgc_y'],
                                      b0_deg=thismap.heliographic_latitude,
                                      l0_deg=thismap.carrington_longitude)
            thismap = thismap.submap([x-ar_rad, x+ar_rad], [y-ar_rad, y+ar_rad])

            # Append appropriate temperature values to list
            means.append(functions[parameter](thismap.data))
            #if len(means) > 1:
            #    runningdiffT.append(means[-1]-means[-2])
            #else:
            #    runningdiffT.append(0)
            
        except:
            #failed = True
            print "Failed", time
            means.append(np.nan)
            raise
Ejemplo n.º 18
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
Ejemplo n.º 19
0
Archivo: map.py Proyecto: 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
Ejemplo n.º 20
0
def HGToHPC(x, y, t):
    carringtonRotation = sun.carrington_rotation_number(t)
    carringtonLongitude = x + (carringtonRotation-int(carringtonRotation))*360
    hpc = wcs.convert_hg_hpc(carringtonLongitude, y)
    return hpc
        
        if not exists(paramvals_fname):
          paramvals = np.zeros((11, ntimes))
          for t, time in enumerate(times):
            # Load/calculate temperature map data
            print time
            try:
                data_dir = data_root#join(data_root, '{:%Y/%m/%d}'.format(time))
                maps_dir = join(home, "AR-tmaps/{:%Y/%m/%d}".format(time))

                thismap = tmap(time, data_dir=data_dir, maps_dir=maps_dir)#, verbose=True)#,
                #               submap=([x-ar_rad, x+ar_rad], [y-ar_rad, y+ar_rad]))
                thismap.save()
                # Crop temperature map to active region
                x, y = wcs.convert_hg_hpc(coords[0], coords[1],
                                          b0_deg=thismap.heliographic_latitude,
                                          l0_deg=thismap.carrington_longitude)
                print x, y
                largemap = thismap.submap([x-200, x+200], [y-200, y+200])
                thismap = thismap.submap([x-ar_rad, x+ar_rad], [y-ar_rad, y+ar_rad])

                if density:
                    thismap = thismap.calculate_density(wlen=density)
                # Crop temperature map to active region
                #x, y = flare['xpos'], flare['ypos']
                #largemap = thismap.submap([x-200, x+200], [y-200, y+200])
                #thismap = thismap.submap([x-ar_rad, x+ar_rad], [y-ar_rad, y+ar_rad])
                plt.figure('tmaps')
                plt.clf()
                axt = tmapfig.add_subplot(111)
                if density:
Ejemplo n.º 22
0
Archivo: map.py Proyecto: 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
Ejemplo n.º 23
0
    def draw_grid(self, axes=None, grid_spacing=15, **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()
        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)

        hg_longitude_deg = np.linspace(-180, 180, num=361) + self.heliographic_longitude
        hg_latitude_deg = np.arange(-90, 90, grid_spacing)

        # draw the latitude lines
        for lat in hg_latitude_deg:
            x, y = wcs.convert_hg_hpc(hg_longitude_deg, lat * np.ones(361),
                                      b0_deg=b0, l0_deg=l0, dsun_meters=dsun,
                                      angle_units=units[0], occultation=True)
            valid = np.logical_and(np.isfinite(x), np.isfinite(y))
            x = x[valid]
            y = y[valid]
            axes.plot(x, y, **plot_kw)

        hg_longitude_deg = np.arange(-180, 180, grid_spacing) + self.heliographic_longitude
        hg_latitude_deg = np.linspace(-90, 90, num=181)

        # draw the longitude lines
        for lon in hg_longitude_deg:
            x, y = wcs.convert_hg_hpc(lon * np.ones(181), hg_latitude_deg,
                                      b0_deg=b0, l0_deg=l0, dsun_meters=dsun,
                                      angle_units=units[0], occultation=True)
            valid = np.logical_and(np.isfinite(x), np.isfinite(y))
            x = x[valid]
            y = y[valid]
            axes.plot(x, y, **plot_kw)

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

        return axes
Ejemplo n.º 24
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
Ejemplo n.º 25
0
    def draw_grid(self, axes=None, grid_spacing=15, **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()
        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)

        hg_longitude_deg = np.linspace(-180, 180,
                                       num=361) + self.heliographic_longitude
        hg_latitude_deg = np.arange(-90, 90, grid_spacing)

        # draw the latitude lines
        for lat in hg_latitude_deg:
            x, y = wcs.convert_hg_hpc(hg_longitude_deg,
                                      lat * np.ones(361),
                                      b0_deg=b0,
                                      l0_deg=l0,
                                      dsun_meters=dsun,
                                      angle_units=units[0],
                                      occultation=True)
            valid = np.logical_and(np.isfinite(x), np.isfinite(y))
            x = x[valid]
            y = y[valid]
            axes.plot(x, y, **plot_kw)

        hg_longitude_deg = np.arange(
            -180, 180, grid_spacing) + self.heliographic_longitude
        hg_latitude_deg = np.linspace(-90, 90, num=181)

        # draw the longitude lines
        for lon in hg_longitude_deg:
            x, y = wcs.convert_hg_hpc(lon * np.ones(181),
                                      hg_latitude_deg,
                                      b0_deg=b0,
                                      l0_deg=l0,
                                      dsun_meters=dsun,
                                      angle_units=units[0],
                                      occultation=True)
            valid = np.logical_and(np.isfinite(x), np.isfinite(y))
            x = x[valid]
            y = y[valid]
            axes.plot(x, y, **plot_kw)

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

        return axes
Ejemplo n.º 26
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))