Changeset 2884 for trunk/python


Ignore:
Timestamp:
12/20/13 21:57:13 (10 years ago)
Author:
WataruKawasaki
Message:

New Development: No

JIRA Issue: Yes CAS-5859

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: parameter syntax

Test Programs:

Put in Release Notes:

Module(s): sd

Description: changed accepting selection syntax given in unit of frequency or velocity so that unit string should be given only to the second value.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2882 r2884  
    316316    return (s[-2:].lower() == "hz")
    317317
    318 def get_freq_by_string(s):
    319     if not is_frequency(s):
     318def get_freq_by_string(s1, s2):
     319    if not (is_number(s1) and is_frequency(s2)):
    320320        raise RuntimeError("Invalid input string.")
    321321   
     
    323323    factor_list = [1e-18, 1e-15, 1e-12, 1e-9, 1e-6, 1e-3, 1.0, 1e+3, 1e+6, 1e+9, 1e+12, 1e+15, 1e+18]
    324324
    325     s = s.strip()
    326     factor = 1.0
     325    s1 = s1.strip()
     326    s2 = s2.strip()
    327327   
    328     prefix = s[-3:-2]
     328    prefix = s2[-3:-2]
    329329    if is_number(prefix):
    330         res = float(s[:-2])
     330        res1 = float(s1)
     331        res2 = float(s2[:-2])
    331332    else:
    332         res = float(s[:-3]) * factor_list[prefix_list.index(prefix)]
    333 
    334     return res
     333        factor = factor_list[prefix_list.index(prefix)]
     334        res1 = float(s1) * factor
     335        res2 = float(s2[:-3]) * factor
     336
     337    return (res1, res2)
    335338
    336339def is_velocity(s):
     
    338341    return (s[-3:].lower() == "m/s")
    339342
    340 def get_velocity_by_string(s):
    341     if not is_velocity(s):
     343def get_velocity_by_string(s1, s2):
     344    if not (is_number(s1) and is_velocity(s2)):
    342345        raise RuntimeError("Invalid input string.")
    343346
     347    # note that the default velocity unit is km/s
    344348    prefix_list = [".", "k"]
    345349    factor_list = [1e-3, 1.0]
    346350
    347     s = s.strip()
    348     factor = 1.0
    349 
    350     prefix = s[-4:-3]
    351     if is_number(prefix):
    352         res = float(s[:-3]) * 1e-3
     351    s1 = s1.strip()
     352    s2 = s2.strip()
     353
     354    prefix = s2[-4:-3]
     355    if is_number(prefix): # in case velocity unit m/s
     356        res1 = float(s1) * 1e-3
     357        res2 = float(s2[:-3]) * 1e-3
    353358    else:
    354         res = float(s[:-4]) * factor_list[prefix_list.index(prefix)]
    355 
    356     return res # in km/s
     359        factor = factor_list[prefix_list.index(prefix)]
     360        res1 = float(s1) * factor
     361        res2 = float(s2[:-4]) * factor
     362
     363    return (res1, res2)
    357364
    358365def get_frequency_by_velocity(restfreq, vel):
     
    17161723                           '0~1:2~6,8' = channels 2 to 6 in spws 0,1, and
    17171724                                         all channels in spw8
    1718                            '1.3GHz~1.5GHz' = all spws that fall in or have
    1719                                              at least some overwrap with
    1720                                              frequency range between 1.3GHz
    1721                                              and 1.5GHz.
    1722                            '1.3GHz~1.5GHz:1.3GHz~1.5GHz' = channels that
    1723                                                            fall between the
    1724                                                            specified frequency
    1725                                                            range in spws that
    1726                                                            fall in or have
    1727                                                            overwrap with the
    1728                                                            specified frequency
    1729                                                            range.
    1730                            '1:-200km/s~250km/s' = channels that fall between
    1731                                                   the specified velocity range
    1732                                                   in spw 1.
     1725                           '1.3~1.5GHz' = all spws that fall in or have at
     1726                                          least some overwrap with frequency
     1727                                          range between 1.3GHz and 1.5GHz.
     1728                           '1.3~1.5GHz:1.3~1.5GHz' = channels that fall
     1729                                                     between the specified
     1730                                                     frequency range in spws
     1731                                                     that fall in or have
     1732                                                     overwrap with the
     1733                                                     specified frequency
     1734                                                     range.
     1735                           '1:-200~250km/s' = channels that fall between the
     1736                                              specified velocity range in
     1737                                              spw 1.
    17331738        Returns:
    17341739        A dictionary of selected (valid) spw and masklist pairs,
     
    17781783            # parse spw expression and store result in spw_list.
    17791784            # allowed cases include '', '*', 'a', '<a', '>a', 'a~b',
    1780             # 'a*Hz~b*Hz' (where * can be '', 'k', 'M', 'G' etc.),
    1781             # 'a*m/s~b*m/s' (where * can be '' or 'k') and also
     1785            # 'a~b*Hz' (where * can be '', 'k', 'M', 'G' etc.),
     1786            # 'a~b*m/s' (where * can be '' or 'k') and also
    17821787            # several of the above expressions connected with ';'.
    17831788           
     
    18541859                                    spw_list.append(i)
    18551860                           
    1856                         elif is_frequency(expr0) and is_frequency(expr1):
    1857                             # 'a*Hz~b*Hz'
    1858                             expr_f0 = get_freq_by_string(expr0)
    1859                             expr_f1 = get_freq_by_string(expr1)
     1861                        elif is_number(expr0) and is_frequency(expr1):
     1862                            # 'a~b*Hz'
     1863                            (expr_f0, expr_f1) = get_freq_by_string(expr0, expr1)
    18601864
    18611865                            for coord in self._get_coordinate_list():
     
    18721876                                    spw_list.append(spw)
    18731877                               
    1874                         elif is_velocity(expr0) and is_velocity(expr1):
    1875                             # 'a*m/s~b*m/s'
    1876                             expr_v0 = get_velocity_by_string(expr0)
    1877                             expr_v1 = get_velocity_by_string(expr1)
     1878                        elif is_number(expr0) and is_velocity(expr1):
     1879                            # 'a~b*m/s'
     1880                            (expr_v0, expr_v1) = get_velocity_by_string(expr0, expr1)
    18781881                            expr_vmin = min(expr_v0, expr_v1)
    18791882                            expr_vmax = max(expr_v0, expr_v1)
     
    19551958                                expr_pmax = max(float(expr0), float(expr1))
    19561959
    1957                             elif is_frequency(expr0) and is_frequency(expr1):
    1958                                 # 'a*Hz~b*Hz'
    1959                                 expr_p0 = coord.to_pixel(get_freq_by_string(expr0))
    1960                                 expr_p1 = coord.to_pixel(get_freq_by_string(expr1))
     1960                            elif is_number(expr0) and is_frequency(expr1):
     1961                                # 'a~b*Hz'
     1962                                (expr_f0, expr_f1) = get_freq_by_string(expr0, expr1)
     1963                                expr_p0 = coord.to_pixel(expr_f0)
     1964                                expr_p1 = coord.to_pixel(expr_f1)
    19611965                                expr_pmin = min(expr_p0, expr_p1)
    19621966                                expr_pmax = max(expr_p0, expr_p1)
    19631967
    1964                             elif is_velocity(expr0) and is_velocity(expr1):
    1965                                 # 'a*m/s~b*m/s'
     1968                            elif is_number(expr0) and is_velocity(expr1):
     1969                                # 'a~b*m/s'
    19661970                                restf = self.get_restfreqs().values()[0][0]
    1967                                 expr_f0 = get_frequency_by_velocity(restf, get_velocity_by_string(expr0))
    1968                                 expr_f1 = get_frequency_by_velocity(restf, get_velocity_by_string(expr1))
     1971                                (expr_v0, expr_v1) = get_velocity_by_string(expr0, expr1)
     1972                                expr_f0 = get_frequency_by_velocity(restf, expr_v0)
     1973                                expr_f1 = get_frequency_by_velocity(restf, expr_v1)
    19691974                                expr_p0 = coord.to_pixel(expr_f0)
    19701975                                expr_p1 = coord.to_pixel(expr_f1)
Note: See TracChangeset for help on using the changeset viewer.