Changeset 1725


Ignore:
Timestamp:
04/27/10 15:48:24 (15 years ago)
Author:
Malte Marquarding
Message:

Finishing touches to opacity calculations, docs, plotting and model

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/CHANGELOG

    r1600 r1725  
    22=========
    33
    4 Release 3.0.0 []
     4Release 3.0.0 [2010-04-??]
    55
     6* Ticket #177 Added function skydip to determine opacities.
     7* Ticket #172 Fixed non-working scantable.resample
    68* Ticket #155 Better output filenames. Ignore non-existsing beams/pols/ifs/scans
    79* Ticket #157 numpy >= 1.1 support
    810* Ticket #158 fixed plotter.set_font
    9 * Ticket #160 Aspect ration of pplotter customisable
    10 * Ticket #162 - fill in
     11* Ticket #160 Aspect ratio of plotter is customisable now
    1112* Ticket #163 fixed for scantable.set_sourcetype
    1213* Ticket #164 Upgrade note in wiki FAQ
     
    2223* Interactive plotting annotations via optional argument interactive=True
    2324* Interactive creation of masks on the plotter - plotter.create_mask
     25* Tidy up date range in asapplotter.plotazel/plotpointings
    2426
    2527Release 2.3.1 [2009-03-25]
  • trunk/python/__init__.py

    r1721 r1725  
    393393from linecatalog import linecatalog
    394394from opacity import skydip
     395from opacity import model as opacity_model
    395396
    396397if rcParams['useplotter']:
     
    412413
    413414def is_ipython():
    414     return '__IP' in dir(sys.modules["__main__"])
     415    return 'IPython' in sys.modules.keys()
    415416
    416417if is_ipython():
     
    630631                              scantable.create_mask
    631632        skydip              - gain opacity values from a sky dip observation
     633        opacity_model       - compute opacities fro given frequencies based on
     634                              atmospheric model
    632635
    633636    Note:
  • trunk/python/opacity.py

    r1722 r1725  
    66from asap import selector
    77from asap import rcParams
    8 from asap import xyplotter
     8from asap._asap import atmosphere
     9
     10
     11class model(object):
     12    def _to_pascals(self, val):
     13        if val > 2000:
     14            return val
     15        return val*100
     16
     17    def __init__(self, temperature=288, pressure=101325., humidity=0.5,
     18                 elevation=700.):
     19        """
     20        This class implements opacity/atmospheric brightness temperature model
     21        equivalent to the model available in MIRIAD. The actual math is a
     22        convertion of the Fortran code written by Bob Sault for MIRIAD.
     23        It implements a simple model of the atmosphere and Liebe's model (1985)
     24        of the complex refractive index of air.
     25
     26        The model of the atmosphere is one with an exponential fall-off in
     27        the water vapour content (scale height of 1540 m) and a temperature
     28        lapse rate of 6.5 mK/m. Otherwise the atmosphere obeys the ideal gas
     29        equation and hydrostatic equilibrium.
     30
     31        Note, the model includes atmospheric lines up to 800 GHz, but was not
     32        rigorously tested above 100 GHz and for instruments located at
     33        a significant elevation. For high-elevation sites it may be necessary to
     34        adjust scale height and lapse rate.
     35
     36        Parameters:
     37            temperature:    air temperature at the observatory (K)
     38            pressure:       air pressure at the sea level if the observatory
     39                            elevation is set to non-zero value (note, by
     40                            default is set to 700m) or at the observatory
     41                            ground level if the elevation is set to 0. (The
     42                            value is in Pascals or hPa, default 101325 Pa
     43            humidity:       air humidity at the observatory (fractional),
     44                            default is 0.5
     45            elevation:     observatory elevation about sea level (in meters)
     46        """
     47        self._atm = atmosphere(temp, self._to_pascals(pressure), humidity)
     48        self.set_observatory_elevation(elevation):
     49
     50    def get_opacities(self, freq, elevation=None):
     51        """Get the opacity value(s) for the fiven frequency(ies).
     52        If no elevation is given the opacities for the zenith are returned.
     53        If an elevation is specified refraction is also taken into account.
     54        Parameters:
     55            freq:       a frequency value in Hz, or a list of frequency values.
     56                        One opacity value per frequency is returned as a scalar
     57                        or list.
     58            elevation:  the elevation at which to compute the opacity. If `None`
     59                        is given (default) the zenith opacity is returned.
     60
     61
     62        """
     63        func = None
     64        if isinstance(freq, (list, tuple)):
     65            if elevation is None:
     66                return self._atm.zenith_opacities(freq)
     67            else:
     68                elevation *= math.pi/180.
     69                return self._atm.opacities(freq, elevation)
     70        else:
     71            if elevation is None:
     72                return self._atm.zenith_opacity(freq)
     73            else:
     74                elevation *= math.pi/180.
     75                return self._atm.opacity(freq, elevation)
     76
     77    def set_weather(self, temperature, pressure, humidity):
     78        """Update the model using the given environmental parameters.
     79        Parameters:
     80            temperature:    air temperature at the observatory (K)
     81            pressure:       air pressure at the sea level if the observatory
     82                            elevation is set to non-zero value (note, by
     83                            default is set to 700m) or at the observatory
     84                            ground level if the elevation is set to 0. (The
     85                            value is in Pascals or hPa, default 101325 Pa
     86            humidity:       air humidity at the observatory (fractional),
     87                            default is 0.5
     88        """
     89        pressure = self._to_pascals(pressure)
     90        self._atm.set_weather(temperature, pressure, humidity)
     91
     92    def set_observatory_elevation(self, elevation:
     93        """Update the model using the given the observatory elevation
     94        Parameters:
     95            elevation:  the elevation at which to compute the opacity. If `None`
     96                        is given (default) the zenith opacity is returned.
     97        """
     98        self._atm.set_observatory_elevation(el)
     99
    9100
    10101def _import_data(data):
     
    27118    return merge(tables)
    28119
    29 def skydip(data, averagepol=True, tsky=300., plot=False):
     120def skydip(data, averagepol=True, tsky=300., plot=False,
     121           temperature=288, pressure=101325., humidity=0.5):
    30122    """Determine the opacity from a set of 'skydip' obervations.
    31123    This can be any set of observations over a range of elevations,
     
    60152    rcsave = rcParams['verbose']
    61153    rcParams['verbose'] = False
     154    if plot:
     155        from matplotlib import pylab
    62156    scan = _import_data(data)
    63157    f = fitter()
     
    68162    pnos = scan.getpolnos()
    69163    opacities = []
     164    om = opacitymodel(temperature, pressure, humidity)
    70165    for ino in inos:
    71166        sel.set_ifs(ino)
     
    74169        airms = []
    75170        tsyss = []
    76 
    77171        if plot:
    78             xyplotter.cla()
    79             xyplotter.ioff()
    80             xyplotter.clf()
    81             xyplotter.xlabel("Airmass")
    82             xyplotter.ylabel(r"$T_{sys}$")
     172            pylab.cla()
     173            pylab.ioff()
     174            pylab.clf()
     175            pylab.xlabel("Airmass")
     176            pylab.ylabel(r"$T_{sys}$")
    83177        for pno in pnos:
    84178            sel.set_polarisations(pno)
     
    102196        if plot:
    103197            colors = ['b','g','k']
    104             for i in range(len(airms)):
    105                 xyplotter.plot(airms[i], tsyss[i], 'o', color=colors[i])
    106                 xyplotter.plot(airms[i], fits[i], '-', color=colors[i])
    107                 xyplotter.figtext(0.7,0.3-(i/30.0),
     198            n = len(airms)
     199            for i in range(n):
     200                pylab.plot(airms[i], tsyss[i], 'o', color=colors[i])
     201                pylab.plot(airms[i], fits[i], '-', color=colors[i])
     202                pylab.figtext(0.7,0.3-(i/30.0),
    108203                                  r"$\tau_{fit}=%0.2f$" % opacity[i],
    109204                                  color=colors[i])
    110205            if averagepol:
    111                 xyplotter.figtext(0.7,0.3-(len(airms)/30.0),
    112                                   r"$\tau=%0.2f$" % opacities[-1],
     206                pylab.figtext(0.7,0.3-(n/30.0),
     207                                  r"$\tau_{avg}=%0.2f$" % opacities[-1],
    113208                                  color='r')
    114             xyplotter.title("IF%d : %s" % (ino, freqstr))
    115 
    116             xyplotter.ion()
    117             xyplotter.draw()
     209                n +=1
     210            pylab.figtext(0.7,0.3-(n/30.0),
     211                          r"$\tau_{model}=%0.2f$" % om.get_opacities(freq*1e9),
     212                          color='grey')
     213           
     214            pylab.title("IF%d : %s" % (ino, freqstr))
     215
     216            pylab.ion()
     217            pylab.draw()
    118218            raw_input("Hit <return> for next fit...")
    119219        sel.reset()
     
    122222    rcParams['verbose'] = rcsave
    123223    if plot:
    124         xyplotter.close()
     224        pylab.close()
    125225    return opacities
  • trunk/python/scantable.py

    r1697 r1725  
    11151115
    11161116    @print_log_dec
    1117     def opacity(self, tau, insitu=None):
     1117    def opacity(self, tau=None, insitu=None):
    11181118        """
    11191119        Apply an opacity correction. The data
     
    11261126                         nIF*nPol or 1 and in order of IF/POL, e.g.
    11271127                         [opif0pol0, opif0pol1, opif1pol0 ...]
     1128                         if tau is `None` the opacities are determined from a
     1129                         model.
    11281130            insitu:      if False a new scantable is returned.
    11291131                         Otherwise, the scaling is done in-situ
  • trunk/src/STFiller.cpp

    r1586 r1725  
    241241    if ( status != 0 ) break;
    242242    n += 1;
    243    
    244243    Regex filterrx(".*[SL|PA]$");
    245244    Regex obsrx("^AT.+");
  • trunk/src/python_STAtmosphere.cpp

    r1715 r1725  
    4444        .def( init < double, double, double > () )
    4545        .def("set_weather", &STAtmosphere::setWeather)
    46         .def("set_observatory_elevation", &STAtmosphere::setObservatoryElevation)
     46        .def("set_observatory_elevation",
     47             &STAtmosphere::setObservatoryElevation)
    4748        .def("zenith_opacity", &STAtmosphere::zenithOpacity)
    4849        .def("zenith_opacities", &STAtmosphere::zenithOpacities)
  • trunk/test/test_scantable.py

    r1600 r1725  
    11import unittest
    22import datetime
    3 from asap import scantable, selector, rcParams
     3from asap import scantable, selector, rcParams, mask_not
    44rcParams["verbose"] = False
    55
     
    88
    99        self.st = scantable("data/MOPS.rpf", average=True)
     10        restfreqs = [86.243]     # 13CO-1/0, SiO the two IF
     11        self.st.set_restfreqs(restfreqs,"GHz")
    1012
    1113    def test_init(self):
     
    135137        self.assertEqual(s1.getscannos(), (1,))
    136138
     139    def test_flag(self):
     140        q = self.st.auto_quotient()
     141        q.set_unit('km/s')
     142        q0 = q.copy()
     143        q1 = q.copy()
     144        msk = q0.create_mask([-10,20])
     145        q0.flag(mask=mask_not(msk))
     146        self.assertAlmostEqual(q0.stats(stat='max')[0], 95.62171936)
     147        q1.flag(mask=msk)
     148        self.assertAlmostEqual(q1.stats(stat='max')[0], 2.66563416)
    137149
    138150if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.