コード例 #1
0
ファイル: test_wcs.py プロジェクト: amhuertash/sunpy
def test_conv_hpc_hcc(angle_unit, dsun):
    coord = [40.0, 32.0]
    result = wcs.convert_hpc_hcc(coord[0], coord[1], angle_units=angle_unit, dsun_meters=dsun)
    known_answer = [28512914, 22810332]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)

    result = wcs.convert_hpc_hcc(coord[0], coord[1], angle_units=angle_unit, dsun_meters=0.5*dsun)
    known_answer = [14323802., 11459042.]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)

    # Make sure that z coordinate is returned if parameter z is True
    result = wcs.convert_hpc_hcc(coord[0], coord[1], angle_units=angle_unit, dsun_meters=dsun, z=True)
    known_answer = [28748691, 22998953, 695016924]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
コード例 #2
0
def test_conv_hpc_hcc():
    coord = [40.0, 32.0]
    result = wcs.convert_hpc_hcc(coord[0],
                                 coord[1],
                                 angle_units=img.units['x'])
    known_answer = [28748691, 22998953]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
コード例 #3
0
ファイル: test_wcs.py プロジェクト: sharmarahul20/sunpy
def test_conv_hpc_hcc():
    coord = [40.0, 32.0]
    result = wcs.convert_hpc_hcc(coord[0], coord[1], angle_units=img.units['x'])
    known_answer = [28748691, 22998953]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
    
    # Test the dsun_meters parameter for a distance of 0.5 AU
    dist = 0.5 * sun.constants.au.si.value
    result = wcs.convert_hpc_hcc(coord[0], coord[1], dist, img.units['x'])
    known_answer = [14370494, 11496395]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
    
    # Make sure that z coordinate is returned if parameter z is True
    result = wcs.convert_hpc_hcc(coord[0], coord[1], angle_units=img.units['x'],
                                                     z=True)
    known_answer = [28748691, 22998953, 695016924]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
コード例 #4
0
ファイル: test_wcs.py プロジェクト: tdunn19/sunpy
def test_conv_hpc_hcc():
    coord = [40.0, 32.0]
    result = wcs.convert_hpc_hcc(img.rsun_meters, 
                                 img.dsun, img.units['x'], img.units['y'], 
                                 coord[0], coord[1])
    known_answer = [28748691, 22998953]
    magnitude = np.floor(np.log10(np.abs(known_answer)))
    assert_array_almost_equal(result*10**(-magnitude), 
                              known_answer*10**(-magnitude), decimal=2)
コード例 #5
0
def test_hpc_hcc(Tx, Ty):
    hpc = Helioprojective(Tx, Ty)
    hcc = hpc.transform_to(Heliocentric)

    x, y, z = wcs.convert_hpc_hcc(Tx.value, Ty.value, angle_units='arcsec',
                                  dsun_meters=hpc.D0.to(u.m), z=True)

    assert_quantity_allclose(x*u.m, hcc.x)
    assert_quantity_allclose(y*u.m, hcc.y)
    assert_quantity_allclose(z*u.m, hcc.z)
コード例 #6
0
ファイル: test_wcs.py プロジェクト: sharmarahul20/sunpy
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)
コード例 #7
0
def test_hpc_hcc(Tx, Ty):
    hpc = Helioprojective(Tx, Ty,
                          observer=HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU))
    hcc = hpc.transform_to(Heliocentric)
    d0 = hpc.observer.radius

    x, y, z = wcs.convert_hpc_hcc(Tx.value, Ty.value, angle_units='arcsec',
                                  dsun_meters=d0.to(u.m), z=True)

    assert_quantity_allclose(x*u.m, hcc.x)
    assert_quantity_allclose(y*u.m, hcc.y)
    assert_quantity_allclose(z*u.m, hcc.z)
コード例 #8
0
ファイル: test_wcs.py プロジェクト: yudhik11/sunpy
def test_conv_hpc_hcc(angle_unit, dsun):
    coord = [40.0, 32.0]
    result = wcs.convert_hpc_hcc(coord[0],
                                 coord[1],
                                 angle_units=angle_unit,
                                 dsun_meters=dsun)
    known_answer = [28512914, 22810332]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)

    result = wcs.convert_hpc_hcc(coord[0],
                                 coord[1],
                                 angle_units=angle_unit,
                                 dsun_meters=0.5 * dsun)
    known_answer = [14323802., 11459042.]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)

    # Make sure that z coordinate is returned if parameter z is True
    result = wcs.convert_hpc_hcc(coord[0],
                                 coord[1],
                                 angle_units=angle_unit,
                                 dsun_meters=dsun,
                                 z=True)
    known_answer = [28748691, 22998953, 695016924]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
コード例 #9
0
def test_hpc_hcc(Tx, Ty):
    hpc = Helioprojective(Tx,
                          Ty,
                          observer=HeliographicStonyhurst(
                              0 * u.deg, 0 * u.deg, 1 * u.AU))
    hcc = hpc.transform_to(Heliocentric)
    d0 = hpc.observer.radius

    x, y, z = wcs.convert_hpc_hcc(Tx.value,
                                  Ty.value,
                                  angle_units='arcsec',
                                  dsun_meters=d0.to(u.m),
                                  z=True)

    assert_quantity_allclose(x * u.m, hcc.x)
    assert_quantity_allclose(y * u.m, hcc.y)
    assert_quantity_allclose(z * u.m, hcc.z)
コード例 #10
0
ファイル: test_wcs.py プロジェクト: yudhik11/sunpy
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))
コード例 #11
0
ファイル: test_wcs.py プロジェクト: sharmarahul20/sunpy
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))
コード例 #12
0
ファイル: test_wcs.py プロジェクト: amhuertash/sunpy
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))
コード例 #13
0
def map_hpc_to_hg_rotate(m,
                         epi_lon=0*u.degree, epi_lat=90*u.degree,
                         lon_bin=1*u.degree, lat_bin=1*u.degree,
                         lon_num=None, lat_num=None, **kwargs):
    """
    Transform raw data in HPC coordinates to HG' coordinates

    HG' = HG, except center at wave epicenter
    """
    x, y = wcs.convert_pixel_to_data([m.data.shape[1], m.data.shape[0]],
                                     [m.scale.x.value, m.scale.y.value],
                                     [m.reference_pixel.x.value, m.reference_pixel.y.value],
                                     [m.reference_coordinate.x.value, m.reference_coordinate.y.value])

    hccx, hccy, hccz = wcs.convert_hpc_hcc(x,
                                           y,
                                           angle_units=m.spatial_units.x,
                                           dsun_meters=m.dsun.to('meter').value,
                                           z=True)

    rot_hccz, rot_hccx, rot_hccy = euler_zyz((hccz,
                                              hccx,
                                              hccy),
                                             (0.,
                                              epi_lat.to('degree').value-90.,
                                              -epi_lon.to('degree').value))

    lon_map, lat_map = wcs.convert_hcc_hg(rot_hccx,
                                          rot_hccy,
                                          b0_deg=m.heliographic_latitude.to('degree').value,
                                          l0_deg=m.heliographic_longitude.to('degree').value,
                                          z=rot_hccz)

    lon_range = (np.nanmin(lon_map), np.nanmax(lon_map))
    lat_range = (np.nanmin(lat_map), np.nanmax(lat_map))

    # This method results in a set of lons and lats that in general does not
    # exactly span the range of the data.
    # lon = np.arange(lon_range[0], lon_range[1], lon_bin)
    # lat = np.arange(lat_range[0], lat_range[1], lat_bin)

    # This method gives a set of lons and lats that exactly spans the range of
    # the data at the expense of having to define values of cdelt1 and cdelt2
    if lon_num is None:
        cdelt1 = lon_bin.to('degree').value
        lon = np.arange(lon_range[0], lon_range[1], cdelt1)
    else:
        nlon = lon_num.to('pixel').value
        cdelt1 = (lon_range[1] - lon_range[0]) / (1.0*nlon - 1.0)
        lon = np.linspace(lon_range[0], lon_range[1], num=nlon)

    if lat_num is None:
        cdelt2 = lat_bin.to('degree').value
        lat = np.arange(lat_range[0], lat_range[1], cdelt2)
    else:
        nlat = lat_num.to('pixel').value
        cdelt2 = (lat_range[1] - lat_range[0]) / (1.0*nlat - 1.0)
        lat = np.linspace(lat_range[0], lat_range[1], num=nlat)

    # Create the grid
    x_grid, y_grid = np.meshgrid(lon, lat)

    ng_xyz = wcs.convert_hg_hcc(x_grid,
                                y_grid,
                                b0_deg=m.heliographic_latitude.to('degree').value,
                                l0_deg=m.heliographic_longitude.to('degree').value,
                                z=True)

    ng_zp, ng_xp, ng_yp = euler_zyz((ng_xyz[2],
                                     ng_xyz[0],
                                     ng_xyz[1]),
                                    (epi_lon.to('degree').value,
                                     90.-epi_lat.to('degree').value,
                                     0.))

    # The function ravel flattens the data into a 1D array
    points = np.vstack((lon_map.ravel(), lat_map.ravel())).T
    values = np.array(m.data).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
    points = points[index]
    values = values[index]

    newdata = griddata(points, values, (x_grid, y_grid), **kwargs)
    newdata[ng_zp < 0] = np.nan

    dict_header = {
        'CDELT1': cdelt1,
        'NAXIS1': len(lon),
        'CRVAL1': lon.min(),
        'CRPIX1': crpix12_value_for_HG,
        'CRPIX2': crpix12_value_for_HG,
        'CUNIT1': "deg",
        'CTYPE1': "HG",
        'CDELT2': cdelt2,
        'NAXIS2': len(lat),
        'CRVAL2': lat.min(),
        'CUNIT2': "deg",
        'CTYPE2': "HG",
        'DATE_OBS': m.meta['date-obs'],
        'DSUN_OBS': m.dsun.to('m').value,
        "CRLN_OBS": m.carrington_longitude.to('degree').value,
        "HGLT_OBS": m.heliographic_latitude.to('degree').value,
        "HGLN_OBS": m.heliographic_longitude.to('degree').value,
        'EXPTIME': m.exposure_time.to('s').value
    }

    # Find out where the non-finites are
    mask = np.logical_not(np.isfinite(newdata))

    # Return a masked array is appropriate
    if mask is None:
        hg = Map(newdata, MapMeta(dict_header))
    else:
        hg = Map(ma.array(newdata, mask=mask), MapMeta(dict_header))

    hg.plot_settings = m.plot_settings
    return hg
コード例 #14
0
ファイル: util.py プロジェクト: aringlis/eitwave
def map_hpc_to_hg_rotate(map, epi_lon = 0, epi_lat = 90, lon_bin = 1, lat_bin = 1):
    """
    Transform raw data in HPC coordinates to HG' coordinates

    HG' = HG, except center at wave epicenter
    """
    x, y = sunpy.wcs.convert_pixel_to_data([map.shape[1], map.shape[0]],
                                           [map.scale['x'], map.scale['y']],
                                           [map.reference_pixel['x'], map.reference_pixel['y']],
                                           [map.reference_coordinate['x'],map.reference_coordinate['y']])

    hccx, hccy, hccz = wcs.convert_hpc_hcc(x, y, angle_units=map.units['x'], z=True)

    rot_hccz, rot_hccx, rot_hccy = euler_zyz((hccz, hccx, hccy), (0., epi_lat-90., -epi_lon))

    lon_map, lat_map = wcs.convert_hcc_hg(rot_hccx, rot_hccy, b0_deg=map.heliographic_latitude,
                                          l0_deg=map.heliographic_longitude,z = rot_hccz)

    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)
    x_grid, y_grid = np.meshgrid(lon, lat)

    ng_xyz = wcs.convert_hg_hcc(x_grid, y_grid,b0_deg=map.heliographic_latitude,
                                l0_deg=map.heliographic_longitude,z=True)

    ng_zp, ng_xp, ng_yp = euler_zyz((ng_xyz[2], ng_xyz[0], ng_xyz[1]),
                                        (epi_lon, 90.-epi_lat, 0.))

        #ravel flattens the data into a 1D array
    points = np.vstack((lon_map.ravel(), lat_map.ravel())).T
    values = np.array(map).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
    points = points[index]
    values = values[index]

    newdata = griddata(points, values, (x_grid,y_grid), method="linear")
    newdata[ng_zp < 0] = np.nan

    dict_header = {
        'CDELT1': lon_bin,
        'NAXIS1': len(lon),
        'CRVAL1': lon.min(),
        'CRPIX1': 1,
        'CRPIX2': 1,
        'CUNIT1': "deg",
        'CTYPE1': "HG",
        'CDELT2': lat_bin,
        'NAXIS2': len(lat),
        'CRVAL2': lat.min(),
        'CUNIT2': "deg",
        'CTYPE2': "HG",
        'DATE_OBS': map.meta['date-obs']
    }

    header = dict_header
    transformed_map = sunpy.map.Map(newdata, header)
    transformed_map.name = map.name

    return transformed_map
コード例 #15
0
def map_hpc_to_hg_rotate(map, epi_lon=0, epi_lat=90, lon_bin=1, lat_bin=1):
    """
    Transform raw data in HPC coordinates to HG' coordinates

    HG' = HG, except center at wave epicenter
    """
    x, y = sunpy.wcs.convert_pixel_to_data(
        [map.shape[1], map.shape[0]], [map.scale['x'], map.scale['y']],
        [map.reference_pixel['x'], map.reference_pixel['y']],
        [map.reference_coordinate['x'], map.reference_coordinate['y']])

    hccx, hccy, hccz = wcs.convert_hpc_hcc(x,
                                           y,
                                           angle_units=map.units['x'],
                                           z=True)

    rot_hccz, rot_hccx, rot_hccy = euler_zyz((hccz, hccx, hccy),
                                             (0., epi_lat - 90., -epi_lon))

    lon_map, lat_map = wcs.convert_hcc_hg(rot_hccx,
                                          rot_hccy,
                                          b0_deg=map.heliographic_latitude,
                                          l0_deg=map.heliographic_longitude,
                                          z=rot_hccz)

    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)
    x_grid, y_grid = np.meshgrid(lon, lat)

    ng_xyz = wcs.convert_hg_hcc(x_grid,
                                y_grid,
                                b0_deg=map.heliographic_latitude,
                                l0_deg=map.heliographic_longitude,
                                z=True)

    ng_zp, ng_xp, ng_yp = euler_zyz((ng_xyz[2], ng_xyz[0], ng_xyz[1]),
                                    (epi_lon, 90. - epi_lat, 0.))

    #ravel flattens the data into a 1D array
    points = np.vstack((lon_map.ravel(), lat_map.ravel())).T
    values = np.array(map).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
    points = points[index]
    values = values[index]

    newdata = griddata(points, values, (x_grid, y_grid), method="linear")
    newdata[ng_zp < 0] = np.nan

    dict_header = {
        'CDELT1': lon_bin,
        'NAXIS1': len(lon),
        'CRVAL1': lon.min(),
        'CRPIX1': 1,
        'CRPIX2': 1,
        'CUNIT1': "deg",
        'CTYPE1': "HG",
        'CDELT2': lat_bin,
        'NAXIS2': len(lat),
        'CRVAL2': lat.min(),
        'CUNIT2': "deg",
        'CTYPE2': "HG",
        'DATE_OBS': map.meta['date-obs']
    }

    header = dict_header
    transformed_map = sunpy.map.Map(newdata, header)
    transformed_map.name = map.name

    return transformed_map
コード例 #16
0
ファイル: test_wcs.py プロジェクト: quintusdias/sunpy
def test_conv_hpc_hcc():
    coord = [40.0, 32.0]
    result = wcs.convert_hpc_hcc(coord[0], coord[1], angle_units=img.units['x'])
    known_answer = [28748691, 22998953]
    assert_allclose(result, known_answer, rtol=1e-2, atol=0)
コード例 #17
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))