def distanceToSun(self): """ Find the distance between the Sun and the target pointings """ lofar = Observer() lofar.lon = '6.869882' lofar.lat = '52.915129' lofar.elevation = 15.*u.m lofar.date = self.startTime # Create Sun object sun = Sun() sun.compute(lofar) # Create the target object target = FixedBody() target._epoch = '2000' target._ra = self.coordPoint1.ra.radian target._dec = self.coordPoint1.dec.radian target.compute(lofar) print 'INFO: Sun is {:0.2f} degrees away from {}'.format(\ float(separation(target, sun))*180./np.pi, self.namePoint1) target._ra = self.coordPoint2.ra.radian target._dec = self.coordPoint2.dec.radian target.compute(lofar) print 'INFO: Sun is {:0.2f} degrees away from {}'.format(\ float(separation(target, sun))*180./np.pi, self.namePoint2)
def get_elevation_solar(obs_date, offender): """For a given observation date and bright solar system object, return its elevation over the course of that day. Input parameters: * obs_date: Observation date in datetime.datetime format * offender: Name of the solar system object. Allowed names are Sun, Moon, and Jupiter. Returns: List of elevations in degrees. If offender is invalid, return None. """ # Create the telescope object lofar = get_dutch_lofar_object() if offender == 'Sun': obj = Sun() elif offender == 'Moon': obj = Moon() elif offender == 'Jupiter': obj = Jupiter() else: return None yaxis = [] for time in obs_date: lofar.date = time obj.compute(lofar) elevation = float(obj.alt)*180./np.pi if elevation < 0: elevation = np.nan yaxis.append(elevation) return yaxis
def _findDistanceToSun(self, coord): """ Print the distance between the specified pointing center and the Sun. """ # Find the coordinates of the Sun at the start of the observing run sun = Sun() sun.compute(self.startTime) coordSun = SkyCoord('{} {}'.format(sun.ra, sun.dec), unit=(u.hourangle, u.deg)) coordTarget = SkyCoord('{} {}'.format(coord.split(';')[0], \ coord.split(';')[1]), \ unit=(u.hourangle, u.deg)) # Find the separation between the Sun and the target return coordSun.separation(coordTarget).deg
def from_observer(obs=None, date=None, yaw=0., theta_t=0., phi_t=0.): """ Creates sky using an Ephem observer (Requires Ephem library) :param obs: the observer (location on Earth) :param date: the date of the observation :param yaw: the heading orientation of the observer :param theta_t: the heading tilt (pitch) :param phi_t: the heading tilt (roll) :return: """ from ephem import Sun from datetime import datetime from utils import get_seville_observer sun = Sun() if obs is None: obs = get_seville_observer() obs.date = datetime(2017, 6, 21, 10, 0, 0) if date is None else date sun.compute(obs) theta_s, phi_s = np.pi/2 - sun.alt, (sun.az - yaw + np.pi) % (2 * np.pi) - np.pi return Sky(theta_s=theta_s, phi_s=phi_s, theta_t=theta_t, phi_t=phi_t)
def get_distance_solar(target, obs_date, offender): """Compute the angular distance in degrees between the specified target and the offending radio source in the solar system on the specified observing date. Input parameters: * target - Coordinate of the target as an Astropy SkyCoord object * obs_date - Observing date in datetime.datetime format * offender - Name of the offending bright source. Allowed values are Sun, Moon, Jupiter. Returns: For Moon, the minimum and maximum separation are returned. For others, distance,None is returned.""" # Get a list of values along the time axis d = obs_date.split('-') start_time = datetime(int(d[0]), int(d[1]), int(d[2]), 0, 0, 0) end_time = start_time + timedelta(hours=24) taxis = [] temp_time = start_time while temp_time < end_time: taxis.append(temp_time) temp_time += timedelta(hours=1) angsep = [] if offender == 'Sun': obj = Sun() elif offender == 'Moon': obj = Moon() elif offender == 'Jupiter': obj = Jupiter() else: pass # Estimate the angular distance over the entire time axis for time in taxis: obj.compute(time) coord = SkyCoord('{} {}'.format(obj.ra, obj.dec), unit=(u.hourangle, u.deg)) angsep.append(coord.separation(target).deg) # Return appropriate result if offender == 'Moon': return np.min(angsep), np.max(angsep) else: return np.mean(angsep), None
def plot_ephemeris(obs, dt=10): sun = Sun() delta = timedelta(minutes=dt) azi, azi_diff, ele = [], [], [] for month in xrange(12): obs.date = datetime(year=2018, month=month + 1, day=13) cur = obs.next_rising(sun).datetime() + delta end = obs.next_setting(sun).datetime() if cur > end: cur = obs.previous_rising(sun).datetime() + delta while cur <= end: obs.date = cur sun.compute(obs) a, e = sun.az, np.pi / 2 - sun.alt if len(azi) > 0: d = 60. / dt * np.absolute((a - azi[-1] + np.pi) % (2 * np.pi) - np.pi) if d > np.pi / 2: azi_diff.append(0.) else: azi_diff.append(d) else: azi_diff.append(0.) azi.append(a % (2 * np.pi)) ele.append(e) # increase the current time cur = cur + delta ele = np.rad2deg(ele) azi = np.rad2deg(azi) azi_diff = np.rad2deg(azi_diff) azi = azi[ele < 90] azi_diff = azi_diff[ele < 90] ele = ele[ele < 90] ele_nonl = np.exp(.1 * (54 - ele)) x = np.array([9 + np.exp(.1 * (54 - ele)), np.ones_like(azi_diff)]).T # w = np.linalg.pinv(x).dot(azi_diff) w = np.array([1., 0.]) y = x.dot(w) error = np.absolute(y - azi_diff) print "Error: %.4f +/- %.4f" % (error.mean(), error.std() / np.sqrt(len(error))), print "| N = %d" % len(error) plt.figure(figsize=(10, 10)) plt.subplot(221) plt.scatter(azi, ele, c=azi_diff, cmap='Reds', marker='.') plt.ylabel(r'$\theta_s (\circ)$') plt.xlim([0, 360]) plt.ylim([85, 0]) plt.xticks([0, 45, 90, 135, 180, 225, 270, 315, 360], [""] * 9) plt.yticks([0, 15, 30, 45, 60, 75]) plt.subplot(222) plt.scatter(azi_diff, ele, c=azi, cmap='coolwarm', marker='.') xx = np.linspace(0, 90, 100, endpoint=True) yy = 9 + np.exp(.1 * (54 - xx)) plt.plot(yy, xx, 'k-') plt.ylim([85, 0]) plt.xlim([7, 60]) plt.xticks([10, 20, 30, 40, 50, 60], [""] * 6) plt.yticks([0, 15, 30, 45, 60, 75], [""] * 6) plt.subplot(223) plt.scatter(azi, x[:, 0], c=azi_diff, cmap='Reds', marker='.') plt.xlabel(r'$\phi_s (\circ)$') plt.ylabel(r'$\Delta\phi_s (\circ/h)$ -- prediction') plt.xlim([0, 360]) plt.ylim([7, 65]) plt.xticks([0, 45, 90, 135, 180, 225, 270, 315, 360]) plt.yticks([10, 20, 30, 40, 50, 60]) plt.subplot(224) plt.scatter(azi_diff, x[:, 0], c=azi, cmap='coolwarm', marker='.') plt.plot([w[0] * 7 + w[1], w[0] * 65 + w[1]], [7, 65], 'k-') plt.xlabel(r'$\Delta\phi_s (\circ/h)$ -- true') plt.xlim([7, 60]) plt.xticks([10, 20, 30, 40, 50, 60]) plt.ylim([7, 65]) plt.yticks([10, 20, 30, 40, 50, 60], [""] * 6) return plt
#data.astype({'time':'int32'}).dtypes # print data.dtypes # print int(data['time'][0]) # print(data['time']) # plt.figure(figsize=(14,10)) # #plt.scatter(data['t2'],data['mag']) # n, bins, patches = plt.hist(data['t2'], bins=96) # plt.xlim(-12,12) # plt.show() dt = '2016/5/27 00:00' sun = Sun() sun.compute(dt) elginfield = Observer() elginfield.lat = 43.19237 elginfield.lon = -81.31799 elginfield.date = dt ra, dec = elginfield.radec_of('0', '-90') print('RA_sun:',sun.ra) print('Elgin nadir', ra) print('Solar time:', hours((ra-sun.ra)%(2*pi)), 'hours') fig, ax = plt.subplots(figsize=(14,10)) n, bins, patches = ax.hist(data['t2'], bins=192, rwidth=0.9, edgecolor='black') ax.axvline(0, color='red')
plt.show() elif mode is "res2azi": azi, azi_diff, ele, res = [], [], [], [] for month in xrange(12): obs.date = datetime(year=2018, month=month + 1, day=13) cur = obs.next_rising(sun).datetime() + delta end = obs.next_setting(sun).datetime() if cur > end: cur = obs.previous_rising(sun).datetime() + delta while cur <= end: obs.date = cur sun.compute(obs) a, e = sun.az, np.pi / 2 - sun.alt if len(azi) > 0: d = 60. / dt * np.absolute((a - azi[-1] + np.pi) % (2 * np.pi) - np.pi) if d > np.pi / 2: azi_diff.append(0.) else: azi_diff.append(d) else: azi_diff.append(0.) d_err, d_eff, tau, _, _ = evaluate(sun_azi=a, sun_ele=e, tilting=False, noise=0.)