# -*- coding: utf-8 -*- """ Created on Mon Dec 30 15:56:49 2019 @author: ppantina """ ##Import some libraries import platform import sys from matplotlib import pyplot as plt import numpy as np import urllib3 import time ##Determine radar name radar_name_idx = input('Which RADAR are you running?\n\ CRS = 1\n\ EXRAD = 2\n\ HIWRAP KU = 3\n\ HIWRAP KA = 4\n\ QUIT = q\n') if radar_name_idx == '1': radar_name = 'CRS' elif radar_name_idx == '2': radar_name = 'EXRAD' elif radar_name_idx == '3': radar_name = 'HIWRAP_KU' elif radar_name_idx == '4': radar_name = 'HIWRAP_KA' else: sys.exit() ##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? ') ##Choose computer-name-based paths computer_name = platform.node() if (computer_name == 'gs614-ppantinwl'): plot_path = 'C:/HAR/programs/radar_rt_plot/' + radar_name + '/' sys.path.append('C:/HAR/programs/subroutines') if (computer_name == 'erika.gsfc.nasa.gov'): plot_path = '/eraid2a/webshare/IMPACTS-2022/radar_rt_plot/' + radar_name + '/' sys.path.append('/home/ppantina/programs/subroutines') 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 = 1638825300 ##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: ')) ##Pull radar-specific variables from subroutine profile_bytes, num_gates, sample_rate, gate_spacing, http_path_rt = sub_radar_processing.radar_variables(radar_name) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) ##disable http complaints from Python #Declare empty lists secs = [] usecs = [] profile_num = [] moment0 = [] angle = [] #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) checker = 0 ##Main loop for k in range(100000): ##for real life change this to while (True). A large number also works. ######################################DATA READ###################################### print('Reading data, step ' + str(k)) 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, raw_angle = sub_radar_processing.data_parse(pointer, raw_data, num_gates, radar_name) ##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 = np.copy(raw_moment0) angle = np.copy(raw_angle) checker = 1 else: ##otherwise, add to the array moment0 = np.vstack((moment0, raw_moment0)) angle = np.vstack((angle, raw_angle)) #endfor i ##Find the zero gate by plotting just the first third of the last profile, then finding the argmax zero_gate = np.argmax(moment0[-1, 1:int(num_gates/3)]) ##skipping first gate ######################################SDATE CALCULATOR###################################### sdate = sub_radar_processing.secs2sdate (secs) ######################################DATA CORRECTION###################################### moment0_array, angle_array, X, Y = sub_radar_processing.data_correction(moment0, angle, num_gates, zero_gate, gate_spacing, sdate) ######################################ARRAY SHIFTING FOR PLOT###################################### ##Simply the plots if enough profiles (400) have been already displayed. if moment0_array.shape[0] > 600: moment0_array = moment0_array[-600:, :] angle_array = angle_array [-600:, :] X = X [:, -600:] Y = Y [:, -600:] secs = secs [-600: ] ######################################NOISE CORRECTION###################################### ##For EXRAD, this is done in lower/upper halves separately, due to different channels. if radar_name != 'EXRAD' : power_array_noise_removed, angle_array = sub_radar_processing.noise_correction(noise_seg_len, moment0_array, angle_array, num_gates) else: ##Calculate the halves separately, then stack them power_array_noise_bottom, angle_array_bottom = sub_radar_processing.noise_correction(noise_seg_len, moment0_array[:,0 :int(num_gates/2)], angle_array[:,0 :int(num_gates/2)], int(num_gates/2)) power_array_noise_top , angle_array_top = sub_radar_processing.noise_correction(noise_seg_len, moment0_array[:,int(num_gates/2):: ], angle_array[:,int(num_gates/2):: ], int(num_gates/2)) power_array_noise_removed = np.hstack((power_array_noise_bottom, power_array_noise_top)) angle_array = np.hstack((angle_array_bottom, angle_array_top )) ######################################RANGE CORRECTION###################################### z_uncal_array = 10 * np.log10(power_array_noise_removed * Y.T**2) ######################################MAKE A PLOT###################################### sub_radar_processing.make_plot_nrt (k, plot_path, fig, X, Y, secs, z_uncal_array, angle_array, cmap_n0q, zero_gate, save_step, pause_time, end_time, radar_name) 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