Skip to content

Commit e9571f3

Browse files
committed
Add conesearch
1 parent c302f97 commit e9571f3

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

docs/services/api/conesearch.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
!!! info "List of arguments"
2+
The list of arguments for running a conesearch can be found on the [schema page :lucide-external-link:](https://lsst.fink-portal.org/schemas){target="blank_"} and you can also retrieve it [programmatically](definitions.md).
3+
4+
## Simple conesearch
5+
6+
This service allows you to search objects in the database matching in position on the sky given by (RA, Dec, radius). The initializer for RA/Dec is very flexible and supports inputs provided in a number of convenient formats. The following ways of initializing a conesearch are all equivalent:
7+
8+
* 8.986275, -42.709834, 5
9+
* 00h35m56.71s, -42d42m35.40s, 5
10+
* 00 35 56.71, -42 42 35.40, 5
11+
* 00:35:56.71, -42:42:35.40, 5
12+
13+
!!! warning "Search radius"
14+
The search radius is always in arcsecond, and the maximum radius length is 18,000 arcseconds (5 degrees).
15+
16+
Try this on a terminal:
17+
18+
=== "Python"
19+
20+
```python
21+
import io
22+
import requests
23+
import pandas as pd
24+
25+
# Get all objects falling within (center, radius) = ((ra, dec), radius)
26+
r = requests.post(
27+
"https://api.lsst.fink-portal.org/api/v1/conesearch",
28+
json={
29+
"ra": "8.986275",
30+
"dec": "-42.709834",
31+
"radius": "5",
32+
"columns": "r:diaObjectId,r:midpointMjdTai,r:psfFlux,r:psfFluxErr", # (1)!
33+
}
34+
)
35+
36+
# Format output in a DataFrame
37+
pdf = pd.read_json(io.BytesIO(r.content))
38+
```
39+
40+
1. Select only the column(s) you need to get faster results!
41+
=== "curl"
42+
43+
```bash
44+
# Get all objects falling within (center, radius) = ((ra, dec), radius)
45+
curl -H "Content-Type: application/json" -X POST \
46+
-d '{"ra":"8.986275", "dec":"-42.709834", "radius":"5"}' \
47+
https://api.lsst.fink-portal.org/api/v1/conesearch -o conesearch.json
48+
```
49+
=== "wget"
50+
51+
```bash
52+
# you can also specify parameters in the URL, e.g. with wget:
53+
wget "https://api.lsst.fink-portal.org/api/v1/conesearch?ra=8.986275&dec=-42.709834&radius=5&output-format=json" -O conesearch.json
54+
```
55+
56+
Note that in case of several objects matching, the results will be sorted according to the column
57+
`v:separation_degree`, which is the angular separation in degree between the input (ra, dec) and the objects found. In addition, you can specify time boundaries:
58+
59+
=== "Python"
60+
61+
```python
62+
import io
63+
import requests
64+
import pandas as pd
65+
66+
# Get all objects falling within (center, radius) = ((ra, dec), radius)
67+
# between 2025-12-10 05:59:37.000 (included) and 2025-12-17 05:59:37.000 (excluded)
68+
r = requests.post(
69+
"https://api.lsst.fink-portal.org/api/v1/conesearch",
70+
json={
71+
"ra": "7.4550",
72+
"dec": "-44.635",
73+
"radius": "150",
74+
"startdate": "2025-12-10 05:59:37.000",
75+
"window": 7 # in days
76+
}
77+
)
78+
79+
# Format output in a DataFrame
80+
pdf = pd.read_json(io.BytesIO(r.content))
81+
```
82+
83+
Instead of `window`, you can also use `stopdate`.
84+
85+
!!! warning "Time boundaries and first detection"
86+
When specifying time boundaries, you will restrict the search to alerts whose first detection was within the specified range of dates (and not all transients seen during this period).
87+
88+
Note that we group information and only display the data from the last alert. Hence, if you need lightcurves, that is to query all the _sources_ data for the `diaObjectId` found with a conesearch, you would do it in two steps:
89+
90+
=== "Python"
91+
92+
```python
93+
import io
94+
import requests
95+
import pandas as pd
96+
97+
# Get the diaObjectId for the alert(s) within a circle on the sky
98+
r0 = requests.post(
99+
"https://api.lsst.fink-portal.org/api/v1/conesearch",
100+
json={
101+
"ra": "7.4550",
102+
"dec": "-44.635",
103+
"radius": "5",
104+
"columns": "r:diaObjectId,r:midpointMjdTai"
105+
}
106+
)
107+
108+
mylist = [val["r:diaObjectId"] for val in r0.json()]
109+
# len(mylist) = 26
110+
111+
# get full lightcurves for all these alerts
112+
r1 = requests.post(
113+
"https://api.lsst.fink-portal.org/api/v1/sources",
114+
json={
115+
"diaObjectId": ",".join(mylist),
116+
"columns": "r:diaObjectId,r:midpointMjdTai,r:psfFlux,r:psfFluxErr",
117+
"output-format": "json"
118+
}
119+
)
120+
121+
# Format output in a DataFrame
122+
pdf = pd.read_json(io.BytesIO(r1.content))
123+
# len(pdf) = 34
124+
125+
# group by diaObjectId
126+
pdf.groupby("r:diaObjectId").value_counts()
127+
```
128+
129+
## Crossmatch with catalogs
130+
131+
You can easily perform a crossmatch with a catalog of astronomical sources by looping over entries:
132+
133+
=== "Python"
134+
135+
```python
136+
mycatalog = read(...)
137+
138+
for source in mycatalog:
139+
r0 = requests.post(
140+
"https://api.lsst.fink-portal.org/api/v1/conesearch",
141+
json={
142+
"ra": source["ra"],
143+
"dec": source["dec"],
144+
"radius": "5",
145+
"columns": "r:diaObjectId,r:midpointMjdTai"
146+
}
147+
)
148+
149+
# do whatever
150+
```
151+
152+
But note that for 10,000+ sources, this can be pretty slow, and impact other users. Instead for large catalogs, prefer the [Xmatch service](../../services/xmatch.md).

0 commit comments

Comments
 (0)