Skip to content

external_query.py

das(coord, radius, catalogues, api_url='https://das.datacentral.org.au/vast')

Performs a cone search with the DAS VAST API.

Parameters:

Name Type Description Default
coord SkyCoord

SkyCoord of the search center.

required
radius Angle

Angle of the search radius.

required
catalogues List[str]

List of catalogues to query.

required
api_url str

DAS API endpoint.

'https://das.datacentral.org.au/vast'

Returns:

Type Description
List[Dict[str, Any]]

List of dicts. Each dict contains: - object_name - database (catalogue) - separation_arcsec - ra_hms - dec_dms - object_url - otype (empty string, for serializer compatibility) - otype_long (empty string, for serializer compatibility)

Source code in vast_pipeline/utils/external_query.py
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
def das(
    coord: SkyCoord,
    radius: Angle,
    catalogues: List[str],
    api_url: str = "https://das.datacentral.org.au/vast",
) -> List[Dict[str, Any]]:
    """
    Performs a cone search with the DAS VAST API.

    Args:
        coord: SkyCoord of the search center.
        radius: Angle of the search radius.
        catalogues: List of catalogues to query.
        api_url: DAS API endpoint.

    Returns:
        List of dicts. Each dict contains:
            - object_name
            - database (catalogue)
            - separation_arcsec
            - ra_hms
            - dec_dms
            - object_url
            - otype (empty string, for serializer compatibility)
            - otype_long (empty string, for serializer compatibility)
    """

    naming_dict = {
        "I/355/gaiadr3": "Gaia DR3 ",
        "IV/39": "TIC ", #TIC
        "B/psr/psr": "PSR ", #PSR
        "VIII/65": "NVSS J",
        "J/ApJS/255/30": "VLASS ", #VLASS
        "II/365": "CatWISE ",
    }

    results: List[Dict[str, Any]] = []

    payload = {
        "ra": coord.ra.deg,
        "dec": coord.dec.deg,
        "radius": radius.to(u.deg).value,
        "catalogues": catalogues,
    }

    headers = {"Content-Type": "application/json"}

    try:
        response = requests.post(api_url, json=payload, headers=headers, timeout=30)
        response.raise_for_status()
        data = response.json()

        if data.get("status") != "ok":
            print(f"DAS API returned status: {data.get('status_msg')}")
            return results

        results_data = data.get("results", {})
        for cat in catalogues:
            cat_data = results_data.get(cat, {})
            if not cat_data:
                continue


            offsets = cat_data.get("offsets", [])
            ras = cat_data.get("ra", [])
            decs = cat_data.get("dec", [])
            ids = cat_data.get("ids", [])
            object_url_base = cat_data.get("object_url", "")

            for i in range(len(ids)):
                obj_coord = SkyCoord(ra=float(ras[i]), dec=float(decs[i]), unit="deg")
                results.append({
                    "object_name": f"{naming_dict[cat]}{ids[i]}",
                    "database": f"VizieR",
                    "separation_arcsec": float(offsets[i]) if i < len(offsets) else None,
                    "ra_hms": obj_coord.ra.to_string(unit="hourangle"),
                    "dec_dms": obj_coord.dec.to_string(unit="deg"),
                    "object_url": f"{object_url_base}{ids[i]}",
                    "otype": "",
                    "otype_long": "",
                })

    except (requests.RequestException, KeyError, ValueError) as exc:
        print(f"Error querying DAS API: {exc}")

    return results

fink(coord, radius)

Perform a cone search for sources with Fink.

Parameters:

Name Type Description Default
coord SkyCoord

The coordinate of the centre of the cone.

required
radius Angle

The radius of the cone in angular units.

required

Returns:

Type Description
List[Dict[str, Any]]

A list of dicts, where each dict is a query result row with the following keys:

  • object_name: the name of the transient.
  • database: the source of the result, i.e. TNS.
  • separation_arcsec: separation to the query coordinate in arcsec.
  • otype: object type.
  • otype_long: long form of the object type. Not given by TNS, will always be an empty string.
  • ra_hms: RA coordinate string in hms format.
  • dec_dms: Dec coordinate string in ±dms format.
Source code in vast_pipeline/utils/external_query.py
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
def fink(coord: SkyCoord, radius: Angle) -> List[Dict[str, Any]]:
    """Perform a cone search for sources with Fink.

    Args:
        coord: The coordinate of the centre of the cone.
        radius: The radius of the cone in angular units.

    Returns:
        A list of dicts, where each dict is a query result row with the following keys:

            - object_name: the name of the transient.
            - database: the source of the result, i.e. TNS.
            - separation_arcsec: separation to the query coordinate in arcsec.
            - otype: object type.
            - otype_long: long form of the object type. Not given by TNS, will always be
                an empty string.
            - ra_hms: RA coordinate string in hms format.
            - dec_dms: Dec coordinate string in ±dms format.
    """
    FINK_API_URL = "https://api.fink-portal.org/api/v1/"
    search_dict = {
        'ra': str(coord.ra.deg),
        'dec': str(coord.dec.deg),
        'radius': str(radius.arcsec)
      }
    r = requests.post(
        urljoin(FINK_API_URL,'conesearch'),
        json=search_dict
    )

    fink_results_dict_list: List[Dict[str, Any]]

    if r.ok:
        logger.debug(r.json())


        fink_results_dict_list = r.json()

        for result in fink_results_dict_list:
            object_coord = SkyCoord(
                    ra=result["i:ra"], dec=result["i:dec"], unit="deg"
                )
            result["otype"] = result['d:classification']
            result["otype_long"] = ""
            result['separation_arcsec'] = result['v:separation_degree']*3600.
            result["ra_hms"] = object_coord.ra.to_string(unit="hourangle")
            result["dec_dms"] = object_coord.dec.to_string(unit="deg")
            result['object_name'] = result['i:objectId']
            result['database'] = 'FINK'
            result['object_url'] = urljoin('https://fink-portal.org/',result['object_name'])

    return fink_results_dict_list

ned(coord, radius)

Perform a cone search for sources with NED.

Parameters:

Name Type Description Default
coord SkyCoord

The coordinate of the centre of the cone.

required
radius Angle

The radius of the cone in angular units.

required

Returns:

Type Description
List[Dict[str, Any]]

A list of dicts, where each dict is a query result row with the following keys:

  • object_name: the name of the astronomical object.
  • database: the source of the result, i.e. NED.
  • separation_arcsec: separation to the query coordinate in arcsec.
  • otype: object type.
  • otype_long: long form of the object type.
  • ra_hms: RA coordinate string in hms format.
  • dec_dms: Dec coordinate string in ±dms format.
Source code in vast_pipeline/utils/external_query.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
def ned(coord: SkyCoord, radius: Angle) -> List[Dict[str, Any]]:
    """Perform a cone search for sources with NED.

    Args:
        coord: The coordinate of the centre of the cone.
        radius: The radius of the cone in angular units.

    Returns:
        A list of dicts, where each dict is a query result row with the following keys:

            - object_name: the name of the astronomical object.
            - database: the source of the result, i.e. NED.
            - separation_arcsec: separation to the query coordinate in arcsec.
            - otype: object type.
            - otype_long: long form of the object type.
            - ra_hms: RA coordinate string in hms format.
            - dec_dms: Dec coordinate string in ±dms format.
    """
    # NED API doesn't supply the long-form object types.
    # Copied from https://ned.ipac.caltech.edu/Documents/Guides/Database
    NED_OTYPES = {
        "*": "Star or Point Source",
        "**": "Double star",
        "*Ass": "Stellar association",
        "*Cl": "Star cluster",
        "AbLS": "Absorption line system",
        "Blue*": "Blue star",
        "C*": "Carbon star",
        "EmLS": "Emission line source",
        "EmObj": "Emission object",
        "exG*": "Extragalactic star (not a member of an identified galaxy)",
        "Flare*": "Flare star",
        "G": "Galaxy",
        "GammaS": "Gamma ray source",
        "GClstr": "Cluster of galaxies",
        "GGroup": "Group of galaxies",
        "GPair": "Galaxy pair",
        "GTrpl": "Galaxy triple",
        "G_Lens": "Lensed image of a galaxy",
        "HII": "HII region",
        "IrS": "Infrared source",
        "MCld": "Molecular cloud",
        "Neb": "Nebula",
        "Nova": "Nova",
        "Other": "Other classification (e.g. comet; plate defect)",
        "PN": "Planetary nebula",
        "PofG": "Part of galaxy",
        "Psr": "Pulsar",
        "QGroup": "Group of QSOs",
        "QSO": "Quasi-stellar object",
        "Q_Lens": "Lensed image of a QSO",
        "RadioS": "Radio source",
        "Red*": "Red star",
        "RfN": "Reflection nebula",
        "SN": "Supernova",
        "SNR": "Supernova remnant",
        "UvES": "Ultraviolet excess source",
        "UvS": "Ultraviolet source",
        "V*": "Variable star",
        "VisS": "Visual source",
        "WD*": "White dwarf",
        "WR*": "Wolf-Rayet star",
        "XrayS": "X-ray source",
        "!*": "Galactic star",
        "!**": "Galactic double star",
        "!*Ass": "Galactic star association",
        "!*Cl": "Galactic Star cluster",
        "!Blue*": "Galactic blue star",
        "!C*": "Galactic carbon star",
        "!EmObj": "Galactic emission line object",
        "!Flar*": "Galactic flare star",
        "!HII": "Galactic HII region",
        "!MCld": "Galactic molecular cloud",
        "!Neb": "Galactic nebula",
        "!Nova": "Galactic nova",
        "!PN": "Galactic planetary nebula",
        "!Psr": "Galactic pulsar",
        "!RfN": "Galactic reflection nebula",
        "!Red*": "Galactic red star",
        "!SN": "Galactic supernova",
        "!SNR": "Galactic supernova remnant",
        "!V*": "Galactic variable star",
        "!WD*": "Galactic white dwarf",
        "!WR*": "Galactic Wolf-Rayet star",
    }
    ned_result_table = Ned.query_region(coord, radius=radius)
    if ned_result_table is None or len(ned_result_table) == 0:
        ned_results_dict_list = []
    else:
        ned_results_df = ned_result_table[
            ["Object Name", "Separation", "Type", "RA", "DEC"]
        ].to_pandas()
        ned_results_df = ned_results_df.rename(
            columns={
                "Object Name": "object_name",
                "Separation": "separation_arcsec",
                "Type": "otype",
                "RA": "ra_hms",
                "DEC": "dec_dms",
            }
        )
        ned_results_df["otype_long"] = ned_results_df.otype.replace(NED_OTYPES)
        # convert NED result separation (arcmin) to arcsec
        ned_results_df["separation_arcsec"] = ned_results_df["separation_arcsec"] * 60
        # convert coordinates to RA (hms) Dec (dms) strings
        ned_results_df["ra_hms"] = Longitude(
            ned_results_df["ra_hms"], unit="deg"
        ).to_string(unit="hourangle")
        ned_results_df["dec_dms"] = Latitude(
            ned_results_df["dec_dms"], unit="deg"
        ).to_string(unit="deg")
        ned_results_df["database"] = "NED"
        # convert dataframe to dict and replace float NaNs with None for JSON encoding
        ned_results_dict_list = ned_results_df.sort_values("separation_arcsec").to_dict(
            orient="records"
        )
    return ned_results_dict_list

simbad(coord, radius)

Perform a cone search for sources with SIMBAD.

Parameters:

Name Type Description Default
coord SkyCoord

The coordinate of the centre of the cone.

required
radius Angle

The radius of the cone in angular units.

required

Returns:

Type Description
List[Dict[str, Any]]

A list of dicts, where each dict is a query result row with the following keys:

  • object_name: the name of the astronomical object.
  • database: the source of the result, i.e. SIMBAD.
  • separation_arcsec: separation to the query coordinate in arcsec.
  • otype: object type.
  • otype_long: long form of the object type.
  • ra_hms: RA coordinate string in hms format.
  • dec_dms: Dec coordinate string in ±dms format.
Source code in vast_pipeline/utils/external_query.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def simbad(coord: SkyCoord, radius: Angle) -> List[Dict[str, Any]]:
    """Perform a cone search for sources with SIMBAD.

    Args:
        coord: The coordinate of the centre of the cone.
        radius: The radius of the cone in angular units.

    Returns:
        A list of dicts, where each dict is a query result row with the following keys:

            - object_name: the name of the astronomical object.
            - database: the source of the result, i.e. SIMBAD.
            - separation_arcsec: separation to the query coordinate in arcsec.
            - otype: object type.
            - otype_long: long form of the object type.
            - ra_hms: RA coordinate string in hms format.
            - dec_dms: Dec coordinate string in ±dms format.
    """
    CustomSimbad = Simbad()
    CustomSimbad.add_votable_fields(
        "distance_result",
        "otype(S)",
        "otype(V)",
        "otypes",
    )
    try:
        simbad_result_table = CustomSimbad.query_region(coord, radius=radius)
    except requests.HTTPError:
        # try the Harvard mirror
        CustomSimbad.SIMBAD_URL = "https://simbad.harvard.edu/simbad/sim-script"
        simbad_result_table = CustomSimbad.query_region(coord, radius=radius)
    if simbad_result_table is None:
        simbad_results_dict_list = []
    else:
        simbad_results_df = simbad_result_table[
            ["MAIN_ID", "DISTANCE_RESULT", "OTYPE_S", "OTYPE_V", "RA", "DEC"]
        ].to_pandas()
        simbad_results_df = simbad_results_df.rename(
            columns={
                "MAIN_ID": "object_name",
                "DISTANCE_RESULT": "separation_arcsec",
                "OTYPE_S": "otype",
                "OTYPE_V": "otype_long",
                "RA": "ra_hms",
                "DEC": "dec_dms",
            }
        )
        simbad_results_df["database"] = "SIMBAD"
        # convert coordinates to RA (hms) Dec (dms) strings
        simbad_results_df["ra_hms"] = Longitude(
            simbad_results_df["ra_hms"], unit="hourangle"
        ).to_string(unit="hourangle")
        simbad_results_df["dec_dms"] = Latitude(
            simbad_results_df["dec_dms"], unit="deg"
        ).to_string(unit="deg")
        simbad_results_dict_list = simbad_results_df.to_dict(orient="records")
    return simbad_results_dict_list

tns(coord, radius)

Perform a cone search for sources with the Transient Name Server (TNS).

Parameters:

Name Type Description Default
coord SkyCoord

The coordinate of the centre of the cone.

required
radius Angle

The radius of the cone in angular units.

required

Returns:

Type Description
List[Dict[str, Any]]

A list of dicts, where each dict is a query result row with the following keys:

  • object_name: the name of the transient.
  • database: the source of the result, i.e. TNS.
  • separation_arcsec: separation to the query coordinate in arcsec.
  • otype: object type.
  • otype_long: long form of the object type. Not given by TNS, will always be an empty string.
  • ra_hms: RA coordinate string in hms format.
  • dec_dms: Dec coordinate string in ±dms format.
Source code in vast_pipeline/utils/external_query.py
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
def tns(coord: SkyCoord, radius: Angle) -> List[Dict[str, Any]]:
    """Perform a cone search for sources with the Transient Name Server (TNS).

    Args:
        coord: The coordinate of the centre of the cone.
        radius: The radius of the cone in angular units.

    Returns:
        A list of dicts, where each dict is a query result row with the following keys:

            - object_name: the name of the transient.
            - database: the source of the result, i.e. TNS.
            - separation_arcsec: separation to the query coordinate in arcsec.
            - otype: object type.
            - otype_long: long form of the object type. Not given by TNS, will always be
                an empty string.
            - ra_hms: RA coordinate string in hms format.
            - dec_dms: Dec coordinate string in ±dms format.
    """

    TNS_API_URL = "https://www.wis-tns.org/api/"
    headers = {
        "user-agent": settings.TNS_USER_AGENT,
    }

    search_dict = {
        "ra": coord.ra.to_string(unit="hourangle", sep=":", pad=True),
        "dec": coord.dec.to_string(unit="deg", sep=":", alwayssign=True, pad=True),
        "radius": str(radius.value),
        "units": radius.unit.name,
    }
    r = requests.post(
        urljoin(TNS_API_URL, "get/search"),
        data={"api_key": settings.TNS_API_KEY, "data": json.dumps(search_dict)},
        headers=headers,
    )
    tns_results_dict_list: List[Dict[str, Any]]
    if r.ok:
        logger.debug(r.json())
        tns_results_dict_list = r.json()["data"]
        # Get details for each object result. TNS API doesn't support doing this in one
        # request, so we iterate.
        for result in tns_results_dict_list:
            search_dict = {
                "objname": result["objname"],
            }
            r = requests.post(
                urljoin(TNS_API_URL, "get/object"),
                data={"api_key": settings.TNS_API_KEY, "data": json.dumps(search_dict)},
                headers=headers,
            )
            if r.ok:
                logger.debug(r.json())
                object_dict = r.json()["data"]
                object_coord = SkyCoord(
                    ra=object_dict["radeg"], dec=object_dict["decdeg"], unit="deg"
                )
                result["otype"] = object_dict["object_type"]["name"]
                if result["otype"] is None:
                    result["otype"] = ""
                result["otype_long"] = ""
                result["separation_arcsec"] = coord.separation(object_coord).arcsec
                result["ra_hms"] = object_coord.ra.to_string(unit="hourangle")
                result["dec_dms"] = object_coord.dec.to_string(unit="deg")
                result["database"] = "TNS"
                result["object_name"] = object_dict["objname"]
    return tns_results_dict_list