Created
March 18, 2011 03:30
-
-
Save astrofrog/875572 to your computer and use it in GitHub Desktop.
Interface to the SMA sensitivity/beam calculator at http://sma1.sma.hawaii.edu/beamcalc.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import urllib | |
| import string | |
| URL = "http://sma1.sma.hawaii.edu/beamcalc.html" | |
| VALID_SIDEBANDS = ['lower', 'upper'] | |
| VALID_PWVS = [0.2, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0] | |
| VALID_CONFIGURATIONS = ['subcompact', 'compact', 'compact-north', | |
| 'extended', 'very-extended'] | |
| def estimate(frequency, sideband, declination, min_elevation, | |
| ha_start, ha_end, pwv, configuration, filename): | |
| params = {} | |
| params['freq'] = frequency | |
| if sideband in VALID_SIDEBANDS: | |
| params['sb'] = sideband[0] | |
| else: | |
| raise Exception("sideband should be one of %s" % | |
| string.join(VALID_SIDEBANDS, '/')) | |
| params['dec'] = declination | |
| params['elmin'] = min_elevation | |
| params['hastart'] = ha_start | |
| params['haend'] = ha_end | |
| if pwv in VALID_PWVS: | |
| params['pwv'] = pwv | |
| else: | |
| raise Exception("PWV should be one of %s" % | |
| string.join([str(p) for p in VALID_PWVS], '/')) | |
| if configuration in VALID_CONFIGURATIONS: | |
| params['config'] = configuration | |
| else: | |
| raise Exception("configuration should be one of %s" % | |
| string.join(VALID_CONFIGURATIONS, '/')) | |
| params['ps'] = 'ps' | |
| params = urllib.urlencode(params) | |
| u = urllib.urlopen(URL, params) | |
| if filename.endswith('.pdf'): | |
| filename = filename.replace('.pdf', '.ps') | |
| f = open(filename, 'wb') | |
| f.write(u.read()) | |
| f.close() | |
| os.system('ps2pdf %s' % filename) | |
| os.system('rm %s' % filename) | |
| else: | |
| f = open(filename, 'wb') | |
| f.write(u.read()) | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This belongs in astroquery, doesn't it? Or the new thing... =)
(I got here from google)