Created
February 12, 2011 17:44
-
-
Save astrofrog/823908 to your computer and use it in GitHub Desktop.
Example of how to download cutouts from IRSA
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 urllib2 | |
| from xml.etree.ElementTree import ElementTree | |
| mission = 'GLIMPSE' | |
| base_url = 'http://irsa.ipac.caltech.edu/cgi-bin/Cutouts/nph-cutouts' | |
| options = {} | |
| options['locstr'] = '308.0 +0.7 gal' | |
| options['sizeX'] = '120' | |
| options['units'] = 'arcsec' | |
| options['mode'] = 'PI' | |
| if mission == 'GLIMPSE': | |
| options['mission'] = 'GLIMPSE' | |
| options['min_size'] = 1 | |
| options['max_size'] = 599 | |
| options['ntable_cutouts'] = 8 | |
| options['cutouttbl1'] = 'IRAC1_0.6ResMos' | |
| options['cutouttbl2'] = 'IRAC2_0.6ResMos' | |
| options['cutouttbl3'] = 'IRAC3_0.6ResMos' | |
| options['cutouttbl4'] = 'IRAC4_0.6ResMos' | |
| options['cutouttbl5'] = 'IRAC1_1.2ResMos' | |
| options['cutouttbl6'] = 'IRAC2_1.2ResMos' | |
| options['cutouttbl7'] = 'IRAC3_1.2ResMos' | |
| options['cutouttbl8'] = 'IRAC4_1.2ResMos' | |
| # Encode options | |
| options = urllib.urlencode(options) | |
| # Request page | |
| req = urllib2.Request(base_url, options) | |
| response = urllib2.urlopen(req) | |
| # Download cutouts | |
| tree = ElementTree() | |
| for cutout in tree.parse(response).find('images').find('cutouts').findall('fits'): | |
| url = cutout.text | |
| response = urllib2.urlopen(url) | |
| open(os.path.basename(cutout.text), 'wb').write(response.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment