Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect ordering of multiple exposures due to behavior of glob #18

Open
lorenzo-pino1 opened this issue Jun 7, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@lorenzo-pino1
Copy link

lorenzo-pino1 commented Jun 7, 2024

In my version of python and with my filesystem, the glob function returns file names in an incorrect ordering (see example in the end, which is the 'fits_item' generator converted to a list). Since naming output is based on the fits_idx index generated by enumerate, the spectra result reshuffled after the analysis.

I have noticed this behavior only in fit_gaussian, while in other functions the order is correctly enforced.

Proposed fix (inelegant, but is compatible with the rest of the code):

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

        fits_files.sort(key=lambda x: int(x.stem.split('_')[2]))

/Users/pino/Programs_work/HD169142_appo/analysis_raw_data/product/custom_extract_2d/cr2res_combinedB_002_extr2d.fits
/Users/pino/Programs_work/HD169142_appo/analysis_raw_data/product/custom_extract_2d/cr2res_combinedB_007_extr2d.fits
/Users/pino/Programs_work/HD169142_appo/analysis_raw_data/product/custom_extract_2d/cr2res_combinedB_004_extr2d.fits
/Users/pino/Programs_work/HD169142_appo/analysis_raw_data/product/custom_extract_2d/cr2res_combinedB_008_extr2d.fits
/Users/pino/Programs_work/HD169142_appo/analysis_raw_data/product/custom_extract_2d/cr2res_combinedB_001_extr2d.fits
/Users/pino/Programs_work/HD169142_appo/analysis_raw_data/product/custom_extract_2d/cr2res_combinedB_006_extr2d.fits
/Users/pino/Programs_work/HD169142_appo/analysis_raw_data/product/custom_extract_2d/cr2res_combinedB_003_extr2d.fits
/Users/pino/Programs_work/HD169142_appo/analysis_raw_data/product/custom_extract_2d/cr2res_combinedB_000_extr2d.fits
/Users/pino/Programs_work/HD169142_appo/analysis_raw_data/product/custom_extract_2d/cr2res_combinedB_005_extr2d.fits

@tomasstolker tomasstolker added the bug Something isn't working label Jun 10, 2024
@tomasstolker
Copy link
Owner

Thanks for opening this issue! I have pushed an update which hopefully fixes this. Applying sorted() should probably be sufficient. Just in case, I have also added sorted() to other glob() cases where the sorting was missing. Let me know if that works as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants