### PITCH VS YAW MOVIE MAKER ### ''' This script creates a series of stills that can be used in order to create a time-lapse. Its focus is on the pitch and yaw motion of an optic. In this case it is the ASC control loop for SRC2. Improvements can be made: - Adding a colorbar - Asking for input channel - Asking for times of interest - Asking for how much time you want to elapse between stills Author: Michael Antia Email: michael_antia@knights.ucf.edu Acknowledgements: Jess McIver, TJ Massinger, Duncan Macleod ''' import math import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import numpy as np from gwpy.timeseries import TimeSeries from gwpy.time import tconvert from gwpy.time import LIGOTimeGPS from gwpy.time import to_gps from gwpy.time import from_gps # The line below helps to create a legend import matplotlib.patches as mpatches # Here the time series is downloaded. verbose = True helps to see the status of the download, host = ... argument dramatically increases the download speed pitch = TimeSeries.get('L1:ASC-SRC2_P_OUT_DQ', 'November 06 2015 00:45', 'November 06 2015 02:30', verbose=True, host='nds.ligo.caltech.edu' ) yaw = TimeSeries.get('L1:ASC-SRC2_Y_OUT_DQ', 'November 06 2015 00:45', 'November 06 2015 02:30', verbose=True, host='nds.ligo.caltech.edu' ) # this segment below will be used to indicate time of event in the time-lapse time_legend = 'November 06 2015 00:45' # The time series is stored in the following arrays. X - for yaw, Y - for pitch. x = [] y = [] # COUNT is just to see the progress on the terminal. # CLOCK is used in conjunction with time_interval in order to show the time elapsed on the plot's legend. count = 1 clock = 0 time_interval = 0 ''' Here the data is taken from the time series and copied into the array. The second for loop has the arguments sample and sample+1 in order to fill the next empty space in the x and y arrays, otherwise the arrays recopy the information of the prior indices. ''' for sample in range(0,len(pitch)): for z in range(sample,sample+1): x.append(yaw[z]) y.append(pitch[z]) # This segment is used to show the time elapsed on the interval. It is set for 5 minute intervals. Perhaps this can be changed as a raw input in the future. clock += 1 if clock % (1*60*512) == 0: # 1 minutes, 60 seconds, 512 samples per second time_interval += 60 time_legend = to_gps(time_legend) time_legend += time_interval time_legend = from_gps(time_legend) time_legend = time_legend.strftime('%H:%M') time_interval = 0 clock = 0 #The data in the time series is sampled at 512 s^-1. Here I chose 4096, equivalent to 8 sec time elapsed per plot saved. This could also be a user defined input. # The following segment creates the plots if sample%4096 == 0: plt.clf() plt.hist2d(x,y,100, cmin = 1) plt.plot(x[sample],y[sample], 'm*', markersize = 15) ax = plt.gca() ax.set_title('Angular Motion for L1:ASC-SRC2 on November 06, 2015, 00:45 - 02:30') ax.set_xlabel('Yaw (Counts)') ax.set_ylabel('Pitch (Counts)') ax.set_xlim(-50,-25) ax.set_ylim(-40,-15) ax.title.set_position([0.5,1.05]) # Adjust the time displayed in legend # Artist created to add legend because hist2d doesn't support a legend. time_label = 'Current Time (UTC): ' + time_legend red_patch = mpatches.Patch(color='red', label= time_label) plt.legend(handles=[red_patch]) #Files saved file_name = "" file_name += str(count) file_name += "plot.png" plt.savefig(file_name) print "\n\n" #Again, counting mechanism in order to see progress on the terminal count += 1 print count print "\n\n\n ALL DONE !!!!"