Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion spectractor/astrometry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import warnings
from copy import deepcopy
import subprocess
import shutil
Expand Down Expand Up @@ -153,7 +154,9 @@ def get_gaia_coords_after_proper_motion(gaia_catalog, date_obs):
np.array(gaia_catalog['dec']) * np.pi / 180),
pm_dec=gaia_catalog['pmdec'].filled(0),
distance=Distance(parallax=parallax * u.mas, allow_negative=True))
gaia_coords_after_proper_motion = gaia_stars.apply_space_motion(new_obstime=Time(date_obs))
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message=".*distance overridden.*", category=Warning)
gaia_coords_after_proper_motion = gaia_stars.apply_space_motion(new_obstime=Time(date_obs))
return gaia_coords_after_proper_motion


Expand Down
13 changes: 8 additions & 5 deletions spectractor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,19 @@ def load_config(config_filename, rebin=True):
"""
my_logger = set_logger(__name__)
mypath = os.path.dirname(__file__)
if not os.path.isfile(os.path.join(mypath, parameters.CONFIG_DIR, "default.ini")):
# Use the bundled config/ directory relative to this file, not parameters.CONFIG_DIR
# (parameters.CONFIG_DIR can be overwritten at runtime, e.g. by loading a spectrum FITS file)
config_dir = os.path.join(mypath, "config")
if not os.path.isfile(os.path.join(config_dir, "default.ini")):
raise FileNotFoundError('Config file default.ini does not exist.')
# Load the configuration file
from_config_to_parameters(os.path.join(mypath, parameters.CONFIG_DIR, "default.ini"))
from_config_to_parameters(os.path.join(config_dir, "default.ini"))

if not os.path.isfile(config_filename):
if not os.path.isfile(os.path.join(mypath, parameters.CONFIG_DIR, config_filename)):
if not os.path.isfile(os.path.join(config_dir, config_filename)):
raise FileNotFoundError(f'Config file {config_filename} does not exist.')
else:
config_filename = os.path.join(mypath, parameters.CONFIG_DIR, config_filename)
config_filename = os.path.join(config_dir, config_filename)
# Load the configuration file
my_logger.info(f"\n\tLoading {config_filename} with {parameters.VERBOSE=}...")
from_config_to_parameters(config_filename)
Expand Down Expand Up @@ -160,7 +163,7 @@ def load_config(config_filename, rebin=True):
txt = ""
# default.ini should be the config file with the most parameters
config = configparser.ConfigParser()
config.read(os.path.join(mypath, parameters.CONFIG_DIR, "default.ini"))
config.read(os.path.join(config_dir, "default.ini"))
for section in config.sections():
txt += f"Section: {section}\n"
for options in config.options(section):
Expand Down
6 changes: 6 additions & 0 deletions spectractor/extractor/dispersers/HoloAmAg_7.5/NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- ratio_order_2over1.txt: fit of a model to Sylvie's data from CTIO spectra observed with a blue filter
- transmission.txt: fit on CTIO data 2017/30/05 normalized with multispectra_Thor300_HD111980_CTIO_throughput_prod7.5.txt
../CTIODataJune2017_reduced_RG715_v2_prod7.5/data_30may17_A2=0.1/multispectra_HoloAmAg_HD111980_HoloAmAg_throughput.txt
(see jupyter notebook Multispectra.ipynb)
- N.txt: interpolation of Neff estimated with CTIO scan of the hologram
- hologram_*.txt: same
5 changes: 5 additions & 0 deletions spectractor/extractor/dispersers/Thor300_7.5/NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- ratio_order_2over1.txt: fit of a model to Sylvie's data from CTIO spectra observed with a blue filter
- transmission.txt: model best fit on a mix of measurements coming from the Thorlabs data sheet (300-450nm), Laurent's measurement
at DCCD=200mm (450-920nm), Arthur's measurement at DCCD=58mm (1000>920nm) and Thorlabs data sheet again (>1000nm)
(see jupyter notebook Disperser_efficiencies.ipynb)
- N.txt: estimation with CTIO data
1 change: 1 addition & 0 deletions spectractor/extractor/dispersers/blue300lpmm_qn1_old/NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Blue quad notch filter
9 changes: 5 additions & 4 deletions spectractor/extractor/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def save_spectrum(self, output_file_name, overwrite=False):
Path of the output fits file.
overwrite: bool
If True overwrite the output file if needed (default: False).

Examples
--------
>>> import os
Expand Down Expand Up @@ -677,7 +677,8 @@ def save_spectrum(self, output_file_name, overwrite=False):
hdu1.header[header_key] = value
# print(f"Set header key {header_key} to {value} from attr {attribute}")

extnames = ["SPECTRUM", "SPEC_COV", "ORDER2", "ORDER0"] # spectrum data
extnames = ["SPECTRUM", "SPEC_COV", "ORDER2"] # spectrum data
extnames += ["ORDER0"] # spectrum order0 timestamps
extnames += ["S_DATA", "S_ERR", "S_BGD", "S_BGD_ER", "S_FIT", "S_RES", "S_FLAT", "S_STAR", "S_MASK"]
extnames += ["PSF_TAB"] # PSF parameter table
extnames += ["LINES"] # spectroscopic line table
Expand Down Expand Up @@ -1095,9 +1096,9 @@ def load_spectrum_latest(self, input_file_name):

if not self.fast_load:
with (fits.open(input_file_name) as hdu_list):
# load other spectrum info
self.cov_matrix = hdu_list["SPEC_COV"].data
_, self.data_next_order, self.err_next_order = hdu_list["ORDER2"].data
# load other spectrum info
self.target.image = hdu_list["ORDER0"].data
self.target.image_x0 = float(hdu_list["ORDER0"].header["IM_X0"])
self.target.image_y0 = float(hdu_list["ORDER0"].header["IM_Y0"])
Expand All @@ -1117,7 +1118,7 @@ def load_spectrum_latest(self, input_file_name):
if self.spectrogram_mask is not None:
self.spectrogram_mask = self.spectrogram_mask.astype(bool)
self.chromatic_psf.init_from_table(Table.read(hdu_list["PSF_TAB"]),
saturation=self.spectrogram_saturation)
saturation=self.spectrogram_saturation)
self.lines.table = Table.read(hdu_list["LINES"], unit_parse_strict="silent")

def load_spectrogram(self, input_file_name): # pragma: no cover
Expand Down
23 changes: 2 additions & 21 deletions spectractor/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,6 @@ def _safe_tight_layout(self, *args, **kwargs):
plt.Figure.tight_layout = _safe_tight_layout


# Monkey-patch matplotlib tight_layout to handle LaTeX parsing errors
# This is needed for matplotlib versions in LSST environment that don't fully support LaTeX
_original_tight_layout = plt.Figure.tight_layout


def _safe_tight_layout(self, *args, **kwargs):
"""Wrapper for Figure.tight_layout that catches ValueError from LaTeX parsing errors."""
try:
return _original_tight_layout(self, *args, **kwargs)
except ValueError:
# Silently ignore LaTeX parsing errors in tight_layout
# This typically happens with Greek letters and complex math expressions
# in axis labels or titles when matplotlib's mathtext parser has issues
pass


plt.Figure.tight_layout = _safe_tight_layout


# do not increase speed:
# @njit(fastmath=True, cache=True)
def gauss(x, A, x0, sigma):
Expand Down Expand Up @@ -1896,11 +1877,11 @@ def plot_image_simple(ax, data, scale="lin", title="", units="Image units", cmap
>>> if parameters.DISPLAY: plt.show()
"""
if cmap is not None and isinstance(cmap, str):
colormap = copy.copy(cm.get_cmap(cmap))
colormap = copy.copy(matplotlib.colormaps[cmap])
elif isinstance(cmap, matplotlib.colors.Colormap):
colormap = cmap
else:
colormap = copy.copy(cm.get_cmap('viridis'))
colormap = copy.copy(matplotlib.colormaps['viridis'])
cmap_nan = copy.copy(colormap)
cmap_nan.set_bad(color='lightgrey')

Expand Down
Loading