Skip to content

Commit

Permalink
specializd methods
Browse files Browse the repository at this point in the history
  • Loading branch information
burnout87 committed Sep 18, 2023
1 parent 941a685 commit 09352bf
Showing 1 changed file with 117 additions and 2 deletions.
119 changes: 117 additions & 2 deletions oda_api/gallery_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,124 @@ def get_yaml_files_observation_with_title(self,
return response_json


def get_list_lightcurve_with_conditions(self,
token: str = None,
instrument=None,
src_name=None,
e1_kev=None, e2_kev=None,
t1=None, t2=None
):
rev1_value = None
if t1 is not None:
params = {'time_to_convert': t1,

Check warning on line 144 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L142-L144

Added lines #L142 - L144 were not covered by tests
'token': token}

c = requests.get(os.path.join(self.url, "get_revnum"),

Check warning on line 147 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L147

Added line #L147 was not covered by tests
params={**params}
)
revnum_obj = c.json()
rev1_value = revnum_obj['revnum']

Check warning on line 151 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L150-L151

Added lines #L150 - L151 were not covered by tests

rev2_value = None
if t2 is not None:
params = {'time_to_convert': t2,

Check warning on line 155 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L153-L155

Added lines #L153 - L155 were not covered by tests
'token': token}

c = requests.get(os.path.join(self.url, "get_revnum"),

Check warning on line 158 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L158

Added line #L158 was not covered by tests
params={**params}
)
revnum_obj = c.json()
rev2_value = revnum_obj['revnum']

Check warning on line 162 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L161-L162

Added lines #L161 - L162 were not covered by tests

return self.get_list_products_with_conditions(token=token,

Check warning on line 164 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L164

Added line #L164 was not covered by tests
instrument_name=instrument,
product_type='lightcurve',
src_name=src_name,
e1_kev=e1_kev,
e2_kev=e2_kev,
rev1_value=rev1_value,
rev2_value=rev2_value)

def get_list_spectra_with_conditions(self,
token: str = None,
instrument=None,
src_name=None,
t1=None, t2=None
):
rev1_value = None
if t1 is not None:
params = {'time_to_convert': t1,

Check warning on line 181 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L179-L181

Added lines #L179 - L181 were not covered by tests
'token': token}

c = requests.get(os.path.join(self.url, "get_revnum"),

Check warning on line 184 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L184

Added line #L184 was not covered by tests
params={**params}
)
revnum_obj = c.json()
rev1_value = revnum_obj['revnum']

Check warning on line 188 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L187-L188

Added lines #L187 - L188 were not covered by tests

rev2_value = None
if t2 is not None:
params = {'time_to_convert': t2,

Check warning on line 192 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L190-L192

Added lines #L190 - L192 were not covered by tests
'token': token}

c = requests.get(os.path.join(self.url, "get_revnum"),

Check warning on line 195 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L195

Added line #L195 was not covered by tests
params={**params}
)
revnum_obj = c.json()
rev2_value = revnum_obj['revnum']

Check warning on line 199 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L198-L199

Added lines #L198 - L199 were not covered by tests

return self.get_list_products_with_conditions(token=token,

Check warning on line 201 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L201

Added line #L201 was not covered by tests
instrument_name=instrument,
src_name=src_name,
product_type='spectrum',
rev1_value=rev1_value,
rev2_value=rev2_value)


def get_list_products_with_conditions(self,
token: str = None,
**kwargs):

"""
:param token: user token
:param kwargs: keyword arguments representing the main parameters values used to generate the product. Amongst them,
it is important to mention the following ones:
* instrument_name: name of the instrument used for the generated product (e.g. isgri, jemx1)
* product_type: type of product generated (e.g. lightcurve, image)
* src_name: name of a single, or a list of, known sources (eg Crab, Cyg X-1)
* others: other parameters used for the product. Not all the parameters are currently supported,
but the list of the supported ones will be extended. E1_kev=25
"""

params = {

Check warning on line 224 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L224

Added line #L224 was not covered by tests
'token': token,
**kwargs
}

res = requests.get(os.path.join(self.url, "get_data_product_list_with_conditions"),

Check warning on line 229 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L229

Added line #L229 was not covered by tests
params=params
)

if res.status_code != 200:
response_json = res.json()
error_message = (f"An issue occurred while performing a request on the product gallery, "

Check warning on line 235 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L233-L235

Added lines #L233 - L235 were not covered by tests
f"the following error was returned:\n")
if 'error_message' in response_json:
error_message += '\n' + response_json['error_message']
if 'drupal_helper_error_message' in response_json:
error_message += '-' + response_json['drupal_helper_error_message']

Check warning on line 240 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L237-L240

Added lines #L237 - L240 were not covered by tests
else:
error_message += res.text
logger.warning(error_message)

Check warning on line 243 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L242-L243

Added lines #L242 - L243 were not covered by tests
else:
response_json = self._decode_res_json(res)

Check warning on line 245 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L245

Added line #L245 was not covered by tests

return response_json

Check warning on line 247 in oda_api/gallery_api.py

View check run for this annotation

Codecov / codecov/patch

oda_api/gallery_api.py#L247

Added line #L247 was not covered by tests


def get_list_products_by_source_name(self,
source_name: str = None,
token: str = None):
source_name: str = None,
token: str = None):

params = {
'token': token,
Expand Down

0 comments on commit 09352bf

Please sign in to comment.