thilos 0.1.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.
- THILOS/BPM/BPM_OSIRIS_PLUS.fits +0 -0
- THILOS/Color_Codes.py +47 -0
- THILOS/DRP.py +219 -0
- THILOS/__init__.py +0 -0
- THILOS/alignment_hcam.py +584 -0
- THILOS/check_files.py +224 -0
- THILOS/config/configuration.json +27 -0
- THILOS/rebinning.py +254 -0
- THILOS/reduction_hcam.py +724 -0
- thilos-0.1.0.dist-info/METADATA +233 -0
- thilos-0.1.0.dist-info/RECORD +15 -0
- thilos-0.1.0.dist-info/WHEEL +5 -0
- thilos-0.1.0.dist-info/entry_points.txt +2 -0
- thilos-0.1.0.dist-info/licenses/LICENSE +676 -0
- thilos-0.1.0.dist-info/top_level.txt +1 -0
|
Binary file
|
THILOS/Color_Codes.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This program is free software: you can redistribute it and/or modify
|
|
3
|
+
it under the terms of the GNU General Public License as published by
|
|
4
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
5
|
+
(at your option) any later version.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful,
|
|
8
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10
|
+
GNU General Public License for more details.
|
|
11
|
+
|
|
12
|
+
You should have received a copy of the GNU General Public License
|
|
13
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
14
|
+
|
|
15
|
+
Copyright (C) 2026 Gran Telescopio Canarias <https://www.gtc.iac.es>
|
|
16
|
+
Fabricio Manuel Pérez Toledo <fabricio.perez@gtc.iac.es>
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
class bcolors:
|
|
20
|
+
"""
|
|
21
|
+
A class to define string color formatting for terminal output using ANSI escape sequences.
|
|
22
|
+
|
|
23
|
+
This class provides various color codes and text styles that can be used to format terminal output.
|
|
24
|
+
The colors and styles are defined as class variables, and each variable represents a different format
|
|
25
|
+
that can be applied to text in the terminal.
|
|
26
|
+
|
|
27
|
+
Class variables:
|
|
28
|
+
HEADER (str): Color for header text.
|
|
29
|
+
OKBLUE (str): Color for informational text (blue).
|
|
30
|
+
OKCYAN (str): Color for informational text (cyan).
|
|
31
|
+
OKGREEN (str): Color for successful operation text (green).
|
|
32
|
+
WARNING (str): Color for warning text (yellow).
|
|
33
|
+
FAIL (str): Color for error or failed operation text (red).
|
|
34
|
+
ENDC (str): Resets the text formatting to default.
|
|
35
|
+
BOLD (str): Bold text style.
|
|
36
|
+
UNDERLINE (str): Underlined text style.
|
|
37
|
+
"""
|
|
38
|
+
HEADER = '\033[33m'
|
|
39
|
+
OKBLUE = '\033[94m'
|
|
40
|
+
OKCYAN = '\033[96m'
|
|
41
|
+
OKGREEN = '\033[92m'
|
|
42
|
+
WARNING = '\033[93m'
|
|
43
|
+
ERROR = '\033[91m'
|
|
44
|
+
FAIL = '\033[91m'
|
|
45
|
+
ENDC = '\033[0m'
|
|
46
|
+
BOLD = '\033[1m'
|
|
47
|
+
UNDERLINE = '\033[4m'
|
THILOS/DRP.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This program is free software: you can redistribute it and/or modify
|
|
3
|
+
it under the terms of the GNU General Public License as published by
|
|
4
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
5
|
+
(at your option) any later version.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful,
|
|
8
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10
|
+
GNU General Public License for more details.
|
|
11
|
+
|
|
12
|
+
You should have received a copy of the GNU General Public License
|
|
13
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
14
|
+
|
|
15
|
+
Copyright (C) 2026 Gran Telescopio Canarias <https://www.gtc.iac.es>
|
|
16
|
+
Fabricio Manuel Pérez Toledo <fabricio.perez@gtc.iac.es>
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
__author__="Fabricio M. Pérez-Toledo"
|
|
20
|
+
__version__ = "0.1.0"
|
|
21
|
+
__license__ = "GPL v3.0"
|
|
22
|
+
|
|
23
|
+
from THILOS.check_files import *
|
|
24
|
+
from THILOS.reduction_hcam import *
|
|
25
|
+
from THILOS.alignment_hcam import *
|
|
26
|
+
#from THILOS.astrometry_hcam import * FUTURE TOOL
|
|
27
|
+
|
|
28
|
+
import argparse, time, os, shutil, sys
|
|
29
|
+
import json, warnings
|
|
30
|
+
from importlib.resources import files
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
from THILOS.Color_Codes import bcolors as bcl
|
|
34
|
+
from loguru import logger
|
|
35
|
+
|
|
36
|
+
warnings.filterwarnings("ignore", category=UserWarning)
|
|
37
|
+
warnings.filterwarnings("ignore", category=RuntimeWarning)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
############## Predefined functions #############
|
|
41
|
+
|
|
42
|
+
def create_config_file_home():
|
|
43
|
+
"""
|
|
44
|
+
This function creates a copy of the configuration file in .config/thilos
|
|
45
|
+
/ for easier accessibility.
|
|
46
|
+
"""
|
|
47
|
+
with files('THILOS').joinpath('config/configuration.json') as config_path:
|
|
48
|
+
shutil.copy(config_path, Path(os.getcwd())/'configuration.json')
|
|
49
|
+
logger.info(f"Configuration file created successfully in the current directory.")
|
|
50
|
+
sys.exit()
|
|
51
|
+
|
|
52
|
+
def readJSON() -> json:
|
|
53
|
+
"""
|
|
54
|
+
Reads the file containing the configuration parameters.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
json: Collection of configuration parameters
|
|
58
|
+
"""
|
|
59
|
+
return json.load(open(Path(os.getcwd())/'configuration.json'))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def run(path_config: str = None):
|
|
63
|
+
"""
|
|
64
|
+
This function
|
|
65
|
+
"""
|
|
66
|
+
# Parse configuration
|
|
67
|
+
parser = argparse.ArgumentParser(
|
|
68
|
+
prog = 'THILOS',
|
|
69
|
+
description = 'This software reduces observations taken with HIPERCAM\
|
|
70
|
+
in Deep Field mode. It can process any filter configuration and is suitable\
|
|
71
|
+
for observations affected by fringing (Sloan_z).')
|
|
72
|
+
|
|
73
|
+
parser.add_argument('-e', '--execute', help='Execute the configuration file in the current directory.',
|
|
74
|
+
action='store_true')
|
|
75
|
+
|
|
76
|
+
parser.add_argument('-c', '--create_config', help='Create a configuration file in the current directory.',
|
|
77
|
+
action='store_true')
|
|
78
|
+
|
|
79
|
+
parser.add_argument('-p', '--path_config', type=str, help='Path to the configuration file and raw data.',
|
|
80
|
+
default=None)
|
|
81
|
+
|
|
82
|
+
args = parser.parse_args()
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
print(f"{bcl.OKBLUE}***********************************************************************{bcl.ENDC}")
|
|
86
|
+
print(f"{bcl.OKBLUE}************************* WELCOME TO THILOS **************************{bcl.ENDC}")
|
|
87
|
+
print(f"{bcl.OKBLUE}***********************************************************************{bcl.ENDC}")
|
|
88
|
+
print("\n")
|
|
89
|
+
print(f"{bcl.BOLD}---------------------- LICENSE ----------------------{bcl.ENDC}")
|
|
90
|
+
print("\n")
|
|
91
|
+
print(f"This program is free software: you can redistribute it and/or modify\n\
|
|
92
|
+
it under the terms of the GNU General Public License as published by\n\
|
|
93
|
+
the Free Software Foundation, either version 3 of the License, or\n\
|
|
94
|
+
(at your option) any later version.\n\n\
|
|
95
|
+
This program is distributed in the hope that it will be useful,\n\
|
|
96
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
|
|
97
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
|
|
98
|
+
GNU General Public License for more details.\n\n\
|
|
99
|
+
You should have received a copy of the GNU General Public License\n\
|
|
100
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.")
|
|
101
|
+
print("\n")
|
|
102
|
+
print(f"{bcl.BOLD}************************ IMPORTANT INFORMATION ************************{bcl.ENDC}")
|
|
103
|
+
print("\n")
|
|
104
|
+
print(f"This software is designed to reduce Deep Field Imaging observations obtained with HIPERCAM.\n\
|
|
105
|
+
For proper use, you need to modify the configuration file, which can be found\n\
|
|
106
|
+
in the directory where this software is installed. Additionally, you need to create\n\
|
|
107
|
+
an account on Astrometry.net. Once you have the code that allows you to use the API,\n\
|
|
108
|
+
you need to fill in the correct variable.")
|
|
109
|
+
print(f"\n")
|
|
110
|
+
|
|
111
|
+
# Check if the configuration file exists (2025-08-04)
|
|
112
|
+
if args.create_config:
|
|
113
|
+
logger.info(f"Creating configuration file...")
|
|
114
|
+
logger.info(f"Configuration file created successfully in the current directory")
|
|
115
|
+
create_config_file_home()
|
|
116
|
+
sys.exit()
|
|
117
|
+
|
|
118
|
+
conf = check_files(path_config=args.path_config)
|
|
119
|
+
|
|
120
|
+
PRG = conf['PRG']
|
|
121
|
+
OB = conf['OB']
|
|
122
|
+
|
|
123
|
+
hora_local = time.localtime()
|
|
124
|
+
print(conf)
|
|
125
|
+
logger.add(Path(conf['DIRECTORIES']['PATH'])/f"thilos_{time.strftime('%Y-%m-%d_%H:%M:%S', hora_local)}.log", format="{time} {level} {message} ({module}:{line})", level="INFO",
|
|
126
|
+
filter=lambda record: 'astropy' not in record["name"])
|
|
127
|
+
|
|
128
|
+
logger.info(f'{bcl.OKGREEN}Log file created{bcl.ENDC}')
|
|
129
|
+
logger.info(f'{bcl.OKGREEN}Configuration has been updated successfully{bcl.ENDC}')
|
|
130
|
+
logger.info(f'{bcl.OKGREEN}Read the configuration file successfully{bcl.ENDC}')
|
|
131
|
+
|
|
132
|
+
#Reduction Recipe. This recipe is responsible for cleaning the images by subtracting
|
|
133
|
+
#the masterbias and dividing by the normalized masterflat.
|
|
134
|
+
#Subsequently, the cleaned images are saved.
|
|
135
|
+
logger.info(f'{bcl.OKBLUE}---------- Starting the reductions for {PRG}-{OB} ----------{bcl.ENDC}')
|
|
136
|
+
|
|
137
|
+
with as_file(files('THILOS').joinpath('BPM/BPM_OSIRIS_PLUS.fits')) as bpm_path:
|
|
138
|
+
bpm_path_str = str(bpm_path)
|
|
139
|
+
|
|
140
|
+
o = Reduction(main_path=conf['DIRECTORIES']['PATH_DATA'],
|
|
141
|
+
path_mask=bpm_path_str)
|
|
142
|
+
o.get_imagetypes()
|
|
143
|
+
o.load_BPM()
|
|
144
|
+
o.check_binning()
|
|
145
|
+
o.sort_down_drawer()
|
|
146
|
+
|
|
147
|
+
if conf['REDUCTION']['use_BIAS']:
|
|
148
|
+
o.do_masterbias()
|
|
149
|
+
|
|
150
|
+
else:
|
|
151
|
+
logger.warning(f'{bcl.WARNING}The masterbiases are not going to be created{bcl.ENDC}')
|
|
152
|
+
|
|
153
|
+
if conf['REDUCTION']['use_FLAT']:
|
|
154
|
+
o.do_masterflat()
|
|
155
|
+
|
|
156
|
+
else:
|
|
157
|
+
logger.warning(f'{bcl.WARNING}The masterflats are not going to be created{bcl.ENDC}')
|
|
158
|
+
|
|
159
|
+
if conf['REDUCTION']['use_STD']:
|
|
160
|
+
o.get_std(no_CRs=conf['REDUCTION']['no_CRs'], contrast_arg = conf['REDUCTION']['contrast'],
|
|
161
|
+
cr_threshold_arg = conf['REDUCTION']['cr_threshold'],
|
|
162
|
+
neighbor_threshold_arg = conf['REDUCTION']['neighbor_threshold'], apply_flat=conf['REDUCTION']['use_FLAT'])
|
|
163
|
+
|
|
164
|
+
else:
|
|
165
|
+
logger.warning(f'{bcl.WARNING}The STD star is not going to be reduced{bcl.ENDC}')
|
|
166
|
+
|
|
167
|
+
o.get_target(no_CRs=conf['REDUCTION']['no_CRs'], contrast_arg = conf['REDUCTION']['contrast'],
|
|
168
|
+
cr_threshold_arg = conf['REDUCTION']['cr_threshold'],
|
|
169
|
+
neighbor_threshold_arg = conf['REDUCTION']['neighbor_threshold'], apply_flat=conf['REDUCTION']['use_FLAT'])
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
if conf['REDUCTION']['save_fringing']:
|
|
173
|
+
o.remove_fringing()
|
|
174
|
+
logger.info(f'{bcl.OKGREEN}Fringing correction applied successfully{bcl.ENDC}')
|
|
175
|
+
else:
|
|
176
|
+
logger.warning(f'{bcl.WARNING}The fringing correction is not going to be executed{bcl.ENDC}')
|
|
177
|
+
|
|
178
|
+
if conf['REDUCTION']['save_not_sky']:
|
|
179
|
+
o.sustract_sky()
|
|
180
|
+
logger.info(f'{bcl.OKGREEN}The sky subtraction has been applied successfully{bcl.ENDC}')
|
|
181
|
+
else:
|
|
182
|
+
logger.warning(f'{bcl.WARNING}The sky substraction is not going to be executed{bcl.ENDC}')
|
|
183
|
+
|
|
184
|
+
o.save_target(std=conf['REDUCTION']['save_std'])
|
|
185
|
+
o.save_target(std=conf['REDUCTION']['save_std'], fringing=conf['REDUCTION']['save_fringing'])
|
|
186
|
+
o.save_target(sky=conf['REDUCTION']['save_sky'])
|
|
187
|
+
o.save_target(fringing=conf['REDUCTION']['save_fringing'])
|
|
188
|
+
o.save_target(not_sky=conf['REDUCTION']['save_not_sky'])
|
|
189
|
+
logger.info(f'{bcl.OKBLUE}-------------- End of the reductions successfully --------------{bcl.ENDC}')
|
|
190
|
+
print(2*"\n")
|
|
191
|
+
|
|
192
|
+
#Aligned Recipe. The cleaned science images are aligned based on the filter used in each case.
|
|
193
|
+
#Then, they are saved as aligned images.
|
|
194
|
+
if conf['ALIGNING']['use_aligning']:
|
|
195
|
+
logger.info(f"{bcl.OKBLUE}---------- Starting the alignments ----------{bcl.ENDC}")
|
|
196
|
+
aligner = AstroImageAligner(min_snr=10.0, conf = conf)
|
|
197
|
+
for filt in list(set(aligner.ic.summary['filtro'])):
|
|
198
|
+
for sky in ['SKY', 'NOSKY']:
|
|
199
|
+
if conf['REDUCTION']['save_not_sky'] or sky == 'SKY':
|
|
200
|
+
logger.info(f'{bcl.OKCYAN}++++++++++ Aligment for {filt} & {sky} ++++++++++{bcl.ENDC}')
|
|
201
|
+
aligner.run_aligning(filt, sky=sky)
|
|
202
|
+
header = aligner.ref_header.copy()
|
|
203
|
+
header['STACKED'] = (True, 'Stacked image')
|
|
204
|
+
header['exptime'] = aligner.ref_header['exptime'] * aligner.num
|
|
205
|
+
logger.info(f"Estimated total exposure time: {header['exptime']} sec")
|
|
206
|
+
wcs = aligner.ref_wcs.copy()
|
|
207
|
+
logger.info(f"Updating the WCS information")
|
|
208
|
+
save_fits(aligner.stacked_image, header, wcs, str(aligner.PATH_REDUCED / f'{PRG}_{OB}_{filt}_stacked_{sky}.fits'))
|
|
209
|
+
|
|
210
|
+
else:
|
|
211
|
+
logger.warning(f'{bcl.WARNING}Alignments are not going to be executed for NOSKY{bcl.ENDC}')
|
|
212
|
+
|
|
213
|
+
logger.info(f'{bcl.OKBLUE}------------------- End of the alignments -------------------{bcl.ENDC}')
|
|
214
|
+
print(2*"\n")
|
|
215
|
+
else:
|
|
216
|
+
logger.warning(f'{bcl.WARNING}The alignments are not going to be executed{bcl.ENDC}')
|
|
217
|
+
|
|
218
|
+
if __name__ == '__main__':
|
|
219
|
+
run()
|
THILOS/__init__.py
ADDED
|
File without changes
|