- Timestamp:
- 01/16/14 13:06:13 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2890 r2891 379 379 return restfreq * math.sqrt((1.0 - r) / (1.0 + r)) 380 380 381 def get_restfreq_in_Hz(s_restfreq): 382 value = 0.0 383 unit = "" 384 s = s_restfreq.replace(" ","") 385 386 for i in range(len(s))[::-1]: 387 if s[i].isalpha(): 388 unit = s[i] + unit 389 else: 390 value = float(s[0:i+1]) 391 break 392 393 if (unit == "") or (unit.lower() == "hz"): 394 return value 395 elif (len(unit) == 3) and (unit[1:3].lower() == "hz"): 396 unitprefix = unit[0] 397 factor = 1.0 398 399 prefix_list = ["a", "f", "p", "n", "u", "m", ".", "k", "M", "G", "T", "P", "E"] 400 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] 401 factor = factor_list[prefix_list.index(unitprefix)] 402 """ 403 if (unitprefix == 'a'): 404 factor = 1.0e-18 405 elif (unitprefix == 'f'): 406 factor = 1.0e-15 407 elif (unitprefix == 'p'): 408 factor = 1.0e-12 409 elif (unitprefix == 'n'): 410 factor = 1.0e-9 411 elif (unitprefix == 'u'): 412 factor = 1.0e-6 413 elif (unitprefix == 'm'): 414 factor = 1.0e-3 415 elif (unitprefix == 'k'): 416 factor = 1.0e+3 417 elif (unitprefix == 'M'): 418 factor = 1.0e+6 419 elif (unitprefix == 'G'): 420 factor = 1.0e+9 421 elif (unitprefix == 'T'): 422 factor = 1.0e+12 423 elif (unitprefix == 'P'): 424 factor = 1.0e+15 425 elif (unitprefix == 'E'): 426 factor = 1.0e+18 427 """ 428 return value*factor 429 else: 430 mesg = "wrong unit of restfreq." 431 raise Exception, mesg 432 433 def normalise_restfreq(in_restfreq): 434 if isinstance(in_restfreq, float): 435 return in_restfreq 436 elif isinstance(in_restfreq, int) or isinstance(in_restfreq, long): 437 return float(in_restfreq) 438 elif isinstance(in_restfreq, str): 439 return get_restfreq_in_Hz(in_restfreq) 440 elif isinstance(in_restfreq, list) or isinstance(in_restfreq, numpy.ndarray): 441 if isinstance(in_restfreq, numpy.ndarray): 442 if len(in_restfreq.shape) > 1: 443 mesg = "given in numpy.ndarray, in_restfreq must be 1-D." 444 raise Exception, mesg 445 446 res = [] 447 for i in xrange(len(in_restfreq)): 448 elem = in_restfreq[i] 449 if isinstance(elem, float): 450 res.append(elem) 451 elif isinstance(elem, int) or isinstance(elem, long): 452 res.append(float(elem)) 453 elif isinstance(elem, str): 454 res.append(get_restfreq_in_Hz(elem)) 455 elif isinstance(elem, dict): 456 if isinstance(elem["value"], float): 457 res.append(elem) 458 elif isinstance(elem["value"], int): 459 dictelem = {} 460 dictelem["name"] = elem["name"] 461 dictelem["value"] = float(elem["value"]) 462 res.append(dictelem) 463 elif isinstance(elem["value"], str): 464 dictelem = {} 465 dictelem["name"] = elem["name"] 466 dictelem["value"] = get_restfreq_in_Hz(elem["value"]) 467 res.append(dictelem) 468 else: 469 mesg = "restfreq elements must be float, int, or string." 470 raise Exception, mesg 471 return res 472 else: 473 mesg = "wrong type of restfreq given." 474 raise Exception, mesg 475 476 def set_restfreq(s, restfreq): 477 rfset = (restfreq != '') and (restfreq != []) 478 if rfset: 479 s.set_restfreqs(normalise_restfreq(restfreq)) 381 480 382 481 class scantable(Scantable): … … 1766 1865 orig_doppler = orig_coord[2] 1767 1866 1768 if restfreq is None: restfreq = orig_restfreq_list 1769 if frame is None: frame = orig_frame 1770 if doppler is None: doppler = orig_doppler 1771 1772 self.set_restfreqs(restfreq) 1867 #if restfreq is None: restfreq = orig_restfreq_list 1868 #self.set_restfreqs(restfreq) 1869 if restfreq is not None: 1870 set_restfreq(self, restfreq) #<---------------------- 1871 1872 if frame is None: frame = orig_frame 1773 1873 self.set_freqframe(frame) 1874 1875 if doppler is None: doppler = orig_doppler 1774 1876 self.set_doppler(doppler) 1775 1877 … … 2042 2144 2043 2145 # restore original values 2044 self.set_restfreqs(orig_restfreq_list) 2146 2147 if restfreq is not None: 2148 #self.set_restfreqs(orig_restfreq_list)#<-- SHOULD BE set_restfreqs(normalise_restfreq(orig_restfreq)) 2149 set_restfreq(self, orig_restfreq_list) 2045 2150 self.set_freqframe(orig_frame) 2046 2151 self.set_doppler(orig_doppler)
Note:
See TracChangeset
for help on using the changeset viewer.