def test(): test_date = swdt.parse('2000-01-01_00:00:00') print "Diff rot: ", coords.diff_rot(86400, 0),sdiff.diff_rot(86400*u.second,0*u.degree) print "P, B0, SD: ", coords.get_pb0sd(test_date),sdiff._calc_P_B0_SD(test_date) print "Solar position: ",coords.get_solar_position(test_date),sdiff._sun_pos(test_date) l0 = 0 b0 = 0 scale = 0.6,0.6 reference_pixel = 2048.5,2048.5 reference_coordinate = 0, 0 rotation = 180 ij = 1000,1000 print "Input coords: ",ij xy = coords.convert_pixel_to_data(ij, scale, reference_pixel, reference_coordinate,rotation) print "Convert to data: ",xy recall_ij = coords.convert_data_to_pixel(xy, scale, reference_pixel, reference_coordinate,rotation) print "Recall: ", recall_ij lonlat = coords.convert_hpc_hg(xy,b0,l0) print "Convert to hg", lonlat recall_xy = coords.convert_hg_hpc(lonlat,b0,l0) print "Recall to hpc", recall_xy recall_ij = coords.convert_data_to_pixel(recall_xy, scale, reference_pixel, reference_coordinate,rotation) print "Recall to pixel", recall_ij
def diff_rot(m1, m2): """Given two CRD objects, differentially rotate image 2 to match image 1 Args: m1 (obj): first image to rotate to m2 (obj): second image to be rotated differentially Returns: rotation: rotation array containing values to add to longitude """ time_diff = u.Quantity( (m1.im_raw.date - m2.im_raw.date).total_seconds(), 'second') rotation = d.diff_rot(time_diff, m2.lath.v*u.deg, rot_type='snodgrass', frame_time='synodic') if np.nanmean(rotation).value > 90: rotation -= 360*u.deg return rotation
def test_synodic(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='howard', frame_time='synodic') assert_quantity_allclose(rot, 126.9656 * u.deg, rtol=1e-3)
def test_single(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg) assert_quantity_allclose(rot, 136.8216 * u.deg, rtol=1e-3)
def test_snodgrass(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='snodgrass') assert_quantity_allclose(rot, 135.4232 * u.deg, rtol=1e-3)
def test_sidereal(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='howard', frame_time='sidereal') assert_quantity_allclose(rot, 136.8216 * u.deg, rtol=1e-3)
def test_array(seconds_per_day): rot = diff_rot(10 * seconds_per_day, np.linspace(-70, 70, 2) * u.deg) assert_quantity_allclose(rot, Longitude(np.array([110.2725, 110.2725]) * u.deg), rtol=1e-3)
import astropy.units as u from astropy.coordinates import SkyCoord from astropy.time import TimeDelta import sunpy.data.sample import sunpy.map from sunpy.physics.differential_rotation import diff_rot, solar_rotate_coordinate ############################################################################## # Next lets explore solar differential rotation by replicating Figure 1 # in Beck 1999. latitudes = np.arange(0, 90, 1) * u.deg dt = 1 * u.day rotation_rate = [diff_rot(dt, this_lat) / dt for this_lat in latitudes] rotation_period = [360 * u.deg / this_rate for this_rate in rotation_rate] plt.figure() plt.plot(np.sin(latitudes), [this_period.value for this_period in rotation_period]) plt.ylim(38, 24) plt.ylabel('Rotation Period [{}]'.format(rotation_period[0].unit)) plt.xlabel('Sin(Latitude)') plt.title('Solar Differential Rotation Rate') ############################################################################## # Next let's show how to this looks like on the Sun. # Load in an AIA map: aia_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
def rot_location(loc_test, ts, te): # example inputs to function ''' ts = datetime.datetime.strptime('2018-12-02 10:22', '%Y-%m-%d %H:%M') te = datetime.datetime.strptime('2018-12-04 09:27', '%Y-%m-%d %H:%M') loc_test = 'S44W42 ''' #time difference in seconds in astropy.units.Quantity dt = (te - ts).total_seconds() * u.s #lat and lon values in astropy.units.Quantity lat = int(loc_test[1:3]) * u.deg lon = int(loc_test[4:6]) * u.deg #positive N, negative S, positive W, negative E if loc_test[0] == 'S': lat = -lat if loc_test[3] == 'E': lon = -lon #convert into SkyCoord sunpy coordinates coords_old = SkyCoord(lon, lat, frame=frames.HeliographicStonyhurst, obstime=ts) #calculate rotation of lon (i.e. x) after time dt new_lon = (round(diff_rot(dt, lat).value) + lon.value) * u.deg #check is regions are off limb - if so set to 91 (west limb) or -91 (east limb) if new_lon.value > 90: new_lon = 91 * u.deg if new_lon.value < -90: new_lon = -91 * u.deg #new Skycoord after time dt coords_new = SkyCoord(new_lon, lat, frame=frames.HeliographicStonyhurst, obstime=te) #convert back to N, S, E, W format if coords_new.lat.value <= 0: lat_end = 'S' + str('%02d' % np.abs(int(coords_new.lat.value))) elif coords_new.lat.value > 0: lat_end = 'N' + str('%02d' % np.abs(int(coords_new.lat.value))) else: print('problem') if coords_new.lon.value <= 0: lon_end = 'E' + str('%02d' % np.abs(int(coords_new.lon.value))) elif coords_new.lon.value > 0: lon_end = 'W' + str('%02d' % np.abs(int(coords_new.lon.value))) else: print('problem') loc_end = lat_end + lon_end coords_new_hpc = coords_new.transform_to(frames.Helioprojective) solar_xy = [coords_new_hpc.Tx.value, coords_new_hpc.Ty.value] return loc_end, solar_xy
def test_snodgrass(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='snodgrass') assert rot == 135.4232 * u.deg
def test_allen(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='allen') assert rot == 136.9 * u.deg
def test_howard(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='howard') assert rot == 136.8216 * u.deg
def test_sidereal(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='howard', frame_time='sidereal') assert rot == 136.8216 * u.deg
def test_synodic(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='howard', frame_time='synodic') assert rot == 126.9656 * u.deg
def test_howard(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='howard') assert_quantity_allclose(rot, 136.8216 * u.deg, rtol=1e-3)
def test_single(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg) assert rot == 136.8216 * u.deg
import matplotlib.pyplot as plt import astropy.units as u from astropy.coordinates import SkyCoord import sunpy.map import sunpy.data.sample from sunpy.physics.differential_rotation import diff_rot, solar_rotate_coordinate ############################################################################## # Next lets explore solar differential rotation by replicating Figure 1 # in Beck 1999 latitudes = u.Quantity(np.arange(0, 90, 1), 'deg') dt = 1 * u.day rotation_rate = [diff_rot(dt, this_lat) / dt for this_lat in latitudes] rotation_period = [360 * u.deg / this_rate for this_rate in rotation_rate] fig = plt.figure() plt.plot(np.sin(latitudes), [this_period.value for this_period in rotation_period]) plt.ylim(38, 24) plt.ylabel('Rotation Period [{0}]'.format(rotation_period[0].unit)) plt.xlabel('Sin(Latitude)') plt.title('Solar Differential Rotation Rate') ############################################################################## # Next let's show how to this looks like on the Sun. # Load in an AIA map: aia_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
def test_fail(seconds_per_day): with pytest.raises(ValueError): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='garbage')
def test_rigid(seconds_per_day): rot = diff_rot(10 * seconds_per_day, [0, 30, 60] * u.deg, rot_type='rigid') assert_quantity_allclose(rot, [141.844 * u.deg] * 3, rtol=1e-3)
def test_allen(seconds_per_day): rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='allen') assert_quantity_allclose(rot, 136.9 * u.deg, rtol=1e-3)