Beispiel #1
0
def test_errors():
    """Test errors are raised properly """

    gs_id = 'N13I000018'
    guider = 1

    # Test 1: data only includes 2MASS
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)
    fgs.gsc_series = fgscountrate.utils.query_gsc(gs_id=gs_id,
                                                  catalog='GSC241').iloc[0]

    fgs._present_calculated_mags = ['tmassJmag', 'tmassHmag', 'tmassKsMag']
    for index in set(fgscountrate.fgs_countrate_core.GSC_BAND_NAMES) - set(
            fgs._present_calculated_mags):
        fgs.gsc_series.loc[index] = -999
    fgs._all_calculated_mag_series = fgs.gsc_series.loc[
        fgscountrate.fgs_countrate_core.GSC_BAND_NAMES]

    with pytest.raises(ValueError) as excinfo:
        fgs.calc_fgs_cr_mag_and_err()
    assert 'Cannot compute' in str(excinfo.value), 'Attempted to compute the FGS countrate & ' \
                                                   'magnitude despite only having the 2MASS bands'

    # Test 2: Guider number is invalid
    guider = 3
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)
    fgs.gsc_series = fgscountrate.utils.query_gsc(gs_id=gs_id,
                                                  catalog='GSC241').iloc[0]

    with pytest.raises(ValueError) as excinfo:
        fgs.calc_fgs_cr_mag_and_err()
    assert '1 or 2' in str(
        excinfo.value), 'Allowed invalid guider number to pass'
def test_sdss_or_gsc():
    """Test that only SDSS or GSC data is used to compute CR and Mag, and not a combination of the two"""

    gs_id = 'N13I000018'
    guider = 1

    # Test SDSS only - set tmass to missing (sdss will be chosen over gsc already)
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)
    fgs.gsc_series = copy.copy(GSC_SERIES)
    for ind in TMASS_BANDS:
        fgs.gsc_series.loc[ind] = -999
    fgs.calc_jhk_mag(fgs.gsc_series)
    _ = fgs.calc_fgs_cr_mag_and_err()
    # check gsc bands have been fully removed
    assert False not in ['pgMag' not in i for i in fgs._present_calculated_mags]
    # check that gsc bands are all excluded from calculations
    assert fgs.survey == 'sdss'
    gsc_index = [i for i in fgs.band_dataframe['ABMag'].index if 'pgMag' in i]
    assert all(-999 == fgs.band_dataframe['ABMag'][gsc_index].values)

    # Test GSC only - set tmass and SDSS g, z, and i to missing (keep r).
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)
    fgs.gsc_series = copy.copy(GSC_SERIES)
    for ind in TMASS_BANDS:
        fgs.gsc_series.loc[ind] = -999
    fgs.gsc_series['SDSSgMag'] = -999
    fgs.gsc_series['SDSSzMag'] = -999
    fgs.gsc_series['SDSSiMag'] = -999
    fgs.calc_jhk_mag(fgs.gsc_series)
    _ = fgs.calc_fgs_cr_mag_and_err()
    # check sdss bands have been fully removed
    assert False not in ['SDSS' not in i for i in fgs._present_calculated_mags]
    # check that sdss bands are all excluded from calculations
    assert fgs.survey == 'gsc2'
    sdss_index = [i for i in fgs.band_dataframe['ABMag'].index if 'SDSS' in i]
    assert all(-999 == fgs.band_dataframe['ABMag'][sdss_index].values)

    # Test 2MASS only - set everything to missing except for tmass
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)
    fgs.gsc_series = copy.copy(GSC_SERIES)
    for ind in SDSS_BANDS:
        fgs.gsc_series.loc[ind] = -999
    for ind in GSC2_BANDS:
        fgs.gsc_series.loc[ind] = -999
    fgs.calc_jhk_mag(fgs.gsc_series)
    _ = fgs.calc_fgs_cr_mag_and_err()
    # check sdss and gsc bands have been fully removed
    assert False not in ['SDSS' not in i for i in fgs._present_calculated_mags]
    assert False not in ['pgMag' not in i for i in fgs._present_calculated_mags]
    # check that sdss and gsc bands are all excluded from calculations
    assert fgs.survey == 'gsc2'
    sdss_index = [i for i in fgs.band_dataframe['ABMag'].index if 'SDSS' in i]
    assert all(-999 == fgs.band_dataframe['ABMag'][sdss_index].values)
    gsc_index = [i for i in fgs.band_dataframe['ABMag'].index if 'pgMag' in i]
    assert all(-999 == fgs.band_dataframe['ABMag'][gsc_index].values)
def test_errors():
    """Test errors are raised properly """

    gs_id = 'N13I000018'
    guider = 1

    # Test 1: data is missing too many bands - only has J and H (so cannot compute K)
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)
    fgs.gsc_series = fgscountrate.utils.query_gsc(gs_id=gs_id, catalog='GSC242').iloc[0]

    fgs._present_calculated_mags = ['tmassJMag', 'tmassHMag']
    for index in set(fgscountrate.fgs_countrate_core.GSC_BAND_NAMES) - set(fgs._present_calculated_mags):
        fgs.gsc_series.loc[index] = -999
    fgs._all_calculated_mag_series = fgs.gsc_series.loc[fgscountrate.fgs_countrate_core.GSC_BAND_NAMES]
    fgs._all_calculated_mag_err_series = fgs.gsc_series.loc[[band+'Err' for band
                                                             in fgscountrate.fgs_countrate_core.GSC_BAND_NAMES]]
    fgs.survey = 'gsc2'

    with pytest.raises(ValueError) as excinfo:
        fgs.calc_fgs_cr_mag_and_err()
    assert 'Cannot compute' in str(excinfo.value), 'Attempted to compute the FGS countrate & ' \
                                                   'magnitude despite only have J and H bands'

    # Test 2: Guider number is invalid
    guider = 3
    with pytest.raises(ValueError) as excinfo:
        fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)
    assert '1 or 2' in str(excinfo.value), 'Allowed invalid guider number to pass'
def test_band_missing():
    """Test that when a band (SDSS_g) is missing, it's signal is set to 0"""

    gs_id = 'N13I000018'
    guider = 1
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)

    # Reset data to a set of constant, fake data with SDSS_g missing
    fgs.gsc_series = copy.copy(GSC_SERIES)
    fgs.gsc_series['SDSSgMag'] = -999
    fgs.gsc_series['SDSSgMagErr'] = -999

    # Convert to JHK magnitudes
    fgs.j_mag, fgs.j_mag_err, fgs.h_mag, fgs.h_mag_err, fgs.k_mag, fgs.k_mag_err = \
        fgs.calc_jhk_mag(fgs.gsc_series)

    # Compute FGS countrate and magnitude to get fgs.band_dataframe attribute
    _ = fgs.calc_fgs_cr_mag_and_err()

    # Check Mag, ABMag, Flux, and Signal = -999
    assert fgs.survey == 'sdss'
    assert fgs.band_dataframe.at['SDSSgMag', 'Mag'] == -999
    assert fgs.band_dataframe.at['SDSSgMag', 'ABMag'] == -999
    assert fgs.band_dataframe.at['SDSSgMag', 'Flux'] == -999
    assert fgs.band_dataframe.at['SDSSgMag', 'Signal'] == -999
Beispiel #5
0
def test_tmass_to_jhk():
    """
    Check the _tmass_to_jhk method produces the expected result
    which is no change to the input values
    """
    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=2)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_j = 10
    input_h = 11
    input_k = 12
    input_j_err = 0.10
    input_h_err = 0.11
    input_k_err = 0.12
    fgs.gsc_series['tmassJMag'] = input_j
    fgs.gsc_series['tmassHMag'] = input_h
    fgs.gsc_series['tmassKsMag'] = input_k
    fgs.gsc_series['tmassJMagErr'] = input_j_err
    fgs.gsc_series['tmassHMagErr'] = input_h_err
    fgs.gsc_series['tmassKsMagErr'] = input_k_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_tmass_to_jhk(data=fgs.gsc_series,
                                                        output_mag='J')
    h_ser, h_err_ser = conversions.convert_tmass_to_jhk(data=fgs.gsc_series,
                                                        output_mag='H')
    k_ser, k_err_ser = conversions.convert_tmass_to_jhk(data=fgs.gsc_series,
                                                        output_mag='K')

    # Run method with tuple input
    j_tup, j_err_tup = conversions.convert_tmass_to_jhk(data=(input_j,
                                                              input_j_err),
                                                        output_mag='J')
    h_tup, h_err_tup = conversions.convert_tmass_to_jhk(data=(input_h,
                                                              input_h_err),
                                                        output_mag='H')
    k_tup, k_err_tup = conversions.convert_tmass_to_jhk(data=(input_k,
                                                              input_k_err),
                                                        output_mag='K')

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert np.isclose(j_ser, input_j, 1e-5)
    assert np.isclose(h_ser, input_h, 1e-5)
    assert np.isclose(k_ser, input_k, 1e-5)

    # Check uncertainties
    assert np.isclose(j_err_ser, input_j_err, 1e-5)
    assert np.isclose(h_err_ser, input_h_err, 1e-5)
    assert np.isclose(k_err_ser, input_k_err, 1e-5)
Beispiel #6
0
def test_gsc2bjrf_to_jhk():
    """Check the _gsc2bjrf_to_jhk method produces the expected result """

    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=2)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_bj = 10
    input_rf = 11
    input_bj_err = 0.10
    input_rf_err = 0.11
    fgs.gsc_series['JpgMag'] = input_bj
    fgs.gsc_series['FpgMag'] = input_rf
    fgs.gsc_series['JpgMagErr'] = input_bj_err
    fgs.gsc_series['FpgMagErr'] = input_rf_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_gsc2bjrf_to_jhk(data=fgs.gsc_series,
                                                           output_mag='J')
    h_ser, h_err_ser = conversions.convert_gsc2bjrf_to_jhk(data=fgs.gsc_series,
                                                           output_mag='H')
    k_ser, k_err_ser = conversions.convert_gsc2bjrf_to_jhk(data=fgs.gsc_series,
                                                           output_mag='K')

    # Run method with tuple input
    data = (input_bj, input_bj_err, input_rf, input_rf_err)
    j_tup, j_err_tup = conversions.convert_gsc2bjrf_to_jhk(data=data,
                                                           output_mag='J')
    h_tup, h_err_tup = conversions.convert_gsc2bjrf_to_jhk(data=data,
                                                           output_mag='H')
    k_tup, k_err_tup = conversions.convert_gsc2bjrf_to_jhk(data=data,
                                                           output_mag='K')

    # Do calculation
    val = input_bj - input_rf
    output_j = input_bj - 0.39 * val**2 - 0.96 * val - 0.55
    output_h = input_bj - 0.24 * val**2 - 1.66 * val - 0.41
    output_k = input_bj - 0.26 * val**2 - 1.70 * val - 0.45

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert j_ser == output_j
    assert h_ser == output_h
    assert k_ser == output_k

    # Check uncertainties
    assert np.isclose(j_err_ser, 0.3268272426848776, 1e-5)
    assert np.isclose(h_err_ser, 0.387910756252002, 1e-5)
    assert np.isclose(k_err_ser, 0.44586387576927555, 1e-5)
Beispiel #7
0
def test_gsc2rfin_to_jhk():
    """Check the _gsc2rfin_to_jhk method produces the expected result """

    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=1)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_rf = 10
    input_in = 11
    input_rf_err = 0.10
    input_in_err = 0.11
    fgs.gsc_series['FpgMag'] = input_rf
    fgs.gsc_series['NpgMag'] = input_in
    fgs.gsc_series['FpgMagErr'] = input_rf_err
    fgs.gsc_series['NpgMagErr'] = input_in_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_gsc2rfin_to_jhk(data=fgs.gsc_series,
                                                           output_mag='J')
    h_ser, h_err_ser = conversions.convert_gsc2rfin_to_jhk(data=fgs.gsc_series,
                                                           output_mag='H')
    k_ser, k_err_ser = conversions.convert_gsc2rfin_to_jhk(data=fgs.gsc_series,
                                                           output_mag='K')

    # Run method with tuple input
    data = (input_rf, input_rf_err, input_in, input_in_err)
    j_tup, j_err_tup = conversions.convert_gsc2rfin_to_jhk(data=data,
                                                           output_mag='J')
    h_tup, h_err_tup = conversions.convert_gsc2rfin_to_jhk(data=data,
                                                           output_mag='H')
    k_tup, k_err_tup = conversions.convert_gsc2rfin_to_jhk(data=data,
                                                           output_mag='K')

    # Do calculation
    val = input_rf - input_in
    output_j = input_rf + 0.01 * val**2 - 1.56 * val - 0.44
    output_h = input_rf + 0.25 * val**2 - 2.17 * val - 0.67
    output_k = input_rf + 0.28 * val**2 - 2.35 * val - 0.73

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert j_ser == output_j
    assert h_ser == output_h
    assert k_ser == output_k

    # Check uncertainties
    assert np.isclose(j_err_ser, 0.30678481748776193, 1e-5)
    assert np.isclose(h_err_ser, 0.46706206827893615, 1e-5)
    assert np.isclose(k_err_ser, 0.5290933057070359, 1e-5)
Beispiel #8
0
def test_gsc2bjin_to_jhk():
    """Check the _gsc2bjin_to_jhk method produces the expected result """

    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=2)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_bj = 10
    input_in = 11
    input_bj_err = 0.10
    input_in_err = 0.11
    fgs.gsc_series['JpgMag'] = input_bj
    fgs.gsc_series['NpgMag'] = input_in
    fgs.gsc_series['JpgMagErr'] = input_bj_err
    fgs.gsc_series['NpgMagErr'] = input_in_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_gsc2bjin_to_jhk(data=fgs.gsc_series,
                                                           output_mag='J')
    h_ser, h_err_ser = conversions.convert_gsc2bjin_to_jhk(data=fgs.gsc_series,
                                                           output_mag='H')
    k_ser, k_err_ser = conversions.convert_gsc2bjin_to_jhk(data=fgs.gsc_series,
                                                           output_mag='K')

    # Run method with tuple input
    data = (input_bj, input_bj_err, input_in, input_in_err)
    j_tup, j_err_tup = conversions.convert_gsc2bjin_to_jhk(data=data,
                                                           output_mag='J')
    h_tup, h_err_tup = conversions.convert_gsc2bjin_to_jhk(data=data,
                                                           output_mag='H')
    k_tup, k_err_tup = conversions.convert_gsc2bjin_to_jhk(data=data,
                                                           output_mag='K')

    # Do calculation
    val = input_bj - input_in
    output_j = input_bj - 1.30 * val - 0.15
    output_h = input_bj + 0.06 * val**2 - 1.71 * val - 0.10
    output_k = input_bj + 0.06 * val**2 - 1.78 * val - 0.11

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert j_ser == output_j
    assert h_ser == output_h
    assert k_ser == output_k

    # Check uncertainties
    assert np.isclose(j_err_ser, 0.24527127838375157, 1e-5)
    assert np.isclose(h_err_ser, 0.3236128314452318, 1e-5)
    assert np.isclose(k_err_ser, 0.3649689782378769, 1e-5)
Beispiel #9
0
def test_sdssiz_to_jhk():
    """Check the _sdssiz_to_jhk method produces the expected result """

    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=1)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_i = 10
    input_z = 11
    input_i_err = 0.10
    input_z_err = 0.11
    fgs.gsc_series['SDSSiMag'] = input_i
    fgs.gsc_series['SDSSzMag'] = input_z
    fgs.gsc_series['SDSSiMagErr'] = input_i_err
    fgs.gsc_series['SDSSzMagErr'] = input_z_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_sdssiz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='J')
    h_ser, h_err_ser = conversions.convert_sdssiz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='H')
    k_ser, k_err_ser = conversions.convert_sdssiz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='K')

    # Run method with tuple input
    data = (input_i, input_i_err, input_z, input_z_err)
    j_tup, j_err_tup = conversions.convert_sdssiz_to_jhk(data=data,
                                                         output_mag='J')
    h_tup, h_err_tup = conversions.convert_sdssiz_to_jhk(data=data,
                                                         output_mag='H')
    k_tup, k_err_tup = conversions.convert_sdssiz_to_jhk(data=data,
                                                         output_mag='K')

    # Do calculation
    val = input_i - input_z
    output_j = input_i - 0.794 - 2.839 * val + 3.071 * val**2 - 3.139 * val**3 + 1.164 * val**4
    output_h = input_i - 1.051 - 5.361 * val + 8.398 * val**2 - 7.240 * val**3 + 2.111 * val**4
    output_k = input_i - 1.127 - 5.379 * val + 6.454 * val**2 - 3.499 * val**3 + 0.057 * val**4

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert j_ser == output_j
    assert h_ser == output_h
    assert k_ser == output_k

    # Check uncertainties
    assert np.isclose(j_err_ser, 3.4386988607490627, 1e-5)
    assert np.isclose(h_err_ser, 7.868447911817022, 1e-5)
    assert np.isclose(k_err_ser, 4.308133116754037, 1e-5)
Beispiel #10
0
def test_sdssgz_to_jhk():
    """Check the _sdssgz_to_jhk method produces the expected result """

    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=1)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_g = 10
    input_z = 11
    input_g_err = 0.10
    input_z_err = 0.11
    fgs.gsc_series['SDSSgMag'] = input_g
    fgs.gsc_series['SDSSzMag'] = input_z
    fgs.gsc_series['SDSSgMagErr'] = input_g_err
    fgs.gsc_series['SDSSzMagErr'] = input_z_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_sdssgz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='J')
    h_ser, h_err_ser = conversions.convert_sdssgz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='H')
    k_ser, k_err_ser = conversions.convert_sdssgz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='K')

    # Run method with tuple input
    data = (input_g, input_g_err, input_z, input_z_err)
    j_tup, j_err_tup = conversions.convert_sdssgz_to_jhk(data=data,
                                                         output_mag='J')
    h_tup, h_err_tup = conversions.convert_sdssgz_to_jhk(data=data,
                                                         output_mag='H')
    k_tup, k_err_tup = conversions.convert_sdssgz_to_jhk(data=data,
                                                         output_mag='K')

    # Do calculation
    val = input_g - input_z
    output_j = input_g - 0.59 - 1.54 * val + 0.20 * val**2 - 0.04 * val**3 + 0.002 * val**4
    output_h = input_g - 0.77 - 1.78 * val + 0.08 * val**2 - 0.04 * val**3 + 0.009 * val**4
    output_k = input_g - 0.87 - 1.70 * val + 0.01 * val**2 - 0.07 * val**3 + 0.001 * val**4

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert j_ser == output_j
    assert h_ser == output_h
    assert k_ser == output_k

    # Check uncertainties
    assert np.isclose(j_err_ser, 0.27265120293170503, 1e-5)
    assert np.isclose(h_err_ser, 0.28721836344780965, 1e-5)
    assert np.isclose(k_err_ser, 0.2946740530383989, 1e-5)
def test_sdssgi_to_jhk():
    """Check the _sdssgi_to_jhk method produces the expected result """

    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=2)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_g = 10
    input_i = 11
    input_g_err = 0.10
    input_i_err = 0.11
    fgs.gsc_series['SDSSgMag'] = input_g
    fgs.gsc_series['SDSSiMag'] = input_i
    fgs.gsc_series['SDSSgMagErr'] = input_g_err
    fgs.gsc_series['SDSSiMagErr'] = input_i_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_sdssgi_to_jhk(data=fgs.gsc_series,
                                                         output_mag='J')
    h_ser, h_err_ser = conversions.convert_sdssgi_to_jhk(data=fgs.gsc_series,
                                                         output_mag='H')
    k_ser, k_err_ser = conversions.convert_sdssgi_to_jhk(data=fgs.gsc_series,
                                                         output_mag='K')

    # Run method with tuple input
    data = (input_g, input_g_err, input_i, input_i_err)
    j_tup, j_err_tup = conversions.convert_sdssgi_to_jhk(data=data,
                                                         output_mag='J')
    h_tup, h_err_tup = conversions.convert_sdssgi_to_jhk(data=data,
                                                         output_mag='H')
    k_tup, k_err_tup = conversions.convert_sdssgi_to_jhk(data=data,
                                                         output_mag='K')

    # Do calculation
    val = input_g - input_i
    output_j = input_g - 0.411 - 2.260 * val + 0.826 * val**2 - 0.317 * val**3 + 0.037 * val**4
    output_h = input_g - 0.597 - 2.400 * val + 0.450 * val**2 - 0.078 * val**3 + 0.00025 * val**4
    output_k = input_g - 0.637 - 2.519 * val + 0.568 * val**2 - 0.151 * val**3 + 0.013 * val**4

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert j_ser == output_j
    assert h_ser == output_h
    assert k_ser == output_k

    # Check uncertainties
    assert pytest.approx(j_err_ser, 0.700281564042489, 5)
    assert pytest.approx(h_err_ser, 0.4895968466769927, 5)
    assert pytest.approx(k_err_ser, 0.5969626012226404, 5)
Beispiel #12
0
def test_sdssiz_to_jhk():
    """Check the _sdssiz_to_jhk method produces the expected result """

    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=1)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_i = 10
    input_z = 11
    input_i_err = 0.10
    input_z_err = 0.11
    fgs.gsc_series['SDSSiMag'] = input_i
    fgs.gsc_series['SDSSzMag'] = input_z
    fgs.gsc_series['SDSSiMagErr'] = input_i_err
    fgs.gsc_series['SDSSzMagErr'] = input_z_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_sdssiz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='J')
    h_ser, h_err_ser = conversions.convert_sdssiz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='H')
    k_ser, k_err_ser = conversions.convert_sdssiz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='K')

    # Run method with tuple input
    data = (input_i, input_i_err, input_z, input_z_err)
    j_tup, j_err_tup = conversions.convert_sdssiz_to_jhk(data=data,
                                                         output_mag='J')
    h_tup, h_err_tup = conversions.convert_sdssiz_to_jhk(data=data,
                                                         output_mag='H')
    k_tup, k_err_tup = conversions.convert_sdssiz_to_jhk(data=data,
                                                         output_mag='K')

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert np.isclose(j_ser, 19.419, 1e-5)
    assert np.isclose(h_ser, 32.059, 1e-5)
    assert np.isclose(k_ser, 24.261999999999997, 1e-5)

    # Check uncertainties
    assert np.isclose(j_err_ser, 3.4386988607490627, 1e-5)
    assert np.isclose(h_err_ser, 7.868447911817022, 1e-5)
    assert np.isclose(k_err_ser, 4.308133116754037, 1e-5)
Beispiel #13
0
def test_sdssgz_to_jhk():
    """Check the _sdssgz_to_jhk method produces the expected result """

    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=1)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_g = 10
    input_z = 11
    input_g_err = 0.10
    input_z_err = 0.11
    fgs.gsc_series['SDSSgMag'] = input_g
    fgs.gsc_series['SDSSzMag'] = input_z
    fgs.gsc_series['SDSSgMagErr'] = input_g_err
    fgs.gsc_series['SDSSzMagErr'] = input_z_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_sdssgz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='J')
    h_ser, h_err_ser = conversions.convert_sdssgz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='H')
    k_ser, k_err_ser = conversions.convert_sdssgz_to_jhk(data=fgs.gsc_series,
                                                         output_mag='K')

    # Run method with tuple input
    data = (input_g, input_g_err, input_z, input_z_err)
    j_tup, j_err_tup = conversions.convert_sdssgz_to_jhk(data=data,
                                                         output_mag='J')
    h_tup, h_err_tup = conversions.convert_sdssgz_to_jhk(data=data,
                                                         output_mag='H')
    k_tup, k_err_tup = conversions.convert_sdssgz_to_jhk(data=data,
                                                         output_mag='K')

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert np.isclose(j_ser, 11.191999999999998, 1e-5)
    assert np.isclose(h_ser, 11.041, 1e-5)
    assert np.isclose(k_ser, 10.74, 1e-5)

    # Check uncertainties
    assert np.isclose(j_err_ser, 0.27265120293170503, 1e-5)
    assert np.isclose(h_err_ser, 0.24635741034709235, 1e-5)
    assert np.isclose(k_err_ser, 0.24035821994429607, 1e-5)
Beispiel #14
0
def test_sdssgi_to_jhk():
    """Check the _sdssgi_to_jhk method produces the expected result """

    # Create instance and get data
    fgs = FGSCountrate(guide_star_id="N13I000018", guider=2)
    fgs.gsc_series = BASE_DATA

    # Change data
    input_g = 10
    input_i = 11
    input_g_err = 0.10
    input_i_err = 0.11
    fgs.gsc_series['SDSSgMag'] = input_g
    fgs.gsc_series['SDSSiMag'] = input_i
    fgs.gsc_series['SDSSgMagErr'] = input_g_err
    fgs.gsc_series['SDSSiMagErr'] = input_i_err

    # Run method with series input
    j_ser, j_err_ser = conversions.convert_sdssgi_to_jhk(data=fgs.gsc_series,
                                                         output_mag='J')
    h_ser, h_err_ser = conversions.convert_sdssgi_to_jhk(data=fgs.gsc_series,
                                                         output_mag='H')
    k_ser, k_err_ser = conversions.convert_sdssgi_to_jhk(data=fgs.gsc_series,
                                                         output_mag='K')

    # Run method with tuple input
    data = (input_g, input_g_err, input_i, input_i_err)
    j_tup, j_err_tup = conversions.convert_sdssgi_to_jhk(data=data,
                                                         output_mag='J')
    h_tup, h_err_tup = conversions.convert_sdssgi_to_jhk(data=data,
                                                         output_mag='H')
    k_tup, k_err_tup = conversions.convert_sdssgi_to_jhk(data=data,
                                                         output_mag='K')

    # Check tuple and series input produces same result
    assert j_tup == j_ser
    assert h_tup == h_ser
    assert k_tup == k_ser

    # Check conversion function matches hand-check here
    assert np.isclose(j_ser, 13.029000000000002, 1e-5)
    assert np.isclose(h_ser, 12.331249999999999, 1e-5)
    assert np.isclose(k_ser, 12.613999999999999, 1e-5)

    # Check uncertainties
    assert np.isclose(j_err_ser, 0.700281564042489, 1e-5)
    assert np.isclose(h_err_ser, 0.4895968466769927, 1e-5)
Beispiel #15
0
def test_gscbj_sdssg_missing():
    """Test that when GSC_B_J and SDSS_g are missing, their signal is set to 0"""

    gs_id = 'N13I000018'
    guider = 1
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)

    # Reset data to a set of constant, fake data with GSC_B_J and SDSS_g missing
    values = [
        'N13I000018', 420900912, 273.207, 65.5335, 8.30302e-05, 0.000185965,
        -999, -999, 14.0877, 0.2927929, 13.7468, 0.239294, 13.339,
        0.0250000003, 12.993, 0.0270000007, 12.901, 0.0270000007, 15.78594,
        0.005142, -999, -999, 14.27808, 0.003273380, 14.1443, 0.003414216,
        14.1067, 0.00433389
    ]
    index = [
        'hstID', 'gsc1ID', 'ra', 'dec', 'raErr', 'decErr', 'JpgMag',
        'JpgMagErr', 'FpgMag', 'FpgMagErr', 'NpgMag', 'NpgMagErr', 'tmassJmag',
        'tmassJmagErr', 'tmassHmag', 'tmassHmagErr', 'tmassKsMag',
        'tmassKsMagErr', 'SDSSuMag', 'SDSSuMagErr', 'SDSSgMag', 'SDSSgMagErr',
        'SDSSrMag', 'SDSSrMagErr', 'SDSSiMag', 'SDSSiMagErr', 'SDSSzMag',
        'SDSSzMagErr'
    ]
    fgs.gsc_series = pd.Series(values, index=index)

    # Convert to JHK magnitudes
    fgs.j_mag, fgs.j_mag_err, fgs.h_mag, fgs.h_mag_err, fgs.k_mag, fgs.k_mag_err = \
        fgs.calc_jhk_mag(fgs.gsc_series)

    # Compute FGS countrate and magnitude to get fgs.band_dataframe attribute
    fgs.calc_fgs_cr_mag_and_err()

    # Check Mag, ABMag, and Flux = -999 and Signal is set to 0 for both
    assert fgs.band_dataframe.at['JpgMag', 'Mag'] == -999
    assert fgs.band_dataframe.at['SDSSgMag', 'Mag'] == -999
    assert fgs.band_dataframe.at['JpgMag', 'ABMag'] == -999
    assert fgs.band_dataframe.at['SDSSgMag', 'ABMag'] == -999
    assert fgs.band_dataframe.at['JpgMag', 'Flux'] == -999
    assert fgs.band_dataframe.at['SDSSgMag', 'Flux'] == -999
    assert fgs.band_dataframe.at['JpgMag', 'Signal'] == 0.0
    assert fgs.band_dataframe.at['SDSSgMag', 'Signal'] == 0.0
def test_compute_countrate_magnitude():
    """
    Test the conversion from GSC magnitudes to FGS countrate
    returns values as expected
    """

    gs_id = 'N13I000018'
    guider = 1
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)

    # Reset data to a set of constant, fake data
    values = [
        'N13I000018 ', 420900912, 273.206729760604, 65.5335149359777,
        8.3030233068735e-05, 0.000185964552890292, 14.9447, 0.285722, 14.0877,
        0.29279299999999997, 13.7468, 0.239294, 13.33899974823,
        0.025000000372529, 12.9930000305176, 0.0270000007003546,
        12.9010000228882, 0.0270000007003546, 15.78594, 0.005142466,
        14.654670000000001, 0.003211281, 14.27808, 0.0032733809999999997,
        14.14432, 0.003414216, 14.106670000000001, 0.00433389
    ]
    index = [
        'hstID', 'gsc1ID', 'ra', 'dec', 'raErr', 'decErr', 'JpgMag',
        'JpgMagErr', 'FpgMag', 'FpgMagErr', 'NpgMag', 'NpgMagErr', 'tmassJMag',
        'tmassJMagErr', 'tmassHMag', 'tmassHMagErr', 'tmassKsMag',
        'tmassKsMagErr', 'SDSSuMag', 'SDSSuMagErr', 'SDSSgMag', 'SDSSgMagErr',
        'SDSSrMag', 'SDSSrMagErr', 'SDSSiMag', 'SDSSiMagErr', 'SDSSzMag',
        'SDSSzMagErr'
    ]
    fgs.gsc_series = pd.Series(values, index=index)

    # Convert to JHK magnitudes
    fgs.j_mag, fgs.j_mag_err, fgs.h_mag, fgs.h_mag_err, fgs.k_mag, fgs.k_mag_err = \
        fgs.calc_jhk_mag(fgs.gsc_series)

    # Compute FGS countrate and magnitude
    cr, cr_err, mag, mag_err = fgs.calc_fgs_cr_mag_and_err()

    assert np.isclose(cr, 1777234.5129574337, 1e-5)
    assert np.isclose(cr_err, 154340.24919027157, 1e-5)
    assert np.isclose(mag, 13.310964314752303, 1e-5)
    assert np.isclose(mag_err, 0.6657930516063038, 1e-5)
def test_dim_limits_partialsdss():
    """Test that when some SDSS bands are below the dim limits, those bands
    are not included in the JHK or count rate/magnitude calculations, but
    the remaining SDSS bands are used."""

    gs_id = 'N13I000018'
    guider = 1
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)

    # Reset data to a set of constant, fake data with TMASS not present and 2 SDSS bands set to dim
    fgs.gsc_series = copy.copy(GSC_SERIES)
    for ind in TMASS_BANDS:
        fgs.gsc_series.loc[ind] = -999
    fgs.gsc_series['SDSSgMag'] = 17
    fgs.gsc_series['SDSSrMag'] = 24  # dim
    fgs.gsc_series['SDSSzMag'] = 24  # dim
    fgs.gsc_series['SDSSiMag'] = 17

    # Convert to JHK magnitudes
    fgs.j_mag, fgs.j_mag_err, fgs.h_mag, fgs.h_mag_err, fgs.k_mag, fgs.k_mag_err = \
        fgs.calc_jhk_mag(fgs.gsc_series)

    # Check conversion method
    assert fgs.j_convert_method == 'convert_sdssgi_to_jhk'
    assert fgs.h_convert_method == 'convert_sdssgi_to_jhk'
    assert fgs.k_convert_method == 'convert_sdssgi_to_jhk'

    # Compute FGS countrate and magnitude to get fgs.band_dataframe attribute
    _ = fgs.calc_fgs_cr_mag_and_err()

    # Check Mag, ABMag, Flux, and Signal = -999 for g and r
    assert fgs.survey == 'sdss'

    assert fgs.band_dataframe.at['SDSSzMag', 'ABMag'] == -999
    assert fgs.band_dataframe.at['SDSSzMag', 'Flux'] == -999
    assert fgs.band_dataframe.at['SDSSzMag', 'Signal'] == -999

    assert fgs.band_dataframe.at['SDSSrMag', 'ABMag'] == -999
    assert fgs.band_dataframe.at['SDSSrMag', 'Flux'] == -999
    assert fgs.band_dataframe.at['SDSSrMag', 'Signal'] == -999
Beispiel #18
0
def test_compute_countrate_magnitude():
    """
    Test the conversion from GSC magnitudes to FGS countrate
    returns values as expected
    """

    gs_id = 'N13I000018'
    guider = 1
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)

    # Reset data to a set of constant, fake data
    values = [
        'N13I000018', 420900912, 273.207, 65.5335, 8.30302e-05, 0.000185965,
        14.9447, 0.285722, 14.0877, 0.2927929, 13.7468, 0.239294, 13.339,
        0.0250000003, 12.993, 0.0270000007, 12.901, 0.0270000007, 15.78594,
        0.005142, 14.6547, 0.003211281, 14.27808, 0.003273380, 14.1443,
        0.003414216, 14.1067, 0.00433389
    ]
    index = [
        'hstID', 'gsc1ID', 'ra', 'dec', 'raErr', 'decErr', 'JpgMag',
        'JpgMagErr', 'FpgMag', 'FpgMagErr', 'NpgMag', 'NpgMagErr', 'tmassJmag',
        'tmassJmagErr', 'tmassHmag', 'tmassHmagErr', 'tmassKsMag',
        'tmassKsMagErr', 'SDSSuMag', 'SDSSuMagErr', 'SDSSgMag', 'SDSSgMagErr',
        'SDSSrMag', 'SDSSrMagErr', 'SDSSiMag', 'SDSSiMagErr', 'SDSSzMag',
        'SDSSzMagErr'
    ]
    fgs.gsc_series = pd.Series(values, index=index)

    # Convert to JHK magnitudes
    fgs.j_mag, fgs.j_mag_err, fgs.h_mag, fgs.h_mag_err, fgs.k_mag, fgs.k_mag_err = \
        fgs.calc_jhk_mag(fgs.gsc_series)

    # Compute FGS countrate and magnitude
    cr, cr_err, mag, mag_err = fgs.calc_fgs_cr_mag_and_err()

    assert pytest.approx(cr, 1777234.5129574337, 5)
    assert pytest.approx(cr_err, 154340.24919027157, 5)
    assert pytest.approx(mag, -39.77243568524769, 5)
    assert pytest.approx(mag_err, 1.9887037388556956, 5)
def test_dim_limits_allsdss():
    """Test that when all SDSS bands are below the dim limits, they are not included in the
    JHK or count rate/magnitude calculations, and GSC2 bands are used instead."""

    gs_id = 'N13I000018'
    guider = 1
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)

    # Reset data to a set of constant, fake data with TMASS not present and all SDSS bands set to dim
    fgs.gsc_series = copy.copy(GSC_SERIES)
    for ind in TMASS_BANDS:
        fgs.gsc_series.loc[ind] = -999
    fgs.gsc_series['SDSSgMag'] = 24
    fgs.gsc_series['SDSSrMag'] = 24
    fgs.gsc_series['SDSSzMag'] = 24
    fgs.gsc_series['SDSSiMag'] = 24

    # Convert to JHK magnitudes
    fgs.j_mag, fgs.j_mag_err, fgs.h_mag, fgs.h_mag_err, fgs.k_mag, fgs.k_mag_err = \
        fgs.calc_jhk_mag(fgs.gsc_series)

    # Check conversion method
    assert fgs.j_convert_method == 'convert_gsc2bjin_to_jhk'
    assert fgs.h_convert_method == 'convert_gsc2bjin_to_jhk'
    assert fgs.k_convert_method == 'convert_gsc2bjin_to_jhk'

    # Check that no SDSS bands made it into the present bands list
    assert ['sdss' not in substring.lower() for substring in fgs._present_queried_mags]
    assert ['sdss' not in substring.lower() for substring in fgs._present_calculated_mags]

    # Compute FGS countrate and magnitude to get fgs.band_dataframe attribute
    _ = fgs.calc_fgs_cr_mag_and_err()

    # Check this calculation should only be done with GSC bands
    assert fgs.survey == 'gsc2'
    assert fgs.band_dataframe.at['JpgMag', 'ABMag'] != -999
    assert fgs.band_dataframe.at['FpgMag', 'ABMag'] != -999
    assert fgs.band_dataframe.at['NpgMag', 'ABMag'] != -999
Beispiel #20
0
def test_bad_sdss_gz_limits():
    """Test that when SDSSgMag and SDSSzMag color differences are bad, that conversion is skipped"""

    gs_id = 'N13I000018'
    guider = 1
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)

    # Reset data to a set of constant, fake data with SDSS_g and z having bad color ranges and tmass missing
    fgs.gsc_series = BASE_DATA
    fgs.gsc_series['tmassJMag'] = -999
    fgs.gsc_series['tmassHMag'] = -999
    fgs.gsc_series['tmassKsMag'] = -999
    fgs.gsc_series['SDSSgMag'] = 20
    fgs.gsc_series['SDSSzMag'] = 14

    # Convert to JHK magnitudes
    fgs.j_mag, fgs.j_mag_err, fgs.h_mag, fgs.h_mag_err, fgs.k_mag, fgs.k_mag_err = \
        fgs.calc_jhk_mag(fgs.gsc_series)

    # Check that the conversion method is the next SDSS one that doesn't include SDSS_g-z
    assert fgs.j_convert_method == 'convert_sdssrz_to_jhk'
    assert fgs.h_convert_method == 'convert_sdssrz_to_jhk'
    assert fgs.k_convert_method == 'convert_sdssrz_to_jhk'
def test_compute_countrate_magnitude():
    """
    Test the conversion from GSC magnitudes to FGS countrate
    returns values as expected
    """

    gs_id = 'N13I000018'
    guider = 1
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)

    # Reset data to a set of constant, fake data
    fgs.gsc_series = copy.copy(GSC_SERIES)

    # Convert to JHK magnitudes
    fgs.j_mag, fgs.j_mag_err, fgs.h_mag, fgs.h_mag_err, fgs.k_mag, fgs.k_mag_err = \
        fgs.calc_jhk_mag(fgs.gsc_series)

    # Compute FGS countrate and magnitude
    cr, cr_err, mag, mag_err = fgs.calc_fgs_cr_mag_and_err()

    assert np.isclose(cr, 1786779.2896366853, 1e-5)
    assert np.isclose(cr_err, 153161.72059228245, 1e-5)
    assert np.isclose(mag, 13.304318358662279, 1e-5)
    assert np.isclose(mag_err, 0.665287435671057, 1e-5)
Beispiel #22
0
def test_convert_mag_to_jhk():
    """
    Using a different technique for choosing the conversion method and
    comparing that output to the technique used in calc_jhk_mag.
    This test is done by finding all possible combinations of the
    magnitudes that could be used for the conversion and checking
    that they have the same output with both techniques.

    """

    full_list = [
        'JpgMag', 'FpgMag', 'NpgMag', 'tmassJMag', 'tmassHMag', 'tmassKsMag',
        'SDSSuMag', 'SDSSgMag', 'SDSSrMag', 'SDSSiMag', 'SDSSzMag'
    ]

    for L in range(0, len(full_list) + 1):
        for subset in itertools.combinations(full_list, L):
            if subset == ():
                continue

            # Recreate data
            fgs = FGSCountrate(guide_star_id="N13I000018", guider=1)
            fgs.gsc_series = BASE_DATA

            # Compute conversion
            delete_list = list(set(full_list) - set(subset))
            data2 = copy.copy(fgs.gsc_series)
            for i in delete_list:
                data2[i] = -999
            fgs.calc_jhk_mag(data=data2)

            # Compare output to here
            method_names = []
            for i in ['tmassJMag', 'tmassHMag', 'tmassKsMag']:
                if i in list(subset):
                    method_name_test = "convert_tmass_to_jhk"

                elif {'SDSSgMag', 'SDSSzMag'}.issubset(subset):
                    method_name_test = "convert_sdssgz_to_jhk"
                elif {'SDSSrMag', 'SDSSzMag'}.issubset(subset):
                    method_name_test = "convert_sdssrz_to_jhk"
                elif {'SDSSgMag', 'SDSSiMag'}.issubset(subset):
                    method_name_test = "convert_sdssgi_to_jhk"
                # elif {'SDSSiMag', 'SDSSzMag'}.issubset(subset):  # Add back in once GSSS uses this pair
                #     method_name_test = "convert_sdssiz_to_jhk"

                elif {'JpgMag', 'NpgMag'}.issubset(subset):
                    method_name_test = "convert_gsc2bjin_to_jhk"
                elif {'FpgMag', 'NpgMag'}.issubset(subset):
                    method_name_test = "convert_gsc2rfin_to_jhk"
                elif {'JpgMag', 'FpgMag'}.issubset(subset):
                    method_name_test = "convert_gsc2bjrf_to_jhk"

                else:
                    method_name_test = 'cannot_calculate'

                method_names.append(method_name_test)

                failure_message = f'For input {list(subset)} and band {i[5]}: the test called {method_name_test} ' \
                                  f'while the calc_jhk_mag method called ' \
                                  f'{getattr(fgs, f"{i[5].lower()}_convert_method")}'

                assert method_name_test == getattr(
                    fgs, f'{i[5].lower()}_convert_method'), failure_message
Beispiel #23
0
def test_convert_mag_to_jhk():
    """
    Using a different technique for choosing the conversion method and
    comparing that output to the technique used in calc_jhk_mag.
    This test is done by finding all possible combinations of the
    magnitudes that could be used for the conversion and checking
    that they have the same output with both techniques.

    """

    full_list = [
        'JpgMag', 'FpgMag', 'NpgMag', 'tmassJMag', 'tmassHMag', 'tmassKsMag',
        'SDSSuMag', 'SDSSgMag', 'SDSSrMag', 'SDSSiMag', 'SDSSzMag'
    ]

    for L in range(0, len(full_list) + 1):
        for subset in itertools.combinations(full_list, L):
            if subset == ():
                continue

            # Recreate data
            fgs = FGSCountrate(guide_star_id="N13I000018", guider=1)
            fgs.gsc_series = BASE_DATA

            # Compute conversion
            delete_list = list(set(full_list) - set(subset))
            data2 = copy.copy(fgs.gsc_series)
            for i in delete_list:
                data2[i] = -999
            try:
                fgs.calc_jhk_mag(data=data2)
                error = False
            except ValueError:
                error = True

            # Compare output to here
            method_names = []
            for i in ['tmassJMag', 'tmassHMag', 'tmassKsMag']:
                if i in list(subset):
                    method_name_test = "convert_tmass_to_jhk"

                elif set(['SDSSgMag', 'SDSSzMag']).issubset(subset):
                    method_name_test = "convert_sdssgz_to_jhk"
                elif set(['SDSSgMag', 'SDSSiMag']).issubset(subset):
                    method_name_test = "convert_sdssgi_to_jhk"
                elif set(['SDSSiMag', 'SDSSzMag']).issubset(subset):
                    method_name_test = "convert_sdssiz_to_jhk"

                elif set(['JpgMag', 'NpgMag']).issubset(subset):
                    method_name_test = "convert_gsc2bjin_to_jhk"
                elif set(['FpgMag', 'NpgMag']).issubset(subset):
                    method_name_test = "convert_gsc2rfin_to_jhk"
                elif set(['JpgMag', 'FpgMag']).issubset(subset):
                    method_name_test = "convert_gsc2bjrf_to_jhk"

                else:
                    method_name_test = 'cannot_convert_to_jhk'

                method_names.append(method_name_test)

                if method_name_test != getattr(
                        fgs, '{}_convert_method'.format(i[5].lower())):
                    if error is False:
                        print(subset)
                        print(
                            "    **", error, method_name_test,
                            getattr(fgs,
                                    '{}_convert_method'.format(i[5].lower())))

                # If you could compute the JHK mags, check the same conversion method as used
                if error is False:
                    failure_message = 'For input {} and band {}: the test called {} while the calc_jhk_mag ' \
                                      'method called {}'.format(list(subset), i[5], method_name_test,
                                                                getattr(fgs, '{}_convert_method'.format(i[5].lower())))

                    assert method_name_test == getattr(
                        fgs, '{}_convert_method'.format(
                            i[5].lower())), failure_message

            # If you can't compute the JHK mags, check methods agree it's not possible
            if error is True:
                assert 'cannot_convert_to_jhk' in method_names
def test_output_options():
    """
    Test the output options for calc_fgs_cr_mag_and_err()
    and _calc_fgs_cr_mag() are as expected
    """

    gs_id = 'N13I000018'
    guider = 2
    fgs = FGSCountrate(guide_star_id=gs_id, guider=guider)
    fgs.gsc_series = fgscountrate.utils.query_gsc(gs_id=gs_id, catalog='GSC242').iloc[0]
    fgs._present_calculated_mags = ['tmassJMag', 'tmassHMag', 'tmassKsMag', 'SDSSgMag', 'SDSSrMag', 'SDSSiMag']
    fgs._all_calculated_mag_series = fgs.gsc_series.loc[fgscountrate.GSC_BAND_NAMES]
    mag_err_list = [fgs.gsc_series[ind + 'Err'] for ind in fgs._all_calculated_mag_series.index]
    fgs._all_calculated_mag_err_series = pd.Series(mag_err_list, index=fgs._all_calculated_mag_series.index+'Err')
    fgs.survey = 'sdss'

    # Test output from calc_fgs_cr_mag_and_err()
    return_list = fgs.calc_fgs_cr_mag_and_err()
    assert len(return_list) == 4

    # Test output from _calc_fgs_cr_mag()
    band_series = fgs._all_calculated_mag_series
    guider_throughput = fgscountrate.fgs_countrate_core.THROUGHPUT_G2
    guider_gain = fgscountrate.fgs_countrate_core.CR_CONVERSION_G2

    # Case 1: Only Countrate
    return_list = fgs._calc_fgs_cr_mag(to_compute='countrate',
                                       band_series=band_series, guider_throughput=guider_throughput,
                                       guider_gain=guider_gain, return_dataframe=False)
    assert len(return_list) == 1
    assert np.isclose(return_list[0], fgs.fgs_countrate, 1e-5)

    # Case 2: Only Magnitude
    return_list = fgs._calc_fgs_cr_mag(to_compute='magnitude',
                                       band_series=band_series, guider_throughput=guider_throughput,
                                       guider_gain=guider_gain, return_dataframe=False)
    assert len(return_list) == 1
    assert np.isclose(return_list[0], fgs.fgs_magnitude, 1e-5)

    # Case 3: Both
    return_list = fgs._calc_fgs_cr_mag(to_compute='both',
                                       band_series=band_series, guider_throughput=guider_throughput,
                                       guider_gain=guider_gain, return_dataframe=False)
    assert len(return_list) == 2
    assert np.isclose(return_list[0], fgs.fgs_countrate, 1e-5)
    assert np.isclose(return_list[1], fgs.fgs_magnitude, 1e-5)

    # Case 4: Countrate + Dataframe Only
    return_list = fgs._calc_fgs_cr_mag(to_compute='countrate',
                                       band_series=band_series, guider_throughput=guider_throughput,
                                       guider_gain=guider_gain, return_dataframe=True)
    assert len(return_list) == 2
    assert np.isclose(return_list[0], fgs.fgs_countrate, 1e-5)
    np.testing.assert_array_almost_equal(return_list[1].values.flatten().tolist(),
                                         fgs.band_dataframe.values.flatten().tolist(), 5)

    # Case 5: Magnitude + Dataframe Only
    return_list = fgs._calc_fgs_cr_mag(to_compute='magnitude',
                                       band_series=band_series, guider_throughput=guider_throughput,
                                       guider_gain=guider_gain, return_dataframe=True)
    assert len(return_list) == 2
    assert np.isclose(return_list[0], fgs.fgs_magnitude, 1e-5)
    np.testing.assert_array_almost_equal(return_list[1].values.flatten().tolist(),
                                         fgs.band_dataframe.values.flatten().tolist(), 5)

    # Case 6: Countrate, Magnitude, and Dataframe
    return_list = fgs._calc_fgs_cr_mag(to_compute='both',
                                       band_series=band_series, guider_throughput=guider_throughput,
                                       guider_gain=guider_gain, return_dataframe=True)
    assert len(return_list) == 3
    assert np.isclose(return_list[0], fgs.fgs_countrate, 1e-5)
    assert np.isclose(return_list[1], fgs.fgs_magnitude, 1e-5)
    np.testing.assert_array_almost_equal(return_list[2].values.flatten().tolist(),
                                         fgs.band_dataframe.values.flatten().tolist(), 5)