Skip to content

Commit

Permalink
added explanation of responses of catshtm and whare are we doing with…
Browse files Browse the repository at this point in the history
… it in the htmx
  • Loading branch information
claudiomansillab committed Nov 18, 2024
1 parent 3464cca commit 030fecc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lightcurve/src/crossmatch_api/get_crossmatch_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import requests

def get_alerce_data(ra, dec, radius):

'''
The catshtm api returns a list with every survey with information in a radius (we use 20 arcsec). Every element in this list is a dictionary with
a survey and all his information. Every dictionary has a key that is the name of the survey and a value that is another dictionary with all the information.
An example of the xmatch response of the object ZTF22aafsqud (not complete because of space):
[{'2MASS': {'Dec': {'unit': 'deg', 'value': 12.072615}, 'Epoch': {'unit': 'JD', 'value': 2450935.7423}, 'ErrMaj': {'unit': 'arcsec', 'value': 0.22}, 'MagErr_H': {'unit': 'mag', 'value': None}, 'MagErr_J': {'unit': 'mag', 'value': 0.147}, 'MagErr_K': {'unit': 'mag', 'value': None}, 'Mag_H': {'unit': 'mag', 'value': 15.02}, 'Mag_J': {'unit': 'mag', 'value': 16.442}, 'Mag_K': {'unit': 'mag', 'value': 14.647}, 'RA': {'unit': 'deg', 'value': 207.026368}, 'distance': {'unit': 'arcsec', 'value': 8.548347834032453}}},
{'2MASSxsc': {'Dec': {'unit': 'deg', 'value': 12.072708055555553}, 'H_K20e': {'unit': 'mag', 'value': 14.352999687194824}, 'Hb_a': {'unit': ' ', 'value': 0.4399999976158142}, 'Hpa': {'unit': 'deg', 'value': 30.0}, 'J_K20e': {'unit': 'mag', 'value': 14.852999687194824}, 'Jb_a': {'unit': ' ', 'value': 0.4000000059604645}, 'Jpa': {'unit': 'deg', 'value': 40.0}, 'K_K20e': {'unit': 'mag', 'value': 13.970999717712402}, 'Kb_a': {'unit': ' ', 'value': 0.4000000059604645}, 'Kpa': {'unit': 'deg', 'value': 40.0}, 'RA': {'unit': 'deg', 'value': 207.02645888888887}, 'distance': {'unit': 'arcsec', 'value': 8.286119001911564}, 'e_H_K20e': {'unit': 'mag', 'value': 0.13300000131130219}, 'e_J_K20e': {'unit': 'mag', 'value': 0.0820000022649765}, 'e_K_K20e': {'unit': 'mag', 'value': 0.1589999943971634}, 'r_K20e': {'unit': 'arcsec', 'value': 9.600000381469727}}},
{'DECaLS': ...},
...]
In this example we can see the name of the surveys (keys) and the values that has every survey in a dictionary (values)
'''


base_url = "https://catshtm.alerce.online/crossmatch_all"

# Parameters for the API request
Expand Down
14 changes: 12 additions & 2 deletions lightcurve/src/crossmatch_api/routes/htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
directory="src/crossmatch_api/templates", autoescape=True, auto_reload=True
)
templates.env.globals["API_URL"] = os.getenv(
"API_URL", "http://localhost:8005"
"API_URL", "http://localhost:8000"
)

@router.get("/crossmatch/{oid}", response_class=HTMLResponse)
Expand All @@ -29,6 +29,16 @@ async def object_mag_app(

cross = get_alerce_data(object.meanra, object.meandec, 20)

'''
get_alerce_data returns a list with several dictionaries. The dict format is one key and then a value that is another dictionary.
Something like:
[{'name1': {key1: info1, key2: info2, key3: info3, ...}}, 'name2' : {key4: info4, key5: info5, key6: info7, ...}, ...]
In the next iteration we want to fill cross_keys with 'name1', 'name2', ... ,i.e., we want to fill cross_keys with the first (and only) key in every dict
so the approach is to take every dict in the list and then take the first key (and only) in the dictionary with next(iter(...))
'''

cross_keys = []
for i in range(len(cross)):
cross_keys.append(next(iter(cross[i].keys())))
Expand All @@ -39,4 +49,4 @@ async def object_mag_app(
'cross': cross,
'crossKeys': cross_keys
},
)
)

0 comments on commit 030fecc

Please sign in to comment.