Changeset 2884 for trunk/python
- Timestamp:
- 12/20/13 21:57:13 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2882 r2884 316 316 return (s[-2:].lower() == "hz") 317 317 318 def get_freq_by_string(s ):319 if not is_frequency(s):318 def get_freq_by_string(s1, s2): 319 if not (is_number(s1) and is_frequency(s2)): 320 320 raise RuntimeError("Invalid input string.") 321 321 … … 323 323 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] 324 324 325 s = s.strip()326 factor = 1.0325 s1 = s1.strip() 326 s2 = s2.strip() 327 327 328 prefix = s [-3:-2]328 prefix = s2[-3:-2] 329 329 if is_number(prefix): 330 res = float(s[:-2]) 330 res1 = float(s1) 331 res2 = float(s2[:-2]) 331 332 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) 335 338 336 339 def is_velocity(s): … … 338 341 return (s[-3:].lower() == "m/s") 339 342 340 def get_velocity_by_string(s ):341 if not is_velocity(s):343 def get_velocity_by_string(s1, s2): 344 if not (is_number(s1) and is_velocity(s2)): 342 345 raise RuntimeError("Invalid input string.") 343 346 347 # note that the default velocity unit is km/s 344 348 prefix_list = [".", "k"] 345 349 factor_list = [1e-3, 1.0] 346 350 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 353 358 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) 357 364 358 365 def get_frequency_by_velocity(restfreq, vel): … … 1716 1723 '0~1:2~6,8' = channels 2 to 6 in spws 0,1, and 1717 1724 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. 1733 1738 Returns: 1734 1739 A dictionary of selected (valid) spw and masklist pairs, … … 1778 1783 # parse spw expression and store result in spw_list. 1779 1784 # 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 also1785 # 'a~b*Hz' (where * can be '', 'k', 'M', 'G' etc.), 1786 # 'a~b*m/s' (where * can be '' or 'k') and also 1782 1787 # several of the above expressions connected with ';'. 1783 1788 … … 1854 1859 spw_list.append(i) 1855 1860 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) 1860 1864 1861 1865 for coord in self._get_coordinate_list(): … … 1872 1876 spw_list.append(spw) 1873 1877 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) 1878 1881 expr_vmin = min(expr_v0, expr_v1) 1879 1882 expr_vmax = max(expr_v0, expr_v1) … … 1955 1958 expr_pmax = max(float(expr0), float(expr1)) 1956 1959 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) 1961 1965 expr_pmin = min(expr_p0, expr_p1) 1962 1966 expr_pmax = max(expr_p0, expr_p1) 1963 1967 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' 1966 1970 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) 1969 1974 expr_p0 = coord.to_pixel(expr_f0) 1970 1975 expr_p1 = coord.to_pixel(expr_f1)
Note:
See TracChangeset
for help on using the changeset viewer.