teareduce 0.5.4__py3-none-any.whl → 0.5.7__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,4 +7,6 @@
7
7
  # License-Filename: LICENSE.txt
8
8
  #
9
9
 
10
- from .cleanest import cleanest
10
+ from .interpolate import interpolate
11
+ from .lacosmicpad import lacosmicpad
12
+ from .mergemasks import merge_peak_tail_masks
@@ -10,39 +10,142 @@
10
10
  """Interactive Cosmic Ray cleaning tool."""
11
11
 
12
12
  import argparse
13
+ from ast import arg
13
14
  import tkinter as tk
15
+ from tkinter import filedialog
16
+ from tkinter import simpledialog
14
17
  import os
18
+ from pathlib import Path
19
+ import platform
15
20
  from rich import print
16
21
  from rich_argparse import RichHelpFormatter
17
22
 
23
+ from .definitions import DEFAULT_FONT_FAMILY
24
+ from .definitions import DEFAULT_FONT_SIZE
25
+ from .definitions import DEFAULT_TK_WINDOW_SIZE_X
26
+ from .definitions import DEFAULT_TK_WINDOW_SIZE_Y
18
27
  from .cosmicraycleanerapp import CosmicRayCleanerApp
28
+ from ..version import VERSION
19
29
 
20
30
  import matplotlib
31
+
21
32
  matplotlib.use("TkAgg")
22
33
 
23
34
 
24
35
  def main():
25
36
  parser = argparse.ArgumentParser(
26
37
  description="Interactive cosmic ray cleaner for FITS images.",
27
- formatter_class=RichHelpFormatter)
28
- parser.add_argument("input_fits", help="Path to the FITS file to be cleaned.")
29
- parser.add_argument("--extension", type=int, default=0,
30
- help="FITS extension to use (default: 0).")
31
- parser.add_argument("--auxfile", type=str, default=None,
32
- help="Auxiliary FITS file")
33
- parser.add_argument("--extension_auxfile", type=int, default=0,
34
- help="FITS extension for auxiliary file (default: 0).")
38
+ formatter_class=RichHelpFormatter,
39
+ )
40
+ parser.add_argument("input_fits", nargs="?", default=None, help="Path to the FITS file to be cleaned.")
41
+ parser.add_argument("--extension", type=str, default="0", help="FITS extension to use (default: 0).")
42
+ parser.add_argument("--auxfile", type=str, default=None, help="Auxiliary FITS file")
43
+ parser.add_argument(
44
+ "--extension_auxfile",
45
+ type=str,
46
+ default="0",
47
+ help="FITS extension for auxiliary file (default: 0).",
48
+ )
49
+ parser.add_argument(
50
+ "--fontfamily",
51
+ type=str,
52
+ default=DEFAULT_FONT_FAMILY,
53
+ help=f"Font family for the GUI (default: {DEFAULT_FONT_FAMILY}).",
54
+ )
55
+ parser.add_argument(
56
+ "--fontsize",
57
+ type=int,
58
+ default=DEFAULT_FONT_SIZE,
59
+ help=f"Font size for the GUI (default: {DEFAULT_FONT_SIZE}).",
60
+ )
61
+ parser.add_argument(
62
+ "--width",
63
+ type=int,
64
+ default=DEFAULT_TK_WINDOW_SIZE_X,
65
+ help=f"Width of the GUI window in pixels (default: {DEFAULT_TK_WINDOW_SIZE_X}).",
66
+ )
67
+ parser.add_argument(
68
+ "--height",
69
+ type=int,
70
+ default=DEFAULT_TK_WINDOW_SIZE_Y,
71
+ help=f"Height of the GUI window in pixels (default: {DEFAULT_TK_WINDOW_SIZE_Y}).",
72
+ )
73
+ parser.add_argument("--version", action="version", version=f"%(prog)s {VERSION}")
74
+ parser.add_argument("--verbose", "-v", action="store_true", help="Enable verbose output.")
35
75
  args = parser.parse_args()
36
76
 
77
+ # Welcome message
78
+ print("[bold green]Cosmic Ray Cleaner[/bold green]")
79
+ print("Interactive tool to clean cosmic rays from FITS images.")
80
+ print("teareduce version: " + VERSION)
81
+ print(f"https://nicocardiel.github.io/teareduce-cookbook/docs/cleanest/cleanest.html\n")
82
+
83
+ # If input_file is not provided, ask for it using a file dialog
84
+ if args.input_fits is None:
85
+ root = tk.Tk()
86
+ root.withdraw() # Hide the root window
87
+ args.input_fits = filedialog.askopenfilename(
88
+ title="Select FITS file to be cleaned",
89
+ filetypes=[("FITS files", "*.fits *.fit *.fts"), ("All files", "*.*")],
90
+ )
91
+ if not args.input_fits:
92
+ print("No input FITS file selected. Exiting.")
93
+ exit(1)
94
+ print(f"Selected input FITS file: {args.input_fits}")
95
+ 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
+ )
100
+ # Ask for auxiliary file if not provided
101
+ if args.auxfile is None:
102
+ use_auxfile = tk.messagebox.askyesno(
103
+ "Auxiliary File",
104
+ "Do you want to use an auxiliary FITS file?",
105
+ default=tk.messagebox.NO,
106
+ )
107
+ if use_auxfile:
108
+ args.auxfile = filedialog.askopenfilename(
109
+ title="Select Auxiliary FITS file",
110
+ filetypes=[("FITS files", "*.fits *.fit *.fts"), ("All files", "*.*")],
111
+ initialfile=args.auxfile,
112
+ )
113
+ if not args.auxfile:
114
+ print("No auxiliary FITS file selected. Exiting.")
115
+ exit(1)
116
+ else:
117
+ use_auxfile = True
118
+ if use_auxfile:
119
+ print(f"Selected auxiliary FITS file: {args.auxfile}")
120
+ args.extension_auxfile = simpledialog.askstring(
121
+ "Select Extension for Auxiliary File",
122
+ f"\nEnter extension number or name for auxiliary file:\n{Path(args.auxfile).name}",
123
+ initialvalue=args.extension_auxfile,
124
+ )
125
+ root.destroy()
126
+
127
+ # Check that input files, and the corresponding extensions, exist
37
128
  if not os.path.isfile(args.input_fits):
38
129
  print(f"Error: File '{args.input_fits}' does not exist.")
39
- return
130
+ exit(1)
40
131
  if args.auxfile is not None and not os.path.isfile(args.auxfile):
41
132
  print(f"Error: Auxiliary file '{args.auxfile}' does not exist.")
42
- return
133
+ exit(1)
43
134
 
44
135
  # Initialize Tkinter root
45
136
  root = tk.Tk()
137
+ system = platform.system()
138
+ if system == "Darwin": # macOS
139
+ # Center the window on the screen
140
+ xoffset = root.winfo_screenwidth() // 2 - args.width // 2
141
+ yoffset = root.winfo_screenheight() // 2 - args.height // 2
142
+ else:
143
+ # Note that geometry("XxY+Xoffset+Yoffset") does not work properly on Fedora Linux
144
+ xoffset = 0
145
+ yoffset = 0
146
+ root.geometry(f"+{xoffset}+{yoffset}")
147
+ root.focus_force() # Request focus
148
+ root.lift() # Bring to front
46
149
 
47
150
  # Create and run the application
48
151
  CosmicRayCleanerApp(
@@ -50,7 +153,12 @@ def main():
50
153
  input_fits=args.input_fits,
51
154
  extension=args.extension,
52
155
  auxfile=args.auxfile,
53
- extension_auxfile=args.extension_auxfile
156
+ extension_auxfile=args.extension_auxfile,
157
+ fontfamily=args.fontfamily,
158
+ fontsize=args.fontsize,
159
+ width=args.width,
160
+ height=args.height,
161
+ verbose=args.verbose,
54
162
  )
55
163
 
56
164
  # Execute
@@ -0,0 +1,46 @@
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
+ """Function to center a tk child window on its parent."""
11
+
12
+
13
+ def center_on_parent(child, parent, offset_x=0, offset_y=0):
14
+ """Center child window on parent window.
15
+
16
+ Parameters
17
+ ----------
18
+ child : tk.Toplevel or tk.Tk
19
+ The child window to be centered.
20
+ parent : tk.Toplevel or tk.Tk
21
+ The parent window.
22
+ offset_x : int, optional
23
+ Horizontal offset from center position (default is 0).
24
+ offset_y : int, optional
25
+ Vertical offset from center position (default is 0).
26
+ """
27
+ # Update to get accurate dimensions
28
+ child.update_idletasks()
29
+ parent.update_idletasks()
30
+
31
+ # Get parent position and size
32
+ parent_x = parent.winfo_x()
33
+ parent_y = parent.winfo_y()
34
+ parent_width = parent.winfo_width()
35
+ parent_height = parent.winfo_height()
36
+
37
+ # Get child size
38
+ child_width = child.winfo_width()
39
+ child_height = child.winfo_height()
40
+
41
+ # Calculate center position
42
+ x = parent_x + (parent_width - child_width) // 2
43
+ y = parent_y + (parent_height - child_height) // 2
44
+
45
+ # Set child position
46
+ child.geometry(f"+{x + offset_x}+{y + offset_y}")