panoptes.pipeline.utils.sources¶
panoptes.pipeline.utils.sources ¶
read_catalog ¶
Read a catalog file, choosing the reader from its suffix.
The parsed catalog is cached (:py:data:CATALOG_CACHE_SIZE), keyed on the
file's path, modification time and size, so re-reading the same unchanged
file is free and a rewritten one is picked up. The cache lives in the
calling process: a pool of frame workers reads the catalog once each, not
once per frame. Call read_catalog.cache_clear() to drop it.
What comes back is a shallow copy, so a caller that adds or replaces a
column cannot corrupt the cached catalog for everything after it. That is
copy-on-write doing the work, and it costs nothing until something is
actually written -- which is why pyproject.toml floors pandas at 3, where
copy-on-write is unconditional. On 2.x it can be off, and a caller writing
through .loc would reach the cached frame through the shared blocks.
picid comes back as a category. It identifies a star rather than
measuring anything, and nothing downstream should be doing arithmetic on it.
One thing to know when consuming it: groupby over a categorical iterates
every category by default, so pass observed=True when grouping on it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_filename
|
str | Path
|
Path to a |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the path does not exist. |
ValueError
|
If the suffix is not a recognized format, a required column
is missing, or |
Source code in src/panoptes/pipeline/utils/sources.py
get_stars_from_wcs ¶
get_stars_from_wcs(wcs0: WCS, round_to: int = 0, pad: float = 1.0, pad_size=(20, 10), **kwargs: Any) -> pandas.DataFrame
Lookup star information from WCS footprint.
Generates the correct layout for an SQL POLYGON that can be passed to
:py:func:get_stars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wcs0
|
WCS
|
A valid (i.e. |
required |
round_to
|
int
|
Round the limits to this decimal place, default 0. Keeps the requested bounds stable between frames of the same sequence. |
0
|
pad
|
float
|
The amount of padding in degrees to add to each of the RA and Dec limits, default 0.5 [degrees]. |
1.0
|
**kwargs
|
Any
|
Optional keywords to pass to :py:func: |
{}
|
Source code in src/panoptes/pipeline/utils/sources.py
get_stars ¶
get_stars(shape=None, vmag_min=7, vmag_max=14, catalog_filename=None, **kwargs: Any) -> pandas.DataFrame
Look up star information from a local copy of the PANOPTES Input Catalog.
picid is exactly the Gaia DR3 source_id, so the catalog is a Gaia cone
search with its columns renamed and there is no crossmatch step -- see
scripts/fetch_catalog.py, which builds one. It is read from a local file --
parquet, ECSV or CSV, see :py:func:read_catalog -- and getting that file
onto disk is a separate fetch step, not something this function does. There
is no network lookup; see improvement plan 4.3.
The file is expected to carry the mapped column names
(:py:data:REQUIRED_CATALOG_COLUMNS) rather than the raw upstream ones.
Note:
In the upstream catalog the GAIA `bp` and `rp` magnitude and error
columns are switched. Whatever produces the catalog is responsible for
correcting that; this function does not second-guess the file it is
given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
dict | None
|
A dictionary containing the keys |
None
|
vmag_min
|
float
|
Minimum Vmag to include, inclusive. |
7
|
vmag_max
|
float
|
Maximum Vmag to include, exclusive. |
14
|
catalog_filename
|
str | Path
|
Path to the catalog file: parquet, ECSV or CSV. Required; there is no default. |
None
|
**kwargs
|
Any
|
Ignored, for call-site compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no catalog path is given, or the file is missing columns. |
FileNotFoundError
|
If the catalog path does not exist. |
Source code in src/panoptes/pipeline/utils/sources.py
get_catalog_match ¶
get_catalog_match(point_sources, wcs=None, catalog_stars=None, max_separation_arcsec=None, ra_column='measured_ra', dec_column='measured_dec', **kwargs: Any) -> pandas.DataFrame
Match the point source positions to the catalog.
picid in the catalog is exactly the Gaia DR3 source_id, so the catalog is
a Gaia cone search with its columns renamed and there is no crossmatch step
-- see scripts/fetch_catalog.py, which builds one.
The catalog is read from a local file. This function matches the ra_column
and dec_column positions to the catalog_ra and catalog_dec columns of
the catalog. When catalog_stars is not supplied the lookup is done via
:py:func:get_stars_from_wcs.
The matched catalog row is joined onto each source and the result returned.
The columns added are whatever the catalog file carries
(:py:data:REQUIRED_CATALOG_COLUMNS, plus :py:data:GAIA_CATALOG_COLUMNS
when the file has them), together with:
* catalog_sep -- separation from the matched catalog position, in arcsec
* catalog_wcs_x, catalog_wcs_y -- the catalog position in pixels
* catalog_wcs_x_int, catalog_wcs_y_int -- the same, truncated to int
Note:
Every source is matched to its *nearest* catalog star, so a detection
with no real counterpart still gets a row -- `max_separation_arcsec` is
what removes those. Catalog entries with no detection are not returned,
so the result has at most one row per source in `point_sources`.
If a max_separation_arcsec is given then results will be filtered if their
separation from the catalog was larger than the number given. Typical values
would be in the range of 20-30 arcsecs, which corresponds to 2-3 pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point_sources
|
`pandas.DataFrame`
|
The DataFrame containing point sources
to be matched. This usually comes from the output of
:py:func: |
required |
wcs
|
`astropy.wcs.WCS`
|
Required, despite the |
None
|
catalog_stars
|
`pandas.DataFrame`
|
If provided, the catalog match will be performed against this set of stars rather than performing a lookup. |
None
|
max_separation_arcsec
|
float | None
|
If not None, sources more than this many arcsecs from catalog will be filtered. |
None
|
ra_column
|
str
|
The column name to use for the RA coordinates, default |
'measured_ra'
|
dec_column
|
str
|
The column name to use for the Dec coordinates, default
|
'measured_dec'
|
**kwargs
|
Any
|
Extra options are passed to |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in src/panoptes/pipeline/utils/sources.py
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 | |