Skip to content

Commit

Permalink
Applied sorted on list of filenames when glob is used
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstolker committed Jun 10, 2024
1 parent e2fcd55 commit 456c179
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions pycrires/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ def extract_header(self) -> None:
key_file = os.path.dirname(__file__) + "/keywords.txt"
keywords = np.genfromtxt(key_file, dtype="str", delimiter=",")

raw_files = Path(self.path / "raw").glob("*.fits")
raw_files = sorted(Path(self.path / "raw").glob("*.fits"))

header_dict = {}
for key_item in keywords:
Expand Down Expand Up @@ -1599,17 +1599,17 @@ def cal_dark(self, verbose: bool = True, create_sof: bool = True) -> None:

print("Output files:")

fits_files = Path(self.path / "calib/cal_dark").glob(
"cr2res_cal_dark_*master.fits"
fits_files = sorted(
Path(self.path / "calib/cal_dark").glob("cr2res_cal_dark_*master.fits")
)

for item in fits_files:
self._update_files("CAL_DARK_MASTER", str(item))

# Update file dictionary with bad pixel map

fits_files = Path(self.path / "calib/cal_dark").glob(
"cr2res_cal_dark_*bpm.fits"
fits_files = sorted(
Path(self.path / "calib/cal_dark").glob("cr2res_cal_dark_*bpm.fits")
)

for item in fits_files:
Expand Down Expand Up @@ -1800,16 +1800,20 @@ def cal_flat(self, verbose: bool = True, create_sof: bool = True) -> None:

print("\nOutput files:")

fits_files = Path(self.path / "calib/cal_flat").glob(
"cr2res_cal_flat_*master_flat.fits"
fits_files = sorted(
Path(self.path / "calib/cal_flat").glob(
"cr2res_cal_flat_*master_flat.fits"
)
)

for item in fits_files:
self._update_files("CAL_FLAT_MASTER", str(item))

# Update file dictionary with TraceWave table

fits_files = Path(self.path / "calib/cal_flat").glob("cr2res_cal_flat_*tw.fits")
fits_files = sorted(
Path(self.path / "calib/cal_flat").glob("cr2res_cal_flat_*tw.fits")
)

for item in fits_files:
self._update_files("CAL_FLAT_TW", str(item))
Expand Down Expand Up @@ -3447,7 +3451,7 @@ def util_genlines(self, verbose: bool = True, create_sof: bool = True) -> None:
data_static = Path(esorex_path[:-10] + "share/esopipes/datastatic")

if data_static.is_dir():
if data_static.glob("cr2re-*"):
if sorted(data_static.glob("cr2re-*")):
cr2re_folder = list(data_static.glob("cr2re-*"))[0]
cr2re_data = glob.glob(f"{cr2re_folder}/*")

Expand Down Expand Up @@ -3962,7 +3966,7 @@ def obs_staring(
name_pattern = "cr2res_obs_staring_extracted*.fits"

files_i = sorted(
[int(x.stem.split("_")[-1]) for x in folder.glob(name_pattern)]
[int(x.stem.split("_")[-1]) for x in sorted(folder.glob(name_pattern))]
)

if len(files_i) > 1:
Expand Down Expand Up @@ -4187,9 +4191,11 @@ def obs_nodding(
files_raw_b = self.header_data[nod_b_exp]["ORIGFILE"]
files_raw = list(files_raw_a) + list(files_raw_b)

files_cal = glob.glob(
str(self.calib_folder) + "/util_calib_nodding/"
"CRIRES_SPEC_*_calibrated.fits"
files_cal = sorted(
glob.glob(
str(self.calib_folder) + "/util_calib_nodding/"
"CRIRES_SPEC_*_calibrated.fits"
)
)

for file_idx, file_item in enumerate(files_cal):
Expand Down Expand Up @@ -4387,8 +4393,10 @@ def obs_nodding(
if esorex_path is not None:
data_static = esorex_path[:-10] + "share/esopipes/datastatic"

if glob.glob(f"{data_static}/cr2re-*"):
cr2re_folder = glob.glob(f"{data_static}/cr2re-*")[0]
if sorted(glob.glob(f"{data_static}/cr2re-*")):
cr2re_folder = sorted(glob.glob(f"{data_static}/cr2re-*"))[
0
]
cr2re_data = sorted(glob.glob(f"{cr2re_folder}/*"))
tw_file = f"{cr2re_folder}/{science_wlen}_tw.fits"

Expand Down Expand Up @@ -5746,7 +5754,7 @@ def correct_wavelengths(
str(self.product_folder)
+ f"/obs_nodding/cr2res_obs_nodding_extracted{nod_ab}_*.fits"
)
fits_files = glob.glob(input_files)
fits_files = sorted(glob.glob(input_files))

elif input_folder == "util_extract_science":
fits_files = list(self.file_dict[f"UTIL_EXTRACT_SCIENCE_{nod_ab}"].keys())
Expand Down Expand Up @@ -6845,11 +6853,13 @@ def fit_gaussian(
)

input_folder = self.product_folder / extraction_input
fits_files = Path(input_folder).glob(f"cr2res_combined{nod_ab}_*_extr2d.fits")
n_exp = len(
list(Path(input_folder).glob(f"cr2res_combined{nod_ab}_*_extr2d.fits"))

fits_files = sorted(
Path(input_folder).glob(f"cr2res_combined{nod_ab}_*_extr2d.fits")
)

n_exp = len(fits_files)

print_msg = ""
out_files = []

Expand Down

0 comments on commit 456c179

Please sign in to comment.