Modules
A collection of utility functions for data manipulation.
This module contains a collection of utility functions for astronomical data manipulation.
catalog_quest(name, service='Vizier')
¶
Fetch a catalog from a given astronomical service e.g. VizieR, Simbad.
:param name: The name of the catalog to be fetched. :type name: str
:param service: The name of the astronomical service to be used. :type service: str
:return: A pandas DataFrame containing the fetched catalog. :rtype: pd.DataFrame
:raises _UnsupportedServiceError: If an unsupported service is provided.
Source code in rgc/utils/data.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
celestial_capture(survey, ra, dec, filename)
¶
Capture a celestial image using the SkyView service.
:param survey: The name of the survey to be used e.g. 'VLA FIRST (1.4 GHz)'. :type survey: str
:param ra: The right ascension of the celestial object. :type ra: Skycoord
:param dec: The declination of the celestial object. :type dec: Skycoord
:param filename: The name of the file to save the image. :type filename: str
Source code in rgc/utils/data.py
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 |
|
celestial_capture_bulk(catalog, survey, img_dir, classes=None, cls_col=None)
¶
Capture celestial images for a catalog of celestial objects.
:param catalog: A pandas DataFrame containing the catalog of celestial objects. :type catalog: pd.DataFrame
:param survey: The name of the survey to be used e.g. 'VLA FIRST (1.4 GHz)'. :type survey: str
:param img_dir: The path to the directory to save the images. :type img_dir: str
:param classes: A dictionary containing the classes of the celestial objects. :type classes: dict
:param cls_col: The name of the column containing the class labels.
:raises _InvalidCoordinatesError: If coordinates are invalid.
Source code in rgc/utils/data.py
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 |
|
celestial_tag(entry)
¶
Generate a name tag for a celestial object based on its coordinates.
:param entry: A pandas Series entry of the catalog. :type entry: pd.Series
:return: A string containing the name tag. :rtype: str
:raises _NoValidCelestialCoordinatesError: If no valid celestial coordinates are found in the entry.
Source code in rgc/utils/data.py
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 |
|
compute_mean_std(dataloader)
¶
Compute the mean and standard deviation of the dataset.
:param dataloader: The dataloader for the dataset. :type dataloader: torch.utils.data.DataLoader
:return: The mean and standard deviation of the dataset. :rtype: tuple[torch.Tensor, torch.Tensor]
Source code in rgc/utils/data.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
dataframe_to_html(catalog, save_dir)
¶
Save the catalog as an HTML file.
:param catalog: Catalog of the astronomical objects :type catalog: pd.DataFrame :param save_dir: Path to the directory to save the HTML file :type save_dir: str
Source code in rgc/utils/data.py
372 373 374 375 376 377 378 379 380 381 382 |
|
fits_to_png(fits_file, img_size=None)
¶
Convert a FITS file to a PNG image.
:param fits_file: The path to the FITS file. :type fits_file: str
:param img_size: The size of the output image. :type img_size: Optional[tuple[int, int]]
:return: A PIL Image object containing the PNG image. :rtype: Image.Image
:raises _FileNotFoundError: If the FITS file is not found.
Source code in rgc/utils/data.py
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 |
|
fits_to_png_bulk(fits_dir, png_dir, img_size=None)
¶
Convert a directory of FITS files to PNG images.
:param fits_dir: The path to the directory containing the FITS files. :type fits_dir: str
:param png_dir: The path to the directory to save the PNG images. :type png_dir: str
:param img_size: The size of the output image. :type img_size: Optional[tuple[int, int]]
Source code in rgc/utils/data.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
generate_mask(image_path, mask_dir, freq, beam, dilation, threshold_pixel=5.0, threshold_island=3.0)
¶
Detect sources in the image and generate a mask.
:param image_path: Path to the image file :type image_path: str
:param mask_dir: Path to the directory to save the mask :type mask_dir: str
:param freq: Frequency of the image in MHz :type freq: float
:param beam: Beam size of the image in arcsec :type beam: tuple
:param dilation: Dilation factor for the mask :type dilation: int
:param threshold_pixel: Threshold for island peak in number of sigma above the mean :type threshold_pixel: float
:param threshold_island: Threshold for island detection in number of sigma above the mean :type threshold_island: float
Source code in rgc/utils/data.py
421 422 423 424 425 426 427 428 429 430 431 432 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 |
|
generate_mask_bulk(catalog, img_dir, mask_dir, freq, beam)
¶
Generate masks for a catalog of celestial objects.
:param catalog: A pandas DataFrame containing the catalog of celestial objects. :type catalog: pd.DataFrame
:param img_dir: The path to the directory containing the images. :type img_dir: str
:param mask_dir: The path to the directory to save the masks. :type mask_dir: str
:param freq: Frequency of the image in MHz :type freq: float
:param beam: Beam size of the image in arcsec :type beam: tuple
Source code in rgc/utils/data.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
|
mask_image(image, mask)
¶
Mask an image with a given mask image.
:param image: The image to be masked. :type image: Image.Image
:param mask: The mask image. :type mask: Image.Image
:return: A PIL Image object containing the masked image. :rtype: Image.Image
:raises _ImageMaskDimensionError: If the dimensions of the image and mask do not match.
Source code in rgc/utils/data.py
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 |
|
mask_image_bulk(image_dir, mask_dir, masked_dir)
¶
Mask a directory of images with a directory of mask images.
:param image_dir: The path to the directory containing the images. :type image_dir: str
:param mask_dir: The path to the directory containing the mask images. :type mask_dir: str
:param masked_dir: The path to the directory to save the masked images. :type masked_dir: str
:raises _FileNotFoundError: If no images or masks are found in the directories. :raises _ImageMaskCountMismatchError: If the number of images and masks do not match.
Source code in rgc/utils/data.py
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 |
|
remove_artifacts(folder, extension)
¶
Remove files with the given extensions from a folder.
:param folder: Path to the folder to clear :type folder: str :param extension: List of file with the given extensions to keep :type extension: list
Source code in rgc/utils/data.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
|