Changeset 2887
- Timestamp:
- 12/25/13 17:49:49 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2886 r2887 1814 1814 1815 1815 else: # single number 1816 #checking if the given number is valid for spw ID 1817 idx = valid_ifs.index(int(scs_elem)) 1818 spw_list.append(valid_ifs[idx]) 1819 1816 expr = int(scs_elem) 1817 spw_list.append(expr) 1818 if expr not in valid_ifs: 1819 asaplog.push("Invalid spw given. Ignored.") 1820 1820 1821 else: # (len_product == 2) 1821 # namely, one of '<', '>' or '~' appe rs just once.1822 # namely, one of '<', '>' or '~' appears just once. 1822 1823 1823 1824 if (lt_sep_length == 2): # '<a' … … 1857 1858 expr_pmin = min(float(expr0), float(expr1)) 1858 1859 expr_pmax = max(float(expr0), float(expr1)) 1860 has_invalid_spw = False 1859 1861 no_valid_spw = True 1860 1862 … … 1863 1865 spw_list.append(i) 1864 1866 no_valid_spw = False 1867 else: 1868 has_invalid_spw = True 1869 1870 if has_invalid_spw: 1871 msg = "Invalid spw is given. Ignored." 1872 asaplog.push(msg) 1873 asaplog.post() 1865 1874 1866 1875 if no_valid_spw: 1867 1876 raise ValueError("No valid spw in range ('" + str(expr_pmin) + "~" + str(expr_pmax) + "').") 1868 1877 1869 1878 elif is_number(expr0) and is_frequency(expr1): 1870 1879 # 'a~b*Hz' … … 1919 1928 raise RuntimeError("Invalid spw selection.") 1920 1929 1930 # check spw list and remove invalid ones. 1931 # if no valid spw left, emit ValueError. 1932 if len(spw_list) == 0: 1933 raise ValueError("No valid spw in given range.") 1934 """ 1935 no_valid_spw = True 1936 for spw in spw_list: 1937 print spw_list 1938 if spw in valid_ifs: 1939 no_valid_spw = False 1940 else: 1941 spw_list.remove(spw) 1942 1943 if no_valid_spw: 1944 raise ValueError("No valid spw in given range.") 1945 """ 1946 1921 1947 # parse channel expression and store the result in crange_list. 1922 1948 # allowed cases include '', 'a~b', 'a*Hz~b*Hz' (where * can be … … 1943 1969 break 1944 1970 1945 if not found: 1946 raise RuntimeError("Invalid spw value.") 1947 1948 semicolon_sep = colon_sep[1].split(";") 1949 for scs_elem in semicolon_sep: 1950 scs_elem = scs_elem.strip() 1951 1952 ti_sep = scs_elem.split("~") 1953 ti_sep_length = len(ti_sep) 1954 1955 if (ti_sep_length > 2): 1956 raise RuntimeError("Invalid channel selection.") 1971 if found: 1972 semicolon_sep = colon_sep[1].split(";") 1973 for scs_elem in semicolon_sep: 1974 scs_elem = scs_elem.strip() 1975 1976 ti_sep = scs_elem.split("~") 1977 ti_sep_length = len(ti_sep) 1978 1979 if (ti_sep_length > 2): 1980 raise RuntimeError("Invalid channel selection.") 1957 1981 1958 elif (ti_sep_length == 1):1959 if (scs_elem == "") or (scs_elem == "*"):1960 # '' and '*' for all channels1961 crange_list = [[pmin, pmax]]1962 break1963 elif (is_number(scs_elem)):1964 # single channel given1965 crange_list.append([float(scs_elem), float(scs_elem)])1966 else:1967 raise RuntimeError("Invalid channel selection.")1968 1969 else: #(ti_sep_length == 2)1970 expr0 = ti_sep[0].strip()1971 expr1 = ti_sep[1].strip()1972 1973 if is_number(expr0) and is_number(expr1):1974 # 'a~b'1975 expr_pmin = min(float(expr0), float(expr1))1976 expr_pmax = max(float(expr0), float(expr1))1977 1978 elif is_number(expr0) and is_frequency(expr1):1979 # 'a~b*Hz'1980 (expr_f0, expr_f1) = get_freq_by_string(expr0, expr1)1981 expr_p0 = coord.to_pixel(expr_f0)1982 expr_p1 = coord.to_pixel(expr_f1)1983 expr_pmin = min(expr_p0, expr_p1)1984 expr_pmax = max(expr_p0, expr_p1)1985 1986 elif is_number(expr0) and is_velocity(expr1):1987 # 'a~b*m/s'1988 restf = self.get_restfreqs().values()[0][0]1989 (expr_v0, expr_v1) = get_velocity_by_string(expr0, expr1)1990 expr_f0 = get_frequency_by_velocity(restf, expr_v0)1991 expr_f1 = get_frequency_by_velocity(restf, expr_v1)1992 expr_p0 = coord.to_pixel(expr_f0)1993 expr_p1 = coord.to_pixel(expr_f1)1994 expr_pmin = min(expr_p0, expr_p1)1995 expr_pmax = max(expr_p0, expr_p1)1982 elif (ti_sep_length == 1): 1983 if (scs_elem == "") or (scs_elem == "*"): 1984 # '' and '*' for all channels 1985 crange_list = [[pmin, pmax]] 1986 break 1987 elif (is_number(scs_elem)): 1988 # single channel given 1989 crange_list.append([float(scs_elem), float(scs_elem)]) 1990 else: 1991 raise RuntimeError("Invalid channel selection.") 1992 1993 else: #(ti_sep_length == 2) 1994 expr0 = ti_sep[0].strip() 1995 expr1 = ti_sep[1].strip() 1996 1997 if is_number(expr0) and is_number(expr1): 1998 # 'a~b' 1999 expr_pmin = min(float(expr0), float(expr1)) 2000 expr_pmax = max(float(expr0), float(expr1)) 2001 2002 elif is_number(expr0) and is_frequency(expr1): 2003 # 'a~b*Hz' 2004 (expr_f0, expr_f1) = get_freq_by_string(expr0, expr1) 2005 expr_p0 = coord.to_pixel(expr_f0) 2006 expr_p1 = coord.to_pixel(expr_f1) 2007 expr_pmin = min(expr_p0, expr_p1) 2008 expr_pmax = max(expr_p0, expr_p1) 2009 2010 elif is_number(expr0) and is_velocity(expr1): 2011 # 'a~b*m/s' 2012 restf = self.get_restfreqs().values()[0][0] 2013 (expr_v0, expr_v1) = get_velocity_by_string(expr0, expr1) 2014 expr_f0 = get_frequency_by_velocity(restf, expr_v0) 2015 expr_f1 = get_frequency_by_velocity(restf, expr_v1) 2016 expr_p0 = coord.to_pixel(expr_f0) 2017 expr_p1 = coord.to_pixel(expr_f1) 2018 expr_pmin = min(expr_p0, expr_p1) 2019 expr_pmax = max(expr_p0, expr_p1) 1996 2020 1997 else:1998 # cases such as 'aGHz~bkm/s' are not allowed now1999 raise RuntimeError("Invalid channel selection.")2000 2001 cmin = max(pmin, expr_pmin)2002 cmax = min(pmax, expr_pmax)2003 # if the given range of channel selection has overwrap with2004 # that of current spw, output the overwrap area.2005 if (cmin <= cmax):2006 cmin = float(int(cmin + 0.5))2007 cmax = float(int(cmax + 0.5))2008 crange_list.append([cmin, cmax])2021 else: 2022 # cases such as 'aGHz~bkm/s' are not allowed now 2023 raise RuntimeError("Invalid channel selection.") 2024 2025 cmin = max(pmin, expr_pmin) 2026 cmax = min(pmax, expr_pmax) 2027 # if the given range of channel selection has overwrap with 2028 # that of current spw, output the overwrap area. 2029 if (cmin <= cmax): 2030 cmin = float(int(cmin + 0.5)) 2031 cmax = float(int(cmax + 0.5)) 2032 crange_list.append([cmin, cmax]) 2009 2033 2010 2034 if (len(crange_list) == 0): … … 2016 2040 res[spw] = crange_list 2017 2041 2042 for spw in res.keys(): 2043 if spw not in valid_ifs: 2044 del res[spw] 2045 2046 if len(res) == 0: 2047 raise RuntimeError("No valid spw.") 2048 2018 2049 # restore original values 2019 2050 self.set_restfreqs(orig_restfreq_list)
Note:
See TracChangeset
for help on using the changeset viewer.