Skip to content

Commit

Permalink
function renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
burnout87 committed Sep 22, 2023
1 parent af1e7b8 commit 9807e0d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
48 changes: 30 additions & 18 deletions oda_api/gallery_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,40 @@ def get_yaml_files_observation_with_title(self,

return response_json

def get_list_images_angular_distance(self,
token: str = None,
instrument=None,
e1_kev=None, e2_kev=None,
t1=None, t2=None,
ra_ref=None, dec_ref=None,
r=None
):

product_list = self.get_list_images_with_conditions(token=token,
instrument=instrument,
e1_kev=e1_kev, e2_kev=e2_kev,
t1=t1, t2=t2)

if isinstance(product_list, list) and ra_ref is not None and dec_ref is not None and r is not None:
source_coord_ref = SkyCoord(ra_ref, dec_ref, unit=(u.deg, u.deg))

ra_values_prod_list = list(map(lambda x: x['ra'], filter(lambda x: 'ra' in x, product_list)))
dec_values_prod_list = list(map(lambda x: x['dec'], filter(lambda x: 'dec' in x, product_list)))
coords_prod_list = SkyCoord(ra_values_prod_list, dec_values_prod_list, unit=(u.deg, u.deg))

separation = source_coord_ref.separation(coords_prod_list).deg

ind = (separation <= r)

product_list = list(np.array(product_list)[ind])

return product_list

def get_list_images_with_conditions(self,
token: str = None,
instrument=None,
e1_kev=None, e2_kev=None,
t1=None, t2=None,
ra_ref=None, dec_ref=None,
r=None
t1=None, t2=None
):
rev1_value = None
if t1 is not None:
Expand All @@ -164,28 +190,14 @@ def get_list_images_with_conditions(self,
revnum_obj = c.json()
rev2_value = revnum_obj['revnum']

product_list = self.get_list_products_with_conditions(token=token,
return self.get_list_products_with_conditions(token=token,
instrument_name=instrument,
product_type='image',
e1_kev=e1_kev,
e2_kev=e2_kev,
rev1_value=rev1_value,
rev2_value=rev2_value)

if isinstance(product_list, list) and ra_ref is not None and dec_ref is not None and r is not None:
source_coord_ref = SkyCoord(ra_ref, dec_ref, unit=(u.deg, u.deg))

ra_values_prod_list = list(map(lambda x: x['ra'], filter(lambda x: 'ra' in x, product_list)))
dec_values_prod_list = list(map(lambda x: x['dec'], filter(lambda x: 'dec' in x, product_list)))
coords_prod_list = SkyCoord(ra_values_prod_list, dec_values_prod_list, unit=(u.deg, u.deg))

separation = source_coord_ref.separation(coords_prod_list).deg

ind = (separation <= r)

product_list = list(np.array(product_list)[ind])

return product_list

def get_list_lightcurve_with_conditions(self,
token: str = None,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_drupal.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,11 @@ def test_product_gallery_get_product_with_conditions(dispatcher_api_with_gallery

elif product_type == 'image':
for r in [0, 20, 200]:
images_list = disp.get_list_images_with_conditions(e1_kev=100, e2_kev=400,
t1='2022-07-20T00:00:00', t2='2022-08-24T23:59:59',
ra_ref=100, dec_ref=0, r=r,
instrument=instrument_name,
token=encoded_token)
images_list = disp.get_list_images_angular_distance(e1_kev=100, e2_kev=400,
t1='2022-07-20T00:00:00', t2='2022-08-24T23:59:59',
ra_ref=100, dec_ref=0, r=r,
instrument=instrument_name,
token=encoded_token)
assert isinstance(images_list, list)

if r > 20:
Expand Down

0 comments on commit 9807e0d

Please sign in to comment.