0 votes
27 views

How can I obtain the url(s) to download an image from the name of the exposure?

For example, I know that my object is on  the exposure c4d_150918_093321_ooi_i_v1 and I would like to obtain - from within my python code - all the urls corresponding to this exposure in order to download the image.

asked Nov 2 by anonymous | 27 views

2 Answers

0 votes

Hi there,

So I think this is probably best done using the Astro Archive, have a look at astroarchive.noao.edu.  The web interface there will let you put in the above string as the Archive filename, and quickly give you the resulting URL.  To do this from within Python, you can use the API.  From the example notebook on advanced-search available at https://github.com/NOAO/nat-nb, you could do:

import requests
import json
import pandas as pd

adsurl = 'https://astroarchive.noao.edu/api/adv_search'

jj = {
    "outfields" : ["original_filename","archive_filename", "md5sum", "url"],
    "search" : [
        ["archive_filename","c4d_150918_093321_ooi_i_v1", 'icontains'],
    ]
}
df_full = pd.read_json(json.dumps(requests.post(f'{adsurl}/fasearch/?limit=9',json=jj).json()[1:]))
df_full['url'].values

which gives: 

array(['https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/'],
      dtype=object)

The jj object in the above is the ElasticSearch string used to query the Archive.  See advanced-search.ipynb for more examples on how to construct this object.

If you want to search individual FITS extensions rather than the full frame image:

jj = {
    "outfields" : ["fitsfile__original_filename","fitsfile__archive_filename", "fitsfile__md5sum","url"],
    "search" : [
        ["fitsfile__archive_filename","c4d_150918_093321_ooi_i_v1", 'icontains'],
    ]
}
df_hdus = pd.read_json(json.dumps(requests.post(f'{adsurl}/hasearch/?limit=70',json=jj).json()[1:]))
df_hdus['url'].values

which gives (notice that you can thus use the full-frame URL to construct those for the extensions):
array(['https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,50',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,27',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,26',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,25',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,23',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,21',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,19',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,17',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,15',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,13',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,59',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,58',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,57',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,56',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,55',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,54',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,53',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,52',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,51',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,49',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,48',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,47',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,46',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,45',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,44',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,43',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,42',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,41',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,40',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,39',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,38',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,37',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,36',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,35',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,34',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,33',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,32',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,31',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,30',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,29',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,28',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,24',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,22',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,20',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,18',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,16',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,14',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,12',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,11',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,10',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,9',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,8',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,7',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,6',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,5',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,4',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,3',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,2',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,1',
       'https://astroarchive.noao.edu/api/retrieve/0ca19865c90dac5bbaf879aaa795d511/?hdus=0,0'],
      dtype=object)

answered Nov 2 by Knut Olsen
0 votes

From within Data Lab, access URLs for archive images are all of the same form, making it possible to construct the URL directly given just a filename:

name = 'c4d_150918_093321_ooi_i_v1'
base = "https://datalab.noao.edu/svc/cutout?col=&siaRef="
extn = ".fits.fz"
url = base + name + extn

It is also possible to query the exposure table directly:

url = queryClient.query('select access_url from ivoa_nsa.exposure where fileref = "%s.fits.fz" limit 1' % name).split('\n')[1]

where 'name' would be the name of your image without the extension.  The returned URL is for the entire image, if you want a particular extension or a cutout around a specific position there are parameters than can be added to the URL to do this as well.

answered Nov 2 by datalab (9,260 points)

206 questions

204 answers

198 comments

1,396 users

Welcome to Data Lab Help Desk, where you can ask questions and receive answers from other members of the community.