Ejemplo n.º 1
0
def project_to_ss(seeds, vsw, obstime):
    """
    Project a set of abitrary coordinates in the heliosphere on to the source
    surface.
    
    Parameters
    ----------
    seeds : astropy.coordinates.SkyCoord
        Seed points to be projected onto the source surface
    vsw : Quantity
        Solar wind velocity used to ballistically project backwards
    obstime : datetime
        Observation time of the map that the seeds will be traced through
        
    Returns
    -------
    seeds_ss : astropy.coordinates.SkyCoord
        Seed points projected on to the source surface.
    """
    seeds.representation_type = 'spherical'
    # Calculate the time it takes for the solar wind to travel radially to
    # the source surface
    dt = (seeds.radius - rss * const.R_sun) / vsw
    # Construct the Carrington frame that existed when the plasma left th
    # source surface
    ss_frame = sunframes.HeliographicCarrington(obstime=seeds.obstime - dt)
    # Transform to this frame
    seeds_ss = seeds.transform_to(ss_frame)
    # Finally, set the radius to the source surface
    seeds_ss = SkyCoord(seeds_ss.lon,
                        seeds_ss.lat,
                        rss * 0.99 * const.R_sun,
                        obstime=obstime,
                        frame='heliographic_carrington')
    return seeds_ss
Ejemplo n.º 2
0
def rot_hgc():
    return (f.HeliographicCarrington,
            RotatedSunFrame(lon=1 * u.deg,
                            lat=2 * u.deg,
                            radius=3 * u.AU,
                            base=f.HeliographicCarrington(
                                observer='earth', obstime='2001-01-01'),
                            duration=4 * u.day))
Ejemplo n.º 3
0
def map_interp_carrington(m, fpoints):
    """
    Given a SunPy map, and a series of footpoints, interpolate
    the map data on to the footpoints.
    """
    fpoints = sunframes.HeliographicCarrington(fpoints.lon,
                                               fpoints.lat,
                                               fpoints.radius,
                                               obstime=m.date)
    pixels = m.world_to_pixel(fpoints)
    x, y = (pixels.x / u.pix).astype(int), (pixels.y / u.pix).astype(int)
    trace = m.data[y, x]
    # Remove points that are behind the Sun
    # trace = trace.astype(float)
    # trace[fpoints.distance > m.dsun] = np.nan
    return trace
Ejemplo n.º 4
0
def project_to_ss(coords, vsw, source_surface_r):
    """
    Project a set of abitrary coordinates in the heliosphere on to the source
    surface.

    Parameters
    ----------
    coords : astropy.coordinates.SkyCoord
        Coordinates to be projected onto the source surface.
    vsw : Quantity
        Solar wind velocity used to ballistically project backwards.
    source_surface_r : astropy.units.Quantity
        Source surface radius to project on to.

    Returns
    -------
    seeds_ss : astropy.coordinates.SkyCoord
        Seed points projected on to the source surface.
    """
    coords.representation_type = 'spherical'
    # Calculate the time it takes for the solar wind to travel radially to
    # the source surface
    dt = ((coords.radius - source_surface_r) / vsw).to(u.s)
    # Construct the Carrington frame that existed when the plasma left the
    # source surface
    ss_frame = sunframes.HeliographicCarrington(obstime=coords.obstime - dt)
    # Transform to this frame
    coords_ss = coords.transform_to(ss_frame)
    # Finally, set the radius to the source surface
    coords_ss = SkyCoord(coords_ss.lon,
                         coords_ss.lat,
                         source_surface_r,
                         obstime=coords.obstime,
                         observer=coords.observer,
                         frame='heliographic_carrington')
    return coords_ss
Ejemplo n.º 5
0
# to_skycoord function. Units are converted to meters.
# Note: this must be in the GEO system.
skycoord = coord.to_skycoord()
print(skycoord)

# See the Astropy documentation for `transforming coordinates <https://docs.astropy.org/en/stable/coordinates/transforming.html#astropy-coordinates-transforming>`_. Here is a simple
# example that transforms the skycoord into the FK5 system.
sky_fk5 = skycoord.transform_to('fk5')
print(sky_fk5)

##############################################################################
# Use the `SunPy frames <https://docs.sunpy.org/en/stable/code_ref/coordinates/index.html>`_ function to transform this coordinate into a
# Heliogaphic Carrington coordinate.
# Note: helioprojective frames require that an observer be defined.
sky_helio = skycoord.transform_to(
    frames.HeliographicCarrington(observer="earth"))
print(sky_helio)

# See the `Astropy Coordinates and SunPy Demo <https://heliopython.org/gallery/generated/gallery/coordinates_demo.html#sphx-glr-generated-gallery-coordinates-demo-py>`_ for coordinate
# transformations in SunPy.

##############################################################################
# Now, convert the coordinate back into its original form to demonstrate
# transformations in the other direction, and the loss of precision. First,
# convert this back to GEO coordinates (ITRS in Astropy).
sun_geo = sky_helio.transform_to('itrs')
print(sun_geo)

# Lastly, use the SpacePy from_skycoord function to transform this back into a
# SpacePy coordinate.
coord = Coords.from_skycoord(sun_geo)
Ejemplo n.º 6
0
    def __init__(self,
                 date,
                 body_list,
                 vsw_list=[],
                 reference_long=None,
                 reference_lat=None):
        body_list = list(dict.fromkeys(body_list))
        bodies = deepcopy(body_dict)

        self.date = date
        self.reference_long = reference_long
        self.reference_lat = reference_lat

        pos_E = get_horizons_coord(
            399, self.date, 'id')  # (lon, lat, radius) in (deg, deg, AU)
        self.pos_E = pos_E.transform_to(
            frames.HeliographicCarrington(observer='Sun'))

        if len(vsw_list) == 0:
            vsw_list = np.zeros(len(body_list)) + 400

        random_cols = [
            'forestgreen', 'mediumblue', 'm', 'saddlebrown', 'tomato', 'olive',
            'steelblue', 'darkmagenta', 'c', 'darkslategray', 'yellow',
            'darkolivegreen'
        ]
        body_lon_list = []
        body_lat_list = []
        body_dist_list = []
        longsep_E_list = []
        latsep_E_list = []
        body_vsw_list = []
        footp_long_list = []
        longsep_list = []
        latsep_list = []
        footp_longsep_list = []

        for i, body in enumerate(body_list.copy()):
            if body in bodies:
                body_id = bodies[body][0]
                body_lab = bodies[body][1]
                body_color = bodies[body][2]

            else:
                body_id = body
                body_lab = str(body)
                body_color = random_cols[i]
                bodies.update(
                    dict.fromkeys([body_id], [body_id, body_lab, body_color]))

            try:
                pos = get_horizons_coord(
                    body_id, date,
                    'id')  # (lon, lat, radius) in (deg, deg, AU)
                pos = pos.transform_to(
                    frames.HeliographicCarrington(observer='Sun'))
                bodies[body_id].append(pos)
                bodies[body_id].append(vsw_list[i])

                longsep_E = pos.lon.value - self.pos_E.lon.value
                if longsep_E > 180:
                    longsep_E = longsep_E - 360.
                latsep_E = pos.lat.value - self.pos_E.lat.value

                body_lon_list.append(pos.lon.value)
                body_lat_list.append(pos.lat.value)
                body_dist_list.append(pos.radius.value)
                longsep_E_list.append(longsep_E)
                latsep_E_list.append(latsep_E)

                body_vsw_list.append(vsw_list[i])

                sep, alpha = self.backmapping(pos,
                                              date,
                                              reference_long,
                                              vsw=vsw_list[i])
                bodies[body_id].append(sep)

                body_footp_long = pos.lon.value + alpha
                if body_footp_long > 360:
                    body_footp_long = body_footp_long - 360
                footp_long_list.append(body_footp_long)

                if self.reference_long is not None:
                    bodies[body_id].append(sep)
                    long_sep = pos.lon.value - self.reference_long
                    if long_sep > 180:
                        long_sep = long_sep - 360.

                    longsep_list.append(long_sep)
                    footp_longsep_list.append(sep)

                if self.reference_lat is not None:
                    lat_sep = pos.lat.value - self.reference_lat
                    latsep_list.append(lat_sep)
            except ValueError:
                print('')
                print('!!! No ephemeris for target "' + str(body) +
                      '" for date ' + self.date)
                body_list.remove(body)

        body_dict_short = {sel_key: bodies[sel_key] for sel_key in body_list}
        self.body_dict = body_dict_short
        self.max_dist = np.max(body_dist_list)
        self.coord_table = pd.DataFrame({
            'Spacecraft/Body':
            list(self.body_dict.keys()),
            'Carrington Longitude (°)':
            body_lon_list,
            'Latitude (°)':
            body_lat_list,
            'Heliocentric Distance (AU)':
            body_dist_list,
            "Longitudinal separation to Earth's longitude":
            longsep_E_list,
            "Latitudinal separation to Earth's latitude":
            latsep_E_list,
            'Vsw':
            body_vsw_list,
            'Magnetic footpoint longitude (Carrington)':
            footp_long_list
        })

        if self.reference_long is not None:
            self.coord_table[
                'Longitudinal separation between body and reference_long'] = longsep_list
            self.coord_table[
                "Longitudinal separation between body's mangetic footpoint and reference_long"] = footp_longsep_list
        if self.reference_lat is not None:
            self.coord_table[
                'Latitudinal separation between body and reference_lat'] = latsep_list

        pass
        self.coord_table.style.set_properties(**{'text-align': 'left'})
Ejemplo n.º 7
0
import astropy.units as u
from astropy.coordinates import SkyCoord
from sunpy.coordinates import frames
import pandas as pd
from datetime import datetime

data = pd.read_csv('SigmoidCatalogAll_filament.csv')

#remove first 30 which were not reanalyzed
data = data.iloc[28:,:]
data = data.loc[[isinstance(i,str) for i in data.tobs],:]

dfmt = '%Y-%m-%dT%H:%M:%S.000'

for j in range(data.shape[0]):
    c = SkyCoord(data.iloc[j,:].X*u.arcsec, data.iloc[j,:].Y*u.arcsec, obstime=datetime.strptime(data.iloc[j,:].tobs,dfmt), frame=frames.Helioprojective)
    p = c.transform_to(frames.HeliographicCarrington(obstime=datetime.strptime(data.iloc[j,:].TBEST,dfmt)))
    print('ID = {0:3d} ==> SOL{1}L{3:03.0f}C{2:03.0f}'.format(data.iloc[j,:].ID,datetime.strptime(data.iloc[j,:].TBEST,dfmt).strftime('%Y-%m-%dT%H:%M:%S'),90.-p.lat.value,p.lon.value))