From 6269a343373a7249d06f9348995b4dde0eedb410 Mon Sep 17 00:00:00 2001 From: arjunsavel Date: Thu, 6 Mar 2025 12:33:42 -0500 Subject: [PATCH 1/2] more logging...plus feed instrument to blaze --- src/scope/noise.py | 9 ++++++++- src/scope/run_simulation.py | 12 ++++++++---- src/scope/tellurics.py | 6 ++++++ src/scope/utils.py | 5 ----- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/scope/noise.py b/src/scope/noise.py index dbd0c0a..3203cc7 100644 --- a/src/scope/noise.py +++ b/src/scope/noise.py @@ -3,8 +3,11 @@ """ import numpy as np +from scope.logger import get_logger from scope.utils import * +logger = get_logger() + test_data_path = os.path.join(os.path.dirname(__file__), "data") @@ -92,7 +95,8 @@ def add_quadratic_noise(flux_cube_model, wl_grid, SNR, IGRINS=False, **kwargs): else: raise NotImplementedError("Only IGRINS data is currently supported.") - + logger.debug("Added quadratic IGRINS noise to the flux cube model.") + logger.debug("mean noisy flux: {}".format(np.mean(noisy_flux))) return noisy_flux @@ -130,6 +134,9 @@ def add_crires_plus_noise(flux_cube_model, wl_grid, SNR): # a few quick checks to make sure that nothing has gone wrong with adding noise noisy_flux[order][exposure][noisy_flux[order][exposure] < 0.0] = 0.0 noisy_flux[order][exposure][~np.isfinite(noisy_flux[order][exposure])] = 0.0 + logger.debug("Added CRIRES+ noise to the flux cube model.") + logger.debug("mean SNR: {}".format(np.mean(SNR))) + logger.debug("mean noisy flux: {}".format(np.mean(noisy_flux))) return noisy_flux diff --git a/src/scope/run_simulation.py b/src/scope/run_simulation.py index bfe9125..ae25fb0 100644 --- a/src/scope/run_simulation.py +++ b/src/scope/run_simulation.py @@ -93,6 +93,7 @@ def make_data( np.random.seed(seed) logger.info(f"Seed set to {seed}") + logger.debug(f"Mean stellar flux: {np.mean(Fstar_conv)}") rv_planet, rv_star = calc_rvs( v_sys, v_sys_measured, Kp, rv_semiamp_orbit, phases @@ -143,7 +144,7 @@ def make_data( flux_cube[:, i, :], 90 ) flux_cube[:, i, :] *= throughput_factor - + logger.debug(f"Mean flux post-throughput variation: {np.mean(flux_cube)}") if tellurics: if instrument != "IGRINS": raise NotImplementedError( @@ -174,8 +175,11 @@ def make_data( just_tellurics[just_tellurics < 0.0] = 0.0 flux_cube = detrend_cube(flux_cube, n_order, n_exposure) if blaze: - flux_cube = add_blaze_function(wlgrid, flux_cube, n_order, n_exposure) + flux_cube = add_blaze_function( + wlgrid, flux_cube, n_order, n_exposure, instrument=instrument + ) flux_cube[flux_cube < 0.0] = 0.0 + logger.debug(f"Mean flux post-blaze: {np.mean(flux_cube)}") flux_cube[np.isnan(flux_cube)] = 0.0 flux_cube = detrend_cube(flux_cube, n_order, n_exposure) @@ -255,13 +259,14 @@ def make_data( flux_cube /= median_out_of_transit # todo: check axes work out if do_pca: + logger.debug("mean flux pre-pca: ", np.mean(flux_cube)) for j in range(n_order): flux_cube[j] -= np.mean(flux_cube[j]) flux_cube[j] /= np.std(flux_cube[j]) flux_cube[j], pca_noise_matrix[j] = perform_pca( flux_cube[j], n_princ_comp, pca_removal=pca_removal ) - + logger.debug("mean flux post-pca: ", np.mean(flux_cube)) else: for j in range(n_order): for i in range(n_exposure): @@ -523,7 +528,6 @@ def simulate_observation( star_flux, star_wave, v_rot_star, phases, Rstar, inc, lambda_misalign, a, Rp ) - # todo: swap out Fstar_conv = get_star_spline( star_wave, star_flux, wl_model, instrument_kernel, smooth=False ) diff --git a/src/scope/tellurics.py b/src/scope/tellurics.py index 90aefb5..213f1e8 100644 --- a/src/scope/tellurics.py +++ b/src/scope/tellurics.py @@ -9,6 +9,10 @@ import pandas as pd from scipy import interpolate +from scope.logger import get_logger + +logger = get_logger() + abs_path = os.path.dirname(__file__) @@ -230,4 +234,6 @@ def add_tellurics( flux_cube_model = add_tellurics_atran( wl_cube_model, flux_cube_model, n_order, n_exp, vary_airmass=vary_airmass ) + logger.debug("Tellurics added.") + logger.debug("mean flux post-tellurics: ", np.mean(flux_cube_model)) return flux_cube_model diff --git a/src/scope/utils.py b/src/scope/utils.py index 804ed80..a01b487 100644 --- a/src/scope/utils.py +++ b/src/scope/utils.py @@ -191,11 +191,6 @@ def calc_limb_darkening(u1, u2, a, b, Rstar, ph, LD): return I -# todo: download atran scripts -# todo: fit wavelength solution stuff -# todo: plot the maps - - @njit def perform_pca(input_matrix, n_princ_comp, pca_removal="subtract"): """ From d3f0b6e8dfe632c3d33bd28adda443f9a059ba47 Mon Sep 17 00:00:00 2001 From: arjunsavel Date: Thu, 6 Mar 2025 12:36:00 -0500 Subject: [PATCH 2/2] only yell about data driven tellurics if tgellurics are true --- src/scope/input_output.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/scope/input_output.py b/src/scope/input_output.py index 3f2d2f5..843b31a 100644 --- a/src/scope/input_output.py +++ b/src/scope/input_output.py @@ -241,7 +241,11 @@ def parse_input_file( data = calculate_derived_parameters(data) - if data["tell_type"] == "data-driven" and data["blaze"] == False: + if ( + data["tell_type"] == "data-driven" + and data["blaze"] == False + and data["telluric"] == True + ): raise ScopeConfigError("Data-driven tellurics requires blaze set to True.") return data