#!/opt/local/bin/ipython #2019.02.05 Frayer #Python 3.7.2 #IPython 7.2.0 # # #Flip Beam-2/3 positions for an ARGUS SDFITS file where the input file #contains both beam 2 and beam 3 data and the data are in the same #scan and integration order for both beams. # #SDFITS files for the GBT are large tables stored in extension=1 where #each row represents a specific interation number, scan number, #spectral window, beam number, frequency-state, subreflector-state, #and other states/parameters that are used by other instruments (83 #columns) # # #Usage: %swap23.py SDFITSfile.fits #Warning: Replaces data in original input file # # from astropy.io import fits import sys import numpy as np FILEIN = sys.argv[1] #Python notes #How to view FITS info: #fits.info(FILEIN) #Alternative FITS access method: #f=fits.open(FILEIN) #tab=f[1].data ##Uses np.where command: #x=np.array([2,4,5,2,6]) #idx=np.where(x == 2) #print(idx[0]) #type(idx) ##Careful with list vs np.array types ##Careful to work with copies tab=fits.getdata(FILEIN,ext=1) h=fits.getheader(FILEIN,ext=1) ra = tab["CRVAL2"] dec = tab["CRVAL3"] feed = tab["FEED"] nra=np.copy(ra) ndec=np.copy(dec) id2=np.where(feed==2) id3=np.where(feed==3) idx2=id2[0] idx3=id3[0] #swap idexes nra[idx2]=ra[idx3] nra[idx3]=ra[idx2] ndec[idx2]=dec[idx3] ndec[idx3]=dec[idx2] #replace values tab["CRVAL2"]=nra tab["CRVAL3"]=ndec #update input file fits.update(FILEIN,tab,h,ext=1)