Skip to content

Commit

Permalink
Added standard stars filename to dsignation jsons, to be incorporated…
Browse files Browse the repository at this point in the history
… to a new name resolver.
  • Loading branch information
cylammarco committed Apr 6, 2023
1 parent 9107d7a commit 8dfd80d
Show file tree
Hide file tree
Showing 26 changed files with 15,579 additions and 180 deletions.
76 changes: 48 additions & 28 deletions src/aspired/flux_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def __init__(
raise ValueError("Unknonw logging level.")

formatter = logging.Formatter(
"[%(asctime)s] %(levelname)s [%(filename)s:%(lineno)d] "
"%(message)s",
"[%(asctime)s] %(levelname)s [%(filename)s:%(lineno)d] %(message)s",
datefmt="%a, %d %b %Y %H:%M:%S",
)

Expand Down Expand Up @@ -343,17 +342,21 @@ def lookup_standard_libraries(self, target, cutoff=0.4):

if len(target_list) > 0:
self.logger.warning(
"Requested standard star cannot be found, a list of the "
"closest matching names are returned: %s",
(
"Requested standard star cannot be found, a list of the"
" closest matching names are returned: %s"
),
target_list,
)

return target_list, False

else:
error_msg = (
"Please check the name of your standard star, nothing "
"share a similarity above %s.",
(
"Please check the name of your standard star, nothing "
"share a similarity above %s."
),
cutoff,
)
self.logger.critical(error_msg)
Expand Down Expand Up @@ -456,9 +459,11 @@ def load_standard(self, target, library=None, ftype="flux", cutoff=0.4):
self.library = libraries[0]

self.logger.warning(
"The requested standard star cannot be found in the "
"given library, or the library is not specified. "
"ASPIRED is using %s.",
(
"The requested standard star cannot be found in the"
" given library, or the library is not specified."
" ASPIRED is using %s."
),
self.library,
)

Expand All @@ -469,8 +474,10 @@ def load_standard(self, target, library=None, ftype="flux", cutoff=0.4):
self.library = libraries[0]

self.logger.warning(
"The requested library does not exist, %s is used "
"because it has the closest matching name.",
(
"The requested library does not exist, %s is used "
"because it has the closest matching name."
),
self.library,
)

Expand Down Expand Up @@ -677,8 +684,7 @@ def __init__(
if log_level == "DEBUG":
logging.basicConfig(level=logging.DEBUG)
formatter = logging.Formatter(
"[%(asctime)s] %(levelname)s [%(filename)s:%(lineno)d] "
"%(message)s",
"[%(asctime)s] %(levelname)s [%(filename)s:%(lineno)d] %(message)s",
datefmt="%a, %d %b %Y %H:%M:%S",
)

Expand Down Expand Up @@ -951,7 +957,12 @@ def inspect_telluric_profile(
)
)
# show the image on the top
self.logger.info(np.asarray(self.spectrum_oned.wave))
self.logger.debug(np.asarray(self.spectrum_oned.wave))
self.logger.debug(
self.spectrum_oned.telluric_func(
np.asarray(self.spectrum_oned.wave)
)
)
fig.add_trace(
go.Scatter(
x=np.asarray(self.spectrum_oned.wave),
Expand Down Expand Up @@ -1016,8 +1027,9 @@ def get_sensitivity(
sorder=3,
return_function=True,
sens_deg=7,
recompute_continuum=True,
**kwargs,
use_continuum=False,
recompute_continuum=False,
*args,
):
"""
The sensitivity curve is computed by dividing the true values by the
Expand Down Expand Up @@ -1060,10 +1072,12 @@ def get_sensitivity(
sens_deg: int (Default: 7)
The degree of polynomial of the sensitivity curve, only used if
the method is 'polynomial'.
recompute_continuum: bool (Default: True)
use_continuum: bool (Default: False)
Set to True to use continuum for finding the sensitivity function.
recompute_continuum: bool (Default: False)
Recompute the continuum before computing the sensitivity function.
**kwargs:
keyword arguments for passing to the LOWESS functionj for getting
*args:
keyword arguments for passing to the LOWESS function for getting
the continuum, see
`statsmodels.nonparametric.smoothers_lowess.lowess()`
Expand All @@ -1085,8 +1099,10 @@ def get_sensitivity(
exptime = 1.0

self.logger.info(
"The exposure time used for computing sensitivity curve "
"is %s seconds.",
(
"The exposure time used for computing sensitivity curve "
"is %s seconds."
),
exptime,
)

Expand Down Expand Up @@ -1143,14 +1159,18 @@ def get_sensitivity(
# Set the smoothing parameters
self.spectrum_oned.add_smoothing(smooth, slength, sorder)

if (
getattr(self.spectrum_oned, "count_continuum") is None
) or recompute_continuum:
self.spectrum_oned.add_count_continuum(
get_continuum(wave, count, **kwargs)
)
if use_continuum:
if (
getattr(self.spectrum_oned, "count_continuum") is None
) or recompute_continuum:
self.spectrum_oned.add_count_continuum(
get_continuum(wave, count, *args)
)

count = np.asarray(getattr(self.spectrum_oned, "count_continuum"))

count = np.asarray(getattr(self.spectrum_oned, "count_continuum"))
else:
count = np.asarray(getattr(self.spectrum_oned, "count"))

# If the median resolution of the observed spectrum is higher than
# the literature one
Expand Down
21 changes: 7 additions & 14 deletions src/aspired/onedspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4254,7 +4254,7 @@ def add_telluric_function(
"be performed."
)

def get_continuum(self, spec_id=None, **kwargs):
def get_continuum(self, spec_id=None, *args):
"""
** EXPERIMENTAL, as of 1 October 2021 **
Expand Down Expand Up @@ -4292,13 +4292,11 @@ def get_continuum(self, spec_id=None, **kwargs):
count = science_spec.count
flux = science_spec.flux

science_spec.add_count_continuum(
get_continuum(wave, count, **kwargs)
)
science_spec.add_count_continuum(get_continuum(wave, count, *args))

if flux is not None:
science_spec.add_flux_continuum(
get_continuum(wave, flux, **kwargs)
get_continuum(wave, flux, *args)
)

else:
Expand Down Expand Up @@ -4392,7 +4390,7 @@ def get_telluric_correction(
)

def get_telluric_strength(
self, factor=1.0, auto_apply=False, spec_id=None, **kwargs
self, factor=1.0, auto_apply=False, spec_id=None, *args
):
"""
Get the telluric absorption profile from the standard star based on
Expand Down Expand Up @@ -4462,10 +4460,8 @@ def get_telluric_strength(
wave = science_spec.wave
flux = science_spec.flux

if (science_spec.flux_continuum is None) or (
len(kwargs.keys()) > 0
):
self.get_continuum(i, **kwargs)
if (science_spec.flux_continuum is None) or (len(args) > 0):
self.get_continuum(i, *args)

flux_continuum = science_spec.flux_continuum

Expand All @@ -4492,9 +4488,7 @@ def get_telluric_strength(
standard_spec = self.standard_spectrum_list[0]
wave_standard = standard_spec.wave

if (standard_spec.telluric_profile is None) or (
len(kwargs.keys()) > 0
):
if (standard_spec.telluric_profile is None) or (len(args) > 0):
standard_spec.add_telluric_profile(
standard_spec.telluric_func(wave_standard)
)
Expand Down Expand Up @@ -8149,7 +8143,6 @@ def save_fits(
for i in spec_id:
if len(spec_id) == 1:
filename_i = filename + "_science"

else:
filename_i = filename + "_science_" + str(i)

Expand Down

0 comments on commit 8dfd80d

Please sign in to comment.