Example #1
0
def get_COMMONROTATION_vals(MSinfo, server, prefix, ionexPath):
    """
    Call getRM() from RMextract to get the RM values for the opbservation,
    convert this to rotation values and write COMMONROTATION to the parmdb

    Parameters
    ----------
    MSinfo : ReadMs object
       the ReadMs object for the MS for which we compute the rotation values
    server : str or None
       URL of the server where we can find the IONEX files, or None if no download is wanted
    prefix : str
       prefix of the IONEX files
    path : str
       path where we can find or store the IONEX files
    """
    from RMextract import getRM
    rmdict = getRM.getRM(MSinfo.msname,
                         server=server,
                         prefix=prefix,
                         ionexPath=ionexPath,
                         timestep=300.)
    if not rmdict:
        if not server:
            raise ValueError(
                "One or more IONEX files is not found on disk and download is disabled!\n"
                "(You can run \"bin/download_IONEX.py\" outside the pipeline if needed.)"
            )
        else:
            raise ValueError(
                "Couldn't get RM information from RMextract! (But I don't know why.)"
            )

    return rmdict
Example #2
0
def createRMParmdb(MS,
                   parmdbname,
                   create=True,
                   patchname='',
                   server="ftp://cddis.gsfc.nasa.gov/gnss/products/ionex/",
                   prefix='codg',
                   ionexPath="IONEXdata/",
                   earth_rot=0,
                   timestep=900.,
                   stat_names=None):
    myParmdb = parmdb.parmdb(parmdbname, create=create)
    if create:
        myParmdb.addDefValues("Gain:0:0:Ampl", 1.e-4)
        myParmdb.addDefValues("DirectionalGain:0:0:Ampl", 1.)
        myParmdb.addDefValues("DirectionalGain:1:1:Ampl", 1.)
        myParmdb.addDefValues("Gain:0:0:Real", 1.e-4)
        myParmdb.addDefValues("Gain:1:1:Real", 1.e-4)
        myParmdb.addDefValues("DirectionalGain:0:0:Real", 1.)
        myParmdb.addDefValues("DirectionalGain:1:1:Real", 1.)
    myMS = tab.table(MS)
    stations = tab.table(myMS.getkeyword('ANTENNA')).getcol('NAME')
    stat_pos = tab.table(myMS.getkeyword('ANTENNA')).getcol('POSITION')
    if not stat_names == None:
        if not (stat_names == 'all'):
            stat_pos = [stat_pos[stations.index(name)] for name in stat_names]
        else:
            stat_names = stations[:]
    else:
        stat_names = stations[2:3]
        stat_pos = stat_pos[2:3]
    result = gt.getRM(MS=MS,
                      server=server,
                      ionexPath=ionexPath,
                      prefix=prefix,
                      earth_rot=earth_rot,
                      timestep=timestep,
                      stat_names=stat_names,
                      stat_positions=stat_pos)
    RM = result['RM']
    for st in stations:
        #print "storing station",st,(st in RM.keys())
        if not (st in RM.keys()):
            stname = RM.keys()[0]
        else:
            stname = st
        RM[stname] = RM[stname].reshape(RM[stname].shape[:1] + (1, ))
        myValue = myParmdb.makeValue(
            values=RM[stname],
            sfreq=1e10,
            efreq=2e10,
            stime=result['times'],
            etime=np.ones(result['times'].shape, dtype=float) *
            result['timestep'],
            asStartEnd=False)
        if patchname:
            valuename = "RotationMeasure:%s:%s" % (st, patchname)
        else:
            valuename = "RotationMeasure:%s" % (st)
        myParmdb.deleteValues(valuename)
        myParmdb.addValues(valuename, myValue)
def get_COMMONROTATION_vals(MSinfo, server, prefix, ionexPath):
    """
    Call getRM() from RMextract to get the RM values for the opbservation,
    convert this to rotation values and write COMMONROTATION to the parmdb

    Parameters
    ----------
    MSinfo : ReadMs object
       the ReadMs object for the MS for which we compute the rotation values
    server : str or None
       URL of the server where we can find the IONEX files, or None if no download is wanted
    prefix : str
       prefix of the IONEX files
    path : str
       path where we can find or store the IONEX files
    """
    from RMextract import getRM
    rmdict = getRM.getRM(MSinfo.msname,server=server,prefix=prefix,ionexPath=ionexPath,timestep=300.)
    if not rmdict:
        if not ionex_server:
            raise ValueError("One or more IONEX files is not found on disk and download is disabled!\n"
                             "(You can run \"bin/download_IONEX.py\" outside the pipeline if needed.)")
        else:
            raise ValueError("Couldn't get RM information from RMextract! (But I don't know why.)")

    return rmdict
def get_ion_rotation_measures(vis, inputs_dir, ms1):
    """Calculate the ionospheric Faraday rotation for each time slice.
    
    Args:
    vis (ARL object): the visibility data.
    inputs_dir (str): location of input directory.
    ms1 (str): name of measurement set.
    
    Returns:
    ionRM: the ionospheric rotation measures.
    times: the times corresponding to each RM.
    indices: the indices corresponding to unique time periods.
    """

    from RMextract.getRM import getRM
    import RMextract.PosTools as PosTools

    import pyrap.tables as tab

    # The Measurement Set defines the station and dipole positions, the phase centre, and the channel frequencies (and reference frequency) for which the LOFAR beam will be evaluated.
    myms = tab.table(inputs_dir + '/' + ms1)
    stations = tab.table(myms.getkeyword('ANTENNA')).getcol('NAME')
    lofar_stat_pos = tab.table(myms.getkeyword('ANTENNA')).getcol(
        'POSITION')  # in ITRF metres
    # Times are MJD in seconds:
    times = vis.data['time']
    # Find the indices of unique times within the MS:
    _, indices = np.unique(times, return_index=True)
    # Calculate the correction for each time indices:
    ionRM = []
    for i in range(len(indices)):
        use_azel = False  # use az/el or ra/dec?
        use_mean = True  # report for the mean of the station positions?
        time_offset = 120.0  # offset time at start and end to ensure all needed values are calculated,
        time_difference = np.median(np.diff(times[indices])) / 2.0
        min_time = times[indices][i] - time_difference
        max_time = times[indices][i] + time_difference
        time_step = max_time - min_time  # frequency to obtain solutions in seconds.
        # Get the results:
        result = getRM(use_azel=use_azel,
                       use_mean=use_mean,
                       timerange=[min_time, max_time],
                       timestep=time_step,
                       stat_names=stations,
                       stat_positions=lofar_stat_pos,
                       useEMM=True,
                       TIME_OFFSET=time_offset)
        RM = result['RM']
        ionRM.append(np.median(RM[stations[0]]))
    ionRM = np.array(ionRM)
    return ionRM, times, indices
Example #5
0
def createRMParmdb(MS,parmdbname,create=True,patchname='',
                   server="ftp://ftp.unibe.ch/aiub/CODE/",
                   prefix='CODG',
                   ionexPath="IONEXdata/",
                   earth_rot=0,
                   timestep=900.,
                   stat_names=None):
    myParmdb=parmdb.parmdb(parmdbname,create=create)
    if create:
        myParmdb.addDefValues("Gain:0:0:Ampl",1.e-4)
        myParmdb.addDefValues("DirectionalGain:0:0:Ampl",1.)
        myParmdb.addDefValues("DirectionalGain:1:1:Ampl",1.)
        myParmdb.addDefValues("Gain:0:0:Real",1.e-4)
        myParmdb.addDefValues("Gain:1:1:Real",1.e-4)
        myParmdb.addDefValues("DirectionalGain:0:0:Real",1.)
        myParmdb.addDefValues("DirectionalGain:1:1:Real",1.)
    myMS=tab.table(MS)
    stations=tab.table(myMS.getkeyword('ANTENNA')).getcol('NAME')
    stat_pos=tab.table(myMS.getkeyword('ANTENNA')).getcol('POSITION')
    if not stat_names==None:
        if not(stat_names=='all'):
            stat_pos=[stat_pos[stations.index(name)] for name in stat_names] 
        else:
            stat_names=stations[:]
    else:
        stat_names=stations[2:3]
        stat_pos=stat_pos[2:3]
    result=gt.getRM(MS=MS,server=server,ionexPath=ionexPath,prefix=prefix,earth_rot=earth_rot,timestep=timestep,stat_names=stat_names,stat_positions=stat_pos)
    RM=result['RM']    
    for st in stations:
        #print "storing station",st,(st in RM.keys())
        if not (st in RM.keys()):
            stname=RM.keys()[0]
        else:
            stname=st
        RM[stname]=RM[stname].reshape(RM[stname].shape[:1]+(1,))
        myValue=myParmdb.makeValue(values=RM[stname], sfreq=1e10, efreq=2e10, stime=result['times'], etime=np.ones(result['times'].shape,dtype=float)*result['timestep'], asStartEnd=False)
        if patchname:
            valuename = "RotationMeasure:%s:%s"%(st,patchname)
        else:
            valuename = "RotationMeasure:%s"%(st)
        myParmdb.deleteValues(valuename)            
        myParmdb.addValues(valuename,myValue)
def get_ion_rotation_measures_maps(vis, stations, lofar_stat_pos):
    """Calculate the ionospheric Faraday rotation for each time slice.
        
    Args:
    vis (ARL object): the visibility data.
    stations (list): list of stations.
    lofar_stat_pos (list): list of station positions.
    
    Returns:
    ionRM: the ionospheric rotation measures.
    times: the times corresponding to each RM.
    indices: the indices corresponding to unique time periods.
    """
    from RMextract.getRM import getRM
    import RMextract.PosTools as PosTools
    # Times are MJD in seconds:
    times = vis.data['time']
    # Find the indices of unique times within the MS:
    _, indices = np.unique(times, return_index=True)
    # Calculate the correction for each time indices:
    ionRM = []
    for i in range(len(indices)):
        use_azel = False  # use az/el or ra/dec?
        use_mean = True  # report for the mean of the station positions?
        time_offset = 120.0  # offset time at start and end to ensure all needed values are calculated,
        time_difference = np.median(np.diff(times[indices])) / 2.0
        min_time = times[indices][i] - time_difference
        max_time = times[indices][i] + time_difference
        time_step = max_time - min_time  # frequency to obtain solutions in seconds.
        # Get the results:
        result = getRM(use_azel=use_azel,
                       use_mean=use_mean,
                       timerange=[min_time, max_time],
                       timestep=time_step,
                       stat_names=stations,
                       stat_positions=lofar_stat_pos,
                       useEMM=True,
                       TIME_OFFSET=time_offset)
        RM = result['RM']
        ionRM.append(np.median(RM[stations[0]]))
    ionRM = np.array(ionRM)
    return ionRM, times, indices
Example #7
0
def get_RM_vals(MSinfo, server, prefix, ionexPath, timestep):
    """
    Call getRM() from RMextract to get the RM values for the opbservation

    Parameters
    ----------
    MSinfo : ReadMs object
       the ReadMs object for the MS for which we compute the rotation values
    server : str or None
       URL of the server where we can find the IONEX files, or None if no download is wanted
    prefix : str
       prefix of the IONEX files
    path : str
       path where we can find or store the IONEX files
    timestep : float
        timestep to use
    """
    if ionexPath[-1] != '/':
        print "get_RM_vals: ionexPath doesn't end in \"/\", adding that character."
        ionexPath += '/'

    from RMextract import getRM
    rmdict = getRM.getRM(MSinfo.msname,
                         server=server,
                         prefix=prefix,
                         ionexPath=ionexPath,
                         timestep=timestep)
    if not rmdict:
        if not server:
            raise ValueError(
                "One or more IONEX files is not found on disk and download is disabled!\n"
                "(You can run \"bin/download_IONEX.py\" outside the pipeline if needed.)"
            )
        else:
            raise ValueError(
                "Couldn't get RM information from RMextract! (But I don't know why.)"
            )

    return rmdict
rc("lines",lw=3)
rc('font', family='serif', size=16)


#a=tab.taql('calc MJD("2013/03/02/17:02:54")')[0]*3600*24
#b=tab.taql('calc MJD("2013/03/03/01:02:50")')[0]*3600*24
a=tab.taql('calc MJD("2012/12/06/22:46:05")')[0]*3600*24
b=tab.taql('calc MJD("2012/12/07/06:35:55")')[0]*3600*24

statpos=gt.PosTools.posCS002
pointing=array([ 2.15374123,  0.8415521 ]) #3C196
#pointing=array([3.7146860578925645, 0.9111636804140731  ]) #3C295
#tec=gt.getRM(ionexPath='/home/users/mevius/IONEXdata/',earth_rot=0,ha_limit=1*np.pi,radec=pointing,timestep=300, timerange = [a, b],stat_positions=[statpos,],server="ftp://gnss.oma.be/gnss/products/IONEX/",prefix="ROBR")
#tec2=gt.getRM(ionexPath='/home/mevius/IONEXdata/',earth_rot=0,ha_limit=1*np.pi,radec=pointing,timestep=300, timerange = [a, b],stat_positions=[statpos,],prefix='iltg')
tec3=gt.getRM(ionexPath='/home/users/mevius/IONEXdata/',server="ftp://igs-final.man.olsztyn.pl/pub/gps_data/GPS_IONO/cmpcmb/",prefix="igsg",earth_rot=1,radec=pointing,timestep=150, timerange = [a, b+150],stat_positions=[statpos,])
tec2=gt.getRM(ionexPath='/home/users/mevius/IONEXdata/',server='ftp://213.184.6.172/home/gnss/products/ionex/',earth_rot=0.5,ha_limit=1*np.pi,radec=pointing,timestep=150, timerange = [a, b+150],stat_positions=[statpos,],prefix='ILTF')
tec=gt.getRM(ionexPath='/home/users/mevius/IONEXdata/',server='ftp://213.184.6.172/home/gnss/products/ionex/',earth_rot=0.5,ha_limit=1*np.pi,radec=pointing,timestep=150, timerange = [a, b+150],stat_positions=[statpos,],prefix='ILTQ')
#tec3=gt.getRM(ionexPath='/home/mevius/IONEXdata/',earth_rot=1,ha_limit=1*np.pi,radec=pointing,timestep=100, timerange = [a, b],stat_positions=[statpos,])
times=tec['times']
flags=tec['flags']['st1']
timess=[tm/(3600*24.) for tm in times]
dates=tab.taql('calc ctod($timess)')

myf=open("/home/users/mevius/RMextract/examples/dataMB2.txt","r")
dataMB2=[[float(i) for i in j.split()] for j in myf]
dataMB2=array(dataMB2)


rtec2=np.average(tec2['RM']['st1'].reshape((-1,4)),axis=1)
rtec=np.average(tec['RM']['st1'].reshape((-1,4)),axis=1)
     [-2558503.88881043, 5095891.11710898, -2848981.31195756],
     [-2558648.85477276, 5096060.47633611, -2848544.49069260],
     [-2558998.73468649, 5095390.06352995, -2849423.09595365],
     [-2559238.04568324, 5095263.75775157, -2849432.88470164],
     [-2558856.49159020, 5095257.96516587, -2849788.57821277],
     [-2558761.92575271, 5095281.91134845, -2849829.99130606],
     [-2558719.21221208, 5095416.28342253, -2849628.99110746],
     [-2558836.79342206, 5095555.42415917, -2849277.33903756],
     [-2558850.45931999, 5095586.71918979, -2849209.71070222],
     [-2558890.31919482, 5095521.92810583, -2849288.42518348]])

result = getRM(use_azel=use_azel,
               use_mean=use_mean,
               object=OBJECT,
               start_time=START_TIME,
               end_time=END_TIME,
               timestep=TIME_STEP,
               stat_positions=MWA_antennas,
               useEMM=True,
               TIME_OFFSET=TIME_OFFSET)

timerange = [result['times'][0], result['times'][-1]]
timegrid = result['times']
stat_pos = result['stat_pos']
reference_time = result['reference_time']
str_start_time = PosTools.obtain_observation_year_month_day_hms(reference_time)
if os.path.exists(out_file):
    os.remove(out_file)
log = open(out_file, 'a')
log.write('Observing %s\n' % OBJECT)
if use_azel:
   [-2558906.48396095,5095592.28259425,-2849148.93562390],
   [-2558894.77687225,5095720.00453191,-2848930.82517056],
   [-2558880.58102582,5095762.06255238,-2848868.27661380],
   [-2558503.88881043,5095891.11710898,-2848981.31195756],
   [-2558648.85477276,5096060.47633611,-2848544.49069260],
   [-2558998.73468649,5095390.06352995,-2849423.09595365],
   [-2559238.04568324,5095263.75775157,-2849432.88470164],
   [-2558856.49159020,5095257.96516587,-2849788.57821277],
   [-2558761.92575271,5095281.91134845,-2849829.99130606],
   [-2558719.21221208,5095416.28342253,-2849628.99110746],
   [-2558836.79342206,5095555.42415917,-2849277.33903756],
   [-2558850.45931999,5095586.71918979,-2849209.71070222],
   [-2558890.31919482,5095521.92810583,-2849288.42518348]])


result = getRM(use_azel=use_azel,use_mean=use_mean,object=OBJECT,start_time=START_TIME,end_time=END_TIME, timestep=TIME_STEP,stat_positions=MWA_antennas,useEMM=True,TIME_OFFSET=TIME_OFFSET)

timerange=[result['times'][0],result['times'][-1]]
timegrid=result['times']
stat_pos=result['stat_pos']
reference_time=result['reference_time'] 
str_start_time=PosTools.obtain_observation_year_month_day_hms(reference_time)
if os.path.exists(out_file):
  os.remove(out_file)
log = open(out_file, 'a')
log.write ('Observing %s\n' % OBJECT)
if use_azel: 
  log.write('observing at a fixed azimuth and elevation\n')
if use_mean:
  log.write ('station_positions %s \n' % MWA_antennas)
  log.write ('mean of station positions %s \n' % stat_pos)
Example #11
0
def get_RM(start_time,
           end_time,
           telescope_location,
           ra,
           dec,
           timestep=600.,
           ionexPath='./IONEXdata/'):
    """
    Calculate the ionospheric Faraday rotation as a function of time, 
    for a given observation (time, location, target direction).
    
    Args:
        start_time (astropy.time Time, or string readable by astropy.time Time): 
            Starting time of observation.
            Example time string: '2010-01-02T00:00:00'
        end_time (astropy.time.Time, or string readable by astropy.time.Time): 
            ending time of observation.
        telescope_location (astropy.coordinates EarthLocation or string):
            location of telescope, or name of telescope known to 
            get_telescope_coordinates() function.
        ra (astropy.coordinates Angle, astropy.units Quantity, or float): 
            right ascension of observation center (if float: in deg, J2000)
        dec (astropy.coordinates Angle, astropy.units Quantity, or float): 
            declination of observation center (if float: in deg, J2000)
        timestep (astropy.time TimeDelta, astropy.units Quantity, or float):
            time between ionosphere FR estimates. If float, time must be in seconds.
        ionexPath (str, default='./IONEXdata/'): path to download IONEX files to
            for ionosphere calculations.
        
    Returns:
        tuple containing
        
        -times (astropy Time array): vector of times of each ionospheric RM calculation   
        
        -RMs (array): vector of RM values computed for each time step  
    
    """
    #If necessary, convert telescope name into telescope location object:
    if type(telescope_location) != EarthLocation:
        telescope_location = get_telescope_coordinates(telescope_location)

    #RMextract wants time ranges in MJD seconds:
    timerange = [Time(start_time).mjd * 86400.0, Time(end_time).mjd * 86400.0]

    #Extract telescope coordinates into expected format (geodetic x,y,z):
    telescope_coordinates = [
        telescope_location.x.value, telescope_location.y.value,
        telescope_location.z.value
    ]

    #Handle all forms of angle input:
    if type(ra) == float or type(ra) == int:
        ra_angle = Angle(ra, 'deg')
    elif type(ra) == astropy.units.quantity.Quantity:
        ra_angle = Angle(ra)
    elif type(ra) == astropy.coordinates.angles.Angle:
        ra_angle = ra
    else:
        raise Exception("""RA input object type not recognized.
                        Only astropy.coordinates Angle, astropy.units Quantity, or float (in deg) allowed."""
                        )

    if type(dec) == float or type(dec) == int:
        dec_angle = Angle(dec, 'deg')
    elif type(dec) == astropy.units.quantity.Quantity:
        dec_angle = Angle(dec)
    elif type(dec) == astropy.coordinates.angles.Angle:
        dec_angle = dec
    else:
        raise Exception("""Dec input object type not recognized.
                        Only astropy.coordinates Angle, astropy.units Quantity, or float (in deg) allowed."""
                        )

    #Handle all forms of time input:
    if type(timestep) == float or type(timestep) == int:
        timestep_Delta = TimeDelta(timestep * u.second)
    elif type(timestep) == astropy.units.quantity.Quantity:
        timestep_Delta = TimeDelta(timestep)
    elif type(timestep) == astropy.time.core.TimeDelta:
        timestep_Delta = timestep
    else:
        raise Exception("""Timestep input object type not recognized.
                        Only astropy.time TimeDelta, astropy.units Quantity, or float (in seconds) allowed."""
                        )

    #Get RMExtract to generate it's RM predictions
    predictions = RME.getRM(ionexPath=ionexPath,
                            radec=[ra_angle.rad, dec_angle.rad],
                            timestep=timestep_Delta.sec,
                            timerange=timerange,
                            stat_positions=[
                                telescope_coordinates,
                            ])
    #predictions dictionary contains STEC, Bpar, BField, AirMass, elev, azimuth
    #  RM, times, timestep, station_names, stat_pos, flags, reference_time
    times = Time(predictions['times'] / 86400., format='mjd')
    RMs = np.squeeze(predictions['RM']['st1'])

    return times, RMs
Example #12
0
from RMextract.getRM import getRM
import RMextract.PosTools as PosTools
import numpy as np
import os

TIME_STEP = 300.0
TIME_OFFSET=120.0
result = getRM(MS="/home/twillis1/ASKAP_related_ionosphere/ATCA_obs.MS",use_mean=True,object= 'ATCA_dec_obs_300_mean',useEMM=True,timestep=TIME_STEP,TIME_OFFSET=TIME_OFFSET)
#result = getRM(MS="/home/twillis1/ASKAP_related_ionosphere/ATCA_obs.MS",object= 'ATCA_dec_obs_300',useEMM=True,timestep=TIME_STEP,TIME_OFFSET=TIME_OFFSET)
import pyrap.tables as tab
from pylab import *
#a=tab.taql('calc MJD("2013/03/02/17:02:54")')[0]*3600*24
#b=tab.taql('calc MJD("2013/03/03/01:02:50")')[0]*3600*24
a = tab.taql('calc MJD("2012/12/06/22:46:05")')[0] * 3600 * 24
b = tab.taql('calc MJD("2012/12/07/06:35:55")')[0] * 3600 * 24

statpos = gt.PosTools.posCS002
pointing = array([2.15374123, 0.8415521])  #3C196
#pointing=array([3.7146860578925645, 0.9111636804140731  ]) #3C295
tec = gt.getRM(ionexPath='/home/mevius/IONEXdata/',
               earth_rot=0,
               ha_limit=1 * np.pi,
               radec=pointing,
               timestep=300,
               timerange=[a, b],
               stat_positions=[
                   statpos,
               ],
               server="ftp://gnss.oma.be/gnss/products/IONEX/",
               prefix="ROBR")
tec2 = gt.getRM(ionexPath='/home/mevius/IONEXdata/',
                earth_rot=0,
                ha_limit=1 * np.pi,
                radec=pointing,
                timestep=300,
                timerange=[a, b],
                stat_positions=[
                    statpos,
                ],
                prefix='iltg')
#a=tab.taql('calc MJD("2013/03/02/17:02:54")')[0]*3600*24
#b=tab.taql('calc MJD("2013/03/03/01:02:50")')[0]*3600*24
a = tab.taql('calc MJD("2012/12/06/22:46:05")')[0] * 3600 * 24
b = tab.taql('calc MJD("2012/12/07/16:35:55")')[0] * 3600 * 24

statpos = gt.PosTools.posCS002
pointing = array([2.15374123, 0.8415521])  #3C196
#pointing=array([3.7146860578925645, 0.9111636804140731  ]) #3C295
#tec=gt.getRM(ionexPath='/home/users/mevius/IONEXdata/',earth_rot=0,ha_limit=1*np.pi,radec=pointing,timestep=300, timerange = [a, b],stat_positions=[statpos,],server="ftp://gnss.oma.be/gnss/products/IONEX/",prefix="ROBR")
#tec2=gt.getRM(ionexPath='/home/mevius/IONEXdata/',earth_rot=0,ha_limit=1*np.pi,radec=pointing,timestep=300, timerange = [a, b],stat_positions=[statpos,],prefix='iltg')
tec3 = gt.getRM(
    ionexPath='/home/users/mevius/IONEXdata/',
    server="ftp://igs-final.man.olsztyn.pl/pub/gps_data/GPS_IONO/cmpcmb/",
    prefix="igsg",
    earth_rot=1,
    radec=pointing,
    timestep=150,
    timerange=[a, b + 150],
    stat_positions=[
        statpos,
    ])
tec2 = gt.getRM(ionexPath='/home/users/mevius/IONEXdata/',
                server='ftp://213.184.6.172/home/gnss/products/ionex/',
                earth_rot=0.5,
                ha_limit=1 * np.pi,
                radec=pointing,
                timestep=150,
                timerange=[a, b + 150],
                stat_positions=[
                    statpos,
                ],
Example #15
0
     [-2558719.21221208, 5095416.28342253, -2849628.99110746],
     [-2558836.79342206, 5095555.42415917, -2849277.33903756],
     [-2558850.45931999, 5095586.71918979, -2849209.71070222],
     [-2558890.31919482, 5095521.92810583, -2849288.42518348]])

ra_rad, dec_rad = ac.radec_str_to_rad2(RA, DEC)
pointing = np.array([ra_rad, dec_rad])
print 'pointing', pointing
upington_position = [[5233099.76611549, 2035838.60712339, -3016689.89007898]]
#result = getRM(use_azel=True,start_time=START_TIME,end_time=END_TIME, timestep=TIME_STEP,stat_positions= MWA_antennas,useEMM=True,TIME_OFFSET=TIME_OFFSET)

result = getRM(use_azel=use_azel,
               radec=pointing,
               out_file='test_report',
               object=OBJECT,
               start_time=START_TIME,
               end_time=END_TIME,
               timestep=TIME_STEP,
               stat_positions=upington_position,
               useEMM=True,
               TIME_OFFSET=TIME_OFFSET)

#result = getRM(radec=pointing,start_time=START_TIME,end_time=END_TIME, timestep=TIME_STEP,stat_positions= MWA_antennas,useEMM=True,TIME_OFFSET=TIME_OFFSET)

location = upington_position
shape = result['times'].shape
timerange = [result['times'][0], result['times'][shape[0] - 1]]
reference_time = result['reference_time']
str_start_time = PosTools.obtain_observation_year_month_day_hms(reference_time)
if os.path.exists(out_file):
    os.remove(out_file)
log = open(out_file, 'a')
Example #16
0
def main(MSfiles,
         h5parmdb,
         solset_name="sol000",
         all_stations=False,
         timestep=300,
         ionex_server="ftp://ftp.aiub.unibe.ch/CODE/",
         ionex_prefix='CODG',
         ionexPath="./",
         earth_rot=0):
    '''Add rotation measure to existing h5parmdb
    
    Args:
        MSfiles (string) :  path + filename of Measurement Set 
        h5parmdb (string) : name of existing h5parm
        solset_name (string) : optional name of solset in h5parmdb, 
                            if not set, first one will be chosen
        all_stations (bool) : optional calculate RM values for all stations in the MS,'
                            default only for position of CS002LBA 
        timestep (float) : timestep in seconds
        ionex_server (string) : ftp server for IONEX files
        ionex_prefix (string) : prefix of IONEX files
        ionexPath (string) : location where IONEX files are stored
        earth_rot (float) : parameter to determine how much earth rotation is taken \
        into account when interpolating IONEX data. (0 is none, 1 is full)
    '''

    mslist = MSfiles.lstrip('[').rstrip(']').replace(' ',
                                                     '').replace("'",
                                                                 "").split(',')

    if len(mslist) == 0:
        raise ValueError(
            "Did not find any existing directory in input MS list!")
        pass
    else:
        MS = mslist[0]
        pass

    if not all_stations:
        rmdict = getRM.getRM(MS,
                             server=ionex_server,
                             prefix=ionex_prefix,
                             ionexPath=ionexPath,
                             timestep=timestep,
                             stat_names=["st0"],
                             stat_pos=[PosTools.posCS002],
                             earth_rot=earth_rot)

    else:
        rmdict = getRM.getRM(MS,
                             server=ionex_server,
                             prefix=ionex_prefix,
                             ionexPath=ionexPath,
                             timestep=timestep,
                             earth_rot=earth_rot)
    if not rmdict:
        if not server:
            raise ValueError(
                "One or more IONEX files is not found on disk and download is disabled!\n"
                "(You can run \"bin/download_IONEX.py\" outside the pipeline if needed.)"
            )
        else:
            raise ValueError(
                "Couldn't get RM information from RMextract! (But I don't know why.)"
            )

    data = h5parm(h5parmdb, readonly=False)
    if not solset_name in data.getSolsetNames():
        makesolset(MS, data, solset_name)
    solset = data.getSolset(solset_name)
    station_names = sorted(solset.getAnt().keys())

    logging.info('Adding rotation measure values to: ' + solset_name + ' of ' +
                 h5parmdb)
    if all_stations:
        rm_vals = np.array(
            [rmdict["RM"][stat].flatten() for stat in station_names])
    else:
        rm_vals = np.ones((len(station_names), rmdict['RM']['st0'].shape[0]),
                          dtype=float)
        rm_vals += rmdict['RM']['st0'].flatten()[np.newaxis]
    new_soltab = solset.makeSoltab(soltype='rotationmeasure',
                                   soltabName='RMextract',
                                   axesNames=['ant', 'time'],
                                   axesVals=[station_names, rmdict['times']],
                                   vals=rm_vals,
                                   weights=np.ones_like(rm_vals,
                                                        dtype=np.float16))
Example #17
0
from RMextract.getRM import getRM
import RMextract.PosTools as PosTools
import numpy as np
import os

TIME_STEP = 300.0
TIME_OFFSET = 120.0
result = getRM(MS="/home/twillis1/ASKAP_related_ionosphere/ATCA_obs.MS",
               use_mean=True,
               object='ATCA_dec_obs_300_mean',
               useEMM=True,
               timestep=TIME_STEP,
               TIME_OFFSET=TIME_OFFSET)
#result = getRM(MS="/home/twillis1/ASKAP_related_ionosphere/ATCA_obs.MS",object= 'ATCA_dec_obs_300',useEMM=True,timestep=TIME_STEP,TIME_OFFSET=TIME_OFFSET)
Example #18
0
def main(MSfiles,
         h5parmdb,
         solset_name="sol000",
         timestepRM=300,
         ionex_server="ftp://ftp.aiub.unibe.ch/CODE/",
         ionex_prefix='CODG',
         ionexPath="./",
         earth_rot=0,
         proxyServer=None,
         proxyPort=None,
         proxyType=None,
         proxyUser=None,
         proxyPass=None):
    '''Add rotation measure to existing h5parmdb
    
    Args:
        MSfiles (string) :  path + filename of Measurement Set 
        h5parmdb (string) : name of existing h5parm
        solset_name (string) : optional name of solset in h5parmdb, 
                            if not set, first one will be chosen
        timestep (float) : timestep in seconds
        ionex_server (string) : ftp server for IONEX files
        ionex_prefix (string) : prefix of IONEX files
        ionexPath (string) : location where IONEX files are stored
        earth_rot (float) : parameter to determine how much earth rotation is taken \
        into account when interpolating IONEX data. (0 is none, 1 is full)
    '''

    try:
        mslist = MSfiles.lstrip('[').rstrip(']').replace(' ', '').replace(
            "'", "").split(',')
    except AttributeError:
        mslist = MSfiles

    if len(mslist) == 0:
        raise ValueError(
            "Did not find any existing directory in input MS list!")
        pass
    else:
        MS = mslist[0]
        pass

    if not os.path.exists(h5parmdb):
        logging.error('Could not find h5parmdb: ' + h5parmdb)
        return (1)

    data = h5parm(h5parmdb, readonly=False)
    if not solset_name in data.getSolsetNames():
        makesolset(MS, data, solset_name)
    solset = data.getSolset(solset_name)
    soltabs = solset.getSoltabs()
    station_names = sorted(solset.getAnt().keys())

    if 'RMextract' in [s.name for s in soltabs]:
        logging.warning('Soltab RMextract exists already. Skipping...')
        return (0)

    #extract the timerange information
    (timerange, timestep, pointing, stat_names,
     stat_pos) = PosTools.getMSinfo(MS)
    start_time = timerange[0]
    end_time = timerange[1]
    timerange[0] = start_time - timestep
    timerange[1] = end_time + timestep
    times, timerange = PosTools.getIONEXtimerange(timerange, timestep)
    if len(times[-1]) == 0 or times[-1][-1] < timerange[1]:
        timestmp = list(times[-1])
        timestmp.append(
            timerange[1]
        )  #add one extra step to make sure you have a value for all times in the MS in case timestep hase been changed
        times[-1] = np.array(timestmp)

    for time_array in times[::
                            -1]:  #check in reverse order, since datamight not be available for latest days
        starttime = time_array[0]
        date_parms = PosTools.obtain_observation_year_month_day_fraction(
            starttime)
        if not proxyServer:
            if not "http" in ionex_server:  #ftp server use ftplib
                ionexf = ionex.getIONEXfile(time=date_parms,
                                            server=ionex_server,
                                            prefix=ionex_prefix,
                                            outpath=ionexPath)
            else:
                ionexf = ionex.get_urllib_IONEXfile(time=date_parms,
                                                    server=ionex_server,
                                                    prefix=ionex_prefix,
                                                    outpath=ionexPath)

        else:
            ionexf = ionex.get_urllib_IONEXfile(time=date_parms,
                                                server=ionex_server,
                                                prefix=ionex_prefix,
                                                outpath=ionexPath,
                                                proxy_server=proxyServer,
                                                proxy_type=proxyType,
                                                proxy_port=proxyPort,
                                                proxy_user=proxyUser,
                                                proxy_pass=proxyPass)

        if ionexf == -1:
            if not "igsiono.uwm.edu.pl" in ionex_server:
                logging.info(
                    "cannot get IONEX data, try fast product server instead")
                if not proxyServer:
                    ionexf = ionex.get_urllib_IONEXfile(
                        time=date_parms,
                        server="https://igsiono.uwm.edu.pl",
                        prefix="igrg",
                        outpath=ionexPath)
                else:
                    ionexf = ionex.get_urllib_IONEXfile(
                        time=date_parms,
                        server="https://igsiono.uwm.edu.pl",
                        prefix="igrg",
                        outpath=ionexPath,
                        proxy_server=proxyServer,
                        proxy_type=proxyType,
                        proxy_port=proxyPort,
                        proxy_user=proxyUser,
                        proxy_pass=proxyPass)
        if ionexf == -1:
            logging.error(
                "IONEX data not available, even not from fast product server")
            return (-1)

    if not proxyServer:
        rmdict = getRM.getRM(MS,
                             server=ionex_server,
                             prefix=ionex_prefix,
                             ionexPath=ionexPath,
                             timestep=timestepRM,
                             earth_rot=earth_rot)
    else:
        rmdict = getRM.getRM(MS,
                             server=ionex_server,
                             prefix=ionex_prefix,
                             ionexPath=ionexPath,
                             timestep=timestepRM,
                             earth_rot=earth_rot,
                             proxy_server=proxyServer,
                             proxy_type=proxyType,
                             proxy_port=proxyPort,
                             proxy_user=proxyUser,
                             proxy_pass=proxyPass)

    if not rmdict:
        if not ionex_server:
            raise ValueError(
                "One or more IONEX files is not found on disk and download is disabled!\n"
                "(You can run \"bin/download_IONEX.py\" outside the pipeline if needed.)"
            )
        else:
            raise ValueError(
                "Couldn't get RM information from RMextract! (But I don't know why.)"
            )

    logging.info('Adding rotation measure values to: ' + solset_name + ' of ' +
                 h5parmdb)
    rm_vals = np.array(
        [rmdict["RM"][stat.decode()].flatten() for stat in station_names])
    new_soltab = solset.makeSoltab(soltype='rotationmeasure',
                                   soltabName='RMextract',
                                   axesNames=['ant', 'time'],
                                   axesVals=[station_names, rmdict['times']],
                                   vals=rm_vals,
                                   weights=np.ones_like(rm_vals,
                                                        dtype=np.float16))

    return (0)

    data.close()
Example #19
0
stime = [12., 0., 0.]
etime = [14., 45., 0.]

radec = (sc.ra.radian, sc.dec.radian)
START_TIME = "%4d-%02d-%02d %02d:%02d:%02d" % (date.year, date.month, date.day,
                                               stime[0], stime[1], stime[2])
END_TIME = "%4d-%02d-%02d %02d:%02d:%02d" % (date.year, date.month, date.day,
                                             etime[0], etime[1], etime[2])
TIME_STEP = 120.0
print("Processing for %s; %s - %s" % (OBJECT, START_TIME, END_TIME))

result = RM.getRM(use_azel=False,
                  start_time=START_TIME,
                  end_time=END_TIME,
                  object=OBJECT,
                  radec=radec,
                  timestep=TIME_STEP,
                  stat_positions=MWA_antennas,
                  useEMM=True,
                  EMMpath='/home/corvus/Research/RMextract/EMM/')

# set time relative to zero
timegrid = result['times']
timegrid = (timegrid - timegrid[0]) / 3600.0
RMs = result['RM']
TECs = result['STEC']
times = result['times']
selected_key = False
for key in TECs.keys():
    if not selected_key:
        use_key = key
import RMextract.getRM as gt
import pyrap.tables as tab
from pylab import *
a=tab.taql('calc MJD("2013/11/01/00:00:00")')[0]*3600*24
b=tab.taql('calc MJD("2013/11/09/00:00:00")')[0]*3600*24

statpos=gt.PosTools.posCS002
pointing=array([ 2.15374123,  0.8415521 ]) #3C196
bigdict=gt.getRM(ionexPath='./IONEXdata/',earth_rot=0,ha_limit=45*np.pi/180,radec=pointing,timestep=1800, timerange = [a, b],stat_positions=[statpos,])
flags=np.logical_not(bigdict['flags']['st1'])
times=bigdict['times'][np.logical_not(flags)]
timess=[tm/(3600*24.) for tm in times]
dates=tab.taql('calc ctod($timess)')
if 'array' in dates.keys():
    dates=dates['array']
else:
    dates=dates[dates.keys()[0]] #backward compatibility with older casacore vresions
format="%Y/%m/%d/%H:%M:%S.%f"
mydatetimes=[datetime.datetime.strptime(mydate,format) for mydate in dates]

bpar=bigdict['Bpar']['st1'][np.logical_not(flags)]
bfield=bigdict['BField']['st1'][np.logical_not(flags)]
abs_field=np.sqrt(np.sum(np.square(bfield),axis=1))
bperp=abs_field-np.abs(bpar)
plot_date(mydatetimes,bperp,'-')
plot_date(mydatetimes,bpar,'-')
plot_date(mydatetimes,bperp)
plot_date(mydatetimes,bpar)
plt.gcf().autofmt_xdate()
ylabel("Bpar (nGaus)")
show()
import RMextract.getRM as gt
import pyrap.tables as tab
from pylab import *
a = tab.taql('calc MJD("2013/11/01/00:00:00")')[0] * 3600 * 24
b = tab.taql('calc MJD("2013/11/09/00:00:00")')[0] * 3600 * 24

statpos = gt.PosTools.posCS002
pointing = array([2.15374123, 0.8415521])  #3C196
bigdict = gt.getRM(ionexPath='./IONEXdata/',
                   earth_rot=0,
                   ha_limit=45 * np.pi / 180,
                   radec=pointing,
                   timestep=1800,
                   timerange=[a, b],
                   stat_positions=[
                       statpos,
                   ])
flags = np.logical_not(bigdict['flags']['st1'])
times = bigdict['times'][np.logical_not(flags)]
timess = [tm / (3600 * 24.) for tm in times]
dates = tab.taql('calc ctod($timess)')
if 'array' in dates.keys():
    dates = dates['array']
else:
    dates = dates[dates.keys()
                  [0]]  #backward compatibility with older casacore vresions
format = "%Y/%m/%d/%H:%M:%S.%f"
mydatetimes = [datetime.datetime.strptime(mydate, format) for mydate in dates]

bpar = bigdict['Bpar']['st1'][np.logical_not(flags)]
bfield = bigdict['BField']['st1'][np.logical_not(flags)]