def is_day(t, lats, lons): # Determine whether or not the satellite is on the dayside. # We're using the day-nite terminator function from Basemap. tlons, tlats, tau, dec = daynight_terminator(t, 1.1, -180, 180) # Lon to lat interpolator interpy = interp1d(tlons, tlats, 'linear', fill_value='extrapolate') thresh_lats = interpy(lons) if dec > 0: dayvec = lats > thresh_lats else: dayvec = lats < thresh_lats return dayvec
def _make_SECS_plots(data=None, dtime=None, contour_den=8, s_loc=False): """ @Parameter: dtime input as a string @Parameter: s_loc input as a bool, which means the locations of the virtual stations. """ dtype = 'SECS' if not os.path.exists(CONFIG['plots_dir']): os.makedirs(CONFIG['plots_dir']) dtime_range = [dtime, dtime] pathformat_prefix = dtype + '/%Y/%m/' pathformat_unzipped = pathformat_prefix + '%d/' + dtype + '%Y%m%d_%H%M%S.dat' filename_unzipped = dailynames(file_format=pathformat_unzipped, trange=dtime_range, res=10) out_files_unzipped = [ CONFIG['local_data_dir'] + rf_res for rf_res in filename_unzipped ] Data_Days_time = read_data_files(out_files=out_files_unzipped, dtype=dtype, out_type='df') J_comp = Data_Days_time['J'] Jc_max, Jc_min = J_comp.max(), J_comp.min() Jcm_abs = max(abs(Jc_max), abs(Jc_min)) contour_density = np.linspace(-Jcm_abs, Jcm_abs, num=contour_den) tp = dtime datetime_tp = tp[0:4] + tp[5:7] + tp[8:10] + '_' + tp[11:13] + tp[ 14:16] + tp[17:19] lon = Data_Days_time['longitude'] lat = Data_Days_time['latitude'] J = Data_Days_time['J'] lon = lon.to_numpy() lat = lat.to_numpy() J = J.to_numpy() # plot 1: contour plot # plot map ground (North hemisphere) fig = plt.figure(figsize=(8, 8)) m = Basemap(projection='lcc', resolution='c', width=8E6, height=8E6, lat_0=60, lon_0=-100) # draw coastlines, country boundaries, fill continents. m.drawcoastlines(linewidth=0.25) m.drawcountries(linewidth=0.25) m.fillcontinents(color='None', lake_color='None') # draw the edge of the map projection region (the projection limb) m.drawmapboundary(fill_color=None) m.drawlsmask() m.shadedrelief() # draw parallels and meridians. # label parallels on right and top # meridians on bottom and left parallels = np.arange(0., 81, 10.) m.drawparallels(parallels, labels=[False, True, True, False]) meridians = np.arange(10., 351., 20.) m.drawmeridians(meridians, labels=[True, False, False, True]) date_nightshade = datetime.strptime(dtime, '%Y-%m-%d/%H:%M:%S') delta = 0.25 lons_dd, lats_dd, tau, dec = daynight_terminator(date_nightshade, delta, m.lonmin, m.lonmax) xy = [lons_dd, lats_dd] xy = np.array(xy) xb, yb = xy[0], xy[1] m.plot(xb, yb, marker=None, color='b', latlon=True) # Plot the noon-midnight line. n_interval = len(lons_dd) ni_half = int(np.floor(len(lons_dd) / 2)) ni_otherhalf = n_interval - ni_half noon_midnight = noon_midnight_meridian(dtime, delta) m.plot(noon_midnight['lons_noon'], noon_midnight['lats_noon'], marker=None, color='deepskyblue', latlon=True) # noon semi-circle m.plot(noon_midnight['lons_midnight'], noon_midnight['lats_midnight'], marker=None, color='k', latlon=True) # midnight semi-circle draw_map(m) norm_cb = CenteredNorm() ctrf = m.contourf(lon, lat, J, contour_density, latlon=True, tri=True, cmap=plt.get_cmap('seismic', 20), norm=norm_cb) if s_loc: m.scatter(lon, lat, latlon=True, marker='*', c='black') cb = m.colorbar(matplotlib.cm.ScalarMappable(norm=norm_cb, cmap='seismic'), pad='15%') cb.set_label(r'$\mathit{J} \ (mA/m)$') ax_cb = cb.ax text = ax_cb.yaxis.label font_cb = matplotlib.font_manager.FontProperties(family='times new roman', style='italic', size=20) text.set_font_properties(font_cb) plt.title(label='SECS ' + tp, fontsize=20, color="black", pad=20) plt.tight_layout() plt.savefig(CONFIG['plots_dir'] + 'SECS' + '_' + date_nightshade.strftime('%Y%m%d%H%M%S') + '.jpeg') plt.show() print('SECS plots completed!') return
def _make_EICS_plots(dtime=None, vplot_sized=False, contour_den=8, s_loc=False, quiver_scale=30): """ @Parameter: dtime input as a string @Parameter: s_loc input as a bool, which means the locations of the virtual stations. """ dtype = 'EICS' if not os.path.exists(CONFIG['plots_dir']): os.makedirs(CONFIG['plots_dir']) dtime_range = [dtime, dtime] pathformat_prefix = dtype + '/%Y/%m/' pathformat_unzipped = pathformat_prefix + '%d/' + dtype + '%Y%m%d_%H%M%S.dat' filename_unzipped = dailynames(file_format=pathformat_unzipped, trange=dtime_range, res=10) out_files_unzipped = [ CONFIG['local_data_dir'] + rf_res for rf_res in filename_unzipped ] Data_Days_time = read_data_files(out_files=out_files_unzipped, dtype=dtype, out_type='df') J_comp = Data_Days_time['Jy'] Jc_max, Jc_min = J_comp.max(), J_comp.min() Jcm_abs = max(abs(Jc_max), abs(Jc_min)) contour_density = np.linspace(-Jcm_abs, Jcm_abs, num=contour_den) tp = dtime datetime_tp = tp[0:4] + tp[5:7] + tp[8:10] + '_' + tp[11:13] + tp[ 14:16] + tp[17:19] lon = Data_Days_time['longitude'] lat = Data_Days_time['latitude'] Jx = Data_Days_time['Jx'] # Note: positive is Northward Jy = Data_Days_time['Jy'] # Note: positive is Eastward # plot 1: # plot map ground (North hemisphere) fig1 = plt.figure(figsize=(8, 8)) ax1 = plt.gca() m = Basemap(projection='lcc', resolution='c', width=8E6, height=8E6, lat_0=60, lon_0=-100) # draw coastlines, country boundaries, fill continents. m.drawcoastlines(linewidth=0.25) m.drawcountries(linewidth=0.25) m.fillcontinents(color='None', lake_color='None') # draw the edge of the map projection region (the projection limb) m.drawmapboundary(fill_color=None) # m.drawgreatcircle(-100,0,0,90) m.drawlsmask() # m.bluemarble() m.shadedrelief() # draw parallels and meridians. # label parallels on right and top # meridians on bottom and left parallels = np.arange(0., 81, 10.) # labels = [left,right,top,bottom] m.drawparallels(parallels, labels=[False, True, True, False]) meridians = np.arange(10., 351., 20.) m.drawmeridians(meridians, labels=[True, False, False, True]) date_nightshade = datetime.strptime(dtime, '%Y-%m-%d/%H:%M:%S') m.nightshade(date=date_nightshade) draw_map(m) # plot vector field: lon = lon.to_numpy() lat = lat.to_numpy() Jx = Jx.to_numpy() # Note: positive is Northward Jy = Jy.to_numpy() # Note: positive is Eastward Jx_uni = Jx / np.sqrt(Jx**2 + Jy**2) Jy_uni = Jy / np.sqrt(Jx**2 + Jy**2) n = -2 color = np.sqrt(((Jx_uni - n) / 2)**2 + ((Jy_uni - n) / 2)**2) if vplot_sized == False: qv = m.quiver( lon, lat, Jx_uni, Jy_uni, color, headlength=7, latlon=True, cmap='GnBu') # autumn_r #, color=cm(norm(o)))#, cmap = 'jet') plt.colorbar() else: Jy_rot, Jx_rot, x, y = m.rotate_vector(Jy, Jx, lon, lat, returnxy=True) qv = m.quiver(lon, lat, Jy_rot, Jx_rot, headlength=7, latlon=True, scale_units='dots', scale=quiver_scale) # , transform='lcc') qk = ax1.quiverkey(qv, 0.3, -0.1, 100, r'$100 \ mA/m$', labelpos='E', coordinates='data') # figure plt.title(label='EICS ' + tp, fontsize=20, color="black", pad=20) plt.tight_layout() plt.savefig(CONFIG['plots_dir'] + 'EICS' + '_vector_' + date_nightshade.strftime('%Y%m%d%H%M%S') + '.jpeg') plt.show() # plot 2: contour plot # plot map ground (North hemisphere) fig2 = plt.figure(figsize=(8, 8)) ax2 = plt.gca() m = Basemap(projection='lcc', resolution='c', width=8E6, height=8E6, lat_0=60, lon_0=-100) # draw coastlines, country boundaries, fill continents. m.drawcoastlines(linewidth=0.25) m.drawcountries(linewidth=0.25) m.fillcontinents(color='None', lake_color='None') # draw the edge of the map projection region (the projection limb) m.drawmapboundary(fill_color=None) m.drawlsmask() m.shadedrelief() # draw parallels and meridians. # label parallels on right and top # meridians on bottom and left parallels = np.arange(0., 81, 10.) m.drawparallels(parallels, labels=[False, True, True, False]) meridians = np.arange(10., 351., 20.) m.drawmeridians(meridians, labels=[True, False, False, True]) date_nightshade = datetime.strptime(dtime, '%Y-%m-%d/%H:%M:%S') # m.nightshade(date=date_nightshade, alpha = 0.0) delta = 0.25 lons_dd, lats_dd, tau, dec = daynight_terminator(date_nightshade, delta, m.lonmin, m.lonmax) xy = [lons_dd, lats_dd] xy = np.array(xy) xb, yb = xy[0], xy[1] m.plot(xb, yb, marker=None, color='m', latlon=True) # for dawn-dusk circle line # Plot the noon-midnight line. n_interval = len(lons_dd) ni_half = int(np.floor(len(lons_dd) / 2)) ni_otherhalf = n_interval - ni_half noon_midnight = noon_midnight_meridian(dtime, delta) m.plot(noon_midnight['lons_noon'], noon_midnight['lats_noon'], marker=None, color='deepskyblue', latlon=True) # noon semi-circle m.plot(noon_midnight['lons_midnight'], noon_midnight['lats_midnight'], marker=None, color='k', latlon=True) # midnight semi-circle draw_map(m) Jy_log = Jy / np.abs(Jy) * np.log10(np.abs(Jy)) norm_cb = CenteredNorm() # norm_cb = NoNorm() # norm_cb = CenteredNorm(vmin=Jy.min(), vcenter=0, vmax=Jy.max()) # use Jy for the contour map, not Jy_rot. ctrf = m.contourf(lon, lat, Jy, contour_density, latlon=True, tri=True, cmap='jet_r', norm=norm_cb) ##ctrf = m.contourf(lon, lat, Jy, contour_density, latlon=True, tri=True, cmap='jet_r', norm=norm_cb) # ------------- if s_loc: m.scatter(lon, lat, latlon=True, marker='*', c='black') # ------------- cb = m.colorbar(matplotlib.cm.ScalarMappable(norm=norm_cb, cmap='jet_r'), pad='15%') cb.set_label(r'$\mathit{J}_y \ (mA/m)$') ax_cb = cb.ax text = ax_cb.yaxis.label font_cb = matplotlib.font_manager.FontProperties(family='times new roman', style='italic', size=20) text.set_font_properties(font_cb) plt.title(label='EICS ' + tp, fontsize=20, color="black", pad=20) plt.tight_layout() plt.savefig(CONFIG['plots_dir'] + 'EICS' + '_contour_' + date_nightshade.strftime('%Y%m%d%H%M%S') + '.jpeg') plt.show() print('EICS plots completed!') return