teareduce 0.5.8__py3-none-any.whl → 0.6.0__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.
@@ -7,6 +7,13 @@
7
7
  # License-Filename: LICENSE.txt
8
8
  #
9
9
 
10
+ """Module providing functions for cleaning astronomical images.
11
+ Includes functions for interpolating over bad pixels,
12
+ applying the L.A.Cosmic algorithm to detect cosmic ray pixels.
13
+ """
14
+
10
15
  from .interpolate import interpolate
11
16
  from .lacosmicpad import lacosmicpad
12
- from .mergemasks import merge_peak_tail_masks
17
+ from .mergemasks import merge_peak_tail_masks
18
+
19
+ __all__ = ["interpolate", "lacosmicpad", "merge_peak_tail_masks"]
@@ -10,7 +10,6 @@
10
10
  """Interactive Cosmic Ray cleaning tool."""
11
11
 
12
12
  import argparse
13
- from ast import arg
14
13
  import tkinter as tk
15
14
  from tkinter import filedialog
16
15
  from tkinter import simpledialog
@@ -93,10 +92,10 @@ def main():
93
92
  exit(1)
94
93
  print(f"Selected input FITS file: {args.input_fits}")
95
94
  args.extension = simpledialog.askstring(
96
- "Select Extension",
97
- f"\nEnter extension number or name for file:\n{Path(args.input_fits).name}",
98
- initialvalue=args.extension,
99
- )
95
+ "Select Extension",
96
+ f"\nEnter extension number or name for file:\n{Path(args.input_fits).name}",
97
+ initialvalue=args.extension,
98
+ )
100
99
  # Ask for auxiliary file if not provided
101
100
  if args.auxfile is None:
102
101
  use_auxfile = tk.messagebox.askyesno(
@@ -133,7 +132,13 @@ def main():
133
132
  exit(1)
134
133
 
135
134
  # Initialize Tkinter root
136
- root = tk.Tk()
135
+ try:
136
+ root = tk.Tk()
137
+ except tk.TclError as e:
138
+ print("Error: Unable to initialize Tkinter. Make sure a display is available.")
139
+ print("Detailed error message:")
140
+ print(e)
141
+ exit(1)
137
142
  system = platform.system()
138
143
  if system == "Darwin": # macOS
139
144
  # Center the window on the screen
@@ -0,0 +1,85 @@
1
+ #
2
+ # Copyright 2025 Universidad Complutense de Madrid
3
+ #
4
+ # This file is part of teareduce
5
+ #
6
+ # SPDX-License-Identifier: GPL-3.0+
7
+ # License-Filename: LICENSE.txt
8
+ #
9
+
10
+ """Ask extension dialog for input FITS files."""
11
+
12
+ from astropy.io import fits
13
+ from tkinter import simpledialog, messagebox
14
+ from pathlib import Path
15
+
16
+
17
+ def ask_extension_input_image(filename, imgshape=None):
18
+ """Ask the user for the FITS extension to use for the input image.
19
+
20
+ Parameters
21
+ ----------
22
+ filename : str
23
+ The name of the FITS file.
24
+
25
+ Returns
26
+ -------
27
+ ext : int or str
28
+ The selected FITS extension (0-based index or name).
29
+ """
30
+ # Open the FITS file to get the list of extensions
31
+ try:
32
+ with fits.open(filename) as hdul:
33
+ ext_names = [hdu.name for hdu in hdul]
34
+ ext_indices = list(range(len(hdul)))
35
+ ext_bitpix = [hdu.header["BITPIX"] for hdu in hdul]
36
+ except Exception as e:
37
+ messagebox.showerror("Error", f"Unable to open FITS file '{filename}':\n{str(e)}")
38
+ return None
39
+
40
+ if len(ext_indices) == 1:
41
+ ext = 0
42
+ else:
43
+ # ask for the extension number in a dialog
44
+ ext_str = simpledialog.askstring(
45
+ "Select Extension",
46
+ f"\nEnter extension number (0-{len(ext_indices)-1}) for file:\n{Path(filename).name}\n"
47
+ f"Available extensions:\n"
48
+ + "\n".join(
49
+ [f"{i}: {name} (BITPIX={bitpix})" for i, name, bitpix in zip(ext_indices, ext_names, ext_bitpix)]
50
+ ),
51
+ )
52
+ if ext_str is None:
53
+ return None
54
+ # Validate the input
55
+ try:
56
+ ext = int(ext_str)
57
+ if ext < 0 or ext >= len(ext_indices):
58
+ raise ValueError("Extension number out of range")
59
+ except ValueError as e:
60
+ messagebox.showerror("Invalid Input", f"Error: {str(e)}")
61
+ return None
62
+
63
+ # check if ext is a valid array
64
+ with fits.open(filename) as hdul:
65
+ if hdul[ext] is None:
66
+ messagebox.showerror("Invalid Input", f"Extension {ext} does not exist in file '{filename}'")
67
+ return None
68
+ elif hdul[ext].data is None:
69
+ messagebox.showerror("Invalid Input", f"Extension {ext} in file '{filename}' has no data")
70
+ return None
71
+ elif hdul[ext].data.ndim != 2:
72
+ messagebox.showerror("Invalid Input", f"Extension {ext} in file '{filename}' is not 2D")
73
+ return None
74
+ elif hdul[ext].data.size == 0:
75
+ messagebox.showerror("Invalid Input", f"Extension {ext} in file '{filename}' has no data")
76
+ return None
77
+ elif imgshape is not None and (
78
+ hdul[ext].data.shape[0] != imgshape[0] or hdul[ext].data.shape[1] != imgshape[1]
79
+ ):
80
+ messagebox.showerror(
81
+ "Invalid Input",
82
+ f"Extension {ext} in file '{filename}' has unexpected shape {hdul[ext].data.shape}, expected {imgshape}",
83
+ )
84
+ return None
85
+ return ext