-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun_fornax.py
62 lines (43 loc) · 2.24 KB
/
run_fornax.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
import os
import astropy.coordinates as coord
import pyvo
sys.path.insert(0, os.getcwd())
import fornax
print(f'\nUsing fornax library in: {fornax.__file__}\n')
pos = coord.SkyCoord.from_name("ngc 4151")
# chandra #
query_url = 'https://heasarc.gsfc.nasa.gov/xamin_aws/vo/sia?table=chanmaster&'
# hst #
#query_url = 'https://mast.stsci.edu/portal_vo/Mashup/VoQuery.asmx/SiaV1?MISSION=HST&'
query_result = pyvo.dal.sia.search(query_url, pos=pos, size=0.0)
table_result = query_result.to_table()
access_url_column = query_result.fieldname_with_ucd('VOX:Image_AccessReference')
# data handler
data_product = table_result[0]
line = '+'*40
print(f'\nData product:\n{line}')
print(data_product[['instrument_name', access_url_column]])
print(f'{line}\n')
## ------------------------------------------------------------------------------ ##
## If testing access with credentials, either set profile to the profile
## name in ~/.aws/credentials, or define the environment variables:
## AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN to authenticate.
## Then rename the bucket name in data_product. (e.g. from dh-fornaxdev
## that does not require credentials to heasarc-1, which does).
## Injecting the bucket name here is quick hack that we use instead of
## modifying the server to return data-products with a different bucket name
#data_product['cloud_access'] = data_product['cloud_access'].replace('dh-fornaxdev', 'heasarc-1')
myprofile = None
## ------------------------------------------------------------------------------ ##
# inject multiple access points for testing
# import re
# access_p = re.findall('aws["\']:\s+(.*)\}', data_product['cloud_access'])[0]
# data_product['cloud_access'] = '{"aws": [%s, %s]}'%(access_p.replace('open', 'region'), access_p)
# inject the correct json keys by hand while waiting for the servers to update
#data_product['cloud_access'] = data_product['cloud_access'].replace(
# 'bucket', 'bucket_name').replace('path', 'key')
# attemp to access the data.
#fornax.get_data_product(data_product, 'aws', access_url_column=access_url_column, profile=myprofile)
# pass a pyvo.dal.Record object to use datalinks
fornax.get_data_product(query_result[0], 'aws', access_url_column=access_url_column, profile=myprofile)