def test_fluxcalibration(mock_show): hiltner_spectrum1D = Spectrum1D(log_file_name=None) lhs6328_spectrum1D = Spectrum1D(log_file_name=None) fluxcalibrator = FluxCalibration(log_file_name=None) # Science and Standard counts standard_count = np.loadtxt( os.path.join(HERE, "test_data", "test_full_run_standard_count.csv"), delimiter=",", skiprows=1, )[:, 0] science_count = np.loadtxt( os.path.join(HERE, "test_data", "test_full_run_science_0_count.csv"), delimiter=",", skiprows=1, )[:, 0] wavelength = np.loadtxt( os.path.join( HERE, "test_data", "test_full_run_standard_wavelength.csv" ), skiprows=1, ) hiltner_spectrum1D.add_count(standard_count) hiltner_spectrum1D.add_wavelength(wavelength) lhs6328_spectrum1D.add_count(science_count) lhs6328_spectrum1D.add_wavelength(wavelength) # Add the standard spectrum1D to the flux calibrator fluxcalibrator.from_spectrum1D(hiltner_spectrum1D) # Load standard star from literature fluxcalibrator.load_standard("hiltner102") fluxcalibrator.get_sensitivity() # Get back the spectrum1D and merge fluxcalibrator.apply_flux_calibration( lhs6328_spectrum1D, inspect=True, display=False, return_jsonstring=True, save_fig=True, fig_type="iframe+png", filename=os.path.join(HERE, "test_output", "fluxcal_flux_calibration"), ) fluxcalibrator.apply_flux_calibration(lhs6328_spectrum1D, display=True)
def test_overwritten_copy_of_spectrum1Ds_are_different(): lhs6328_spectrum1D = Spectrum1D(log_file_name=None) wavecal_1 = WavelengthCalibration(log_file_name=None) wavecal_1.from_spectrum1D(lhs6328_spectrum1D) memory_1 = id(wavecal_1.spectrum1D) wavecal_1.from_spectrum1D(copy.copy(lhs6328_spectrum1D), overwrite=True) memory_2 = id(wavecal_1.spectrum1D) assert memory_1 != memory_2
def test_sensitivity(mock_show): hiltner_spectrum1D = Spectrum1D(log_file_name=None) sens = FluxCalibration(log_file_name=None) # Standard count count = np.loadtxt( os.path.join(HERE, "test_data", "test_full_run_standard_count.csv"), delimiter=",", skiprows=1, )[:, 0] wavelength = np.loadtxt( os.path.join( HERE, "test_data", "test_full_run_standard_wavelength.csv" ), skiprows=1, ) hiltner_spectrum1D.add_count(count) hiltner_spectrum1D.add_wavelength(wavelength) sens.from_spectrum1D(hiltner_spectrum1D) # Load standard star from literature sens.load_standard("hiltner102") sens.inspect_standard( display=False, return_jsonstring=True, save_fig=True, fig_type="iframe+png", filename=os.path.join(HERE, "test_output", "fluxcal_inspect_standard"), ) sens.inspect_standard(display=True) sens.get_sensitivity() # Get back the spectrum1D and merge hiltner_spectrum1D.merge(sens.get_spectrum1D()) # Save a FITS file sens.save_fits( output="sensitivity", filename=os.path.join(HERE, "test_output", "test_sensitivity"), overwrite=True, ) # Save a CSV file sens.save_csv( output="sensitivity", filename=os.path.join(HERE, "test_output", "test_sensitivity"), overwrite=True, )
def test_setting_nones_to_known_pairs_expect_fail(): lhs6328_spectrum1D = Spectrum1D(log_file_name=None) wavecal = WavelengthCalibration(log_file_name=None) lhs6328_spectrum1D.add_arc_spec(arc_spec) wavecal.from_spectrum1D(lhs6328_spectrum1D) # Find the peaks of the arc wavecal.find_arc_lines( save_fig=True, fig_type="iframe+png", filename=os.path.join( HERE, "test_output", "test_wavecal_find_arc_lines" ), display=False, return_jsonstring=True, ) wavecal.initialise_calibrator() wavecal.set_known_pairs([None], [None])
def test_setting_known_pairs(mock_show): lhs6328_spectrum1D = Spectrum1D(log_file_name=None) wavecal = WavelengthCalibration(log_file_name=None) lhs6328_spectrum1D.add_arc_spec(arc_spec) wavecal.from_spectrum1D(lhs6328_spectrum1D) # Find the peaks of the arc wavecal.find_arc_lines( save_fig=True, fig_type="iframe+png", filename=os.path.join( HERE, "test_output", "test_wavecal_find_arc_lines" ), display=True, return_jsonstring=True, ) wavecal.initialise_calibrator() wavecal.set_known_pairs([123, 234], [456, 567]) assert len(wavecal.spectrum1D.calibrator.pix_known) == 2 assert len(wavecal.spectrum1D.calibrator.wave_known) == 2
def test_wavecal(): lhs6328_spectrum1D = Spectrum1D(log_file_name=None) wavecal = WavelengthCalibration(log_file_name=None) # Science arc_spec lhs6328_spectrum1D.add_arc_spec(arc_spec) wavecal.from_spectrum1D(lhs6328_spectrum1D) # Find the peaks of the arc wavecal.find_arc_lines( save_fig=True, fig_type="iframe+png", filename=os.path.join( HERE, "test_output", "test_wavecal_find_arc_lines" ), display=False, return_jsonstring=True, ) # Configure the wavelength calibrator wavecal.initialise_calibrator() wavecal.set_hough_properties( num_slopes=1000, xbins=200, ybins=200, min_wavelength=3500, max_wavelength=8500, ) wavecal.set_ransac_properties(filter_close=True) wavecal.add_user_atlas(elements=element, wavelengths=atlas) # Remove all lines between 3500 and 4000 wavecal.remove_atlas_lines_range(wavelength=3750, tolerance=250) wavecal.do_hough_transform() # Solve for the pixel-to-wavelength solution wavecal.fit(max_tries=500, display=False) # Getting the calibrator wavecal.get_calibrator() # Save a FITS file wavecal.save_fits( output="wavecal", filename=os.path.join(HERE, "test_output", "test_wavecal"), overwrite=True, ) # Save a CSV file wavecal.save_csv( output="wavecal", filename=os.path.join(HERE, "test_output", "test_wavecal"), overwrite=True, ) # Getting the calibrator wavecal.get_spectrum1D() wavecal.list_atlas() wavecal.clear_atlas() wavecal.list_atlas()