Source
xxxxxxxxxx
casalog.post('Conversion in situ was not possible. Restoring original ephemeris ...', 'INFO')
from __future__ import absolute_import
import glob
import os
from casatasks.private.casa_transition import is_CASA6
if is_CASA6:
from casatools import table, measures, quanta, ms
from casatasks import casalog
else:
from taskinit import *
from taskinit import tbtool as table
from taskinit import metool as measures
from taskinit import qatool as quanta
from taskinit import mstool as ms
# Conversion of TOPO ephemerides to GEO (ICRS)
#
# Example:
# import recipes.ephemerides.convertephem as ce
# ce.convert2geo('titan.ms', 'Titan')
#
# will find the ephemeris attached to field "Titan" in the MS "titan.ms"
# and convert RA, Dec, and RadVel to the geocentric ref frame (ICRS)
def converttopoephem2geo(tablename='', outtablename='', overwrite=True):
"""
converttopoephem2geo
Convert the given topo ephemeris table to the geocentric ref frame.
Converted are the RA, DEC, and RadVel columns only
tablename -- name of the TOPO frame ephemeris table (in canonical CASA format)
outtablename -- name of the output GEO frame ephemeris table
"""
if type(tablename)!=str or tablename=='':
casalog.post('Invalid parameter tablename', 'WARN')
return False
if type(outtablename)!=str or outtablename=='':
casalog.post('Invalid parameter outtablename', 'WARN')
return False
#convert RA, DEC, and RadVel
tbt = table()
met = measures()
qat = quanta()
tbt.open(tablename)
ra = tbt.getcol('RA')
dec = tbt.getcol('DEC')
radvel = tbt.getcol('RadVel')
radvelunit = 'km/s'
tmpkw = tbt.getcolkeywords('RadVel')
if 'UNIT' in tmpkw:
radvelunit = tmpkw['UNIT']
elif 'QuantumUnits' in tmpkw:
radvelunit = tmpkw['QuantumUnits'][0]
else:
casalog.post('Cannot determine units of radial velocity column. Assuming km/s.', 'WARN')
mjd = tbt.getcol('MJD')
kw = tbt.getkeywords()
tbt.close()
geodist = kw['GeoDist'] # (km above reference ellipsoid)
geolat = kw['GeoLat'] # (deg)
geolong = kw['GeoLong'] # (deg)
if 'obsloc' in kw:
obsloc = kw['obsloc']
else:
casalog.post('Ephemeris does not have the obsloc keyword.', 'INFO')
if (geodist==geolat==geolong==0.):
casalog.post(' Assuming obsloc == GEOCENTRIC since lat, long, and dist are zero.', 'INFO')
obsloc='GEOCENTRIC'
else:
obsloc='unknown'
oldref = 'J2000'
newref = 'ICRS'
if 'posrefsys' in kw:
posref = kw['posrefsys']
else:
casalog.post('Ephemeris does not have the posrefsys keyword. Assuming ICRF/J2000.0', 'WARN')
posref = 'ICRF/J2000.0'
if not ('J2000' in posref):