def test_coord_get(): # Test default (instance=None) obs = Helioprojective.observer assert obs is "earth" # Test get obstime = "2013-04-01" obs = Helioprojective(observer="earth", obstime=obstime).observer earth = get_earth(obstime) assert isinstance(obs, HeliographicStonyhurst) assert_quantity_allclose(obs.lon, earth.lon) assert_quantity_allclose(obs.lat, earth.lat) assert_quantity_allclose(obs.radius, earth.radius) # Test get obstime = "2013-04-01" obs = Helioprojective(obstime=obstime).observer earth = get_earth(obstime) assert isinstance(obs, HeliographicStonyhurst) assert_quantity_allclose(obs.lon, earth.lon) assert_quantity_allclose(obs.lat, earth.lat) assert_quantity_allclose(obs.radius, earth.radius) # Test get mars obstime = Time(parse_time("2013-04-01")) obs = Helioprojective(observer="mars", obstime=obstime).observer out_icrs = ICRS(get_body_barycentric("mars", obstime)) mars = out_icrs.transform_to(HeliographicStonyhurst(obstime=obstime)) assert isinstance(obs, HeliographicStonyhurst) assert_quantity_allclose(obs.lon, mars.lon) assert_quantity_allclose(obs.lat, mars.lat) assert_quantity_allclose(obs.radius, mars.radius)
def test_solar_angle_equivalency_outputs(): observer = get_earth("2020-11-16") distance_in_arcsec = 1 * u.arcsec distance_in_km = distance_in_arcsec.to( u.km, equivalencies=solar_angle_equivalency(observer)) distance_back_to_arcsec = distance_in_km.to( u.arcsec, equivalencies=solar_angle_equivalency(observer)) assert_quantity_allclose(distance_in_km, 717.25668 * u.km) assert_quantity_allclose(distance_back_to_arcsec, distance_in_arcsec)
def _get_new_observer(initial_obstime, observer, time): """ Helper function that interprets the possible ways of specifying the input to the solar coordinate rotation function. If the "observer" argument is not `None`, it is used to specify the location of the new observer in space and time. If the "time" argument is not `None`, it is used to calculate the duration over which to the amount of solar rotation is calculated. Note that using the "time" keyword assumes that the new observer is on the Earth. This may be a reasonable assumption depending on the application. Either the "observer" or "time" argument must be specified, but both cannot be specified at the same time and both cannot be None. Parameters ---------- initial_obstime : `~astropy.time.Time` The initial time before solar rotation has been applied. observer : `~astropy.coordinates.BaseCoordinateFrame`, `~astropy.coordinates.SkyCoord`, None The location of the new observer in space and time (the observer must have an interpretable obstime property). time : `~astropy.time.Time`, `~astropy.time.TimeDelta`, `~astropy.units.Quantity`, None Used to define the duration over which the amount of solar rotation is calculated. If 'time' is an `~astropy.time.Time` then the time interval is "time - initial_obstime"; if 'time' is `~astropy.time.TimeDelta` or `~astropy.units.Quantity` then the calculation is "initial_obstime + time". Returns ------- new_observer : `~astropy.coordinates.SkyCoord`, `~astropy.coordinates.BaseCoordinateFrame` The position of the observer in space and time. If the "time" keyword is used the output is an `~astropy.coordinates.SkyCoord`. If the "observer" keyword is not None the output has the same type as the "observer" keyword. In all cases the output is specified in the heliographic Stonyhurst coordinate system. """ _validate_observer_args(initial_obstime, observer, time) # Check the input and create the new observer if observer is not None: new_observer = observer elif time is not None: warnings.warn("Using 'time' assumes an Earth-based observer.") if isinstance(time, TimeDelta) or isinstance(time, u.Quantity): new_observer_time = initial_obstime + time else: new_observer_time = parse_time(time) new_observer = get_earth(new_observer_time) return new_observer
def test_obstime_hack(): """ Test that the obstime can be updated in place, this is used in the transform pipeline. """ h = frames.Heliocentric(observer="earth") obstime = "2011-01-01" h._obstime = obstime assert isinstance(h.observer, frames.HeliographicStonyhurst) earth = get_earth(obstime) obs = h._observer assert isinstance(obs, HeliographicStonyhurst) assert_quantity_allclose(obs.lon, earth.lon) assert_quantity_allclose(obs.lat, earth.lat) assert_quantity_allclose(obs.radius, earth.radius)
def test_obstime_hack(): """ Test that the obstime can be updated in place, this is used in the transform pipeline. """ h = frames.Heliocentric() assert h.observer is "earth" obstime = "2011-01-01" h._obstime = obstime assert isinstance(h.observer, frames.HeliographicStonyhurst) earth = get_earth(obstime) obs = h._observer assert isinstance(obs, HeliographicStonyhurst) assert_quantity_allclose(obs.lon, earth.lon) assert_quantity_allclose(obs.lat, earth.lat) assert_quantity_allclose(obs.radius, earth.radius)
def make_map_ipa(file): """ Function to make a sunpy.map.GenericMap from a NoRH fits file. This function fixes the header keywords so that it works within map. Parameters ---------- file : `str` path of NoRH fits file to read into a map Returns ------- `sunpy.map.GenericMap """ hdu = fits.open(file)[0] header = hdu.header data = hdu.data header['CUNIT1'], header['CUNIT2'] = 'arcsec', 'arcsec' header['CTYPE1'], header['CTYPE2'] = 'HPLN-TAN', 'HPLT-TAN' header['date-obs'] = header['date-obs'] + 'T' + header['time-obs'] # get observer location observer = get_earth(header['date-obs']) observer = observer.transform_to( frames.HeliographicStonyhurst(obstime=observer.obstime)) header['hgln_obs'] = observer.lon.to_value(u.deg) header['hglt_obs'] = observer.lat.to_value(u.deg) header['dsun_obs'] = observer.radius.to_value(u.m) header['rsun_obs'] = sun.angular_radius( header['date-obs']).to('arcsec').value norh_map = sunpy.map.Map(data, header) norh_map.plot_settings['cmap'] = 'BuPu' #norh_map.plot_settings['norm'] = LogNorm() return norh_map