Skip to content

Commit

Permalink
Changed gaussian fitting to depend on astropy model
Browse files Browse the repository at this point in the history
  • Loading branch information
cylammarco committed Feb 11, 2023
1 parent 5935425 commit 365e9cc
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 124 deletions.
9 changes: 6 additions & 3 deletions src/aspired/flux_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ def get_sensitivity(
self,
k=3,
method="interpolate",
mask_range=[[6850, 6960], [7580, 7700]],
mask_range=[[6850.0, 6960.0], [7580.0, 7700.0]],
mask_fit_order=1,
mask_fit_size=3,
smooth=False,
Expand Down Expand Up @@ -1045,6 +1045,9 @@ def get_sensitivity(
count_err = np.asarray(getattr(self.spectrum1D, "count_err"))
wave = np.asarray(getattr(self.spectrum1D, "wave"))

print(wave)
print(count)

if getattr(self.spectrum1D, "count_continuum") is None:

self.spectrum1D.add_count_continuum(
Expand Down Expand Up @@ -1112,10 +1115,10 @@ def get_sensitivity(

# Get the indices for the two sides of the masking region
left_end = (
int(max(np.where(standard_wave_true <= m[0])[0])) + 1
int(np.max(np.where(standard_wave_true <= m[0]))) + 1
)
left_start = int(left_end - mask_fit_size)
right_start = int(min(np.where(standard_wave_true >= m[1])[0]))
right_start = int(np.min(np.where(standard_wave_true >= m[1])))
right_end = int(right_start + mask_fit_size) + 1

# Get the wavelengths of the two sides
Expand Down
51 changes: 44 additions & 7 deletions src/aspired/spectrum1D.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import copy
import datetime
import logging
import os
Expand Down Expand Up @@ -157,7 +158,9 @@ def __init__(
self.count_err = None
self.count_sky = None
self.var = None

self.profile = None
self.profile_func = None

# Wavelength calibration properties
self.arc_spec = None
self.peaks = None
Expand Down Expand Up @@ -707,6 +710,27 @@ def remove_variances(self):

self.var = None

def add_profile_func(self, profile_func):
"""
Add the fitted trace profile.
Parameters
----------
profile_func: a fitted astropy.model
The fitted trace profile.
"""

self.profile_func = profile_func

def remove_profile_func(self):
"""
Remove the fitted trace profile.
"""

self.profile_func = None

def add_profile(self, profile):
"""
Add the extraction profile.
Expand Down Expand Up @@ -2773,17 +2797,17 @@ def create_flux_fits(self):

# Use the header of the standard
if self.spectrum_header is not None:
header = self.spectrum_header
header = copy.deepcopy(self.spectrum_header)

if self.standard_header is not None:
if header is None:
header = self.standard_header
header = copy.deepcopy(self.standard_header)
else:
header += self.standard_header

if self.arc_header is not None:
if header is None:
header = self.arc_header
header = copy.deepcopy(self.arc_header)
else:
header += self.arc_header

Expand Down Expand Up @@ -2905,17 +2929,17 @@ def create_flux_resampled_fits(self):

# Use the header of the standard
if self.spectrum_header is not None:
header = self.spectrum_header
header = copy.deepcopy(self.spectrum_header)

if self.standard_header is not None:
if header is None:
header = self.standard_header
header = copy.deepcopy(self.standard_header)
else:
header += self.standard_header

if self.arc_header is not None:
if header is None:
header = self.arc_header
header = copy.deepcopy(self.arc_header)
else:
header += self.arc_header

Expand Down Expand Up @@ -3200,6 +3224,7 @@ def create_fits(

hdu_output += self.trace_hdulist
self.hdu_content["trace"] = True
self.logger.info('Added trace ImageHDU.')

if "count" in output_split:

Expand All @@ -3208,6 +3233,7 @@ def create_fits(

hdu_output += self.count_hdulist
self.hdu_content["count"] = True
self.logger.info('Added count ImageHDU.')

if "weight_map" in output_split:

Expand All @@ -3216,6 +3242,7 @@ def create_fits(

hdu_output += self.weight_map_hdulist
self.hdu_content["weight_map"] = True
self.logger.info('Added weight_map ImageHDU.')

if "arc_spec" in output_split:

Expand All @@ -3224,6 +3251,7 @@ def create_fits(

hdu_output += self.arc_spec_hdulist
self.hdu_content["arc_spec"] = True
self.logger.info('Added arc_spec ImageHDU.')

if "wavecal" in output_split:

Expand All @@ -3232,6 +3260,7 @@ def create_fits(

hdu_output += self.wavecal_hdulist
self.hdu_content["wavecal"] = True
self.logger.info('Added wavecal ImageHDU.')

if "wavelength" in output_split:

Expand All @@ -3240,6 +3269,7 @@ def create_fits(

hdu_output += self.wavelength_hdulist
self.hdu_content["wavelength"] = True
self.logger.info('Added wavelength ImageHDU.')

if "count_resampled" in output_split:

Expand All @@ -3248,6 +3278,7 @@ def create_fits(

hdu_output += self.count_resampled_hdulist
self.hdu_content["count_resampled"] = True
self.logger.info('Added count_resampled ImageHDU.')

if "sensitivity" in output_split:

Expand All @@ -3256,6 +3287,7 @@ def create_fits(

hdu_output += self.sensitivity_hdulist
self.hdu_content["sensitivity"] = True
self.logger.info('Added sensitivity ImageHDU.')

if "flux" in output_split:

Expand All @@ -3264,6 +3296,7 @@ def create_fits(

hdu_output += self.flux_hdulist
self.hdu_content["flux"] = True
self.logger.info('Added flux ImageHDU.')

if "sensitivity_resampled" in output_split:

Expand All @@ -3272,6 +3305,7 @@ def create_fits(

hdu_output += self.sensitivity_resampled_hdulist
self.hdu_content["sensitivity_resampled"] = True
self.logger.info('Added sensitivity_resampled ImageHDU.')

if "flux_resampled" in output_split:

Expand All @@ -3280,6 +3314,7 @@ def create_fits(

hdu_output += self.flux_resampled_hdulist
self.hdu_content["flux_resampled"] = True
self.logger.info('Added flux_resampled ImageHDU.')

# If the primary HDU is not chosen to be empty
if not empty_primary_hdu:
Expand All @@ -3290,11 +3325,13 @@ def create_fits(
)
hdu_output.update_extend()
self.empty_primary_hdu = False
self.logger.info('Updated the HDU extend without an empty PrimaryHDU.')

else:

hdu_output.update_extend()
self.empty_primary_hdu = True
self.logger.info('Updated the HDU extend with an empty PrimaryHDU.')

self.hdu_output = hdu_output

Expand Down

0 comments on commit 365e9cc

Please sign in to comment.