API Reference¶
This API reference describes the Python interface to the ASI-SSDC SED Builder service. The package provides functions to query astronomical sources and convert spectral energy distribution data into various formats.
Note
At present, only internally hosted catalogs are supported. More will come.
Functions¶
get_data(ra, dec, timeout=30.0)
¶
Queries the SSDC SED Builder API to retrieve Spectral Energy Distribution data for the specified sky coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ra
|
Annotated[float, Field(ge=0.0, lt=360.0, description='Right ascension in degrees.')]
|
Right ascension in degrees (0 to 360). |
required |
dec
|
Annotated[float, Field(ge=-90.0, le=90.0, description='Declination in degrees.')]
|
Declination in degrees (-90 to 90). |
required |
timeout
|
Annotated[Union[float, int], Field(gt=0.0, description='Request timeout in seconds.')]
|
Request timeout in seconds (default: 30.0). |
30.0
|
Returns:
| Type | Description |
|---|---|
GetDataResponse
|
A response object. Use its methods to recover data in different formats. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If coordinates are out of valid range. |
TimeoutError
|
If the API request exceeds the timeout. |
RuntimeError
|
If the API request fails for other reasons. |
Example
from sedbuilder import get_data
# Get response from SED for astronomical coordinates
response = get_data(ra=194.04625, dec=-5.789167)
# Access data in different formats
table = response.to_astropy() # Astropy Table
data_dict = response.to_dict() # Python dictionary
jt = response.to_jetset(z=0.034) # Jetset table
json_str = response.to_json() # JSON string
df = response.to_pandas() # Pandas DataFrame (requires pandas)
Source code in sedbuilder/requests.py
get_data_from_json(filepath)
¶
Reads a JSON file containing SED Builder API response data and validates it
against get_data response schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Annotated[FilePath, Field(description='Path to JSON file.')]
|
Path to a JSON file containing SED Builder response data.
The file must exist and contain valid JSON matching the |
required |
Returns:
| Type | Description |
|---|---|
GetDataResponse
|
Response object with validated SED data. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the file does not exist, or if file content does not match the expected response schema. |
Source code in sedbuilder/utils.py
catalogs(timeout=30.0)
¶
Queries the SSDC SED Builder API to retrieve the list of available catalogs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
Annotated[Union[float, int], Field(gt=0.0, description='Request timeout in seconds.')]
|
Request timeout in seconds (default: 30.0). |
30.0
|
Returns:
| Type | Description |
|---|---|
CatalogsResponse
|
A response object containing catalog information. Use its methods to recover data in different formats. |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the API request exceeds the timeout. |
RuntimeError
|
If the API request fails for other reasons. |
Example
Source code in sedbuilder/requests.py
catalogs_from_json(filepath)
¶
Reads a JSON file containing SED Builder API catalog data and validates it
against catalogs response schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Annotated[FilePath, Field(description='Path to JSON file.')]
|
Path to a JSON file containing SED Builder catalog data.
The file must exist and contain valid JSON matching the |
required |
Returns:
| Type | Description |
|---|---|
CatalogsResponse
|
Response object with validated catalog information. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the file does not exist, or if file content does not match the expected response schema. |
Source code in sedbuilder/utils.py
Classes¶
GetDataResponse
¶
Bases: BaseModel
SED Builder API response to getData endpoint.
To retrieve data you call .to_astropy(), or .to_dict() and other methods.
Attributes:
| Name | Type | Description |
|---|---|---|
ResponseInfo |
ResponseInfo
|
Status information about the API response. |
Properties |
Properties
|
Additional science properties for the queried source. |
Datasets |
list[Dataset]
|
List of catalog entries with measurements. |
Meta |
Meta
|
Metadata about the response format and other non-science info. |
Source code in sedbuilder/schemas.py
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 262 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 315 316 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 403 404 405 406 407 408 409 410 411 412 413 414 | |
is_successful()
¶
Check if the API response indicates success.
Returns:
| Type | Description |
|---|---|
bool
|
True if the response status code is 'OK'. |
to_astropy()
¶
Convert data to an astropy Table.
Returns:
| Type | Description |
|---|---|
Table
|
Astropy Table with one row per measurements. |
Source code in sedbuilder/schemas.py
to_dict()
¶
to_jetset(z, ul_cl=0.95, restframe='obs', data_scale='lin-lin', obj_name='new-src')
¶
Convert data to Jetset format.
The output includes both the data table with renamed columns and appropriate units, plus metadata needed for Jetset analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Annotated[float, Field(ge=0.0, le=1.0, description='Source redshift, must be between 0 and 1.')]
|
Source redshift, must be between 0 and 1. |
required |
ul_cl
|
Annotated[float, Field(ge=0.0, le=1.0, description='Confidence level for upper limits, must be between 0 and 1.')]
|
Confidence level for upper limits, must be between 0 and 1, exclusive. Default is 0.95. |
0.95
|
restframe
|
Annotated[Literal['obs', 'src'], Field(description="Reference frame for the data. Defaults to 'obs'.")]
|
Reference frame for the data. Options are "obs" for observed flux (default) and "src" for source luminosities. |
'obs'
|
data_scale
|
Annotated[Literal['lin-lin', 'log-log'], Field(description='Scale format of the data.')]
|
Scale format of the data. Options are "lin-lin" for linear scale (default), and "log-log" for logarithmic scale. |
'lin-lin'
|
obj_name
|
Annotated[str, Field(description='Name identifier for the object.')]
|
Name identifier for the object. Default is "new-src". |
'new-src'
|
Returns:
| Type | Description |
|---|---|
Table
|
A table with column names, units and metadata, compatible with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If z < 0, ul_cl is not in (0, 1), restframe or data_scale have invalid values, obj_name is empty, or required table columns are missing. |
Example
Source code in sedbuilder/schemas.py
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 403 404 405 406 407 408 409 410 411 412 413 414 | |
to_json()
¶
to_pandas()
¶
Converts data to a pandas DataFrame.
Requires pandas to be installed. Install with pip install pandas.
Returns:
| Type | Description |
|---|---|
Any
|
A pandas dataframe. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If pandas is not installed. |
Source code in sedbuilder/schemas.py
CatalogsResponse
¶
Bases: BaseModel
SED Builder API response to catalogs endpoint.
Contains information about all available catalogs in the SED Builder system, including their names, identifiers, error radii, and spectral classifications.
Attributes:
| Name | Type | Description |
|---|---|---|
ResponseInfo |
ResponseInfo
|
Status information about the API response. |
Catalogs |
list[Catalog]
|
List of catalog information entries. |
Source code in sedbuilder/schemas.py
is_successful()
¶
Check if the API response indicates success.
Returns:
| Type | Description |
|---|---|
bool
|
True if the response status code is 'OK'. |
to_list()
¶
Converts catalog data to a list of dictionaries.
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of dictionaries, one per catalog, containing all catalog metadata. |