Skip to content

Commit 1496ccf

Browse files
Merge pull request #10 from mirsazzathossain/dev
feat: Add celestial_capture function for downloading images from SkyView
2 parents 838f27c + c04cf53 commit 1496ccf

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

rgc/utils/data.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
__author__ = "Mir Sazzat Hossain"
99

1010

11+
from pathlib import Path
1112
from typing import cast
1213

1314
import pandas as pd
15+
from astroquery.skyview import SkyView
1416
from astroquery.vizier import Vizier
1517

1618

@@ -42,3 +44,33 @@ def catalog_quest(name: str, service: str = "Vizier") -> pd.DataFrame:
4244
return cast(pd.DataFrame, catalog[0].to_pandas())
4345
else:
4446
raise _UnsupportedServiceError()
47+
48+
49+
def celestial_capture(survey: str, ra: float, dec: float, filename: str) -> None:
50+
"""
51+
Capture a celestial image using the SkyView service.
52+
53+
:param survey: The name of the survey to be used e.g. 'VLA FIRST (1.4 GHz)'.
54+
:type survey: str
55+
56+
:param ra: The right ascension of the celestial object.
57+
:type ra: float
58+
59+
:param dec: The declination of the celestial object.
60+
:type dec: float
61+
62+
:param filename: The name of the file to save the image.
63+
:type filename: str
64+
"""
65+
image = SkyView.get_images(position=f"{ra}, {dec}", survey=survey, coordinates="J2000", pixels=(150, 150))[0]
66+
67+
comment = str(image[0].header["COMMENT"])
68+
comment = comment.replace("\n", " ")
69+
comment = comment.replace("\t", " ")
70+
71+
image[0].header.remove("comment", comment, True)
72+
image[0].header.add_comment(comment)
73+
74+
folder_path = Path(filename).parent
75+
Path(folder_path).mkdir(parents=True, exist_ok=True)
76+
image.writeto(filename, overwrite=True)

tests/test_celestial_capture.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from unittest.mock import MagicMock, patch
2+
3+
from rgc.utils.data import celestial_capture
4+
5+
6+
@patch("rgc.utils.data.SkyView")
7+
@patch("rgc.utils.data.Path")
8+
def test_celestial_capture(mock_path, mock_skyview):
9+
# Mock SkyView.get_images method
10+
mock_image = MagicMock()
11+
mock_image[0].header = MagicMock()
12+
mock_image[0].header.__getitem__.return_value = "Sample comment"
13+
mock_image[0].header.remove = MagicMock()
14+
mock_image[0].header.add_comment = MagicMock()
15+
mock_image.writeto = MagicMock()
16+
mock_skyview.get_images.return_value = [mock_image]
17+
18+
# Mock Path functionality
19+
mock_path_instance = MagicMock()
20+
mock_path_instance.parent = "mock_folder"
21+
mock_path.return_value = mock_path_instance
22+
23+
# Call the function
24+
celestial_capture("DSS2 Red", 10.684, 41.269, "test_image.fits")
25+
26+
# Verify that SkyView.get_images was called with correct parameters
27+
mock_skyview.get_images.assert_called_once_with(
28+
position="10.684, 41.269", survey="DSS2 Red", coordinates="J2000", pixels=(150, 150)
29+
)
30+
31+
# Verify that image.writeto was called with correct filename
32+
mock_image.writeto.assert_called_once_with("test_image.fits", overwrite=True)
33+
34+
# Verify Path.mkdir was called to create directories
35+
mock_path_instance.mkdir.assert_called_once_with(parents=True, exist_ok=True)
36+
37+
# Verify header methods were called
38+
mock_image[0].header.remove.assert_called_once_with("comment", "Sample comment", True)
39+
mock_image[0].header.add_comment.assert_called_once_with("Sample comment")

0 commit comments

Comments
 (0)