def create_utservo(servo_file, offsets, utcc, ut): """Create file with servo data with fixed CC and UT Parameters ---------- servo_file : str filename of servo data offsets : ndarray CC offsets computed from gpstime, see find_clock_offsets_from_gpstime utcc : ndarray CC array related to UT ut : ndarray UT array Returns ------- writes utservo.fits file to disk """ print("Create UT timestamped servo data") utservo = OrderedDict() for device in DEVICES: print('Processing ' + device) utservo[device] = fits.read(servo_file, device) utservo[device]['COMPUTERCLOCK'] = apply_cc_offsets(utservo[device]['COMPUTERCLOCK'], offsets) utservo[device]['UT'] = np.interp( utservo[device]['COMPUTERCLOCK'], utcc, ut) filename = 'utservo.fits' print('Writing ' + filename) fits.write(filename, utservo) return utservo
def create_utscience(sci_file, gyro, revcounter, offsets, utcc, ut, freq): """Create file with science data with fixed CC and UT see create_utservo """ data = fits.read(sci_file) splitted_data = OrderedDict() splitted_data['TIME'] = OrderedDict() for ch_n in range(16): ch_name = 'CH%d_' % ch_n splitted_data[ch_name] = OrderedDict() for comp in 'TQU': splitted_data[ch_name][comp] = data[ch_name + comp] splitted_data['TIME']['COMPUTERCLOCK'], splitted_data['TIME']['NOREVCOUNTFLAG']= create_science_computerclock(gyro, revcounter, data['REV'], offsets) splitted_data['TIME']['UT'] = np.interp(splitted_data['TIME']['COMPUTERCLOCK'], utcc, ut) filename = '%s_%dGHz_data.fits' % (os.path.basename(sci_file).split('.')[0], freq) print('Writing ' + filename) fits.write(filename, splitted_data) return splitted_data
h_jumps_scaled[h_jumps] *= np.round(np.diff(ut)[h_jumps]/typical_revlength) unwrapped[1:] += np.cumsum(h_jumps_scaled) * np.pi * 2 #smooth #unwrapped = smooth(unwrapped, 30) #read ut science ut_sci_10 = pyfits.getdata(os.path.join(folder, 'all_10GHz_data.fits'), 'TIME')['UT'] ut_sci_15 = pyfits.getdata(os.path.join(folder, 'all_15GHz_data.fits'), 'TIME')['UT'] #interpolate and reset to -pi pi fixed_az_10 = np.mod(smooth(np.interp(ut_sci_10, ut, unwrapped),30) + np.pi, 2*np.pi) - np.pi fixed_az_15 = np.mod(smooth(np.interp(ut_sci_15, ut, unwrapped),30) + np.pi, 2*np.pi) - np.pi # TODO flagging ###gaps longer than ROTATION are flagged flag_10 = np.ceil(np.interp(ut_sci_10, ut[1:], np.diff(ut) > 80/3600.)).astype(np.uint8) flag_15 = np.ceil(np.interp(ut_sci_15, ut[1:], np.diff(ut) > 80/3600.)).astype(np.uint8) ##self.synched_data[device]['FLAG'] = flag #plt.figure() #plt.plot(ut_sci_10, fixed_az_10, 'r.', label='fixed') #plt.xlabel('UT') #plt.savefig('fixedaz.png') import pycfitsio as fits fits.write(os.path.join(folder, 'fixaz.fits'), OrderedDict([ ('10GHz', OrderedDict([('UT', ut_sci_10), ('AZ', fixed_az_10), ('FLAG', flag_10)])), ('15GHz', OrderedDict([('UT', ut_sci_15), ('AZ', fixed_az_15), ('FLAG', flag_15)])) ]))