def test_nis_wfss_background(filters, pupils, make_wfss_datamodel): """Test background subtraction for NIRISS WFSS modes.""" data = make_wfss_datamodel data.meta.instrument.filter = filters data.meta.instrument.pupil = pupils data.meta.instrument.detector = 'NIS' data.meta.instrument.name = 'NIRISS' data.meta.exposure.type = 'NIS_WFSS' wcs_corrected = AssignWcsStep.call(data) # Get References wavelenrange = Step().get_reference_file(wcs_corrected, "wavelengthrange") bkg_file = Step().get_reference_file(wcs_corrected, 'wfssbkg') mask = mask_from_source_cat(wcs_corrected, wavelenrange) with datamodels.open(bkg_file) as bkg_ref: bkg_ref = no_NaN(bkg_ref) # calculate backgrounds pipeline_data_mean = robust_mean(wcs_corrected.data[mask]) test_data_mean, _, _ = sigma_clipped_stats(wcs_corrected.data, sigma=2) pipeline_reference_mean = robust_mean(bkg_ref.data[mask]) test_reference_mean, _, _ = sigma_clipped_stats(bkg_ref.data, sigma=2) assert np.isclose([pipeline_data_mean], [test_data_mean], rtol=1e-3) assert np.isclose([pipeline_reference_mean], [test_reference_mean], rtol=1e-1)
def test_no_Nan(): """Make sure that nan values are filled with fill value""" # Make data model model = datamodels.ImageModel() data = np.random.rand(10, 10) # Randomly insert NaNs data.ravel()[np.random.choice(data.size, 10, replace=False)] = np.nan model.data = data # Randomly select fill value fill_val = np.random.randint(0, 20) # Call no_NaN result = no_NaN(model, fill_value=fill_val) # Use np.NaN to find NaNs. test_result = np.isnan(model.data) # Assign fill values to NaN indices model.data[test_result] = fill_val # Make sure arrays are equal. assert np.array_equal(model.data, result.data)