Example #1
0
def input_map(file_map):
    import pycfitsio

    f = pycfitsio.open(file_map)
    map = f[f.HDUs.keys()[0]].read_column(0)
    f.close()
    return map
Example #2
0
def get_ahf_wobble(obtx):
    """Read psi1 and psi2 file previously extracted from observation AHF files"""
    filename = sorted(glob.glob(private.cal_folder + '/WDX9/*.fits'))[-1]
    l.info(filename)
    with pycfitsio.open(filename) as fitsfile:
        obt = fitsfile['OBT'].read_column(0)/2.**16 + 20 #shift forward of 20 seconds, so that the abrupt change in wobble angle is within the manouvre and does not impact the pointing between the last AHF quaternion and the manouvre
        psi1 = arcmin2rad(fitsfile['PSI_1'].read_column(0))
        psi2 = arcmin2rad(fitsfile['PSI_2'].read_column(0))
        # reproduce dpc dx9
        #psi1[1:] = psi1[0:-1]
        #psi2[1:] = psi2[0:-1]
    i_interp = np.interp(obtx, obt, np.arange(len(obt)))
    i_rounded = np.floor(i_interp).astype(np.int)
    return psi1[i_rounded], psi2[i_rounded]
from pointingtools import compute_parallactic_angle, altaz2ha 

import pycfitsio as fits
import ephem

def freq2wavelength(freq):
        """Freq [GHz] to wavelength [microns]"""
        return constants.c / freq / 1e3

freq = 10
mag = True

pointing_filename = 'data/all_%dghz_pointing.fits' % freq
if mag:
    pointing_filename = pointing_filename.replace('.fits','_mag.fits')
pointing_file = fits.open(pointing_filename)

channels = list(set([int(c.translate(None, 'AZEL')) for c in pointing_file[0].dtype.names if c != 'UT']))
data_file = fits.open('data/all_%dGHz_data_cal.fits' % freq)
servo_file = fits.open('data/utservo.fits')

# pointing channel is the column in the pointing file

MISSIONSTART = 16.8 #from altitude
MISSIONEND = 36.76 #from issue with latitude
#MISSIONEND = 16.8 + 1./60
#first sun xsing
#MISSIONSTART = 17 + 9/60.
#MISSIONEND = 17 + 13/60.
START_DATE = datetime.datetime(2011, 9, 17)
Example #4
0
from pointingtools import compute_parallactic_angle, altaz2ha 

import pycfitsio as fits
import ephem

def freq2wavelength(freq):
        """Freq [GHz] to wavelength [microns]"""
        return constants.c / freq / 1e3

freq = 10
mag = True

pointing_filename = 'data/all_%dghz_pointing.fits' % freq
if mag:
    pointing_filename = pointing_filename.replace('.fits','_mag.fits')
pointing_file = fits.open(pointing_filename)

channels = list(set([int(c.translate(None, 'AZEL')) for c in pointing_file[0].dtype.names if c != 'UT']))
data_file = fits.open('data/all_%dGHz_data_cal.fits' % freq)
servo_file = fits.open('data/utservo.fits')

# pointing channel is the column in the pointing file

MISSIONSTART = 16.8 #from altitude
MISSIONEND = 36.76 #from issue with latitude
#MISSIONEND = 16.8 + 1./60
#first sun xsing
#MISSIONSTART = 17 + 9/60.
#MISSIONEND = 17 + 13/60.
START_DATE = datetime.datetime(2011, 9, 17)
Example #5
0
    def __init__(
        self,
        obt,
        coord="G",
        horn_pointing=False,
        deaberration=True,
        wobble=True,
        interp="slerp",
        siamfile=None,
        wobble_offset=0,
        ptcorfile=None,
        Pxx=False,
        instrument_db=None,
    ):
        """
        nointerp to use the AHF OBT stamps"""
        l.warning("Pointing setup, coord:%s, deab:%s, wobble:%s" % (coord, deaberration, wobble))
        # get ahf limits
        self.Pxx = Pxx
        self.deaberration = deaberration
        self.wobble = wobble

        filenames = AHF_btw_OBT(obt)
        files = [pycfitsio.open(f) for f in filenames]
        l.debug("reading files %s" % str(files))
        AHF_data_iter = [f[0] for f in files]

        l.debug("reading files")

        ahf_obt = np.concatenate([h.read_column("OBT_SPL") for h in AHF_data_iter])
        ahf_obt /= 2.0 ** 16
        i_start = max(ahf_obt.searchsorted(obt[0]) - 1, 0)
        i_end = min(ahf_obt.searchsorted(obt[-1]) + 1, len(ahf_obt) - 1)
        ahf_obt = ahf_obt[i_start:i_end]

        ahf_quat = np.empty((len(ahf_obt), 4))
        for i, c in enumerate(self.comp):
            ahf_quat[:, i] = np.concatenate([h.read_column("QUATERNION_" + c) for h in AHF_data_iter])[i_start:i_end]

        # debug_here()
        if self.wobble:
            # ahf_quat = qarray.mult(ahf_quat, correction.wobble(ahf_obt,offset=wobble_offset))
            # DX8 wobble angle correction
            wob = correction.ahf_wobble(ahf_obt)
            ahf_quat = qarray.mult(ahf_quat, wob)
            # print(wob[17320:17335])
            # print(ahf_obt[17329])
            # 34690:34705
            qarray.norm_inplace(ahf_quat)

        if ptcorfile == True:
            ptcorfile = private.ptcorfile
        if ptcorfile:
            ahf_quat = qarray.mult(ahf_quat, correction.ptcor(ahf_obt, ptcorfile))

        if coord == "G":
            ahf_quat = quaternion_ecl2gal(ahf_quat)

        if interp is None:
            self.qsatgal_interp = ahf_quat
            # save AHF obt for later interpolation
            self.ahf_obt = ahf_obt
        else:
            l.info("Interpolating quaternions with %s" % interp)
            interpfunc = getattr(qarray, interp)
            self.qsatgal_interp = interpfunc(obt, ahf_obt, ahf_quat)

        # if self.wobble:
        #    self.qsatgal_interp = qarray.mult(self.qsatgal_interp, correction.wobble(obt))
        #    qarray.norm_inplace(self.qsatgal_interp)

        l.info("Quaternions interpolated")
        self.siam = IDBSiam(instrument_db, obt, self.Pxx)

        self.obt = obt
        self.coord = coord

        l.debug("Closing AHF files")
        for f in files:
            f.close()
Example #6
0
 def get_ang(self, ch):
     l.debug("Reading %s" % self.filename)
     with pycfitsio.open(self.filename) as f:
         h = f[ch.tag]
         return h.read_column("THETA"), h.read_column("PHI")
Example #7
0
 def get_ang(self, ch):
     l.debug('Reading %s' % self.filename)
     with pycfitsio.open(self.filename) as f:
         h = f[ch.tag]
         return h.read_column('THETA'), h.read_column('PHI')