def get_twilight_poly(utctime): """Return a polygon enclosing the sunlit part of the globe at *utctime*.""" from pyorbital import astronomy ra, dec = astronomy.sun_ra_dec(utctime) lon = modpi(ra - astronomy.gmst(utctime)) lat = dec vertices = np.zeros((4, 2)) vertices[0, :] = modpi(lon - np.pi / 2), 0 if lat <= 0: vertices[1, :] = lon, np.pi / 2 + lat vertices[3, :] = modpi(lon + np.pi), -(np.pi / 2 + lat) else: vertices[1, :] = modpi(lon + np.pi), np.pi / 2 - lat vertices[3, :] = lon, -(np.pi / 2 - lat) vertices[2, :] = modpi(lon + np.pi / 2), 0 return SphPolygon(vertices)
def get_twilight_poly(utctime): """Return a polygon enclosing the sunlit part of the globe at *utctime*. """ from pyorbital import astronomy ra, dec = astronomy.sun_ra_dec(utctime) lon = modpi(ra - astronomy.gmst(utctime)) lat = dec vertices = np.zeros((4, 2)) vertices[0, :] = modpi(lon - np.pi / 2), 0 if lat <= 0: vertices[1, :] = lon, np.pi / 2 + lat vertices[3, :] = modpi(lon + np.pi), -(np.pi / 2 + lat) else: vertices[1, :] = modpi(lon + np.pi), np.pi / 2 - lat vertices[3, :] = lon, -(np.pi / 2 - lat) vertices[2, :] = modpi(lon + np.pi / 2), 0 return SphPolygon(vertices)
def generateRealTime(satnames,zoom,curlon,curlat): data_graph = {} for satname in satnames: data_graph[satname] = { 'time': [], 'lat': [], 'lon': [], 'alt': [], 'nowtime': 0, 'nowlat': 0, 'nowlon': 0, } # Collect some data for i in range(10): time = datetime.datetime.utcnow() - datetime.timedelta(seconds=i*20) for satname in satnames: lon, lat, alt = satorbs[satname].get_lonlatalt(time) if i == 0: data_graph[satname]['nowtime'] = time.strftime("%Y-%m-%d %H:%M:%S") data_graph[satname]['nowlon'] = lon data_graph[satname]['nowlat'] = lat data_graph[satname]['lon'].append(lon) data_graph[satname]['lat'].append(lat) data_graph[satname]['alt'].append(alt) data_graph[satname]['time'].append(time.strftime("%Y-%m-%d %H:%M:%S")) hovertemplate= '<b>%{text}</b> \ <br>Time:%{customdata[0]} \ <br>Lat:%{customdata[1]:.2f} \ <br>Lon:%{customdata[2]:.2f}' data_graph_list = [] time = datetime.datetime.utcnow() for satname in satnames: print('update_ORBIT_MAP - satname {} lat {}'.format(satname,data_graph[satname]['nowlat'])) # Plot the current position of satellite hoverlist1 = [] hoveritems = [data_graph[satname]['nowtime'],data_graph[satname]['nowlat'],data_graph[satname]['nowlon']] hoverlist1.append(hoveritems) goSat = go.Scattermapbox( lat=[data_graph[satname]['nowlat']], lon=[data_graph[satname]['nowlon']], customdata=hoverlist1, hovertemplate = hovertemplate, text=[satname], name=satname, legendgroup=satname, mode="markers", marker=go.scattermapbox.Marker( #symbol=satlegend[satname]['symbol'], size=satlegend[satname]['size'], color=satlegend[satname]['color'] ), ) data_graph_list.append(goSat) # Plot the trace of satellite hoverlist2 = [] text = [] for i in range(len(data_graph[satname]['time'])): text.append(satname) hoveritems = [data_graph[satname]['time'][i],data_graph[satname]['lat'][i],data_graph[satname]['lon'][i]] hoverlist2.append(hoveritems) data_graph_list.append(go.Scattermapbox( lat=data_graph[satname]['lat'], lon=data_graph[satname]['lon'], customdata=hoverlist2, hovertemplate = hovertemplate, text=text, name=satname, legendgroup=satname, showlegend=False, mode = "lines", #marker = {'size': 10} marker=go.scattermapbox.Marker( # #symbol=satlegend[satname]['symbol'], size=int(satlegend[satname]['size']/3), color=satlegend[satname]['color'] ) )) #data_graph_list.append(goSat) # Plot the Sun # subsolar longitude occurs at noon UTC hour = time.hour + time.minute / 60.0 + time.second / 3600.0 sunlon = 15.0 * (12.0 - hour) if sunlon > 360.0: sunlon -= 360.0 if sunlon < 0.0: sunlon += 360.0 sunlon = round(sunlon,2) # subsolar latitude is given by the solar declination sunra,sunlat = sun_ra_dec(time) sunlat = numpy.rad2deg(sunlat) sunlat = round(sunlat,2) print('sunlon {} at {}'.format(sunlon,time)) print('sunra {} sunlat {}'.format(sunra,sunlat)) goSun = go.Scattermapbox( lat=[sunlat], lon=[sunlon], name='Sun', mode="markers", marker=go.scattermapbox.Marker( #symbol=satlegend['TARGET']['symbol'], size=satlegend['SUN']['size'], color=satlegend['SUN']['color'] ), text=['Sun'], ) data_graph_list.append(goSun) # Build the final figure fig = go.Figure(data_graph_list) print('zoom1 - {}'.format(zoom)) if zoom is None: zoom = 0.5 print('zoom2 - {}'.format(zoom)) fig.update_layout( hovermode='closest', mapbox=dict( #accesstoken=mapbox_access_token, style="outdoors", bearing=0, center=go.layout.mapbox.Center( lat=curlat, lon=curlon ), pitch=0, zoom=zoom ) ) """ if background == 'USGS': fig.update_layout( mapbox_style="white-bg", mapbox_layers=[ { "below": 'traces', "sourcetype": "raster", "source": [ "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}" ] } ] ) #elif background == 'OpenStreetMap': else: """ fig.update_layout(mapbox_style="open-street-map") fig.update_layout(margin={"r":20,"t":22,"l":0,"b":0}) return fig