Extract IO from class
leliel12 opened this issue · comments
Juan BC commented
Prototype
# ==============================================================================
# DOCS
# ==============================================================================
"""Nirdust test suite."""
# ==============================================================================
# IMPORTS
# ==============================================================================
import numpy as np
from astropy.io import fits
import matplotlib.pyplot as plt
import specutils as su
import os
import pathlib
from pathlib import Path
from astropy import units as u
# ==============================================================================
# CONSTANTS
# ==============================================================================
PATH = pathlib.Path(os.path.abspath(os.path.dirname(__file__)))
# ==============================================================================
# CLASSES
# ==============================================================================
class NuclearSpectrum(su.Spectrum1D):
def __init__(
self,
flux,
header,
spectrum_length,
radius=None,
spectral_axis=None,
data=None,
flux_unit=None,
wav_unit=None,
wcs=None,
velocity_convention=None,
rest_value=None,
redshift=None,
radial_velocity=None,
bin_specification=None,
uncertainty=None,
mask=None,
meta=None,
dispersion_key="CRVAL1",
wavelength="CD1_1",
):
self.spectrum_length = spectrum_length
self.radius = radius
super().__init__(
flux=self.spectrum[extension].data * u.adu,
spectral_axis=(
self.header[dispersion_key]
+ self.header[wavelength]
* np.arange(0, spectrum_length)
)
* u.AA,
wcs=wcs,
velocity_convention=velocity_convention,
rest_value=rest_value,
redshift=redshift,
radial_velocity=radial_velocity,
bin_specification=bin_specification,
uncertainty=uncertainty,
mask=mask,
meta=meta,
)
# class OffNuclearSpectrum(NuclearSpectrum):
# ...
# ==============================================================================
# LOAD SPECTRA
# ==============================================================================
def read_nuclear_spectrum(fname, extension, **kwargs): # IO
spectrums = []
with fits.open(fname) spectrum:
fluxx = pectrum[extension].data
header = fits.getheader(spectrum)
spectrum_length = len(spectrum[extension].data)
single_spectrum = NuclearSpectrum(
spectrum_length=spectrum_legth,
flux=flux, header=header,
*args, **kwargs)
return single_spectrum
spectrums = []
for path in glob.glob("/spectrums*.fots"):
spec = nd.read_nuclear_spectrum(path, 0)
spectrums.append(spec)
Gaiana commented
ready