-
-
Notifications
You must be signed in to change notification settings - Fork 419
NOIRLab advanced search #1701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
NOIRLab advanced search #1701
Changes from all commits
c07fa84
6d1c056
9ec854b
b89344b
754ad9c
9cbd7bf
df0ecc5
5b69251
ba5e4b7
613afaa
ea05e55
5bea6d7
75e72a8
3090a69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
This does DB access through web-services. | ||
""" | ||
|
||
import astropy.io.fits as fits | ||
import astropy.table | ||
from ..query import BaseQuery | ||
from ..utils import async_to_sync | ||
|
@@ -19,8 +19,6 @@ class NoirlabClass(BaseQuery): | |
|
||
TIMEOUT = conf.timeout | ||
NAT_URL = conf.server | ||
ADS_URL = f'{NAT_URL}/api/adv_search/fasearch' | ||
SIA_URL = f'{NAT_URL}/api/sia/voimg' | ||
|
||
def __init__(self, which='file'): | ||
"""Return object used for searching the NOIRLab Archive. | ||
|
@@ -31,13 +29,18 @@ def __init__(self, which='file'): | |
is only the case with some pipeline processed files. | ||
""" | ||
self._api_version = None | ||
self._adsurl = f'{self.NAT_URL}/api/adv_search' | ||
|
||
if which == 'hdu': | ||
self.url = f'{self.NAT_URL}/api/sia/vohdu' | ||
elif which == 'file': | ||
self.url = f'{self.NAT_URL}/api/sia/voimg' | ||
self.siaurl = f'{self.NAT_URL}/api/sia/vohdu' | ||
self._adss_url = f'{self._adsurl}/hasearch' | ||
self._adsc_url = f'{self._adsurl}/core_hdu_fields' | ||
self._adsa_url = f'{self._adsurl}/aux_hdu_fields' | ||
else: | ||
self.url = f'{self.NAT_URL}/api/sia/voimg' | ||
self.siaurl = f'{self.NAT_URL}/api/sia/voimg' | ||
self._adss_url = f'{self._adsurl}/fasearch' | ||
self._adsc_url = f'{self._adsurl}/core_file_fields' | ||
self._adsa_url = f'{self._adsurl}/aux_file_fields' | ||
|
||
super().__init__() | ||
|
||
|
@@ -66,6 +69,15 @@ def _validate_version(self): | |
f'{self.api_version} from the API.') | ||
raise Exception(msg) | ||
|
||
def service_metadata(self, cache=True): | ||
"""Denotes a Metadata Query: no images are requested; only metadata | ||
should be returned. This feature is described in more detail in: | ||
http://www.ivoa.net/documents/PR/DAL/PR-SIA-1.0-20090521.html#mdquery | ||
""" | ||
url = f'{self.siaurl}?FORMAT=METADATA&format=json' | ||
response = self._request('GET', url, timeout=self.TIMEOUT, cache=cache) | ||
return response.json()[0] | ||
|
||
@class_or_instance | ||
def query_region(self, coordinate, radius=0.1, cache=True): | ||
pothiers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Query for NOIRLab observations by region of the sky. | ||
|
@@ -90,12 +102,110 @@ def query_region(self, coordinate, radius=0.1, cache=True): | |
""" | ||
self._validate_version() | ||
ra, dec = coordinate.to_string('decimal').split() | ||
url = f'{self.url}?POS={ra},{dec}&SIZE={radius}&format=json' | ||
url = f'{self.siaurl}?POS={ra},{dec}&SIZE={radius}&format=json' | ||
response = self._request('GET', url, | ||
timeout=self.TIMEOUT, | ||
cache=cache) | ||
response.raise_for_status() | ||
Comment on lines
103
to
109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest replacing all of this with:
|
||
return astropy.table.Table(data=response.json()) | ||
|
||
def query_region_async(self, coordinate, radius=0.1, cache=True): | ||
"""Query for NOIRLab observations by region of the sky. | ||
|
||
Given a sky coordinate and radius, returns a `~astropy.table.Table` | ||
of NOIRLab observations. | ||
|
||
Parameters | ||
---------- | ||
coordinates : str or `~astropy.coordinates` object | ||
The target region which to search. It may be specified as a | ||
string or as the appropriate `~astropy.coordinates` object. | ||
radius : str or `~astropy.units.Quantity` object, optional | ||
Default 0.1 degrees. | ||
The string must be parsable by `~astropy.coordinates.Angle`. The | ||
appropriate `~astropy.units.Quantity` object from | ||
`~astropy.units` may also be used. | ||
|
||
Returns | ||
------- | ||
response : `requests.Response` | ||
""" | ||
self._validate_version() | ||
|
||
ra, dec = coordinate.to_string('decimal').split() | ||
url = f'{self.siaurl}?POS={ra},{dec}&SIZE={radius}&format=json' | ||
response = self._request('GET', url, | ||
timeout=self.TIMEOUT, | ||
cache=cache) | ||
response.raise_for_status() | ||
return response | ||
keflavich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def core_fields(self, cache=True): | ||
"""List the available CORE fields. CORE fields are faster to search | ||
than AUX fields..""" | ||
response = self._request('GET', self._adsc_url, | ||
timeout=self.TIMEOUT, | ||
cache=cache) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
def aux_fields(self, instrument, proctype, cache=True): | ||
"""List the available AUX fields. AUX fields are ANY fields in the | ||
Archive FITS files that are not core DB fields. These are generally | ||
common to a single Instrument, Proctype combination. AUX fields are | ||
slower to search than CORE fields. Acceptable values for INSTRUMENT and PROCTYPE | ||
are listed in the results of the CATEGORICALS method. | ||
""" | ||
url = f'{self._adsa_url}/{instrument}/{proctype}/' | ||
response = self._request('GET', url, timeout=self.TIMEOUT, cache=cache) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
def categoricals(self, cache=True): | ||
"""List the currently acceptable values for each 'categorical field' | ||
associated with Archive files. A 'categorical field' is one in | ||
which the values are restricted to a specific set. The specific | ||
set may grow over time, but not often. The categorical fields are: | ||
collection, instrument, obs_mode, proc_type, prod_type, site, survey, | ||
telescope. | ||
""" | ||
url = f'{self._adsurl}/cat_lists/?format=json' | ||
response = self._request('GET', url, timeout=self.TIMEOUT, cache=cache) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
@class_or_instance | ||
def query_metadata(self, qspec, limit=1000, cache=True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could also be it does, however, need some docs! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, this function requires a docstring. |
||
self._validate_version() | ||
url = f'{self._adss_url}/?limit={limit}' | ||
|
||
if qspec is None: | ||
jdata = {"outfields": ["md5sum", ], "search": []} | ||
else: | ||
jdata = qspec | ||
|
||
response = self._request('POST', url, json=jdata, timeout=self.TIMEOUT) | ||
response.raise_for_status() | ||
return astropy.table.Table(rows=response.json()) | ||
pothiers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def retrieve(self, fileid, cache=True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need docstring |
||
url = f'{self.NAT_URL}/api/retrieve/{fileid}/' | ||
hdul = fits.open(url) | ||
return hdul | ||
|
||
def version(self, cache=False): | ||
url = f'{self.NAT_URL}/api/version/' | ||
response = self._request('GET', url, timeout=self.TIMEOUT, cache=cache) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
def get_token(self, email, password, cache=True): | ||
url = f'{self.NAT_URL}/api/get_token/' | ||
response = self._request('POST', url, | ||
json={"email": email, "password": password}, | ||
timeout=self.TIMEOUT) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
|
||
Noirlab = NoirlabClass() |
Uh oh!
There was an error while loading. Please reload this page.