def get_datetime_strs(self): """Get a list of datetime strings to display. Inputs: None Output: datetimestrs: A list of date/time informational strings. """ datetimestrs = [] if self.lst is None: datetimestrs.append("Current date: %s" % \ datetime.date.today().strftime("%b %d, %Y")) datetimestrs.append("Current LST: %s" % \ utils.deg_to_hmsstr(self.site.lstnow()*15)[0].split('.')[0]) datetimestrs.append("Current UTC: %s" % \ datetime.datetime.utcnow().strftime('%H:%M:%S')) else: datetimestrs.append("Date selected: %s" % \ self.date.strftime("%b %d, %Y")) datetimestrs.append("LST selected: %s" % \ utils.deg_to_hmsstr(self.lst*15)[0]) datetimestrs.append("UTC selected: %s" % \ utils.deg_to_hmsstr(self.site.lst_to_utc(self.lst, self.date)*15)[0]) return datetimestrs
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 main(): site = sites.load(args.site) if args.date is None: date = datetime.date.today() else: date = args.date print "Converting LST to UTC for %s on %s" % \ (site.name, date.strftime("%b %d, %Y")) for lst in args.lst: lst_hours = utils.parse_timestr(lst) lst_hms = utils.deg_to_hmsstr(lst_hours*15) utc_hours = site.lst_to_utc(lst_hours, date) utc_hms = utils.deg_to_hmsstr(utc_hours*15) print " LST: %s = UTC: %s" % (lst_hms[0], utc_hms[0])
def main(): site = sites.load(args.site) if args.date is None: date = datetime.date.today() else: date = args.date print "Converting UTC to LST for %s on %s" % \ (site.name, date.strftime("%b %d, %Y")) for utc in args.utc: utc_hours = utils.parse_timestr(utc) utc_hms = utils.deg_to_hmsstr(utc_hours*15) lst_hours = site.utc_to_lst(utc_hours, date) lst_hms = utils.deg_to_hmsstr(lst_hours*15) print " UTC: %s = LST: %s" % (utc_hms[0], lst_hms[0])
def get_rise_set_text(self, site, lst=None, date=None): """Return a list of strings with rise/set information to be displayed. 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: rsinfo: A list of rise/set informational strings. """ if lst is None: lst = site.lstnow() rsinfo = [] try: risetime, settime = self.get_rise_set_times(site, date) if self.is_visible(site, lst, date): rsinfo.append("Source sets in %s" % \ utils.deg_to_hmsstr(((settime-lst)%24)*15)[0]) else: rsinfo.append("Source rises in %s" % \ utils.deg_to_hmsstr(((risetime-lst)%24)*15)[0]) rsinfo.append("Rise to set time: %s" % \ utils.deg_to_hmsstr(((settime-risetime)%24)*15)[0]) rsinfo.append("Rise time (LST): %s" % \ utils.deg_to_hmsstr((risetime%24)*15)[0]) rsinfo.append("Rise time (UTC): %s" % \ utils.deg_to_hmsstr((site.lst_to_utc(risetime, date)%24)*15)[0]) rsinfo.append("Set time (LST): %s" % \ utils.deg_to_hmsstr((settime%24)*15)[0]) rsinfo.append("Set time (UTC): %s" % \ utils.deg_to_hmsstr((site.lst_to_utc(settime, date)%24)*15)[0]) except errors.SourceIsCircumpolar: rsinfo.append("Source is circumpolar.") except errors.SourceNeverRises: rsinfo.append("Source never rises.") except errors.MultipleRiseSets: rsinfo.append("Multiple rise/set times?!") except: rsinfo.append("Error! Oops...") raise return rsinfo
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 on_pick(self, event): # Un-select previously selected pulsar if self.iselected is not None: ec = self.ccycle[self.iselected % len(self.ccycle)] for patch in self.up_patches[self.iselected]: patch.set_alpha(0.5) patch.set_linewidth(1) #patch.set_edgecolor(ec) # Select clicked-on pulsar self.iselected = int(np.round(event.mouseevent.ydata)) psr = self.srclist[self.iselected] # Update selected pulsar's rectangle patches utc_rs_ranges = [] lst_rs_ranges = [] ec = self.ccycle[self.iselected % len(self.ccycle)] for patch in self.up_patches[self.iselected]: patch.set_alpha(1) patch.set_linewidth(4) #patch.set_edgecolor('k') utc_risetime = patch.get_x() utc_settime = utc_risetime+patch.get_width() utc_risestr = utils.deg_to_hmsstr(utc_risetime*15)[0] utc_setstr = utils.deg_to_hmsstr((utc_settime)*15)[0] utc_rs_ranges.append("%s - %s" % (utc_risestr, utc_setstr)) lst_risetime = self.site.utc_to_lst(utc_risetime, date=self.date) lst_settime = self.site.utc_to_lst(utc_settime, date=self.date) lst_risestr = utils.deg_to_hmsstr(lst_risetime*15)[0] lst_setstr = utils.deg_to_hmsstr((lst_settime)*15)[0] lst_rs_ranges.append("%s - %s" % (lst_risestr, lst_setstr)) # Move and show selected point utc = event.mouseevent.xdata self.select_scatt.set_offsets((utc, self.iselected)) self.select_scatt.set_visible(True) self.vertline.set_visible(True) self.vertline.set_xdata((utc,utc)) if self.show_extra_panels: # Compute and show angular separations lst = self.site.utc_to_lst(utc, self.date) ra_picked, decl_picked = psr.get_posn(lst, self.date) max_angsep = 0 for other, rect in zip(self.srclist, self.angsep_bars): ra_other, decl_other = other.get_posn(lst, self.date) angsep = utils.angsep(ra_picked, decl_picked, ra_other, decl_other) rect.set_width(angsep) if angsep > max_angsep: max_angsep = angsep self.angsep_ax.set_xlim(0, max_angsep*1.1) # Compute and show slew times max_slew = 0 alt_picked, az_picked = psr.get_altaz(self.site, lst, self.date) for other, rect in zip(self.srclist, self.slew_bars): if self.site.azspeed is not None and \ self.site.altspeed is not None and \ other.is_visible(self.site, lst, self.date): alt_other, az_other = other.get_altaz(self.site, lst, self.date) slew = self.site.slew_time((alt_picked, az_picked), \ (alt_other, az_other)) slew /= 60 # in minutes rect.set_width(slew) rect.set_facecolor('b') rect.set_hatch('') else: rect.set_width(1e4) rect.set_facecolor('r') rect.set_hatch(r'\/') slew = 0 if slew > max_slew: max_slew = slew self.slew_ax.set_xlim(0, max_slew*1.1) # Update figure's text self.psr_text.set_text(psr.name) self.notes_text.set_text("Notes: %s" % psr.notes) self.utc_rs_text.set_text("Intervals when visible (UTC): " + \ ", ".join(utc_rs_ranges)) self.lst_rs_text.set_text("Intervals when visible (LST): " + \ ", ".join(lst_rs_ranges)) self.canvas.draw()
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)