# -*- coding: utf-8 -*- """ Created on Sat Feb 1 08:09:10 2020 @author: ppantina """ # -*- coding: utf-8 -*- """ Created on Mon Dec 30 15:56:49 2019 @author: ppantina """ ##Import some libraries import sys from matplotlib import pyplot as plt import numpy as np import time import datetime ##Define some paths plot_path = '/eraid2a/webshare/GLOVE/radar_rt_plot/telemetry/' sys.path.append('/home/ppantina/programs/subroutines') ##Choose between real or simulated data. This helps ##with changing the start/end times. ##Right now you still have to manually choose the simulated start time. real_time = int(input('Realtime or Simulated?\n\ REALTIME = 1\n\ SIMULATED = 2\n')) if real_time == 1: end_time = int(time.time())##set the end-time (RHS of plot) to current time, for REALTIME if real_time == 2: end_time = 1720712500 ##Epoch for SIMULATED data if real_time == 1: pause_time = 55 ##time to pause between images (essentially a time-step) if real_time == 2: pause_time = 0.2 ##time to pause between images (essentially a time-step) save_step = 10 import sub_iwg1_reader import sub_plot_options_nrt #plot enhancer import sub_radar_processing from matplotlib.dates import MinuteLocator, DateFormatter minu = MinuteLocator(interval = 20) datesFmt = DateFormatter('%H:%M') fig = plt.figure(figsize = (11,8.5)) plt.ioff() for k in range(100000): start_time = end_time - 3600 ##grab 1 hr of data (LHS of initial plot) ##Read the IWG information lat, lon, alt, pch, roll, drift, epoch = sub_iwg1_reader.sub_iwg1_reader((start_time), int(end_time)) ##Convert epoch time to sdate for plotting sdate = sub_radar_processing.secs2sdate (epoch) ##Format the end_time for figtext plottime = datetime.datetime.fromtimestamp(end_time + 3600*5.).strftime("%m/%d/%Y, %H:%M:%S") ##Define these functions to make a secondary axis on the alt plot def KmtoFt(x): return x * 3.280 def FttoKm(x): return x * 0.3048 ##Make the plot ax = fig.add_subplot(221) #plot latlon ax.plot(lon, lat) ax.plot(lon[-1], lat[-1], 'g.', markersize = 10) ax.set_xlabel ('Lon') ax.set_ylabel ('Lat') xvals = plt.gca().get_xticks() yvals = plt.gca().get_yticks() plt.gca().set_xticklabels(['{:.1f}'.format(x) for x in xvals]) plt.gca().set_yticklabels(['{:.1f}'.format(x) for x in yvals]) ax.xaxis.set_label_position("top") ax.grid(True) ax = fig.add_subplot(223) ##plot the altitude ax.plot(sdate, alt/1000) ax.set_xlabel ('Time') ax.set_ylabel ('Alt [km]') ax.axhspan(0, 15, facecolor='grey', alpha=0.5) ##grey out low alt, where radar is off ax.set_ylim(np.nanmin(alt/1000), np.nanmax(alt/1000)) ax.grid(True) ax.xaxis.set_major_locator (minu) ax.xaxis.set_major_formatter(datesFmt) ax2 = ax.secondary_yaxis('right', functions=(KmtoFt, FttoKm)) ##add the secondary axis ax2.set_ylabel('ft*1000') ax2.tick_params(axis="y",direction="in", pad=-25) #place it on the RHS ax = fig.add_subplot(322) #plot pitch ax.plot(sdate, pch, linewidth = 0.5) ax.set_ylim(-2.5, 2.5) ax.set_ylabel ('Pitch [deg]') ax.yaxis.tick_right() ax.yaxis.set_label_position("right") ax.grid(True) ax.xaxis.set_major_locator (minu) ax.xaxis.set_major_formatter(datesFmt) ax = fig.add_subplot(324) #plot roll ax.plot(sdate, roll, linewidth = 0.5) ax.set_ylim(-30, 30) ax.set_ylabel ('Roll [deg]') ax.yaxis.tick_right() ax.yaxis.set_label_position("right") ax.grid(True) ax.xaxis.set_major_locator (minu) ax.xaxis.set_major_formatter(datesFmt) ax = fig.add_subplot(326) #plot drift ax.plot(sdate, drift, linewidth = 0.5) ax.set_ylim(-8, 8) ax.set_xlabel ('Time') ax.set_ylabel ('Drift [deg]') ax.yaxis.tick_right() ax.yaxis.set_label_position("right") ax.grid(True) ax.xaxis.set_major_locator (minu) ax.xaxis.set_major_formatter(datesFmt) ##Save the fit plt.figtext(0.50, 0.91, 'Telemetry at ' + plottime + 'UTC', fontsize = 12, horizontalalignment = 'center') plt.tight_layout() ##maximixe space plt.savefig(plot_path + 'telemetry_current.png') if np.mod(k, save_step) == 0: ##save an additional figure every x steps plot_savetime = datetime.datetime.fromtimestamp(end_time) plt.savefig(plot_path + 'telemetry_' + str(plot_savetime.year) + str(plot_savetime.month).zfill(2) + str(plot_savetime.day).zfill(2) + str(plot_savetime.hour).zfill(2) + str(plot_savetime.minute).zfill(2) + str(plot_savetime.second).zfill(2) + '.png', bbox_inches='tight') print ('Step ' + str(k)) plt.pause(pause_time) plt.clf() ##Set starttime to endtime. Redefine endtime for next plot if real_time == 1: end_time = int(time.time())#REALTIME if real_time == 2: end_time = end_time + 300 #SIMULATED