def test_pix_6(): """ CASE F: segment has 2 good groups not at array end CASE A: segment has >2 groups, at end of ramp. SCI segs are: seg0[15,25](F), seg1[54, 55, 65, 375, 394, 395, 405](A) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 55., 65., 375., 394., 395., 405.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 0, 4, 4, 0, 0, 0, 0, 0, 0]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [6.092052, 4, 0.14613187, 0.0025974, 0.01875712] # Set truth values for OPTIONAL results: o_true = [[1., 6.195652], [56.870003, 8.8936615], [0.01818182, 0.0030303], [1.0691562, 0.01909207], [15., -143.2391], [56.870003, 58.76999], [-45.92052], [8.4580624e-01, 2.0433204e+03]] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_miri_3(): """ MIRI data with ramp's 0th and final groups flagged as DO_NOT_USE, and final group also flagged as CR. SCI seg is: [6666., 25., 35., 54., 55., 65., 75., 94., 95., 666.] GROUPDQ is: [1, 0, 0, 0, 0, 0, 0, 0, 0, 5] """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [6666., 25., 35., 54., 55., 65., 75., 94., 95., 666.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 5]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [1.025854, 0, 0.12379601, 0.0025974, 0.01272805] # Set truth values for OPTIONAL results: o_true = [ 1.025854, 6.450687, 0.0025974, 0.01272805, 26.439266, 27.842508, 14.74146, 4257.684 ] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_two_groups_fit(self, method): model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=2, gain=1, readnoise=10) model1.data[0, 0, 50, 50] = 10.0 model1.data[0, 1, 50, 50] = 15.0 model1.data[0, 0, 50, 51] = 20.0 model1.data[0, 1, 50, 51] = 60.0 model1.data[0, 0, 50, 52] = 200.0 model1.data[0, 1, 50, 52] = 600.0 model1.meta.exposure.drop_frames1 = 0 # 2nd group is saturated model1.groupdq[0, 1, 50, 51] = SATURATED # 1st group is saturated model1.groupdq[0, 0, 50, 52] = SATURATED model1.groupdq[0, 1, 50, 52] = SATURATED # should not be set this way cds_slope = (model1.data[0, 1, 50, 50] - model1.data[0, 0, 50, 50]) slopes, cube, optional, gls_dummy = ramp_fit(model1, 1024 * 30000., True, rnoise, gain, 'OLS', 'optimal', 'none') data = slopes[0] np.testing.assert_allclose(data[50, 50], cds_slope, 1e-6) # expect SATURATED dq = slopes[1] assert dq[50, 51] == SATURATED # expect SATURATED and DO_NOT_USE, because 1st group is Saturated assert dq[50, 52] == SATURATED + DO_NOT_USE
def test_pix_1(): """ CASE H: the segment has a good 1st group and a bad 2nd group, so is a single group. If there are no later and longer segments in the ramp, this group's data will be used in the 'fit'. If there are later and longer segments, this group's data will not be used. CASE F: segment has 2 good groups not at array end. SCI segs are: seg0[15] (H, ignored), seg1[35, 54] (F) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 55., 65., 75., 94., 95., 105.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 4, 4, 0, 2, 2, 2, 2, 2, 2]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [1.8999999, 6, 1.05057204, 0.03454545, 1.0691562] # Set truth values for OPTIONAL results: o_true = [ 1.9, 56.870003, 0.03454545, 1.0691562, -3., 56.870003, -3.999998, 0.82091206 ] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_pix_11(): """ CASE F: segment has 2 good groups not at array end. SCI seg is: seg0[15,25](F) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 55., 65., 75., 94., 95., 105.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 0, 2, 2, 2, 2, 2, 2, 2, 2]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [1., 2, 1.042755, 0.01818182, 1.0691562] # Set truth values for OPTIONAL results: o_true = [ 1., 56.870003, 0.01818182, 1.0691562, 15., 56.870003, 5., 0.84580624 ] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_miri_1(): """ MIRI data with ramp's 0th and final groups flagged as DO_NOT_USE; 0th group is also as a cosmic ray SCI seg is: [7777., 125., 135., 154., 165., 175., 185., 204., 205., 777.] GROUPDQ is: [5, 0, 0, 0, 0, 0, 0, 0, 0, 1] """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [7777., 125., 135., 154., 165., 175., 185., 204., 205., 777.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([5, 0, 0, 0, 0, 0, 0, 0, 0, 1]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [1.1996487, 0, 0.12379601, 0.0025974, 0.01272805] # Set truth values for OPTIONAL results: o_true = [ 1.1996487, 6.450687, 0.0025974, 0.01272805, 126.110214, 27.842508, 113.00351, 4257.684 ] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_pix_9(): """ CASE F: segment has 2 good groups not at array end. CASE B: segment has >2 groups, not at end of ramp. CASE E: segment has 2 good groups, at end of ramp. SCI seg are: seg0[15,25](F), seg1[54, 55, 65, 75, 94](B), seg2[95, 105](E) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 55., 65., 75., 94., 95., 105.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 0, 4, 4, 0, 0, 0, 0, 4, 0]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [0.9999994, 4, 0.22721863, 0.0030303, 0.048598] # Set truth values for OPTIONAL results: o_true = [[1., 0.9999994, 1.], [56.870003, 13.036095, 56.870003], [0.01818182, 0.00454545, 0.01818182], [1.0691562, 0.05345781, 1.0691562], [15., 20.119896, 15.], [56.870003, 68.618195, 56.870003], [5.000005], [0.84580624, 297.23172, 0.84580624]] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_pix_10(): """ CASE F: segment has 2 good groups not at array end. CASE B: segment has >2 groups, not at end of ramp. CASE A: segment has >2 groups, at end of ramp. SCI segs are: seg0[15,25](F), seg1[35,54,55](B), seg2[65,75,94,95,105](A) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 55., 65., 75., 94., 95., 105.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 0, 4, 0, 0, 4, 0, 0, 0, 0]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [1., 4, 0.21298744, 0.0025974, 0.04276625] # Set truth values for OPTIONAL results: o_true = [[1., 1.0000014, 0.99999964], [56.870003, 28.434996, 13.036095], [0.01818182, 0.00909091, 0.00454545], [1.0691562, 0.26728904, 0.05345781], [15., 17.999956, 15.000029], [56.870003, 88.40799, 93.73906], [5.], [0.84580624, 13.091425, 297.23172]] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_pix_7(): """ CASE B: segment has >2 groups, not at end of ramp. SCI seg is seg0[15,25,35,54,55,65,75,94](B) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 55., 65., 75., 94., 195., 205.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 0, 0, 0, 0, 0, 0, 0, 4, 4]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [1.0757396, 4, 0.12379601, 0.0025974, 0.01272805] # Set truth values for OPTIONAL results: o_true = [ 1.0757396, 6.450687, 0.0025974, 0.01272805, 14.504951, 27.842508, 4.2426033, 4257.684 ] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_pix_8(): """ CASE H: the segment has a good 1st group and a bad 2nd group. CASE B: segment has >2 groups, not at end of ramp. SCI segs are: seg0[15](H, ignored), seg1[25, 35, 54, 55, 65, 75](B) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 55., 65., 75., 94., 95., 105.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 4, 0, 0, 0, 0, 0, 2, 2, 2]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [1.0101178, 6, 0.1848883, 0.00363636, 0.03054732] # Set truth values for OPTIONAL results: o_true = [ 1.0101178, 12.385354, 0.00363636, 0.03054732, 16.508228, 40.81897, 4.898822, 855.78046 ] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_pix_0(): """ CASE A: segment has >2 groups, at end of ramp. SCI seg is [15., 25., 35., 54., 55., 65., 75., 94., 95., 105.](A) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 55., 65., 75., 94., 95., 105.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: # [data, dq, err, var_p, var_r] p_true = [1.0117551, 0, 0.0921951, 0.0020202, 0.00647973] # Set truth values for OPTIONAL results: # [slope, sigslope, var_poisson, var_rnoise, yint, sigyint, ped, weights] o_true = [ 1.0117551, 4.874572, 0.0020202, 0.00647973, 15.911023, 27.789335, 4.882449, 13841.038 ] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_five_groups_two_ints_Poisson_noise_only(self, method): grouptime = 3.0 ingain = 2000 inreadnoise = 7 ngroups = 5 model1, gdq, rnoise, pixdq, err, gain = setup_inputs( ngroups=ngroups, gain=ingain, readnoise=inreadnoise, deltatime=grouptime, nints=2) model1.data[0, 0, 50, 50] = 10.0 model1.data[0, 1, 50, 50] = 15.0 model1.data[0, 2, 50, 50] = 25.0 model1.data[0, 3, 50, 50] = 33.0 model1.data[0, 4, 50, 50] = 60.0 model1.data[1, 0, 50, 50] = 10.0 model1.data[1, 1, 50, 50] = 15.0 model1.data[1, 2, 50, 50] = 25.0 model1.data[1, 3, 50, 50] = 33.0 model1.data[1, 4, 50, 50] = 160.0 slopes, cube, optional, gls_dummy = ramp_fit(model1, 1024 * 30000., True, rnoise, gain, 'OLS', 'optimal', 'none', test_dq_flags) out_slope = slopes[0][50, 50] deltaDN1 = 50 deltaDN2 = 150 np.testing.assert_allclose(out_slope, (deltaDN1 + deltaDN2) / 2.0, 75.0, 1e-6)
def test_pix_5(): """ CASE B: segment has >2 groups, not at end of ramp. CASE A: segment has >2 groups, at end of ramp. SCI segs are: seg0[15, 25, 35, 54](B), seg1[ 2055, 2065, 2075, 2094, 2095, 2105](A) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 2055., 2065., 2075., 2094., 2095., 2105.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 0, 0, 0, 4, 0, 0, 0, 0, 0]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [1.076075, 4, 0.16134359, 0.00227273, 0.02375903] # Set truth values for OPTIONAL results: o_true = [[1.2799551, 1.0144024], [18.312422, 9.920552], [0.00606061, 0.00363636], [0.10691562, 0.03054732], [13.537246, 2015.0737], [35.301933, 67.10882], [4.2391253], [78.34764, 855.78046]] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_pix_4(): """ CASE G: segment is the good 1st group of the entire ramp, and no later groups are good. SCI seg is seg0[15](G) """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array( [15., 25., 35., 54., 1055., 1065., 1075., 2594., 2595., 2605.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 2, 2, 2, 2, 2, 2, 2, 2, 2]) new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none') # Set truth values for PRIMARY results: p_true = [1.5, 2, 1.047105, 0.02727273, 1.0691562] # Set truth values for OPTIONAL results: o_true = [1.5, 0., 0.02727273, 1.0691562, 0., 0., 0., 0.8318386] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0)
def test_miri_no_good_pixel(): """ With no good data, MIRI will remove all groups where all pixels are bad. If all groups are bad, NoneType is returned for all return values from ramp_fit. This test is to force this return of NoneType. """ nints, ngroups, nrows, ncols = 1, 2, 2, 2 deltatime = 3. model1, gdq, rnoise, pixdq, err, gain = setup_small_cube( ngroups, nints, nrows, ncols, deltatime) # Dummy non-zero data to make sure if processing occurs a non-NoneType gets # returned. Processing should not occur and a NoneType should be returned. model1.data[0, :, 0, 0] = np.array([-200., -500.], dtype=np.float32) model1.data[0, :, 0, 1] = np.array([-300., -600.], dtype=np.float32) model1.data[0, :, 1, 0] = np.array([-200., 900.], dtype=np.float32) model1.data[0, :, 1, 1] = np.array([-600., -400.], dtype=np.float32) # Set all groups to DO_NOT_USE model1.groupdq[:, :, :, :] = DO_NOT_USE image_info, int_model, opt_model, gls_opt_model = ramp_fit( model1, 1024 * 30000., True, rnoise, gain, 'OLS', 'optimal', 'none') assert image_info is None
def test_two_groups_unc(self, method): grouptime = 3.0 deltaDN = 5 ingain = 2 inreadnoise = 10 ngroups = 2 model1, gdq, rnoise, pixdq, err, gain = setup_inputs( ngroups=ngroups, gain=ingain, readnoise=inreadnoise, deltatime=grouptime) model1.data[0, 0, 50, 50] = 10.0 model1.data[0, 1, 50, 50] = 10.0 + deltaDN slopes, cube, optional, gls_dummy = ramp_fit(model1, 1024 * 30000., True, rnoise, gain, 'OLS', 'optimal', 'none') data, dq, var_poisson, var_rnoise, err = slopes # delta_electrons = deltaDN * ingain single_sample_readnoise = inreadnoise / np.sqrt(2) np.testing.assert_allclose(var_poisson[50, 50], ((deltaDN / ingain) / grouptime**2), 1e-6) np.testing.assert_allclose(var_rnoise[50, 50], (inreadnoise**2 / grouptime**2), 1e-6) np.testing.assert_allclose(var_rnoise[50, 50], (12 * single_sample_readnoise**2 / (ngroups * (ngroups**2 - 1) * grouptime**2)), 1e-6) np.testing.assert_allclose(err[50, 50], (np.sqrt((deltaDN / ingain) / grouptime**2 + (inreadnoise**2 / grouptime**2))), 1e-6)
def test_gls_vs_ols_two_ints_ols(): """ A test to see if GLS is correctly combining integrations. The combination should only use the read noise variance. The current version of GLS does not work correctly. """ model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=11, gain=5, readnoise=1, nints=2) ramp = np.asarray([x * 100 for x in range(11)]) model1.data[0, :, 50, 50] = ramp model1.data[1, :, 50, 50] = ramp * 2 slopes = ramp_fit( model1, 1024 * 30000., True, rnoise, gain, 'OLS', 'optimal', 'none', dqflags.pixel) np.testing.assert_allclose(slopes[0].data[50, 50], 150.0, 1e-6) slopes_gls = ramp_fit( model1, 1024 * 30000., True, rnoise, gain, 'GLS', 'optimal', 'none', dqflags.pixel) np.testing.assert_allclose(slopes_gls[0].data[50, 50], 150.0, 1e-6)
def test_one_group_small_buffer_fit_gls(): model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=1, gain=1, readnoise=10) model1.data[0, 0, 50, 50] = 10.0 slopes, cube, optional, gls_dummy = ramp_fit( model1, 512, True, rnoise, gain, 'GLS', 'optimal', 'none', dqflags.pixel) data = slopes[0] np.testing.assert_allclose(data[50, 50], 10.0, 1e-6)
def test_one_group_two_ints_fit_gls(): model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=1, gain=1, readnoise=10, nints=2) model1.data[0, 0, 50, 50] = 10.0 model1.data[1, 0, 50, 50] = 12.0 slopes = ramp_fit( model1, 1024 * 30000., True, rnoise, gain, 'GLS', 'optimal', 'none', dqflags.pixel) np.testing.assert_allclose(slopes[0].data[50, 50], 11.0, 1e-6)
def test_multiprocessing(): nints, ngroups, nrows = 3, 25, 100 ncols = nrows # make sure these are the same, so the loops below work model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=ngroups, gain=1, readnoise=10, nints=nints, nrows=nrows, ncols=ncols) delta_plane1 = np.zeros((nrows, ncols), dtype=np.float64) delta_plane2 = np.zeros((nrows, ncols), dtype=np.float64) delta_vec = np.asarray([x / 50.0 for x in range(nrows)]) for i in range(ncols): delta_plane1[i, :] = delta_vec * i delta_plane2[:, i] = delta_vec * i model1.data[:, :, :, :] = 0 for j in range(ngroups - 1): model1.data[ 0, j + 1, :, :] = model1.data[0, j, :, :] + delta_plane1 + delta_plane2 model1.data[ 1, j + 1, :, :] = model1.data[1, j, :, :] + delta_plane1 + delta_plane2 model1.data[ 2, j + 1, :, :] = model1.data[2, j, :, :] + delta_plane1 + delta_plane2 model1.data = np.round(model1.data + np.random.normal(0, 5, (nints, ngroups, ncols, nrows))) # TODO change this to be parametrized once GLS gets working. algo = "OLS" # algo = "GLS" slopes, int_model, opt_model, gls_opt_model = ramp_fit( model1, 1024 * 30000., False, rnoise, gain, algo, 'optimal', 'none') slopes_multi, int_model_multi, opt_model_multi, gls_opt_model_multi = ramp_fit( model1, 1024 * 30000., False, rnoise, gain, algo, 'optimal', 'half') np.testing.assert_allclose(slopes.data, slopes_multi.data, rtol=1e-5)
def test_drop_frames1_not_set(): model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=1, gain=1, readnoise=10) model1.data[0, 0, 50, 50] = 10.0 model1.meta.exposure.drop_frames1 = None slopes, cube, optional, gls_dummy = ramp_fit( model1, 512, True, rnoise, gain, 'OLS', 'optimal', 'none', dqflags.pixel) data = slopes[0] np.testing.assert_allclose(data[50, 50], 10.0, 1e-6)
def test_nocrs_noflux_firstrows_are_nan(self, method): model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=5) model1.data[0, :, 0:12, :] = np.nan slopes, cube, optional, gls_dummy = ramp_fit( model1, 60000, False, rnoise, gain, 'OLS', 'optimal', 'none', dqflags.pixel) data = slopes[0] assert(0 == np.max(data)) assert(0 == np.min(data))
def test_nocrs_noflux(self, method): # all pixel values are zero. So slope should be zero model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=5) slopes, cube, optional, gls_dummy = ramp_fit( model1, 60000, False, rnoise, gain, method, 'optimal', 'none', dqflags.pixel) data = slopes[0] assert(0 == np.max(data)) assert(0 == np.min(data))
def test_ngroups_doesnot_match_cube_size(self, method): # all pixel values are zero. So slope should be zero model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=5) model1.meta.exposure.ngroups = 11 slopes, cube, optional, gls_dummy = ramp_fit( model1, 64000, False, rnoise, gain, 'OLS', 'optimal', 'none', dqflags.pixel) data = slopes[0] assert(0 == np.max(data)) assert(0 == np.min(data))
def test_error_when_frame_time_not_set(self, method): # all pixel values are zero. So slope should be zero model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=5) model1.meta.exposure.frame_time = None slopes, cube, optional, gls_dummy = ramp_fit( model1, 64000, False, rnoise, gain, 'OLS', 'optimal', 'none', dqflags.pixel) data = slopes.data assert(0 == np.max(data)) assert(0 == np.min(data))
def test_pix_12(): """ CASE NGROUPS=2: the segment has a good 1st group and a saturated 2nd group, so is a single group. Group 1's data will be used in the 'fit'. """ ngroups, nints, nrows, ncols, deltatime, gain, readnoise = set_scalars() ngroups = 2 nints = 1 ncols = 2 ramp_model, rnoise_model, gain_model, pixdq, groupdq, err = create_mod_arrays( ngroups, nints, nrows, ncols, deltatime, gain, readnoise) # Populate pixel-specific SCI and GROUPDQ arrays ramp_model.data[0, :, 0, 0] = np.array([15., 59025.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 0] = np.array([0, 2]) ramp_model.data[0, :, 0, 1] = np.array([61000., 61000.], dtype=np.float32) ramp_model.groupdq[0, :, 0, 1] = np.array([2, 2]) # call ramp_fit new_mod, int_mod, opt_mod, gls_opt_mod = ramp_fit(ramp_model, 1024 * 300., True, rnoise_model, gain_model, 'OLS', 'optimal', 'none', test_dq_flags) # Set truth values for PRIMARY results for pixel 1: # slope, dq, err, var_p, var_r # slope = group1 / deltatime = 15 / 10 = 1.5 # dq = 2 (saturation) because group2 is saturated, but DO_NOT_USE is *not* set p_true = [1.5, 2, 1.047105, 0.027273, 1.069156] # Set truth values for OPTIONAL results: # slope, sig_slope, var_p, var_r, yint, sig_yint, pedestal, weights # slope = group1 / deltatime = 15 / 10 = 1.5 # sig_slope, yint, sig_yint, and pedestal are all zero, because only 1 good group o_true = [1.5, 0., 0.027273, 1.069156, 0., 0., 0., 0.831839] assert_pri(p_true, new_mod, 0) assert_opt(o_true, opt_mod, 0) # Set truth values for PRIMARY results for pixel 2: # slope, dq, err, var_p, var_r # slope = zero, because no good data # dq = 3 (saturation + do_not_use) because both groups are saturated p_true = [0., 3, 0., 0., 0.] # Set truth values for OPTIONAL results: # slope, sig_slope, var_p, var_r, yint, sig_yint, pedestal, weights # all values zero, because no good data o_true = [0., 0., 0., 0., 0., 0., 0., 0.] assert_pri(p_true, new_mod, 1) assert_opt(o_true, opt_mod, 1)
def test_photon_noise_only_bad_last_frame_two_groups(self, method): model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=2, gain=1000, readnoise=1) model1.data[0, 0, 50, 50] = 10.0 model1.data[0, 1, 50, 50] = 15.0 model1.groupdq[0, 1, :, :] = DO_NOT_USE cds_slope = (model1.data[0, 1, 50, 50] - model1.data[0, 0, 50, 50]) / 1.0 slopes, cube, optional, gls_dummy = ramp_fit( model1, 1024 * 30000., True, rnoise, gain, 'OLS', 'optimal', 'none', dqflags.pixel) data = slopes.data np.testing.assert_allclose(data[50, 50], cds_slope, 1e-6)
def test_one_group_fit(self, method): model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=1, gain=1, readnoise=10) model1.data[0, 0, 50, 50] = 10.0 slopes, cube, optional, gls_dummy = ramp_fit(model1, 1024 * 30000., True, rnoise, gain, 'OLS', 'optimal', 'none') data = slopes[0] np.testing.assert_allclose(data[50, 50], 10.0, 1e-6)
def test_four_groups_CR_causes_orphan_1st_group(self, method): model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=4, gain=.01, readnoise=10000) model1.data[0, 0, 50, 50] = 10.0 model1.data[0, 1, 50, 50] = 125.0 model1.data[0, 2, 50, 50] = 145.0 model1.data[0, 3, 50, 50] = 165.0 model1.groupdq[0, 1, 50, 50] = JUMP_DET slopes, cube, optional, gls_dummy = ramp_fit( model1, 1024 * 30000., True, rnoise, gain, 'OLS', 'optimal', 'none', dqflags.pixel) expected_slope = 20.0 data = slopes[0] np.testing.assert_allclose(data[50, 50], expected_slope, 1e-6)
def test_four_groups_oneCR_orphangroupatend_fit(self, method): model1, gdq, rnoise, pixdq, err, gain = setup_inputs(ngroups=4, gain=1, readnoise=10) model1.data[0, 0, 50, 50] = 10.0 model1.data[0, 1, 50, 50] = 15.0 model1.data[0, 2, 50, 50] = 20.0 model1.data[0, 3, 50, 50] = 145.0 model1.groupdq[0, 3, 50, 50] = JUMP_DET cds_slope = (model1.data[0, 1, 50, 50] - model1.data[0, 0, 50, 50]) slopes, cube, optional, gls_dummy = ramp_fit( model1, 1024 * 30000., True, rnoise, gain, 'OLS', 'optimal', 'none', dqflags.pixel) data = slopes[0] np.testing.assert_allclose(data[50, 50], cds_slope, 1e-6)