# -*- 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 urllib3 import time ##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')) problem = input('Do you need to alter the start time? Y or N? ') plot_path = '/eraid2a/webshare/IMPACTS-2022/radar_rt_plot/ratio/' sys.path.append('/home/ppantina/programs/subroutines') radar_name = ['HIWRAP_KU', 'HIWRAP_KA'] import sub_cmap #colormap maker import sub_radar_processing #radar processing subs 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 = 1581078600 ##Epoch for SIMULATED data if real_time == 1: pause_time = 6 ##time to pause between images (essentially a time-step) if real_time == 2: pause_time = .2 ##time to pause between images (essentially a time-step) start_time = end_time - 3600 ##grab 1 hr of data (LHS of initial plot) save_step = 20 ##loop this many times before saving a timestamped file. noise_seg_len = 1 ##num of profiles for noise averaging...pause_time * save_step ~ number of seconds for a timestamped file if problem == 'Y': start_time = int(input('Enter correct Linux time: ')) #Prepare a figure, suppress the window. fig = plt.figure(figsize = (11,8.5)) plt.ioff() ##Make n0q colormap cmap_n0q = sub_cmap.make_cmap('n0q', bit = True) ##Pull radar-specific variables from subroutine profile_bytes, num_gates, sample_rate, gate_spacing, http_path_rt = sub_radar_processing.radar_variables('HIWRAP_KU') urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) ##disable http complaints from Python #Declare empty lists secs = [] usecs = [] profile_num = [] moment0_ku = [] angle_ku = [] moment0_ka = [] angle_ka = [] checker = 0 ##Main loop for k in range(100000): ##for real life change this to while (True). A large number also works. print('Reading data, step ' + str(k)) ######################################DATA READ###################################### raw_data, num_profiles = sub_radar_processing.data_read (http_path_rt, start_time, end_time, profile_bytes) if num_profiles>0: ##Unpack the data and store in arrays for i, j in enumerate(np.arange(0, num_profiles)): #for all profiles pointer = int(i*profile_bytes) ##keep track of location in file #############################DATA PARSE################################################################################# raw_secs, raw_usecs, raw_moment0_ku, raw_angle_ku = sub_radar_processing.data_parse(pointer, raw_data, num_gates, 'HIWRAP_KU') raw_secs, raw_usecs, raw_moment0_ka, raw_angle_ka = sub_radar_processing.data_parse(pointer, raw_data, num_gates, 'HIWRAP_KA') ##Stack the data as they are read. secs = np.hstack((secs, raw_secs )) usecs = np.hstack((usecs, raw_usecs)) if ((checker == 0) & (i == 0)): ##Create the array on the first time around. Need this for vstack. moment0_ku = np.copy(raw_moment0_ku) angle_ku = np.copy(raw_angle_ku) moment0_ka = np.copy(raw_moment0_ka) angle_ka = np.copy(raw_angle_ka) checker = 1 else: ##otherwise, add to the array moment0_ku = np.vstack((moment0_ku, raw_moment0_ku)) angle_ku = np.vstack((angle_ku, raw_angle_ku)) moment0_ka = np.vstack((moment0_ka, raw_moment0_ka)) angle_ka = np.vstack((angle_ka, raw_angle_ka)) #endfor i ##Find the zero gate by plotting just the first third of the last profile, then finding the argmax zero_gate_ku = np.argmax(moment0_ku[-1, 0:int(num_gates/3)]) zero_gate_ka = zero_gate_ku #zero_gate_ka = np.argmax(moment0_ka[-1, 0:int(num_gates/3)]) ######################################SDATE CALCULATOR###################################### sdate = sub_radar_processing.secs2sdate (secs) ######################################DATA CORRECTION###################################### moment0_array_ku, angle_array_ku, X, Y = sub_radar_processing.data_correction(moment0_ku, angle_ku, num_gates, zero_gate_ku, gate_spacing, sdate) moment0_array_ka, angle_array_ka, X, Y = sub_radar_processing.data_correction(moment0_ka, angle_ka, num_gates, zero_gate_ka, gate_spacing, sdate) ######################################ARRAY SHIFTING FOR PLOT###################################### ##Simply the plots if enough profiles (400) have been already displayed. if moment0_array_ku.shape[0] > 600: moment0_array_ku = moment0_array_ku[-600:, :] angle_array_ku = angle_array_ku [-600:, :] moment0_array_ka = moment0_array_ka[-600:, :] angle_array_ka = angle_array_ka [-600:, :] X = X [:, -600:] Y = Y [:, -600:] secs = secs [-600: ] ######################################NOISE CORRECTION###################################### power_array_noise_removed_ku, angle_array_ku = sub_radar_processing.noise_correction(noise_seg_len, moment0_array_ku, angle_array_ku, num_gates) power_array_noise_removed_ka, angle_array_ka = sub_radar_processing.noise_correction(noise_seg_len, moment0_array_ka, angle_array_ka, num_gates) ######################################RANGE CORRECTION###################################### z_uncal_array_ku = 10 * np.log10(power_array_noise_removed_ku * Y.T**2) z_uncal_array_ka = 10 * np.log10(power_array_noise_removed_ka * Y.T**2) ######################################MAKE A PLOT###################################### zero_gate = [zero_gate_ku, zero_gate_ka] sub_radar_processing.make_plot_hiwrap_ratio (k, plot_path, fig, X, Y, secs, z_uncal_array_ku, z_uncal_array_ka, cmap_n0q, zero_gate, save_step, pause_time, end_time) else: print ('No Radar data') ##Set starttime to endtime. Redefine endtime for next plot start_time = np.copy(end_time) if real_time == 1: end_time = int(time.time())#REALTIME if real_time == 2: end_time = end_time + 300 #SIMULATED #endfor k