Example #1
0
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
Example #2
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)
def run_asas_periodograms(times,
                          mags,
                          errs,
                          outdir='../results/ASAS_lightcurves/',
                          outname='WASP-18b_BLS_GLS.png'):

    blsdict = kbls.bls_parallel_pfind(times,
                                      mags,
                                      errs,
                                      magsarefluxes=False,
                                      startp=0.5,
                                      endp=1.5,
                                      maxtransitduration=0.3,
                                      nworkers=8,
                                      sigclip=[15, 3])
    gls = periodbase.pgen_lsp(times,
                              mags,
                              errs,
                              magsarefluxes=False,
                              startp=0.5,
                              endp=1.5,
                              nworkers=8,
                              sigclip=[15, 3])
    outpath = outdir + outname
    cpf = checkplot.twolsp_checkplot_png(blsdict,
                                         gls,
                                         times,
                                         mags,
                                         errs,
                                         outfile=outpath,
                                         objectinfo=None)
Example #4
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']
Example #5
0
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)
Example #6
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)
Example #7
0
def allvar_periodogram_checkplot(a):

    ap = int(a['ap'])
    time, flux, err = a['STIME'], a[f'SPCA{ap}'], a[f'SPCAE{ap}']

    spdm = periodbase.stellingwerf_pdm(time,
                                       flux,
                                       err,
                                       magsarefluxes=True,
                                       startp=0.05,
                                       endp=30,
                                       sigclip=5.0,
                                       nworkers=nworkers)

    lsp = periodbase.pgen_lsp(time,
                              flux,
                              err,
                              magsarefluxes=True,
                              startp=0.05,
                              endp=30,
                              autofreq=True,
                              sigclip=5.0,
                              nworkers=nworkers)

    objectinfo = {}
    keys = ['objectid', 'ra', 'decl', 'pmra', 'pmdecl', 'teff', 'gmag']
    hdrkeys = [
        'Gaia-ID', 'RA_OBJ', 'DEC_OBJ', 'PM_RA[mas/yr]', 'PM_Dec[mas/year]',
        'teff_val', 'phot_g_mean_mag'
    ]
    hdr = a['dtr_infos'][0][0]
    for k, hk in zip(keys, hdrkeys):
        if hk in hdr:
            objectinfo[k] = hdr[hk]
        else:
            objectinfo[k] = np.nan

    import matplotlib as mpl
    mpl.rcParams['axes.titlesize'] = 'xx-large'
    mpl.rcParams['axes.labelsize'] = 'xx-large'

    fig = checkplot.twolsp_checkplot_png(lsp,
                                         spdm,
                                         time,
                                         flux,
                                         err,
                                         magsarefluxes=True,
                                         objectinfo=objectinfo,
                                         varepoch='min',
                                         sigclip=None,
                                         plotdpi=100,
                                         phasebin=3e-2,
                                         phasems=6.0,
                                         phasebinms=14.0,
                                         unphasedms=6.0,
                                         figsize=(30, 24),
                                         returnfigure=True,
                                         circleoverlay=APSIZEDICT[ap] * 21,
                                         yticksize=20,
                                         trimylim=True)

    axs = fig.get_axes()

    for ax in axs:
        ax.get_yaxis().set_tick_params(which='both',
                                       direction='in',
                                       labelsize='xx-large')
        ax.get_xaxis().set_tick_params(which='both',
                                       direction='in',
                                       labelsize='xx-large')

    return fig, lsp, spdm, objectinfo
Example #8
0
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
Example #9
0
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