def display( latitude, longitude, tz, date_time ): """Display various sunrise, sunset details. .. todo:: Confirm this output. :param latitude: Latitude of observer :param longitude: longitude of observer :param tz: timezone of observer :param date_time: datetime object with date to display """ rise_a, _, set_a = solar.rise_transit_set( latitude, longitude, date_time, horizon=90+18 ) rise_n, _, set_n = solar.rise_transit_set( latitude, longitude, date_time, horizon=90+12 ) rise_c, _, set_c = solar.rise_transit_set( latitude, longitude, date_time, horizon=90+6 ) rise_v, _, set_v = solar.rise_transit_set( latitude, longitude, date_time ) line= "{0:.<22s} {1:8s} = {2:8s} UTC {3:s}" print( line.format( "Astronomical Dawn", rise_a.strftime( "%H:%M:%S" ), rise_a.astimezone(utc).strftime( "%H:%M:%S" ), "Sun 18° below horizon" ) ) print( line.format("Nautical Dawn", rise_n.strftime( "%H:%M:%S" ), rise_n.astimezone(utc).strftime( "%H:%M:%S" ), "Sun 12° below horizon" ) ) print( line.format("Civil Dawn", rise_c.strftime( "%H:%M:%S" ), rise_c.astimezone(utc).strftime( "%H:%M:%S" ), "Sun 6° below horizon" ) ) print( line.format("Sunrise", rise_v.strftime( "%H:%M:%S" ), rise_v.astimezone(utc).strftime( "%H:%M:%S" ), "Top of sun at the horizon" ) ) print( "────────────────────────────────────────" ) print( line.format("Sunset", set_v.strftime( "%H:%M:%S" ), set_v.astimezone(utc).strftime( "%H:%M:%S" ), "Top of sun at the horizon" ) ) print( line.format("Civil Dusk", set_c.strftime( "%H:%M:%S" ), set_c.astimezone(utc).strftime( "%H:%M:%S" ), "Sun 6° below horizon" ) ) print( line.format("Nautical Dusk", set_n.strftime( "%H:%M:%S" ), set_n.astimezone(utc).strftime( "%H:%M:%S" ), "Sun 12° below horizon" ) ) print( line.format("Astronomical Dusk", set_a.strftime( "%H:%M:%S" ), set_a.astimezone(utc).strftime( "%H:%M:%S" ), "Sun 18° below horizon" ) )
def grid_square(): today = datetime.datetime.now(tz=solar.utc) home= None while home is None: mode= input( "Home QTH (c)oordinates, (g)rid, or (q)uit? (c/g/q) " ).lower() if mode == 'q': return elif mode == 'c': lat= input_float( "ENTER: Latitude in decimal degrees (+° if North, -° if South)? " ) lon= input_float( "ENTER: Longitude in decimal degrees (+° if East, -° if West)? " ) if lat is None or lon is None: return grid= gridsq.latlon_2_grid( lat, lon ) home= grid lat_home, lon_home= lat, lon elif mode == 'g': grid_raw= input( "ENTER: Grid square code (enter 2, 4, or all 6 characters)? " ) lat, lon = gridsq.grid_2_latlon( grid_raw ) home= grid_raw lat_home, lon_home= lat, lon rise, _, set = solar.rise_transit_set( lat, lon, today ) print( "Home", home, gridsq.grid_2_latlon(home), rise, set ) R= None while R is None: dist_choice= input( "Choose: DX in (k)ilometers, (s)tatute miles or (n)autical miles? (k/s/n) " ).lower() if dist_choice == 'k': R = distance.KM elif dist_choice == 's': R = distance.SM elif dist_choice == 'n': R = distance.NM count= 0 while True: mode= input( "Away QTH (c)oordinates, (g)rid, or (q)uit? (c/g/q) " ).lower() if mode == 'q': break elif mode == 'c': lat= input_float( "ENTER: Latitude in decimal degrees (+° if North, -° if South)? " ) lon= input_float( "ENTER: Longitude in decimal degrees (+° if East, -° if West)? " ) if lat is None or lon is None: return grid= gridsq.latlon_2_grid( lat, lon ) elif mode == 'g': grid= input( "ENTER: Grid square code (enter 2, 4, or all 6 characters)? " ) lat, lon = gridsq.grid_2_latlon( grid ) count += 1 dx_range = distance.great_circle_distance( lat_home, lon_home, lat, lon, R ) rx_bearing = distance.great_circle_bearing( lat_home, lon_home, lat, lon ) rise, _, set = solar.rise_transit_set( lat, lon, today ) print( count, grid, lat, lon, dx_range, rx_bearing, rise, set )
def display( latitude, longitude, tz, start, end, increment ): """Display sunup table. :param latitude: Latitude of observer :param longitude: longitude of observer :param tz: timezone of observer :param start: starting date for table :param end: ending date for table :param increment: day increment for table """ heading= """\ Hours Sunrise (EST) Sunset (EST) Elev.& Azimuth of and Azimuth and Azimuth of Noon Sun Date Daylight (degrees) (degrees) (degrees) """ print( heading ) for offset in range( 0, (end-start).days+increment, increment ): date= start+datetime.timedelta(days=offset) rise, transit, set = solar.rise_transit_set( latitude, longitude, date ) az_r, el_r= solar.azimuth_elevation( latitude, longitude, rise ) az_s, el_s= solar.azimuth_elevation( latitude, longitude, set ) az_t, el_t= solar.azimuth_elevation( latitude, longitude, transit ) daylight_hours= (set-rise).total_seconds()/3600 print( "{0:10s} {1:5.2f} {2:8s} {3:5.2f} {4:8s} {5:5.2f} {6:8s} {7:5.2f} {8:5.2f}".format( date.strftime("%Y-%m-%d"), daylight_hours, rise.astimezone(tz).strftime("%H:%H:%S"), az_r, set.astimezone(tz).strftime("%H:%M:%S"), az_s, transit.astimezone(tz).strftime("%H:%M:%S"), el_t, az_t, ) )
def report( latitude, longitude, date_time, tz ): details = solar.Position_Sun( latitude, longitude, date_time ) rise, transit, set = solar.rise_transit_set( latitude, longitude, date_time ) az_r, el_r= solar.azimuth_elevation( latitude, longitude, rise ) az_s, el_s= solar.azimuth_elevation( latitude, longitude, set ) print( "{0:10s} {1:5.2f} {2:8s} {3:6.2f} {4:8s} {5:4.2f} {6:6.2f} {7:6.2f}".format( date_time.strftime("%Y-%m-%d"), details.AA/60, rise.astimezone(tz).strftime("%H:%H:%S"), az_r, set.astimezone(tz).strftime("%H:%M:%S"), az_s, details.AE+180, details.AH , ) )
def display( latitude, longitude, tz, date_time ): """Display various sunrise, sunset details. .. todo:: Confirm this output. :param latitude: Latitude of observer :param longitude: longitude of observer :param tz: timezone of observer :param date_time: datetime object with date to display """ rise, transit, set = solar.rise_transit_set( latitude, longitude, date_time ) detl_rise= solar.Position_Sun( latitude, longitude, rise ) detl_set= solar.Position_Sun( latitude, longitude, set ) template= """\ ======================================== SUNRISE ====== SUNSET ====== DAYLIGHT Local SOLAR Time....................... {lst_rise} {lst_set} {daylight:4.2f} hrs. Local ${std} Time......................... {std_rise} {std_set} UNIVERSAL COORDINATED Time (UTC/GMT)... {utc_rise} {utc_set} Declination of Earth's axis............ {decl_rise}° {decl_set}° =============================================================================== """ dst_offset= date_time.dst() data = dict( lst_rise= detl_rise.X_hms, std_rise= rise.astimezone(tz).strftime("%H:%H:%S"), utc_rise= rise.astimezone(utc).strftime("%H:%H:%S"), lst_set= detl_rise.Y_hms, std_set= set.astimezone(tz).strftime("%H:%H:%S"), utc_set= set.astimezone(utc).strftime("%H:%H:%S"), std = tz.tzname(date_time), decl_rise= "", decl_set= "", daylight= detl_rise.AA/60, ) print( template.format( **data ) ) r = Polar(r=7) r.point( "*", 7, detl_rise.AH ) r.right_label( "SUNRISE @ {0:.0f}°".format(detl_rise.AH), detl_rise.AH ) r.point( "*", 7, detl_set.AH ) r.left_label( "SUNSET @ {0:.0f}°".format(detl_set.AH), detl_set.AH ) for line in r.image(): print( line )