Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
preview_images : list
A list of preview images available in the filesystem for the
given instrument.
"""
# Make sure the instrument is of the proper format (e.g. "Nircam")
instrument = inst[0].upper() + inst[1:].lower()
# Query MAST for all rootnames for the instrument
service = "Mast.Jwst.Filtered.{}".format(instrument)
params = {"columns": "filename",
"filters": []}
response = Mast.service_request_async(service, params)
results = response[0].json()['data']
# Parse the results to get the rootnames
filenames = [result['filename'].split('.')[0] for result in results]
# Get list of all preview_images
preview_images = glob.glob(os.path.join(PREVIEW_IMAGE_FILESYSTEM, '*', '*.jpg'))
# Get subset of preview images that match the filenames
preview_images = [os.path.basename(item) for item in preview_images if
os.path.basename(item).split('_integ')[0] in filenames]
# Return only
return preview_images
List of all filepaths in database for the provided
instrument
filenames: list
List of all filenames in database for the provided
instrument
"""
instrument = instrument.upper()
if self.db_type == 'SQL':
results = self.session.query(self.ObservationWebtest)\
.filter(self.ObservationWebtest.instrument == instrument)
elif self.db_type == 'MAST':
params = {"columns": "*",
"filters": []}
response = Mast.service_request_async(self.service, params)
results = response[0].json()['data']
filepaths = []
filenames = []
for i in results:
if self.db_type == 'SQL':
filename = i.filename
elif self.db_type == 'MAST':
filename = i['filename']
prog_id = filename[2:7]
file_path = os.path.join('jw' + prog_id, filename)
filepaths.append(file_path)
filenames.append(filename)
return filepaths, filenames
----------
mnemonic_identifier : str
Telemetry mnemonic identifier, e.g. ``SA_ZFGOUTFOV``
token : str
MAST token
Returns
-------
info : dict
Object that contains the returned data
"""
mast_authenticate(token=token)
parameters = {"mnemonic": "{}".format(mnemonic_identifier)}
result = Mast.service_request_async(mast_edb_dictionary_service, parameters)
info = process_mast_service_request_result(result, data_as_table=False)[0]
return info
for name, val in add_filters.items()]
# Assemble the request
params = {'columns': 'COUNT_BIG(*)',
'filters': filters,
'removenullcolumns': True}
# Just get the counts
if return_data:
params['columns'] = '*'
# Add requests
if isinstance(add_requests, dict):
params.update(add_requests)
response = Mast.service_request_async(service, params)
result = response[0].json()
# Return all the data
if return_data:
return result
# Or just the counts
else:
return result['data'][0]['Column1']
for name, val in add_filters.items()]
# Assemble the request
params = {'columns': 'COUNT_BIG(*)',
'filters': filters,
'removenullcolumns': True}
# Just get the counts
if return_data:
params['columns'] = '*'
# Add requests
if isinstance(add_requests, dict):
params.update(add_requests)
response = Mast.service_request_async(service, params)
result = response[0].json()
# Return all the data
if return_data:
return result
# Or just the counts
else:
return result['data'][0]['Column1']
def monitor_template_main():
""" The main function of the ``monitor_template`` module."""
# Example of logging
my_variable = 'foo'
logging.info('Some useful information: {}'.format(my_variable))
# Example of querying for a dataset via MAST API
service = "Mast.Jwst.Filtered.Niriss"
params = {"columns": "filename",
"filters": [{"paramName": "filter",
"values": ['F430M']}]}
response = Mast.service_request_async(service, params)
result = response[0].json()['data']
filename_of_interest = result[0]['filename'] # jw00304002001_02102_00001_nis_uncal.fits
# Example of parsing a filename
filename_dict = filename_parser(filename_of_interest)
# Contents of filename_dict:
# {'program_id': '00304',
# 'observation': '002',
# 'visit': '001',
# 'visit_group': '02',
# 'parallel_seq_id': '1',
# 'activity': '02',
# 'exposure_id': '00001',
# 'detector': 'nis',
# 'suffix': 'uncal'}