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

Added WCS support #37

Merged
merged 3 commits into from
Jun 21, 2021
Merged

Added WCS support #37

merged 3 commits into from
Jun 21, 2021

Conversation

mchalela
Copy link
Collaborator

The main changes are the removal of header keyword arguments: dispersion_key, first_wavelength, dispersion_type. These arguments were used solely for reconstructing the spectral axis. This PR implements the use of astropy WCS methods to reconstruct the spectral axis by recognizing the header format.

The extension is now detected automatically but if many extensions are present in a file the user can still specify the extension to use. Solves issue #36.

Those 3 arguments are removed from read_spectrum, spectrum and NirdustSpectrum.

@mchalela mchalela requested review from leliel12 and Gaiana June 20, 2021 17:12
@leliel12
Copy link
Collaborator

Yo cambiaria

ext = _get_science_extension(hdulist, extension)

Por

def read_spectrum(file_name, extension=None, z=0, **kwargs):

    with fits.open(file_name) as hdulist:
        if extension is None:
            ext_candidates = infer_fits_science_extension(hdulist, extension)
            if len(ext_candidates) > 1:
                raise HeaderKeywordError(
                    "More than one extension with relevant keywords. "
                    "Please specify the extension."
                )
        
            extension = extension_candidates[0]
        
        flux = hdulist[ext].data
        header = hdulist[ext].header

    single_spectrum = spectrum(flux, header, z, **kwargs)

    return single_spectrum

Con eso hago public el _get_science_extension y puede usarse para por las dudas para otras cosas y ademas le sacamos responsabilidad de decidir que hacer con el None, cosa que es realmente informacion relevante para read_spectrum

Asi infer_fits_science_extension (tal ves no es el mejor nombre) quedaria:

def infer_fit_science_extension(hdulist, extension):
    """Auto detect fits science extension using the provided keywords."""

    if len(hdulist) == 1:
        return np.array([0])

    keys = {'CRVAL1'}   # keywords that are present in science extensions
    extl = []
    for ext, hdu in enumerate(hdulist):
        if keys.issubset(hdu.header.keys()):
            extl.append(ext)

    return np.array(extl)

@mchalela
Copy link
Collaborator Author

Puse todos los cambios, mas test y docu. Quedo mucho mejor 👍

@mchalela mchalela merged commit 35caff7 into dev Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants