def main(): site = sites.load(args.site) if args.lst is None: lst = site.lstnow() else: lst = args.lst alt_deg, az_deg = args.coords ra_deg, decl_deg = site.get_skyposn(alt_deg, az_deg, lst=lst) lst_hms = utils.deg_to_hmsstr(lst*15)[0] print "%s oriented at (alt=%g deg, az=%g deg) at LST=%s is pointed towards" \ "\n RA=%s\n Dec=%s" % (site.name, alt_deg, az_deg, lst_hms, \ utils.deg_to_hmsstr(ra_deg)[0], utils.deg_to_dmsstr(decl_deg)[0])
def get_posn_text(self, site, lst=None, date=None): """Return a list of strings with position information to be display. Inputs: site: The ObsSite object representing the observing site. lst: Local sidereal time, in hours. (Default: now). date: A datetime.date object. (Default: today). Output: posninfo: A list of position informational strings. """ alt, az = self.get_altaz(site, lst, date) ra_deg, decl_deg = self.get_posn(lst, date) posninfo = [] posninfo.append("R.A. (J2000): %s" % utils.deg_to_hmsstr(ra_deg)[0]) posninfo.append("Dec. (J2000): %s" % utils.deg_to_dmsstr(decl_deg)[0]) if site.above_horizon(alt, az): posninfo.append(u"Alt.: %.2f\u00b0" % alt) posninfo.append(u"Az.: %.2f\u00b0" % az) posninfo.append(u"Alt. above horizon: %.2f\u00b0" % \ (alt - site.horizon(az))) return posninfo
def plot(self): """Create the plot, and add all the unchanging figures. Inputs: None Outputs: None """ self.clear() # Clear the figure, just in case. # Print information self.text(0.02, 0.95, self.site.name, size=32, \ ha='left', va='center') if self.site.lon < 0: londir = "W" else: londir = "E" lonstr = "%s %s" % (utils.deg_to_dmsstr(abs(self.site.lon))[0], londir) if self.site.lat < 0: latdir = "S" else: latdir = "N" latstr = "%s %s" % (utils.deg_to_dmsstr(abs(self.site.lat))[0], latdir) self.text(0.02, 0.91, "%s, %s" % (lonstr, latstr), size='x-small', \ ha='left', va='center') datetimestrs = self.get_datetime_strs() self.datetimetext = self.text(0.98, 0.95, '\n'.join(datetimestrs), \ size='medium', ha='right', va='top') self.horizon_polarax = self.add_axes([0.05, 0.1, 0.8, 0.8], \ projection='polar') self.horizon_polarax.set_theta_zero_location('N') # Set theta to increase clockwise self.horizon_polarax.set_theta_direction(-1) az_deg = np.linspace(0, 360, 361, endpoint=True) az_rad = np.deg2rad(az_deg) horizon = 90-self.site.horizon(az_deg) self.horizon_polarax.plot(az_rad, horizon, \ ls='-', lw=2, c='#006400', zorder=3) maxza = max((90, 90-min(horizon))) # Maximum zenith angle to plot self.horizon_polarax.fill_between(az_rad, horizon, \ y2=maxza, facecolor='#228B22', \ edgecolor='none', alpha=0.5, zorder=3) self.horizon_polarax.fill_between(az_rad, horizon, \ y2=maxza, facecolor='#228B22', \ edgecolor='none', alpha=1.0, zorder=0) # Grid of altitudes and azimuths alts, azs = np.meshgrid(np.linspace(0,90, 361), np.linspace(0,360, 721)) above_horizon = self.site.above_horizon(alts, azs) can_point = self.site.pointing(alts, azs) self.horizon_polarax.contourf(np.deg2rad(azs), 90-alts, \ ~above_horizon | can_point, [-1, 0], colors='r', \ alpha=0.5, zorder=3) self.horizon_polarax.contour(np.deg2rad(azs), 90-alts, \ ~above_horizon | can_point, [-1, 0], colors='r', \ zorder=3, linewidths=2) maxpointza = 90-np.min(alts[can_point & above_horizon]) self.sky_fill = self.horizon_polarax.fill_between(az_rad, horizon, \ y2=0, facecolor='none', \ edgecolor='none', alpha=1.0, zorder=-2) self.horizon_polarax.set_rlim(0, min(maxza, maxpointza+5)) def coord_formatter(az_rad, za): az = np.rad2deg(az_rad)%360 alt = 90-za horalt = self.site.horizon(az) if alt > horalt: status = "(above horizon)" else: status = "(below horizon)" # note: "\u00b0" is the unicode character for the degree symbol string = u"Az: %.2f\u00b0, Alt: %.2f\u00b0 %s" % \ (az, alt, status) return string self.horizon_polarax.format_coord = coord_formatter # Format zenith angle so it is actually displayed as altitude def alt_formatter(za, index): return u"%g\u00b0" % (90-za) fmt = matplotlib.ticker.FuncFormatter(alt_formatter) self.horizon_polarax.yaxis.set_major_formatter(fmt) # Celestial Pole pole_za_deg = 90-np.abs(self.site.lat) if self.site.lat > 0: # Northern observing site pole_az_rad = 0 elif self.site.lat < 0: # Southern observing site pole_az_rad = np.pi # Plot Celestial Pole self.pole_scatt = self.horizon_polarax.scatter(pole_az_rad, pole_za_deg, \ marker='.', s=20, c='k', zorder=0) # Plot the Sun az_rads, zas = self.sun_list.get_plotcoords(self.site, \ lst=self.lst, date=self.date) self.sun_scatt = self.horizon_polarax.scatter(az_rads, zas, \ picker=self.sun_list.pickable, marker=self.sun_list.get_marker(), \ c=self.sun_list.get_colours(), \ s=self.sun_list.get_sizes(), \ edgecolors=self.sun_list.get_edgecolours(), \ zorder=self.sun_list.get_zorder()) # Set sky colour skycolour = self.sun.get_skycolour(self.site, lst=self.lst, \ date=self.date) self.sky_fill.set_facecolor(skycolour) # Plot background stars az_rads, zas = self.bgstars.get_plotcoords(self.site, \ lst=self.lst, date=self.date) self.bgstars_scatt = self.horizon_polarax.scatter(az_rads, zas, \ picker=self.bgstars.pickable, marker=self.bgstars.get_marker(), \ c=self.bgstars.get_colours(), \ s=self.bgstars.get_sizes(), \ edgecolors=self.bgstars.get_edgecolours(), \ zorder=self.bgstars.get_zorder()) # Adjust grid lines and labels if self.sun.is_night(self.site, lst=self.lst, date=self.date): self.horizon_polarax.yaxis.grid(c='w') self.horizon_polarax.xaxis.grid(c='w') self.horizon_polarax.yaxis.set_tick_params(labelcolor='w') self.pole_scatt.set_color('w') self.bgstars_scatt.set_visible(True) else: self.bgstars_scatt.set_visible(False) # Plot targets alt, az = self.targets.get_altaz(self.site, lst=self.lst) za = 90-alt az_rad = np.deg2rad(az) self.target_scatt = self.horizon_polarax.scatter(az_rad, za, \ picker=True, marker='*', c='#FA8072', s=200, zorder=2) # Plot testsources alt, az = self.testsources.get_altaz(self.site, lst=self.lst) za = 90-alt az_rad = np.deg2rad(az) self.test_scatt = self.horizon_polarax.scatter(az_rad, za, \ picker=True, marker='o', c='#1E90FF', s=100, zorder=2) # Plot calibrators alt, az = self.calibrators.get_altaz(self.site, lst=self.lst) za = 90-alt az_rad = np.deg2rad(az) self.cal_scatt = self.horizon_polarax.scatter(az_rad, za, \ picker=True, marker='D', c='#DEB887', s=80, zorder=2) # Add a lengend to the figure self.legend((self.target_scatt, self.test_scatt, self.cal_scatt), \ ("Target pulsars", "Test pulsars", "Calibrators"), \ loc='lower left', prop={'size':'small'}, \ markerscale=0.5, scatterpoints=3) # Connect event handlers self.connect_event_triggers()
def run(site, lst, date, targets, testsources, calibrators, args): if date is None: date = datetime.date.today() if lst is None: utc = utils.utcnow() lst = site.utc_to_lst(utc=utc, date=date) datestr = date.strftime("%b %d, %Y") lststr = utils.deg_to_hmsstr(lst*15)[0] utc = site.lst_to_utc(lst=lst, date=date) utcstr = utils.deg_to_hmsstr(utc*15)[0] print "%s\tLST: %s\tUTC: %s\n" % (datestr, lststr, utcstr) for srclist in [calibrators, targets, testsources]: for src in srclist: ra_deg, dec_deg = src.get_posn(lst, date) rastr = "R.A. (J2000): %s" % utils.deg_to_hmsstr(ra_deg, 2)[0] decstr = "Dec. (J2000): %s" % utils.deg_to_dmsstr(dec_deg, 2)[0] print "%-20s%-27s%27s" % (src.name, rastr, decstr) try: risetime, settime = src.get_rise_set_times(site, date) except errors.SourceIsCircumpolar: srctypestr = "(%s)" % srclist.name print "%-20sSource is circumpolar." % srctypestr except errors.SourceNeverRises: srctypestr = "(%s)" % srclist.name print "%-20sSource never rises." % srctypestr except errors.MultipleRiseSets: srctypestr = "(%s)" % srclist.name print "%-20sMultiple rise/set times?!" % srctypestr except: srctypestr = "(%s)" % srclist.name print "%-20sError! Oops..." % srctypestr raise else: if src.is_visible(site, lst, date): eventstr = "Source sets in %s" % \ utils.deg_to_hmsstr(((settime-lst)%24)*15)[0] else: eventstr = "Source rises in %s" % \ utils.deg_to_hmsstr(((risetime-lst)%24)*15)[0] risetosetstr = "Rise to set time: %s" % \ utils.deg_to_hmsstr(((settime-risetime)%24)*15)[0] riselststr = "Rise (LST): %s" % \ utils.deg_to_hmsstr((risetime%24)*15)[0] riseutcstr = "Rise (UTC): %s" % \ utils.deg_to_hmsstr((site.lst_to_utc(risetime, \ date)%24)*15)[0] setlststr = "Set (LST): %s" % \ utils.deg_to_hmsstr((settime%24)*15)[0] setutcstr = "Set (UTC): %s" % \ utils.deg_to_hmsstr((site.lst_to_utc(settime, \ date)%24)*15)[0] srctypestr = "(%s)" % srclist.name print "%-20s%-27s%27s" % (srctypestr, risetosetstr, eventstr) print " "*20 + "%-22s%22s" % (riselststr, setlststr) print " "*20 + "%-22s%22s" % (riseutcstr, setutcstr) if src.notes: print "" print " "*20 + "NOTES: %s" % src.notes print "" print ""
def get_riseset_info(site, src, utc=None, lst=None, date=None): """Convenience function to get rise/set info for a site/source. Inputs: site: The observing site to get info for. src: The source to generate info for. utc: The UTC to get info for. (Default: now) lst: The LST to get info for. (Default: now) date: The date to get info for. (Default: now) Outputs: riseset_info: A dictionary of rise/set info. """ if (utc is not None) and (lst is not None): raise ValueError("Only one of 'utc' and 'lst' can be provided.") if not isinstance(site, sites.base.BaseSite): site = sites.load(site) if not isinstance(src, sources.Source): src = sources.Source.from_string(src) if utc is not None: lst = site.utc_to_lst(utc, date) if (lst is not None) and (date is None): # A fixed LST is used, but no date is provided. # Fix date to today's date. date = datetime.date.today() if (lst is None) and (date is None): date = datetime.date.today() lst = site.lstnow() if (lst is None) and (date is not None): # Want current LST for a specified date. This doesn't make sense. raise ValueError("Incompatible inputs: 'lst' is None, but 'date' is not None!") rs_info = {'msg':"", 'circumpolar':False, 'neverrises':False} ra_deg, dec_deg = src.get_posn(lst, date) rs_info['ra_deg'] = ra_deg rs_info['dec_deg'] = dec_deg rs_info['ra_hmsstr'] = utils.deg_to_hmsstr(ra_deg, 2)[0] rs_info['dec_dmsstr'] = utils.deg_to_dmsstr(dec_deg, 2)[0] alt, az = src.get_altaz(site, lst, date) rs_info['alt_deg'] = alt[0] rs_info['az_deg'] = az[0] try: risetime, settime = src.get_rise_set_times(site, date) except errors.SourceIsCircumpolar: rs_info['msg'] = "Source is circumpolar." rs_info['circumpolar'] = True rs_info['is_visible'] = True rs_info['next_riseset'] = None except errors.SourceNeverRises: rs_info['msg'] = "Source never rises." rs_info['neverrises'] = True rs_info['is_visible'] = False rs_info['next_riseset'] = None except errors.MultipleRiseSets: rs_info['msg'] = "Multiple rise/set times?!" except: # Any other error raise else: if src.is_visible(site, lst, date): rs_info['is_visible'] = True rs_info['next_riseset'] = \ utils.deg_to_hmsstr(((settime-lst)%24)*15)[0] else: rs_info['is_visible'] = False rs_info['next_riseset'] = \ utils.deg_to_hmsstr(((risetime-lst)%24)*15)[0] rs_info['uptime'] = \ utils.deg_to_hmsstr(((settime-risetime)%24)*15)[0] rs_info['rise_lst'] = \ utils.deg_to_hmsstr((risetime%24)*15)[0] rs_info['rise_utc'] = \ utils.deg_to_hmsstr((site.lst_to_utc(risetime, \ date)%24)*15)[0] rs_info['set_lst'] = \ utils.deg_to_hmsstr((settime%24)*15)[0] rs_info['set_utc'] = \ utils.deg_to_hmsstr((site.lst_to_utc(settime, \ date)%24)*15)[0] return rs_info
def __str__(self): ra_deg, decl_deg = self.get_posn() return "%s %s %s %s -- %s" % (self.name, utils.deg_to_hmsstr(ra_deg)[0], \ utils.deg_to_dmsstr(decl_deg)[0], self.mag, self.notes)