utils.py
Utility functions used throughout the package.
Attributes:
Name | Type | Description |
---|---|---|
use_colorlog | bool | Whether the logging should use colorlog or not. |
build_SkyCoord(catalog)
¶
Create a SkyCoord array for each target source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
catalog | DataFrame | Catalog of source coordinates. | required |
Returns:
Type | Description |
---|---|
SkyCoord | Target source(s) SkyCoord. |
Source code in vasttools/utils.py
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 |
|
build_catalog(coords, source_names)
¶
Build the catalogue of target sources.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coords | str | The coordinates (comma-separated) or filename entered. | required |
source_names | str | Comma-separated source names. | required |
Returns:
Type | Description |
---|---|
DataFrame | Catalogue of target sources. |
Source code in vasttools/utils.py
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 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
calculate_m_metric(flux_a, flux_b)
¶
Calculate the m variability metric which is the modulation index between two fluxes. This is proportional to the fractional variability. See Section 5 of Mooley et al. (2016) for details, DOI: 10.3847/0004-637X/818/2/105.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flux_a | float | flux value "A". | required |
flux_b | float | flux value "B". | required |
Returns:
Type | Description |
---|---|
float | The m metric for flux values "A" and "B". |
Source code in vasttools/utils.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
|
calculate_vs_metric(flux_a, flux_b, flux_err_a, flux_err_b)
¶
Calculate the Vs variability metric which is the t-statistic that the provided fluxes are variable. See Section 5 of Mooley et al. (2016) for details, DOI: 10.3847/0004-637X/818/2/105.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flux_a | float | flux value "A". | required |
flux_b | float | flux value "B". | required |
flux_err_a | float | error of | required |
flux_err_b | float | error of | required |
Returns:
Type | Description |
---|---|
float | The Vs metric for flux values "A" and "B". |
Source code in vasttools/utils.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
|
check_file(path)
¶
Check if logging file exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str | filepath to check | required |
Returns:
Type | Description |
---|---|
bool | Boolean representing the file existence, 'True' if present, otherwise 'False'. |
Source code in vasttools/utils.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
check_racs_exists(base_dir)
¶
Check if RACS directory exists
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_dir | str | Path to base directory | required |
Returns:
Type | Description |
---|---|
bool | True if exists, False otherwise. |
Source code in vasttools/utils.py
486 487 488 489 490 491 492 493 494 495 496 |
|
create_moc_from_fits(fits_file, max_depth=9)
¶
Creates a MOC from (assuming) an ASKAP fits image using the cheat method of analysing the edge pixels of the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fits_file | str | The path of the ASKAP FITS image to generate the MOC from. | required |
max_depth | int | Max depth parameter passed to the MOC.from_polygon_skycoord() function, defaults to 9. | 9 |
Returns:
Type | Description |
---|---|
MOC | The MOC generated from the FITS file. |
Raises:
Type | Description |
---|---|
Exception | The FITS file does not exist. |
Source code in vasttools/utils.py
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
|
create_source_directories(outdir, sources)
¶
Create directory for all sources in a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outdir | str | Base directory. | required |
sources | List[str] | List of source names. | required |
Returns:
Type | Description |
---|---|
None | None |
Source code in vasttools/utils.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
crosshair()
¶
A wrapper function to set the crosshair marker in matplotlib using the function written by L. A. Boogaard.
See https://stackoverflow.com/a/16655800/5064815.
Returns:
Type | Description |
---|---|
None | None |
Source code in vasttools/utils.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
filter_selavy_components(selavy_df, selavy_sc, imsize, target)
¶
Create a shortened catalogue by filtering out selavy components outside of the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selavy_df | DataFrame | Dataframe of selavy components. | required |
selavy_sc | SkyCoord | SkyCoords containing selavy components. | required |
imsize | Union[Angle, Tuple[Angle, Angle]] | Size of the image along each axis. Can be a single Angle object or a tuple of two Angle objects. | required |
target | SkyCoord | SkyCoord of target centre. | required |
Returns:
Type | Description |
---|---|
DataFrame | Shortened catalogue. |
Source code in vasttools/utils.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
|
gen_skycoord_from_df(df, ra_col='ra', dec_col='dec', ra_unit=u.degree, dec_unit=u.degree)
¶
Create a SkyCoord object from a provided dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | DataFrame | A dataframe containing the RA and Dec columns. | required |
ra_col | str | The column to use for the Right Ascension, defaults to 'ra'. | 'ra' |
dec_col | str | The column to use for the Declination, defaults to 'dec'. | 'dec' |
ra_unit | Unit | The unit of the RA column, defaults to degrees. Must be an astropy.unit value. | degree |
dec_unit | Unit | The unit of the Dec column, defaults to degrees. Must be an astropy.unit value. | degree |
Returns:
Type | Description |
---|---|
SkyCoord | A SkyCoord object containing the coordinates of the requested sources. |
Source code in vasttools/utils.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
get_logger(debug, quiet, logfile=None)
¶
Set up the logger.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
debug | bool | Set stream level to debug. | required |
quiet | bool | Suppress all non-essential output. | required |
logfile | str | File to output log to. | None |
Returns:
Type | Description |
---|---|
RootLogger | Logger object. |
Source code in vasttools/utils.py
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 74 75 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 |
|
match_planet_to_field(group, sep_thresh=4.0)
¶
Processes a dataframe that contains observational info and calculates whether a planet is within 'sep_thresh' degrees of the observation.
Used as part of groupby functions hence the argument is a group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group | DataFrame | Required columns are planet, DATEOBS, centre-ra and centre-dec. | required |
sep_thresh | float | The separation threshold for the planet position to the field centre. If the planet is lower than this value then the planet is considered to be in the field. Unit is degrees. | 4.0 |
Returns:
Type | Description |
---|---|
DataFrame | The group with planet location information added and filtered for only those which are within 'sep_thresh' degrees. Hence an empty dataframe could be returned. |
Source code in vasttools/utils.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
|
open_fits(fits_path, memmap=True, comp_nan_fill=True, comp_nan_fill_cut=-10000.0)
¶
This function opens both compressed and uncompressed fits files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fits_path | Union[str, Path] | Path to the fits file | required |
memmap | Optional[bool] | Open the fits file with mmap. Defaults to True. | True |
comp_nan_fill | Optional[bool] | Fill formerly-NaN values with NaNs in compressed images. Defaults to True. | True |
comp_nan_fill_cut | The cutoff value for replacing negative numbers with NaNs. Only relevant if | -10000.0 |
Returns:
Type | Description |
---|---|
HDUList | HDUList loaded from the fits file |
Raises:
Type | Description |
---|---|
ValueError | File extension must be .fits or .fits.fz |
Source code in vasttools/utils.py
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 |
|
pipeline_get_eta_metric(df, peak=False)
¶
Calculates the eta variability metric of a source. Works on the grouped by dataframe using the fluxes of the associated measurements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | DataFrame | A dataframe containing the grouped measurements, i.e. only the measurements from one source. Requires the flux_int/peak and flux_peak/int_err columns. | required |
peak | bool | Whether to use peak flux instead of integrated, defaults to False. | False |
Returns:
Type | Description |
---|---|
float | The eta variability metric. |
Source code in vasttools/utils.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
|
pipeline_get_variable_metrics(df)
¶
Calculates the variability metrics of a source. Works on the grouped by dataframe using the fluxes of the associated measurements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | DataFrame | A dataframe containing the grouped measurements, i.e. only the measurements from one source. Requires the flux_int/peak and flux_peak/int_err columns. | required |
Returns:
Type | Description |
---|---|
Series | The variability metrics, v_int, v_peak, eta_int and eta_peak as a pandas series. |
Source code in vasttools/utils.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
|
read_selavy(selavy_path, cols=None)
¶
Load a selavy catalogue from file. Can handle VOTables and csv files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selavy_path | str | Path to the file. | required |
cols | Optional[List[str]] | Columns to use. Defaults to None, which returns all columns. | None |
Returns:
Type | Description |
---|---|
DataFrame | Dataframe containing the catalogue. |
Source code in vasttools/utils.py
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 |
|
simbad_search(objects, logger=None)
¶
Searches SIMBAD for object coordinates and returns coordinates and names
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objects | List[str] | List of object names to query. | required |
logger | Optional[RootLogger] | Logger to use, defaults to None. | None |
Returns:
Type | Description |
---|---|
Union[Tuple[SkyCoord, List[str]], Tuple[None, None]] | Coordinates and source names. Each will be NoneType if search fails. |
Raises:
Type | Description |
---|---|
Exception | Simbad table length exceeds number of objects queried. |
Source code in vasttools/utils.py
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 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
strip_fieldnames(fieldnames)
¶
Some field names have historically used the interleaving naming scheme, but that has changed as of January 2023. This function removes the "A" that is on the end of the field names
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fieldnames | Series | Series to strip field names from | required |
Returns:
Type | Description |
---|---|
Series | Series with stripped field names |
Source code in vasttools/utils.py
706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
|