def azza_to_radec(az, za, MJD, fctr=350.0, atm=1010.0, temp=283.0, humid=0.5, scope='GBT'): """ azza_to_radec(az, za, MJD): Return RA and DEC (J2000 in deg) from AZ and ZA (in deg) at MJD. Keyword params are fctr=350.0, atm=1010.0, temp=283.0, humid=0.5, scope='GBT'. """ scope, x, lon, lat, hgt = s.sla_obs(0, scope) microns = 3e8/(fctr*1e6)*1e6 app_rarad, app_decrad = s.sla_oap('a',az*DEGTORAD,za*DEGTORAD,MJD, 0.0,-lon,lat,hgt,0.0,0.0,temp,atm,humid,microns,0.0065) ra2000, dec2000 = s.sla_amp(app_rarad, app_decrad, MJD, 2000.0) return ra2000*RADTODEG, dec2000*RADTODEG
def azza_to_radec(az, za, MJD, fctr=350.0, atm=1010.0, temp=283.0, humid=0.5, scope='GBT'): """ azza_to_radec(az, za, MJD): Return RA and DEC (J2000 in deg) from AZ and ZA (in deg) at MJD. Keyword params are fctr=350.0, atm=1010.0, temp=283.0, humid=0.5, scope='GBT'. """ scope, x, lon, lat, hgt = s.sla_obs(0, scope) microns = 3e8 / (fctr * 1e6) * 1e6 app_rarad, app_decrad = s.sla_oap('a', az * DEGTORAD, za * DEGTORAD, MJD, 0.0, -lon, lat, hgt, 0.0, 0.0, temp, atm, humid, microns, 0.0065) ra2000, dec2000 = s.sla_amp(app_rarad, app_decrad, MJD, 2000.0) return ra2000 * RADTODEG, dec2000 * RADTODEG
def translate_header(fits_file, skip, output_subints): fits_hdr = fits_file['PRIMARY'].header subint_hdr = fits_file['SUBINT'].header fil_header = dict.fromkeys(fil_header_keys, None) if fits_hdr['TELESCOP'] in telescope_ids: fil_header["telescope_id"] = telescope_ids[fits_hdr['TELESCOP']] else: fil_header["telescope_id"] = -1 if fits_hdr['BACKEND'] in machine_ids: fil_header["machine_id"] = machine_ids[fits_hdr['BACKEND']] else: fil_header["machine_id"] = -1 fil_header["data_type"] = 1 # filterbank # Get filename in a way that is safe for old versions of pyfits # (i.e. using private attribute) #Let's get the center of our intended output file. #Right now I'm assuming we're in search mode and that we'll take #The subint offset from the first file and add skip + #output_subints / 2 subints to get the position of the telescope. time_subint = subint_hdr['TBIN'] * subint_hdr['NSBLK'] time_offset = subint_hdr['NSUBOFFS'] * time_subint + \ skip * time_subint #Let's set some variables that we'll use to update our position #via pyslalib type = "A" #We need this for SLA dtmp = 0.0 #Delta UT atm = 1010.0 #Local atmospheric pressure in mB temp = 283.0 #Local temperature in DegK humid = 0.5 #Local relative humidity in range 0.0-1.0 tlr = 0.0065 #Tropospheric lapse rate (DegL/meter) eq = 2000.0 #Julian epoch of mean place microns = 3e8 / fits_hdr['OBSFREQ'] * 1e6 * 1e6 az = radians(fits_file['SUBINT'].data[0]['TEL_AZ']) #azimuth za = radians(fits_file['SUBINT'].data[0]['TEL_ZEN']) #zenith tstart = fits_hdr['STT_IMJD'] + \ fits_hdr['STT_SMJD']/86400.0 + \ fits_hdr['STT_OFFS']/86400.0 + \ time_offset/86400.0 #tstart of new file #Now let's get the MJD of the center of the new file #so that we can update the RA/DEC for the new file MJD = tstart + (time_subint * output_subints / 2) / 86400.0 #Ok, I think we're set to update our position. Let's use slalib #to get the position of the telescope telecope,telescope_name,tel_lon,tel_lat,tel_hgt = \ sla.sla_obs(0,fits_hdr['TELESCOP']) #Now we have tel_lon,tel_lat and tel_ght. We need to flip the lon tel_lon = -tel_lon #Let's get the geocentric apparent RA and DEC rap,dap = sla.sla_oap(type,az,za,MJD,dtmp,tel_lon,tel_lat,tel_hgt,\ dtmp,dtmp,temp,atm,humid,microns,tlr) #OK, for reals we are almost there Let's convert to FK5 (mean place) rmn, dmn = sla.sla_amp(rap, dap, MJD, eq) hours, hmin, hsec = presto.hours2hms(degrees(rmn) / 15.0) deg, dmin, dsec = presto.deg2dms(degrees(dmn) / 15.0) fil_header["src_raj"] = float(hours * 10000.0 + hmin * 100.0 + hsec) fil_header["src_dej"] = float(deg * 10000.0 + dmin * 100.0 + dsec) fn = fits_file._HDUList__file.name fil_header["rawdatafile"] = os.path.basename(fn) fil_header["source_name"] = fits_hdr['SRC_NAME'] fil_header["barycentric"] = 0 # always not barycentered? fil_header["pulsarcentric"] = 0 # whats pulsarcentric? fil_header["az_start"] = fits_file['SUBINT'].data[0]['TEL_AZ'] fil_header["za_start"] = fits_file['SUBINT'].data[0]['TEL_ZEN'] # fil_header["src_raj"] = float(fits_hdr['RA'].replace(':','')) # fil_header["src_dej"] = float(fits_hdr['DEC'].replace(':','')) fil_header["tstart"] = fits_hdr['STT_IMJD'] + \ fits_hdr['STT_SMJD']/86400.0 + \ fits_hdr['STT_OFFS']/86400.0 + \ time_offset/86400.0 fil_header["tsamp"] = subint_hdr['TBIN'] fil_header["nbits"] = None # set by user. Input should always be 4-bit. # first channel (fch1) in sigproc is the highest freq # foff is negative to signify this fil_header["fch1"] = fits_hdr['OBSFREQ'] + \ np.abs(fits_hdr['OBSBW'])/2.0 - \ np.abs(subint_hdr['CHAN_BW'])/2.0 fil_header["foff"] = -1.0 * np.abs(subint_hdr['CHAN_BW']) fil_header["nchans"] = subint_hdr['NCHAN'] fil_header["nifs"] = subint_hdr['NPOL'] return fil_header
def translate_header(fits_file,skip,output_subints): fits_hdr = fits_file['PRIMARY'].header subint_hdr = fits_file['SUBINT'].header fil_header = dict.fromkeys(fil_header_keys,None) if fits_hdr['TELESCOP'] in telescope_ids: fil_header["telescope_id"] = telescope_ids[fits_hdr['TELESCOP']] else: fil_header["telescope_id"] = -1 if fits_hdr['BACKEND'] in machine_ids: fil_header["machine_id"] = machine_ids[fits_hdr['BACKEND']] else: fil_header["machine_id"] = -1 fil_header["data_type"] = 1 # filterbank # Get filename in a way that is safe for old versions of pyfits # (i.e. using private attribute) #Let's get the center of our intended output file. #Right now I'm assuming we're in search mode and that we'll take #The subint offset from the first file and add skip + #output_subints / 2 subints to get the position of the telescope. time_subint = subint_hdr['TBIN']*subint_hdr['NSBLK'] time_offset = subint_hdr['NSUBOFFS'] * time_subint + \ skip * time_subint #Let's set some variables that we'll use to update our position #via pyslalib type = "A" #We need this for SLA dtmp = 0.0 #Delta UT atm = 1010.0 #Local atmospheric pressure in mB temp = 283.0 #Local temperature in DegK humid = 0.5 #Local relative humidity in range 0.0-1.0 tlr = 0.0065 #Tropospheric lapse rate (DegL/meter) eq = 2000.0 #Julian epoch of mean place microns = 3e8 / fits_hdr['OBSFREQ']*1e6*1e6 az = radians(fits_file['SUBINT'].data[0]['TEL_AZ']) #azimuth za = radians(fits_file['SUBINT'].data[0]['TEL_ZEN']) #zenith tstart = fits_hdr['STT_IMJD'] + \ fits_hdr['STT_SMJD']/86400.0 + \ fits_hdr['STT_OFFS']/86400.0 + \ time_offset/86400.0 #tstart of new file #Now let's get the MJD of the center of the new file #so that we can update the RA/DEC for the new file MJD = tstart + (time_subint * output_subints / 2)/86400.0 #Ok, I think we're set to update our position. Let's use slalib #to get the position of the telescope telecope,telescope_name,tel_lon,tel_lat,tel_hgt = \ sla.sla_obs(0,fits_hdr['TELESCOP']) #Now we have tel_lon,tel_lat and tel_ght. We need to flip the lon tel_lon = -tel_lon #Let's get the geocentric apparent RA and DEC rap,dap = sla.sla_oap(type,az,za,MJD,dtmp,tel_lon,tel_lat,tel_hgt,\ dtmp,dtmp,temp,atm,humid,microns,tlr) #OK, for reals we are almost there Let's convert to FK5 (mean place) rmn,dmn = sla.sla_amp(rap,dap,MJD,eq) hours,hmin,hsec = presto.hours2hms(degrees(rmn)/15.0) deg,dmin,dsec = presto.deg2dms(degrees(dmn)/15.0) fil_header["src_raj"] = float(hours*10000.0 + hmin*100.0 + hsec) fil_header["src_dej"] = float(deg*10000.0 + dmin*100.0 + dsec) fn = fits_file._HDUList__file.name fil_header["rawdatafile"] = os.path.basename(fn) fil_header["source_name"] = fits_hdr['SRC_NAME'] fil_header["barycentric"] = 0 # always not barycentered? fil_header["pulsarcentric"] = 0 # whats pulsarcentric? fil_header["az_start"] = fits_file['SUBINT'].data[0]['TEL_AZ'] fil_header["za_start"] = fits_file['SUBINT'].data[0]['TEL_ZEN'] # fil_header["src_raj"] = float(fits_hdr['RA'].replace(':','')) # fil_header["src_dej"] = float(fits_hdr['DEC'].replace(':','')) fil_header["tstart"] = fits_hdr['STT_IMJD'] + \ fits_hdr['STT_SMJD']/86400.0 + \ fits_hdr['STT_OFFS']/86400.0 + \ time_offset/86400.0 fil_header["tsamp"] = subint_hdr['TBIN'] fil_header["nbits"] = None # set by user. Input should always be 4-bit. # first channel (fch1) in sigproc is the highest freq # foff is negative to signify this fil_header["fch1"] = fits_hdr['OBSFREQ'] + \ np.abs(fits_hdr['OBSBW'])/2.0 - \ np.abs(subint_hdr['CHAN_BW'])/2.0 fil_header["foff"] = -1.0*np.abs(subint_hdr['CHAN_BW']) fil_header["nchans"] = subint_hdr['NCHAN'] fil_header["nifs"] = subint_hdr['NPOL'] return fil_header