def nominal_to_altaz(nominal, horizon_center=(0, 0)):
    """Transform nominal coordinates to horizon coordinates.

    nominal = (x, y) in meter
    horizon_center = (az_center, alt_center) in deg

    Returns: horizon = (az, alt) in deg
    """
    x, y = np.asarray(nominal, dtype='float64')
    az_center, alt_center = np.asarray(horizon_center, dtype='float64')
    header = {'NAXIS': 2,
              'NAXIS1': 100,
              'NAXIS2': 100,
              'CTYPE1': 'RA---TAN',
              'CRVAL1': az_center,
              'CRPIX1': 0,
              'CUNIT1': 'deg',
              'CDELT1': np.degrees(1),
              'CTYPE2': 'DEC--TAN',
              'CRVAL2': alt_center,
              'CRPIX2': 0,
              'CUNIT2': 'deg',
              'CDELT2': np.degrees(1),
              }
    projection = Projection(header)
    altaz = projection.toworld((y, x))
    return altaz[0], altaz[1]
Example #2
0
def nominal_to_altaz(nominal, horizon_center=(0, 0)):
    """Transform nominal coordinates to horizon coordinates.

    nominal = (x, y) in meter
    horizon_center = (az_center, alt_center) in deg

    Returns: horizon = (az, alt) in deg
    """
    x, y = np.asarray(nominal, dtype='float64')
    az_center, alt_center = np.asarray(horizon_center, dtype='float64')
    header = {'NAXIS': 2,
              'NAXIS1': 100,
              'NAXIS2': 100,
              'CTYPE1': 'RA---TAN',
              'CRVAL1': az_center,
              'CRPIX1': 0,
              'CUNIT1': 'deg',
              'CDELT1': np.degrees(1),
              'CTYPE2': 'DEC--TAN',
              'CRVAL2': alt_center,
              'CRPIX2': 0,
              'CUNIT2': 'deg',
              'CDELT2': np.degrees(1),
              }
    projection = Projection(header)
    altaz = projection.toworld((y, x))
    return altaz[0], altaz[1]
Example #3
0
def add_tan_world_coordinates(csv_file, outfile):
    """Compute alt, az from x, y nominal coordinates
    and add as columns to a CSV file."""
    from kapteyn.wcs import Projection

    logging.info('Reading file: {0}'.format(csv_file))
    data = np.recfromcsv(csv_file)
    camX = data['cameraxevent']
    camY = data['camerayevent']
    alts = data['altsystem']
    azs = data['azsystem']
    infile = open(csv_file)

    logging.info('Writing file: {0}'.format(outfile))
    outfile = open(outfile, 'w')
    names = infile.readline().split()
    names.append(',GnomAz,GnomAlt\n')
    line = ' '.join(names)
    line = line.replace(' ', '')
    outfile.write(line)

    for ii in np.arange(0, len(alts) - 1, 1):
        header = {
            'NAXIS': 2,
            'NAXIS1': 100,
            'NAXIS2': 100,
            'CTYPE1': 'RA---TAN',
            'CRVAL1': azs[ii],
            'CRPIX1': 0,
            'CUNIT1': 'deg',
            'CDELT1': np.degrees(1),
            'CTYPE2': 'DEC--TAN',
            'CRVAL2': alts[ii],
            'CRPIX2': 0,
            'CUNIT2': 'deg',
            'CDELT2': np.degrees(1),
        }
        projection = Projection(header)
        gnoms = projection.toworld((camY[ii], camX[ii]))

        values = infile.readline().split()
        values.append(',%s,%s\n' % (str(gnoms[0]), str(gnoms[1])))
        line = ' '.join(values)
        line = line.replace(' ', '')

        outfile.write(line)

    infile.close()
    outfile.close()
Example #4
0
class GalacticDiffuse:
    """Lookup from FITS cube representing diffuse emission.
    Interpolates linearly in log(e), no interpolation in GLON, GLAT"""
    def __init__(self, filename=None, interp_kind='linear'):
        # TODO: use astropy!
        from kapteyn.wcs import Projection
        from atpy import Table
        if filename != None:
            self.filename = filename
        else:
            self.filename = ('/Users/deil/bin/fermi/ScienceTools-v9r23p1'
                             '-fssc-20110726/external/diffuseModels/'
                             'gal_2yearp7v6_v0.fits')
        self.interp_kind = interp_kind
        print filename
        self.data = fits.getdata(self.filename)
        # Note: the energy axis of the FITS cube is unusable.
        # We only use proj for GLON, GLAT and do ENERGY ourselves
        self.proj = Projection(fits.getheader(self.filename))
        self.e_axis = EnergyAxis(Table(self.filename, 'ENERGIES').Energy)

    def __call__(self, glon, glat, e):
        """Linear interpolation in log(e)"""
        return self.flux(glon, glat, e)

    def flux(self, glon, glat, e):
        from scipy.interpolate import interp1d
        self.set_position(glon, glat)
        f = interp1d(self.e_axis.log_e, self.log_f, kind=self.interp_kind)
        return 10 ** f(np.log10(e))
        # return f_from_points(*self.lookup(glon, glat, e))

    def gamma(self, glon, glat, e):
        f = lambda e: self.flux(glon, glat, e)
        return pl.g_from_f(e, f)
        # return g_from_points(*(self.lookup(glon, glat, e)[:-1]))

    def lookup(self, glon, glat, e):
        # print glon, glat, e
        x, y = self.proj.topixel((glon, glat, 0))[:-1]
        z1, z2, e1, e2 = self.e_axis(e)
        f1, f2 = self.data[z1, y, x], self.data[z2, y, x]
        # print x, y, z1, z2, e1, e2, f1, f2
        return [e1, e2, f1, f2, e]

    def set_position(self, glon, glat):
        x, y = self.proj.topixel((glon, glat, 0))[:-1]
        self.log_f = np.log10(self.data[:, y, x])
def add_tan_world_coordinates(csv_file, outfile):
    """Compute alt, az from x, y nominal coordinates
    and add as columns to a CSV file."""
    from kapteyn.wcs import Projection

    logging.info('Reading file: {0}'.format(csv_file))
    data = np.recfromcsv(csv_file)
    camX = data['cameraxevent']
    camY = data['camerayevent']
    alts = data['altsystem']
    azs = data['azsystem']
    infile = file(csv_file)

    logging.info('Writing file: {0}'.format(outfile))
    outfile = file(outfile, 'w')
    names = infile.readline().split()
    names.append(',GnomAz,GnomAlt\n')
    line = ' '.join(names)
    line = line.replace(' ', '')
    outfile.write(line)

    for ii in np.arange(0, len(alts) - 1, 1):
        header = {'NAXIS':  2,
                  'NAXIS1':  100, 'NAXIS2': 100,
                  'CTYPE1': 'RA---TAN',
                  'CRVAL1':  azs[ii], 'CRPIX1': 0, 'CUNIT1': 'deg',
                  'CDELT1':  np.degrees(1), 'CTYPE2': 'DEC--TAN',
                  'CRVAL2':  alts[ii], 'CRPIX2': 0,
                  'CUNIT2': 'deg', 'CDELT2': np.degrees(1),
                  }
        projection = Projection(header)
        gnoms = projection.toworld((camY[ii], camX[ii]))

        values = infile.readline().split()
        values.append(',%s,%s\n' % (str(gnoms[0]), str(gnoms[1])))
        line = ' '.join(values)
        line = line.replace(' ', '')

        outfile.write(line)

    infile.close()
    outfile.close()
Example #6
0
 def __init__(self, filename=None, interp_kind='linear'):
     # TODO: use astropy!
     from kapteyn.wcs import Projection
     from atpy import Table
     if filename != None:
         self.filename = filename
     else:
         self.filename = ('/Users/deil/bin/fermi/ScienceTools-v9r23p1'
                          '-fssc-20110726/external/diffuseModels/'
                          'gal_2yearp7v6_v0.fits')
     self.interp_kind = interp_kind
     print filename
     self.data = fits.getdata(self.filename)
     # Note: the energy axis of the FITS cube is unusable.
     # We only use proj for GLON, GLAT and do ENERGY ourselves
     self.proj = Projection(fits.getheader(self.filename))
     self.e_axis = EnergyAxis(Table(self.filename, 'ENERGIES').Energy)