Exemplo n.º 1
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
"""
    size = [map.shape[1], map.shape[0]]
    scale = [map.scale['x'], map.scale['y']]
    reference_pixel = [map.reference_pixel['x'], map.reference_pixel['y']]
    reference_coordinate = [map.reference_coordinate['x'], map.reference_coordinate['y']]
    
    x, y = sunpy.wcs.convert_pixel_to_data(size, 
                                           scale,
                                           reference_pixel,
                                           reference_coordinate)
   
    hccx, hccy, hccz = wcs.convert_hpc_hcc(x, y, dsun_meters=map.dsun, angle_units='arcsec', z=True)
    print type(hccx), type(hccy), type(hccz)
    rot_hccz, rot_hccx, rot_hccy = euler_zyz((hccz, hccx, hccy), (0., epi_lat-90., -epi_lon))
    print type(rot_hccz), type(rot_hccy), type(rot_hccz)
    
    lon_map, lat_map = wcs.convert_hcc_hg(rot_hccx, rot_hccy, b0_deg=map.heliographic_latitude,
                                          l0_deg=map.heliographic_longitude)
                              
     
    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,Y = np.meshgrid(lon, lat)
    
  
    
    
    ng_xyz = wcs.convert_hg_hcc(X, Y,
                                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.))
    
    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,Y), 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"
    }

    header = sunpy.map.MapHeader(dict_header)
    transformed_map = sunpy.make_map(newdata, header)
    transformed_map.name = map.name
    transformed_map.date = map.date

    return transformed_map
Exemplo n.º 2
0
def map_hpc_to_hg_rotate(smap, epi_lon = 0, epi_lat = 0, xbin = 1, ybin = 1):
    """Take a map (like an AIA map) and convert it from HPC to HG."""

    #import sunpy
    #import util
    #from sunpy import wcs
    #import numpy as np
    #from scipy.interpolate import griddata
    from sim.wave2d.wave2d import euler_zyz
    #from matplotlib import colors
    
    # epi_lon = -10
    # epi_lat = 0
    
    #aia = sunpy.Map(sunpy.AIA_171_IMAGE).resample([500,500])
    # tmap = util.map_hpc_to_hg(aia)
    # tmap.show()
    
    #map = aia
    
    #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.reference_pixel['x'],
                                     smap.reference_pixel['y'],   
                                     smap.reference_coordinate['x'],
                                     smap.reference_coordinate['y'],
                                     smap.coordinate_system['x'])
    
    #hccx, hccy, hccz = wcs.convert_hpc_hcc_xyz(map.header, x, y)
    hccx, hccy, hccz = wcs.convert_hpc_hcc_xyz(smap.rsun_meters,
                                               smap.dsun,
                                               smap.units['x'],
                                               smap.units['y'],
                                               x,
                                               y)
    
    # rot_hccz, rot_hccy, rot_hccx = euler_zyz((hccz, hccx, hccy), (epi_lon, 90.-epi_lat, 0.))
    rot_hccz, rot_hccx, rot_hccy = euler_zyz((hccz, hccx, hccy), (0., epi_lat-90., -epi_lon))
    # zpp, xpp, ypp = euler_zyz(zxy_p, (0., hglt_obs, total_seconds*rotation))

    #lon_map, lat_map = wcs.convert_hcc_hg(map.header, rot_hccx, rot_hccy, z = rot_hccz)
    lon_map, lat_map = wcs.convert_hcc_hg(smap.rsun_meters,
                                          smap.heliographic_latitude,
                                          smap.carrington_longitude,
                                          rot_hccx, rot_hccy, z = rot_hccz)
    
    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)
    
    #This extra conversion and rotation back are needed to determine where to
    #mask out points that can't have corresponding data
    #ng_xyz = wcs.convert_hg_hcc_xyz(map.header, newgrid[0], newgrid[1])
    ng_xyz = wcs.convert_hg_hcc_xyz(smap.rsun_meters,
                                    smap.heliographic_latitude,
                                    smap.carrington_longitude,
                                    newgrid[0], newgrid[1])
    
    ng_zp, ng_xp, ng_yp = euler_zyz((ng_xyz[2], ng_xyz[0], ng_xyz[1]),
                                    (epi_lon, 90.-epi_lat, 0.))
    
    
    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
    points = points[index]
    values = values[index]
    
    newdata = griddata(points, values, newgrid, method="cubic")
    newdata[ng_zp < 0] = np.nan

    header = smap._original_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 = smap.cmap
    transformed_map.name = smap.name
    transformed_map.date = smap.date
    transformed_map.center['x'] = wcs.get_center(smap.shape[1], smap.scale['x'], smap.reference_coordinate['x'],smap.reference_pixel['x'])
    transformed_map.center['y'] = wcs.get_center(smap.shape[0], smap.scale['y'], smap.reference_coordinate['y'],smap.reference_pixel['y'])
    
    #transformed_map.show()
    
    return transformed_map
Exemplo n.º 3
0
def map_hg_to_hpc_rotate(map, epi_lon = 90, epi_lat = 0, xbin = 2.4, ybin = 2.4):
    """
Transform raw data in HG' coordinates to HPC coordinates

HG' = HG, except center at wave epicenter
"""

    #Origin grid, HG'
    lon_grid, lat_grid = sunpy.wcs.convert_pixel_to_data(size = [1,0],
                                           scale = [map.scale['x'], map.scale['y']],
                                           reference_pixel = [map.reference_pixel['x'], map.reference_pixel['y']],
                                           reference_coordinate = [map.reference_coordinate['x'], map.reference_coordinate['y']])













    #Origin grid, HG' to HCC'
    #HCC' = HCC, except centered at wave epicenter
    x, y, z = sunpy.wcs.convert_hg_hcc_xyz(map.rsun_meters,
                                           map.heliographic_latitude,
                                           map.carrington_longitude,
                                           lon_grid, lat_grid)

    #Origin grid, HCC' to HCC''
    #Moves the wave epicenter to initial conditions
    #HCC'' = HCC, except assuming that HGLT_OBS = 0
    zpp, xpp, ypp = euler_zyz((z, x, y), (epi_lon, 90.-epi_lat, 0.))

    #Origin grid, HCC to HPC (arcsec)
    #xx, yy = sunpy.wcs.convert_hcc_hpc(current_wave_map.header, xpp, ypp)
    xx, yy = sunpy.wcs.convert_hcc_hpc(map.rsun_meters,
                                       map.dsun,
                                       xpp,
                                       ypp)
    xx *= 3600
    yy *= 3600

    #Destination HPC grid
    hpcx_range = (np.nanmin(xx), np.nanmax(xx))
    hpcy_range = (np.nanmin(yy), np.nanmax(yy))

    hpcx = np.arange(hpcx_range[0], hpcx_range[1], xbin)
    hpcy = np.arange(hpcy_range[0], hpcy_range[1], ybin)
    newgrid = np.meshgrid(hpcx, hpcy)

    #Coordinate positions (HPC) with corresponding map data
    points = np.vstack((xx.ravel(), yy.ravel())).T
    values = np.array(map).ravel()

    #2D interpolation from origin grid to destination grid
    newdata = griddata(points[zpp.ravel() >= 0], values[zpp.ravel() >= 0],
                       newgrid, method="linear")

    dict_header = {
        "CDELT1": xbin,
        "NAXIS1": len(hpcx),
        "CRVAL1": hpcx.min(),
        "CRPIX1": 1, #this makes hpcx.min() the center of the first bin
        "CUNIT1": "arcsec",
        "CTYPE1": "HPLN-TAN",
        "CDELT2": ybin,
        "NAXIS2": len(hpcy),
        "CRVAL2": hpcy.min(),
        "CRPIX2": 1, #this makes hpcy.min() the center of the first bin
        "CUNIT2": "arcsec",
        "CTYPE2": "HPLT-TAN",
        "HGLT_OBS": 0,
        "HGLN_OBS": 0,
    }

    header = sunpy.map.MapHeader(dict_header)

    transformed_map = sunpy.make_map(newdata, header)
    transformed_map.name = map.name
    transformed_map.date = map.date

    return transformed_map