fitszoom 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fitszoom/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ import os
2
+
3
+ __version__ = "0.0.1"
4
+
5
+ #set directories where input images are located and outputs are sent to
6
+ fitszoom_dir = os.path.dirname(__file__)
7
+ DATADIR = os.path.join(fitszoom_dir, "images/")
fitszoom/zoom.py ADDED
@@ -0,0 +1,109 @@
1
+ from astropy.io import fits # importing i/o subpackage for reading FITS files
2
+ from astropy.nddata import Cutout2D
3
+ import astropy.units as u # astropy units
4
+ from astropy.wcs import WCS
5
+
6
+ import matplotlib.pyplot as plt
7
+ import numpy as np
8
+
9
+ class FITSZoom(object):
10
+ """
11
+ Zoom into the given coordinates and create a cutout with the given dimensions
12
+ """
13
+
14
+ def __init__(self, filename, extension=0):
15
+ """
16
+ Enter your file directory and your file name should be in .fits format in the DATADIR folder defined in __init__.py.
17
+ Args:
18
+ filename (string): your file name -> "{DATADIR}/<<your image>>.fits"
19
+ """
20
+ self.filename = filename
21
+ self.fits = fits.open(filename) # open the fits file --> this returns as a list of Header and Data units
22
+ self.setup(extension=extension) # pull out the data we need so that they are ready to use right after construction
23
+
24
+ def setup(self, extension=0):
25
+ """
26
+ Extract the necessary attributes from the fits header
27
+ Print out the recommended image bounds and sky coordinates
28
+
29
+ Args:
30
+ extension (int): the index where the desired data is within the fits
31
+ alternative_names (dict): dictionary mapping the names of appropriate values
32
+ """
33
+ self.header = self.fits[extension].header
34
+ self.data = self.fits[extension].data
35
+ self.wcs = WCS(self.header)
36
+ ### TO DO ##
37
+ sky1 = self.wcs.pixel_to_world(0,0)
38
+ sky2 = self.wcs.pixel_to_world(-1,-1)
39
+ print("---------- Recommendations ------------")
40
+ print("---------- Use the ra and dec within the following range ------------")
41
+ print(f"ra between {sky1.ra.value:.6f} and {sky2.ra.value:.6f}.")
42
+ print(f"dec between {sky1.dec.value:.6f} and {sky2.dec.value:.6f}.")
43
+ return
44
+
45
+ def zoom(self, coordinates, cutout_dimensions, save=False):
46
+ """
47
+ Zoom into the given coordinates and create a cutout with the given dimensions
48
+
49
+ Args:
50
+ coordinates (tuple): ra, dec in decimal degrees
51
+ cutout_dimensions (tuple): dimensions
52
+
53
+ Return:
54
+ axes: plt.plot of the cutout image
55
+ cutout:
56
+ """
57
+
58
+ if cutout_dimensions[0].unit != u.arcsec or cutout_dimensions[1].unit != u.arcsec:
59
+ raise ValueError("please use arcseconds for the dimensions")
60
+
61
+ cutout = Cutout2D(self.data, coordinates, cutout_dimensions, wcs=self.wcs)
62
+
63
+ ax = self.plot(data=cutout.data, save=save)
64
+
65
+ return ax, cutout
66
+
67
+
68
+ def plot(self, data=None, save=False, **kwargs):
69
+ """
70
+ Use matplotlib imshow to display the cutout
71
+
72
+ Args:
73
+ data : data from FITS image
74
+
75
+ Returns:
76
+ axes: the plt axes with the image
77
+ """
78
+
79
+ if data is None:
80
+ data = self.data
81
+
82
+ # set some defaults
83
+ if not kwargs.get('vmin', False):
84
+ kwargs['vmin'] = np.percentile(self.data, 1)
85
+
86
+ if not kwargs.get('vmax', False):
87
+ kwargs['vmax'] = np.percentile(self.data, 99)
88
+
89
+ fig, ax = plt.subplots(1,1, subplot_kw=dict(projection=self.wcs))
90
+
91
+ ax.imshow(data, **kwargs, origin='lower')
92
+ ax.grid(color='white', ls='solid')
93
+
94
+ return plt.gca()
95
+
96
+
97
+ def save(self, cutout, output_filename):
98
+ """
99
+ Save a cutout to a new FITS file, without changing the cutout's WCS in the header.
100
+ """
101
+
102
+ new_header = cutout.wcs.to_header()
103
+
104
+ # Wrap the cropped pixel data and the new header into a primary HDU
105
+ hdu = fits.PrimaryHDU(data=cutout.data, header=new_header)
106
+ # Write it out to disk, overwriting any existing file at that path
107
+ hdu.writeto(output_filename, overwrite=True)
108
+
109
+ return output_filename
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: fitszoom
3
+ Version: 0.0.1
4
+ License-File: LICENSE
5
+ Requires-Dist: numpy>=2.0
6
+ Requires-Dist: astropy
7
+ Requires-Dist: matplotlib
8
+ Requires-Dist: pytest
9
+ Dynamic: license-file
@@ -0,0 +1,7 @@
1
+ fitszoom/__init__.py,sha256=u8Vp6ORhsINNcmZ-9CaYV-_GWoRERmJoJfF2Wtg7edk,194
2
+ fitszoom/zoom.py,sha256=7TD0Sz4i-qwXViQKxvmhomfiLxv6CyuvVHpTWAbHG8I,3875
3
+ fitszoom-0.0.1.dist-info/licenses/LICENSE,sha256=BeoIgq35gYaTYUn9W-wi0EyO_K3ox5mwBfohtul1l94,1123
4
+ fitszoom-0.0.1.dist-info/METADATA,sha256=Z6vnqf7PULTNNzRTHckPUDInmwdaA6KR0aGu_aMpPw8,193
5
+ fitszoom-0.0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
+ fitszoom-0.0.1.dist-info/top_level.txt,sha256=VCocApiWyWUW94rmT3XLTZBIq2iYcAHgOI5zGvrGzZM,9
7
+ fitszoom-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2026] [Christa DeCoursey, Haille Perkins, Omar Velasco, Toe Oo Wai Yan]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ fitszoom