Exemple #1
0
def test_fourierfit():
    '''
    Tests lcfit.fourier_fit_magseries.

    '''

    EXPECTED_FOURIERPARAMS = np.array([
        -0.15680457, -0.02936829, 0.0609173, 0.02692699, 0.05093689,
        -0.02880862, -0.0418917, 1.64850372, -5.02156053, -0.26441503,
        -3.15644339, -0.28243494, -0.23831426, -3.35074058
    ])

    EXPECTED_REDCHISQ = 2.756479193621726

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    fit = lcfit.fourier_fit_magseries(lcd['rjd'],
                                      lcd['aep_000'],
                                      lcd['aie_000'],
                                      PERIOD,
                                      fourierorder=7,
                                      sigclip=10.0,
                                      plotfit='test-fourierfit.png')

    assert isinstance(fit, dict)
    assert os.path.exists('test-fourierfit.png')

    assert_allclose(fit['fitredchisq'], EXPECTED_REDCHISQ, rtol=1.0e-3)
    assert_allclose(fit['fitinfo']['fitepoch'],
                    np.array([56092.640558]),
                    rtol=1.0e-5)
    assert_allclose(fit['fitinfo']['finalparams'],
                    EXPECTED_FOURIERPARAMS,
                    rtol=1.0e-5,
                    atol=0.01)
Exemple #2
0
def test_transitfit():
    '''
    Tests lcfit.traptransit_fit_magseries.

    '''

    FITPARAMS = np.array([
        3.08554939e+00, 5.67946743e+04, -3.48312233e-01, 8.94843762e-02,
        2.36164894e-02
    ])

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    fit = lcfit.traptransit_fit_magseries(lcd['rjd'],
                                          lcd['aep_000'],
                                          lcd['aie_000'],
                                          [PERIOD, None, -0.1, 0.1, 0.05],
                                          sigclip=10.0,
                                          plotfit='test-transitfit.png')

    assert isinstance(fit, dict)
    assert os.path.exists('test-transitfit.png')

    assert_allclose(fit['fitredchisq'], 2.9804742789196497)
    assert_allclose(fit['fitinfo']['fitepoch'], np.array([56794.67427438755]))
    assert_allclose(fit['fitinfo']['finalparams'], FITPARAMS, rtol=1.0e-6)
Exemple #3
0
def test_gaussianebfit():
    '''
    This tests lcfit.gaussianeb_fit_magseries.

    '''

    FITPARAMS = np.array([
        3.08556129e+00, 5.67946748e+04, -4.11857480e-01, 1.13484014e-01,
        3.35893325e-01, 5.11450964e-01
    ])

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    fit = lcfit.gaussianeb_fit_magseries(lcd['rjd'],
                                         lcd['aep_000'],
                                         lcd['aie_000'],
                                         [PERIOD, None, -0.3, 0.1, 0.3, 0.5],
                                         sigclip=10.0,
                                         plotfit='test-ebfit.png')

    assert isinstance(fit, dict)
    assert os.path.exists('test-ebfit.png')

    assert_allclose(fit['fitredchisq'], 2.6358311084545702)
    assert_allclose(fit['fitinfo']['fitepoch'], np.array([56794.67481399149]))
    assert_allclose(fit['fitinfo']['finalparams'], FITPARAMS, rtol=1.0e-6)
Exemple #4
0
def test_legendrefit():
    '''
    Tests lcfit.legendre_fit_magseries.

    '''

    LEGCOEFFS = np.array([
        1.51913612e+01, -3.76241414e-02, -4.75784157e-03, 6.41476816e-03,
        1.24890424e-01, 1.50597767e-02, -7.58171649e-02, -2.21526213e-02,
        1.23594509e-01, 2.95992178e-02, -1.33913179e-01
    ])

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    fit = lcfit.legendre_fit_magseries(lcd['rjd'],
                                       lcd['aep_000'],
                                       lcd['aie_000'],
                                       PERIOD,
                                       sigclip=10.0,
                                       plotfit='test-legendrefit.png')

    assert isinstance(fit, dict)
    assert os.path.exists('test-legendrefit.png')

    assert_allclose(
        fit['fitredchisq'],
        4.0964492873537495,
    )
    assert_allclose(fit['fitinfo']['fitepoch'], np.array([56297.8650305]))
    assert_allclose(fit['fitinfo']['finalparams'], LEGCOEFFS, rtol=1.0e-6)
Exemple #5
0
def test_checkplot_pickle_make():
    '''
    Tests if a checkplot pickle can be made.

    '''

    outpath = os.path.join(os.path.dirname(LCPATH),
                           'test-checkplot.pkl')

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    gls = periodbase.pgen_lsp(lcd['rjd'], lcd['aep_000'], lcd['aie_000'])

    assert isinstance(gls, dict)
    assert_allclose(gls['bestperiod'], 1.54289477)

    pdm = periodbase.stellingwerf_pdm(lcd['rjd'],
                                      lcd['aep_000'],
                                      lcd['aie_000'])

    assert isinstance(pdm, dict)
    assert_allclose(pdm['bestperiod'], 3.08578956)

    cpf = checkplot.checkplot_pickle(
        [gls, pdm],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
        outfile=outpath,
        objectinfo=lcd['objectinfo']
    )

    assert os.path.exists(outpath)
Exemple #6
0
def test_fourierfit():
    '''
    Tests lcfit.fourier_fit_magseries.

    '''

    FOURIERPARAMS = np.array(
        [-0.20722085, -0.03259998,  0.06764817,  0.03392241,  0.06109763,
         -0.03714063, -0.0492521 ,  1.6819149 , -5.27918097, -0.23971138,
         -3.23509529, -0.24212238, -0.20960648, -3.36844061]
    )

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    fit = lcfit.fourier_fit_magseries(lcd['rjd'],
                                      lcd['aep_000'],
                                      lcd['aie_000'],
                                      PERIOD,
                                      fourierorder=7,
                                      sigclip=10.0,
                                      plotfit='test-fourierfit.png')

    assert isinstance(fit, dict)
    assert os.path.exists('test-fourierfit.png')

    assert_allclose(fit['fitredchisq'], 2.892135304465803, rtol=1.0e-6)
    assert_allclose(fit['fitinfo']['fitepoch'], np.array([56853.3082622]))
    assert_allclose(fit['fitinfo']['finalparams'], FOURIERPARAMS, rtol=1.0e-5)
Exemple #7
0
def test_gaussianebfit():
    '''
    This tests lcfit.gaussianeb_fit_magseries.

    '''

    FITPARAMS = np.array([
        3.08578957e+00,  5.67946843e+04,
        -3.76719042e-01,  1.30328332e-01,
        3.27081266e-01,  5.09789096e-01
    ])

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    fit = lcfit.gaussianeb_fit_magseries(lcd['rjd'],
                                         lcd['aep_000'],
                                         lcd['aie_000'],
                                         [PERIOD, None, -0.3, 0.1, 0.3, 0.5],
                                         sigclip=10.0,
                                         plotfit='test-ebfit.png')

    assert isinstance(fit, dict)
    assert os.path.exists('test-ebfit.png')

    assert_allclose(fit['fitredchisq'], 2.7854070457947366)
    assert_allclose(fit['fitinfo']['fitepoch'], np.array([56794.68429695685,]))
    assert_allclose(fit['fitinfo']['finalparams'], FITPARAMS, rtol=1.0e-6)
Exemple #8
0
def test_transitfit():
    '''
    Tests lcfit.traptransit_fit_magseries.

    '''

    FITPARAMS = np.array([3.08578957e+00,
                          5.67946843e+04,
                          -4.32689876e-01,
                          1.00188320e-01,
                          4.99058419e-02])

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    fit = lcfit.traptransit_fit_magseries(lcd['rjd'],
                                          lcd['aep_000'],
                                          lcd['aie_000'],
                                          [PERIOD, None,
                                           -0.1, 0.1, 0.05],
                                          sigclip=10.0,
                                          plotfit='test-transitfit.png')

    assert isinstance(fit, dict)
    assert os.path.exists('test-transitfit.png')

    assert_allclose(fit['fitredchisq'], 3.145980551134323)
    assert_allclose(fit['fitinfo']['fitepoch'], np.array([56794.68428345605]))
    assert_allclose(fit['fitinfo']['finalparams'], FITPARAMS, rtol=1.0e-6)
def test_aov():
    '''
    Tests periodbase.aov_periodfind.

    '''
    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    aov = periodbase.aov_periodfind(lcd['rjd'], lcd['aep_000'], lcd['aie_000'])

    assert isinstance(aov, dict)
    assert_allclose(aov['bestperiod'], 3.08578956)
Exemple #10
0
def test_hatlc():
    '''
    Tests that a HAT light curve can be loaded.

    '''

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    assert isinstance(lcd, dict)
    assert msg == 'no SQL filters, LC OK'
def test_checkplot_with_multiple_same_pfmethods():
    '''
    This tests running the same period-finder for different period ranges.

    '''

    outpath = os.path.join(os.path.dirname(LCPATH), 'test-checkplot.pkl')

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    gls_1 = periodbase.pgen_lsp(lcd['rjd'],
                                lcd['aep_000'],
                                lcd['aie_000'],
                                startp=0.01,
                                endp=0.1)
    gls_2 = periodbase.pgen_lsp(lcd['rjd'],
                                lcd['aep_000'],
                                lcd['aie_000'],
                                startp=0.1,
                                endp=300.0)
    pdm_1 = periodbase.stellingwerf_pdm(lcd['rjd'],
                                        lcd['aep_000'],
                                        lcd['aie_000'],
                                        startp=0.01,
                                        endp=0.1)
    pdm_2 = periodbase.stellingwerf_pdm(lcd['rjd'],
                                        lcd['aep_000'],
                                        lcd['aie_000'],
                                        startp=0.1,
                                        endp=300.0)

    assert isinstance(gls_1, dict)
    assert isinstance(gls_2, dict)
    assert isinstance(pdm_1, dict)
    assert isinstance(pdm_2, dict)

    cpf = checkplot.checkplot_pickle([gls_1, gls_2, pdm_1, pdm_2],
                                     lcd['rjd'],
                                     lcd['aep_000'],
                                     lcd['aie_000'],
                                     outfile=outpath,
                                     objectinfo=lcd['objectinfo'])

    assert os.path.exists(cpf)
    assert os.path.abspath(cpf) == os.path.abspath(outpath)

    cpd = _read_checkplot_picklefile(cpf)
    pfmethods = list(cpd['pfmethods'])

    assert len(pfmethods) == 4

    assert '0-gls' in pfmethods
    assert '1-gls' in pfmethods
    assert '2-pdm' in pfmethods
    assert '3-pdm' in pfmethods
Exemple #12
0
def test_checkplot_pickle_update():
    '''
    Tests if a checkplot pickle can be made, read back, and updated.

    '''

    outpath = os.path.join(os.path.dirname(LCPATH),
                           'test-checkplot.pkl')

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    gls = periodbase.pgen_lsp(lcd['rjd'], lcd['aep_000'], lcd['aie_000'])

    assert isinstance(gls, dict)
    assert_allclose(gls['bestperiod'], 1.54289477)

    pdm = periodbase.stellingwerf_pdm(lcd['rjd'],
                                      lcd['aep_000'],
                                      lcd['aie_000'])

    assert isinstance(pdm, dict)
    assert_allclose(pdm['bestperiod'], 3.08578956)

    # test write
    cpf = checkplot.checkplot_pickle(
        [gls, pdm],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
        outfile=outpath,
        objectinfo=lcd['objectinfo']
    )

    assert os.path.exists(outpath)

    # test read back
    cpd = checkplot._read_checkplot_picklefile(cpf)

    assert isinstance(cpd, dict)

    cpdkeys = set(list(cpd.keys()))
    testset = {'0-gls', '1-pdm', 'comments', 'externalplots',
               'finderchart', 'magseries', 'neighbors', 'normmingap',
               'normto', 'objectid', 'objectinfo', 'pfmethods', 'sigclip',
               'signals', 'status', 'varinfo'}
    assert (testset - cpdkeys) == set()

    assert_allclose(cpd['0-gls']['bestperiod'], 1.54289477)
    assert_allclose(cpd['1-pdm']['bestperiod'], 3.08578956)

    # test update write to pickle
    cpd['comments'] = ('this is a test of the checkplot pickle '
                       'update mechanism. this is only a test.')
    cpfupdated = checkplot.checkplot_pickle_update(cpf, cpd)

    cpdupdated = checkplot._read_checkplot_picklefile(cpfupdated)

    assert cpdupdated['comments'] == cpd['comments']
def test_pdm():
    '''
    Tests periodbase.stellingwerf_pdm.

    '''
    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    pdm = periodbase.stellingwerf_pdm(lcd['rjd'], lcd['aep_000'],
                                      lcd['aie_000'])

    assert isinstance(pdm, dict)
    assert_allclose(pdm['bestperiod'], 3.08578956)
def test_win():
    '''
    Tests periodbase.specwindow_lsp

    '''

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    win = periodbase.specwindow_lsp(lcd['rjd'], lcd['aep_000'], lcd['aie_000'])

    assert isinstance(win, dict)
    assert_allclose(win['bestperiod'], 592.0307682142864)
def test_gls():
    '''
    Tests periodbase.pgen_lsp.

    '''

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    gls = periodbase.pgen_lsp(lcd['rjd'], lcd['aep_000'], lcd['aie_000'])

    assert isinstance(gls, dict)
    assert_allclose(gls['bestperiod'], 1.54289477)
def test_kbls_parallel():
    '''
    Tests periodbase.kbls.bls_parallel_pfind.

    '''
    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    bls = kbls.bls_parallel_pfind(lcd['rjd'],
                                  lcd['aep_000'],
                                  lcd['aie_000'],
                                  startp=1.0)

    assert isinstance(bls, dict)
    assert_allclose(bls['bestperiod'], 3.08560655)
def test_acf():
    '''
    Tests periodbase.macf_period_find.

    '''
    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    acf = periodbase.macf_period_find(lcd['rjd'],
                                      lcd['aep_000'],
                                      lcd['aie_000'],
                                      smoothacf=721)

    assert isinstance(acf, dict)
    assert_allclose(acf['bestperiod'], 3.0750854011348565)
def test_abls_parallel():
    '''
    This tests periodbase.abls.bls_parallel_pfind.

    '''

    EXPECTED_PERIOD = 3.0848887

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    bls = abls.bls_parallel_pfind(lcd['rjd'],
                                  lcd['aep_000'],
                                  lcd['aie_000'],
                                  startp=1.0,
                                  ndurations=50)

    assert isinstance(bls, dict)
    assert_allclose(bls['bestperiod'], EXPECTED_PERIOD, atol=1.0e-4)
Exemple #19
0
def test_savgolfit():
    '''
    Tests lcfit.savgol_fit_magseries.

    '''

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    fit = lcfit.savgol_fit_magseries(lcd['rjd'],
                                     lcd['aep_000'],
                                     lcd['aie_000'],
                                     PERIOD,
                                     sigclip=10.0,
                                     plotfit='test-savgolfit.png')

    assert isinstance(fit, dict)
    assert os.path.exists('test-savgolfit.png')

    assert_allclose(fit['fitchisq'], 22198.963657474334)
    assert_allclose(fit['fitinfo']['fitepoch'], np.array([56856.3795333]))
Exemple #20
0
def test_splinefit():
    '''
    Tests lcfit.spline_fit_magseries.

    '''

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

    fit = lcfit.spline_fit_magseries(lcd['rjd'],
                                     lcd['aep_000'],
                                     lcd['aie_000'],
                                     PERIOD,
                                     sigclip=10.0,
                                     plotfit='test-splinefit.png')

    assert isinstance(fit, dict)
    assert os.path.exists('test-splinefit.png')

    assert_allclose(fit['fitredchisq'], 2.0388607985104708)
    assert_allclose(fit['fitinfo']['fitepoch'], np.array([56794.6838758]))
Exemple #21
0
def test_checkplot_png():
    '''
    Tests if a checkplot PNG can be made.

    '''

    outpath = os.path.join(os.path.dirname(LCPATH),
                           'test-checkplot.png')

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    gls = periodbase.pgen_lsp(lcd['rjd'], lcd['aep_000'], lcd['aie_000'])

    assert isinstance(gls, dict)
    assert_allclose(gls['bestperiod'], 1.54289477)

    cpf = checkplot.checkplot_png(gls,
                                  lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
                                  outfile=outpath,
                                  objectinfo=lcd['objectinfo'])

    assert os.path.exists(outpath)
    def test_tls_parallel():
        '''
        This tests periodbase.htls.tls_parallel_pfind.
        '''

        EXPECTED_PERIOD = 3.0848887

        lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)

        tlsdict = htls.tls_parallel_pfind(lcd['rjd'],
                                          lcd['aep_000'],
                                          lcd['aie_000'],
                                          startp=2.0,
                                          endp=5.0)

        tlsresult = tlsdict['tlsresult']

        assert isinstance(tlsresult, dict)

        # ensure period is within 2 sigma of what's expected.
        assert_allclose(tlsdict['bestperiod'],
                        EXPECTED_PERIOD,
                        atol=2.0 * tlsresult['period_uncertainty'])
def test_checkplot_pickle_missing_objectinfo():
    '''This tests if checkplot_pickle can handle various
    missing information in the input objectinfo dict.

    '''

    outpath = os.path.join(os.path.dirname(LCPATH),
                           'test-checkplot.pkl')

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    gls = periodbase.pgen_lsp(lcd['rjd'], lcd['aep_000'], lcd['aie_000'])

    assert isinstance(gls, dict)
    assert_allclose(gls['bestperiod'], 1.54289477)


    # 1. handle case of no information whatsoever
    # should auto-generate the objectid in this case
    cpd = checkplot.checkplot_dict(
        [gls],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
    )

    assert 'objectid' in cpd and cpd['objectid'] == '3f935'


    # 2. handle case of g, r, i mags with no ra, dec provided
    # should have sdssg, sdssr, sdssi, and g-r, r-i, g-i available
    cpd = checkplot.checkplot_dict(
        [gls],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
        objectinfo={'sdssg':12.4,'sdssr':12.2,'sdssi':12.0}
    )

    assert 'objectid' in cpd and cpd['objectid'] is not None

    assert ('sdssg' in cpd['objectinfo'] and
            cpd['objectinfo']['sdssg'] is not None and
            np.isfinite(cpd['objectinfo']['sdssg']))
    assert_almost_equal(12.4, cpd['objectinfo']['sdssg'])

    assert ('sdssr' in cpd['objectinfo'] and
            cpd['objectinfo']['sdssr'] is not None and
            np.isfinite(cpd['objectinfo']['sdssr']))
    assert_almost_equal(12.2, cpd['objectinfo']['sdssr'])

    assert ('sdssi' in cpd['objectinfo'] and
            cpd['objectinfo']['sdssi'] is not None and
            np.isfinite(cpd['objectinfo']['sdssi']))
    assert_almost_equal(12.0, cpd['objectinfo']['sdssi'])

    assert ('sdssg-sdssr' in cpd['objectinfo'] and
            cpd['objectinfo']['sdssg-sdssr'] is not None and
            np.isfinite(cpd['objectinfo']['sdssg-sdssr']))
    assert_almost_equal(0.2, cpd['objectinfo']['sdssg-sdssr'])

    assert ('sdssr-sdssi' in cpd['objectinfo'] and
            cpd['objectinfo']['sdssr-sdssi'] is not None and
            np.isfinite(cpd['objectinfo']['sdssr-sdssi']))
    assert_almost_equal(0.2, cpd['objectinfo']['sdssr-sdssi'])

    assert ('sdssi' in cpd['objectinfo'] and
            cpd['objectinfo']['sdssg-sdssi'] is not None and
            np.isfinite(cpd['objectinfo']['sdssg-sdssi']))
    assert_almost_equal(0.4, cpd['objectinfo']['sdssg-sdssi'])


    # 3. handle case of J, H, K, objectid provided with no ra, dec
    # we should now have BVugriz auto-generated from JHK and the various colors
    #
    cpd = checkplot.checkplot_dict(
        [gls],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
        objectinfo={'jmag':12.4,'hmag':12.2,'kmag':12.0,
                    'objectid':'hello-there'}
    )

    assert 'objectid' in cpd and cpd['objectid'] == 'hello-there'

    expected_bands = ['bmag',
                      'vmag',
                      'jmag',
                      'hmag',
                      'kmag',
                      'sdssu',
                      'sdssg',
                      'sdssr',
                      'sdssi',
                      'sdssz']
    expected_colors = ['bmag-vmag',
                       'jmag-hmag',
                       'vmag-kmag',
                       'hmag-kmag',
                       'jmag-kmag',
                       'sdssu-vmag',
                       'sdssg-kmag',
                       'sdssu-sdssg',
                       'sdssg-jmag',
                       'sdssg-sdssr',
                       'sdssr-sdssi',
                       'sdssg-sdssi',
                       'sdssi-jmag',
                       'sdssi-sdssz',
                       'sdssg-sdssz']

    print(cpd['objectinfo']['available_colors'])

    for b in expected_bands:
        assert b in cpd['objectinfo']['available_bands']

    for c in expected_colors:
        assert c in cpd['objectinfo']['available_colors']


    # 4. handle class of J, H, K, no objectid, ra, dec
    # should have everything with dereddening, GAIA neighbors, finder chart,
    # color classification for object
    cpd = checkplot.checkplot_dict(
        [gls],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
        objectinfo={'jmag':13.303,'hmag':12.65,'kmag':12.461,
                    'ra':219.450491,'decl':-56.816551}
    )

    expected_bands = ['bmag',
                      'vmag',
                      'jmag',
                      'hmag',
                      'kmag',
                      'sdssu',
                      'sdssg',
                      'sdssr',
                      'sdssi',
                      'sdssz']
    expected_colors = ['bmag-vmag',
                       'jmag-hmag',
                       'vmag-kmag',
                       'hmag-kmag',
                       'jmag-kmag',
                       'sdssu-vmag',
                       'sdssg-kmag',
                       'sdssu-sdssg',
                       'sdssg-jmag',
                       'sdssg-sdssr',
                       'sdssr-sdssi',
                       'sdssg-sdssi',
                       'sdssi-jmag',
                       'sdssi-sdssz',
                       'sdssg-sdssz']

    expected_gaia_id = '5891733852050596480'
    expected_gaia_dist = 0.12319158
    expected_gaia_closest_nbrdist = 6.4526230016634329
    expected_gaia_mag = 15.840071
    expected_gb, expected_gl = 3.0933098295258104, 317.13437783525336
    expected_color_classes = ['WD/sdO/sdB']

    assert 'objectid' in cpd and cpd['objectid'] == '3f935'
    assert_equal(expected_color_classes, cpd['objectinfo']['color_classes'])

    for b in expected_bands:
        assert b in cpd['objectinfo']['available_bands']

    for c in expected_colors:
        assert c in cpd['objectinfo']['available_colors']

    assert_equal(cpd['objectinfo']['gaia_ids'][0], expected_gaia_id)
    assert_almost_equal(cpd['objectinfo']['gaia_dists'][0],
                        expected_gaia_dist, decimal=2)
    assert_almost_equal(cpd['objectinfo']['gaia_closest_distarcsec'],
                        expected_gaia_closest_nbrdist, decimal=2)
    assert_almost_equal(cpd['objectinfo']['gaia_mags'][0], expected_gaia_mag)

    assert_almost_equal(cpd['objectinfo']['gb'],expected_gb)
    assert_almost_equal(cpd['objectinfo']['gl'], expected_gl)

    assert cpd['finderchart'] is not None
def test_checkplot_pickle_varepoch_handling(capsys):
    '''This tests the various different ways to give varepoch
    to checkplot_pickle.

    Uses the py.test capsys fixture to capture stdout and see if we reported the
    correct epoch being used.

    '''

    outpath = os.path.join(os.path.dirname(LCPATH),
                           'test-checkplot.pkl')

    lcd, msg = hatlc.read_and_filter_sqlitecurve(LCPATH)
    gls = periodbase.pgen_lsp(lcd['rjd'], lcd['aep_000'], lcd['aie_000'])
    pdm = periodbase.stellingwerf_pdm(lcd['rjd'],
                                      lcd['aep_000'],
                                      lcd['aie_000'])

    assert isinstance(gls, dict)
    assert_allclose(gls['bestperiod'], 1.54289477)

    # 1. usual handling where epoch is None
    # should use min(times) as epoch all the time
    cpf = checkplot.checkplot_pickle(
        [gls, pdm],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
        outfile=outpath,
        objectinfo=lcd['objectinfo'],
        varepoch=None
    )

    assert os.path.exists(outpath)

    # capture the stdout
    captured = capsys.readouterr()

    # see if we used the correct periods and epochs
    splitout = captured.out.split('\n')

    # plot output lines
    plotoutlines = [x for x in splitout if 'phased LC with period' in x]

    # these are the periods and epochs to match per line
    lookfor = ['gls phased LC with period 0: 1.542895, epoch: 56092.64056',
               'gls phased LC with period 1: 0.771304, epoch: 56092.64056',
               'gls phased LC with period 2: 0.514234, epoch: 56092.64056',
               'pdm phased LC with period 0: 3.085790, epoch: 56092.64056',
               'pdm phased LC with period 1: 1.542895, epoch: 56092.64056',
               'pdm phased LC with period 2: 6.157824, epoch: 56092.64056']

    for expected, plotline in zip(lookfor,plotoutlines):
        assert expected in plotline


    # 2. handle varepoch = 'min'
    cpf = checkplot.checkplot_pickle(
        [gls, pdm],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
        outfile=outpath,
        objectinfo=lcd['objectinfo'],
        varepoch='min'
    )

    assert os.path.exists(outpath)

    # capture the stdout
    captured = capsys.readouterr()

    # see if we used the correct periods and epochs
    splitout = captured.out.split('\n')

    # plot output lines
    plotoutlines = [x for x in splitout if 'phased LC with period' in x]

    # these are the periods and epochs to match per line
    lookfor = ['gls phased LC with period 0: 1.542895, epoch: 56341.11968',
               'gls phased LC with period 1: 0.771304, epoch: 56856.46618',
               'gls phased LC with period 2: 0.514234, epoch: 56889.88470',
               'pdm phased LC with period 0: 3.085790, epoch: 56828.62835',
               'pdm phased LC with period 1: 1.542895, epoch: 56341.11968',
               'pdm phased LC with period 2: 6.157824, epoch: 56154.33367']

    for expected, plotline in zip(lookfor,plotoutlines):
        assert expected in plotline


    # 3. handle varepoch = some float
    cpf = checkplot.checkplot_pickle(
        [gls, pdm],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
        outfile=outpath,
        objectinfo=lcd['objectinfo'],
        varepoch=56000.5
    )

    assert os.path.exists(outpath)

    # capture the stdout
    captured = capsys.readouterr()

    # see if we used the correct periods and epochs
    splitout = captured.out.split('\n')

    # plot output lines
    plotoutlines = [x for x in splitout if 'phased LC with period' in x]

    # these are the periods and epochs to match per line
    lookfor = ['gls phased LC with period 0: 1.542895, epoch: 56000.50000',
               'gls phased LC with period 1: 0.771304, epoch: 56000.50000',
               'gls phased LC with period 2: 0.514234, epoch: 56000.50000',
               'pdm phased LC with period 0: 3.085790, epoch: 56000.50000',
               'pdm phased LC with period 1: 1.542895, epoch: 56000.50000',
               'pdm phased LC with period 2: 6.157824, epoch: 56000.50000']

    for expected, plotline in zip(lookfor,plotoutlines):
        assert expected in plotline


    # 4. handle varepoch = list of floats
    cpf = checkplot.checkplot_pickle(
        [gls, pdm],
        lcd['rjd'], lcd['aep_000'], lcd['aie_000'],
        outfile=outpath,
        objectinfo=lcd['objectinfo'],
        varepoch=[[56000.1,56000.2,56000.3],
                  [56000.4,56000.5,56000.6]]
    )

    assert os.path.exists(outpath)

    # capture the stdout
    captured = capsys.readouterr()

    # see if we used the correct periods and epochs
    splitout = captured.out.split('\n')

    # plot output lines
    plotoutlines = [x for x in splitout if 'phased LC with period' in x]

    # these are the periods and epochs to match per line
    lookfor = ['gls phased LC with period 0: 1.542895, epoch: 56000.10000',
               'gls phased LC with period 1: 0.771304, epoch: 56000.20000',
               'gls phased LC with period 2: 0.514234, epoch: 56000.30000',
               'pdm phased LC with period 0: 3.085790, epoch: 56000.40000',
               'pdm phased LC with period 1: 1.542895, epoch: 56000.50000',
               'pdm phased LC with period 2: 6.157824, epoch: 56000.60000']

    for expected, plotline in zip(lookfor,plotoutlines):
        assert expected in plotline