Commit 6746454b authored by Francesco Amadori's avatar Francesco Amadori
Browse files

criresp adjustment

parent 8ce72dac
Loading
Loading
Loading
Loading
+27 −29
Original line number Original line Diff line number Diff line
import re
import re
import tkinter as tk
import tkinter as tk
import traceback
from pathlib import Path
from pathlib import Path
from tkinter import ttk
from tkinter import ttk


@@ -1329,30 +1330,22 @@ class Frame_Gofio:
        listB = list()
        listB = list()
        if instrument == "criresp":
        if instrument == "criresp":
            folder = Path(dirr)
            folder = Path(dirr)
            mjd_key = yaml_file['MJD']
            if obs_mode == "Nodding":
            if obs_mode == "Nodding":
                # Trova file A e B
                # Collect A and B nodding files
                dictA = {int(f.stem.split("_")[-1]): f
                filesA = list(folder.glob("cr2res_obs_nodding_extractedA_*.fits"))
                          for f in folder.glob("cr2res_obs_nodding_extractedA_*.fits")}
                filesB = list(folder.glob("cr2res_obs_nodding_extractedB_*.fits"))
                dictB = {int(f.stem.split("_")[-1]): f
                          for f in folder.glob("cr2res_obs_nodding_extractedB_*.fits")}
                if separate_A_B:
                if separate_A_B:
                    all_indices = sorted(set(dictA.keys()) | set(dictB.keys()))
                    # Sort A and B separately by MJD
                    for i in all_indices:
                    listA = sorted(filesA, key=lambda f: fits.getheader(f)[mjd_key])
                        if i in dictA:
                    listB = sorted(filesB, key=lambda f: fits.getheader(f)[mjd_key])
                            listA.append(dictA[i])
                        if i in dictB:
                            listB.append(dictB[i])
                else:
                else:
                    # Tutti gli indici trovati
                    # Sort all A+B files together by MJD
                    all_indices = sorted(set(dictA.keys()) | set(dictB.keys()))
                    listAB = sorted(filesA + filesB, key=lambda f: fits.getheader(f)[mjd_key])
                    listAB = []
                    for i in all_indices:
                        if i in dictA:
                            listAB.append(dictA[i])
                        if i in dictB:
                            listAB.append(dictB[i])
            else:
            else:
                listAB = list(folder.glob("cr2res_obs_staring_extracted_*.fits"))
                # Staring mode: sort by MJD
                staring_files = list(folder.glob("cr2res_obs_staring_extracted*.fits"))
                listAB = sorted(staring_files, key=lambda f: fits.getheader(f)[mjd_key])
        else:
        else:
            #
            #
            for file in os.listdir(dirr):
            for file in os.listdir(dirr):
@@ -1367,6 +1360,7 @@ class Frame_Gofio:
                        listAB.append(os.path.join(dirr, file))
                        listAB.append(os.path.join(dirr, file))
        #
        #
        self.run_from_gofio.configure(state="disabled")
        self.run_from_gofio.configure(state="disabled")
        try:
            if separate_A_B and instrument in ["gianob", "criresp"] and obs_mode == "Nodding":
            if separate_A_B and instrument in ["gianob", "criresp"] and obs_mode == "Nodding":
                if len(listA) == len(listB):
                if len(listA) == len(listB):
                    self.procedure_fromgofio(listA, "A_", night, dirn, threshold_SNR_f, target, yaml_file, instrument)
                    self.procedure_fromgofio(listA, "A_", night, dirn, threshold_SNR_f, target, yaml_file, instrument)
@@ -1375,6 +1369,9 @@ class Frame_Gofio:
                    print("The amount of files A is not equal to the amount of file B")
                    print("The amount of files A is not equal to the amount of file B")
            else: # for nodding/stare mode of gianob/criresp and for espresso or harpsn
            else: # for nodding/stare mode of gianob/criresp and for espresso or harpsn
                self.procedure_fromgofio(listAB, "", night, dirn, threshold_SNR_f, target, yaml_file, instrument)
                self.procedure_fromgofio(listAB, "", night, dirn, threshold_SNR_f, target, yaml_file, instrument)
        except Exception as e:
            print(str(e), traceback.format_exc())
            tk.messagebox.showerror("Error", "An error occurred during the reduction/separation process. Please check the log file for details.")
        self.run_from_gofio.configure(state="normal")
        self.run_from_gofio.configure(state="normal")


    def procedure_fromgofio(
    def procedure_fromgofio(
@@ -1392,14 +1389,15 @@ class Frame_Gofio:
                        m = re.match(r"(\d+)_01_SPEC", name)
                        m = re.match(r"(\d+)_01_SPEC", name)
                        if m:
                        if m:
                            order = m.group(1)  # es. '07'
                            order = m.group(1)  # es. '07'
                            print(f"Chip: {chip_idx}; Order: {order} ")
                            if order not in channels_per_order:
                            if order not in channels_per_order:
                                channels_per_order[order] = len(chip.data[name])
                                channels_per_order[order] = len(chip.data[name])
                            struct_crires.append((chip_idx, order))
                            struct_crires.append((chip_idx, order))
        else:
        else:
            struct_crires = None
            struct_crires = None
            list_file.sort()
        orders_str = ""
        orders_str = ""
        SNR_mean_str = ""
        SNR_mean_str = ""
        list_file.sort()
        nimages = len(list_file)
        nimages = len(list_file)
        curr_image = ImageAnalysis(list_file[0], target_f, yaml_file, struct_crires)
        curr_image = ImageAnalysis(list_file[0], target_f, yaml_file, struct_crires)
        norder = curr_image.norder
        norder = curr_image.norder
+2 −0
Original line number Original line Diff line number Diff line
@@ -98,6 +98,8 @@ class ImageAnalysis:
        self.npix = yaml_file['npix']
        self.npix = yaml_file['npix']
        # Total number of spectral orders in the echelle spectrum
        # Total number of spectral orders in the echelle spectrum
        self.norder = yaml_file['norder']
        self.norder = yaml_file['norder']
        if self.norder == "xx":
            self.norder = len(struct_crires)


        # ======================== OPEN AND READ FITS FILE ========================
        # ======================== OPEN AND READ FITS FILE ========================
        # Open the FITS file containing the spectroscopic data
        # Open the FITS file containing the spectroscopic data
+1 −1
Original line number Original line Diff line number Diff line
@@ -12,7 +12,7 @@ index_header : 0
data_in_columns : "None"
data_in_columns : "None"
files_type : RAW
files_type : RAW
npix : 2048
npix : 2048
norder : 24
norder : xx # 24
ra_dec_deg : 1
ra_dec_deg : 1
corr_zero : 0
corr_zero : 0
NEED_SUM_EXPOSURE_TO_MJD : 1
NEED_SUM_EXPOSURE_TO_MJD : 1