source: branches/alma/python/linecatalog.py @ 1612

Last change on this file since 1612 was 1612, checked in by Takeshi Nakazato, 15 years ago

New Development: No

JIRA Issue: Yes CAS-729, CAS-1147

Ready to Release: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes

Module(s): Module Names change impacts.

Description: Describe your changes here...

I have changed that almost all log messages are output to casapy.log,
not to the terminal window. After this change, asap becomes to depend on casapy
and is not running in standalone, because asap have to import taskinit module
to access casalogger.


  • Property svn:keywords set to Date Revision
File size: 4.1 KB
Line 
1"""
2A representation of a spectral line catalog.
3
4Author: Malte Marquarding
5
6"""
7__revision__ = "$Revision: 1612 $"
8from asap._asap import linecatalog as lcbase
9from asap import rcParams
10import os
11from taskinit import *
12
13class linecatalog(lcbase):
14    """
15    This class is a warpper for line catalogs. These can be either ASCII tables
16    or the tables saved from this class.
17    ASCII tables have the following restrictions:
18    Comments can be present through lines starting with '#'.
19    The first column contains the name of the Molecule. This can't contain spaces,
20    if it does it has to be wrapped in ""
21    The second column contains the frequency of the transition.
22    The third column contains the error in frequency.
23    The fourth column contains a value describing the intensity
24    """
25
26    def __init__(self, name):
27        fpath = os.path.abspath(os.path.expandvars(os.path.expanduser(name)))
28        if os.path.exists(fpath):
29            lcbase.__init__(self, fpath)
30        else:
31            msg = "File '%s' not found" % fpath
32            if rcParams['verbose']:
33                #print msg
34                casalog.post( msg, 'WARN' )
35                return
36            else:
37                raise IOError(msg)
38
39    def __repr__(self):
40        return lcbase.summary(self, -1)
41
42    def summary(self):
43        """
44        Print the contents of the table.
45        """
46        try:
47            from IPython.genutils import page as pager
48        except ImportError:
49            from pydoc import pager
50        pager(lcbase.summary(self, -1))
51
52    def set_name(self, name, mode="pattern"):
53        """
54        Set a name restriction on the table. This can be a standard unix-style
55        pattern or a regular expression.
56        Parameters:
57            name:       the name patterrn/regex
58            mode:       the matching mode, i.e. "pattern" (default) or "regex"
59        """
60        validmodes = "pattern regex".split()
61        if not mode.lower() in validmodes:
62            return
63        lcbase.set_name(self, name, mode)
64
65    def set_frequency_limits(self, fmin=1.0, fmax=120.0, unit="GHz"):
66        """
67        Set frequency limits on the table.
68        Parameters:
69            fmin:       the lower bound
70            fmax:       the upper bound
71            unit:       the frequency unit (default "GHz")
72
73        Note:
74            The underlying table conatins frequency values in MHz
75        """
76        base = { "GHz": 1000.0, "MHz": 1.0 }
77        if not base.has_key(unit):
78            raise ValueError("%s is not a valid unit." % unit)
79        # the table conatins values in MHz
80        lcbase.set_frequency_limits(self, fmin*base[unit], fmax*base[unit])
81
82    def set_strength_limits(self, smin, smax):
83        """
84        Set line strength limits on the table (arbitrary units)
85        Parameters:
86            smin:       the lower bound
87            smax:       the upper bound
88        """
89        lcbase.set_strength_limits(self, smin, smax)
90
91    def save(self, name, overwrite=False):
92        """
93        Save the subset of the table to disk. This uses an internal data format
94        and can be read in again.
95        """
96        name = os.path.expanduser(os.path.expandvars(name))
97        if os.path.isfile(name) or os.path.isdir(name):
98            if not overwrite:
99                msg = "File %s exists." % name
100                if rcParams['verbose']:
101                    #print msg
102                    casalog.post( msg, 'WARN' )
103                    return
104                else:
105                    raise IOError(msg)
106        lcbase.save(self, name)
107
108    def reset(self):
109        """
110        Reset the table to its initial state, i.e. undo all calls to set_
111        """
112        lcbase.reset(self)
113
114    def get_row(self, row=0):
115        """
116        Get the values in a specified row of the table.
117        Parameters:
118              row:        the row to retrieve
119        """
120        freq = lcbase.get_frequency(self, row)
121        name = lcbase.get_name(self, row)
122        return { 'name':name, 'value': freq }
123
124    def __len__(self):
125        return self.nrow()
126
127    def __getitem__(self, k):
128        if k < 0: k = self.nrow()-k
129        return self.get_row(k)
130
131
132
133
134
Note: See TracBrowser for help on using the repository browser.