Example #1
0
def test_parse_file():
    datpath = pathlib.Path(get_test_file("sample_asos.dat"))
    csvpath = pathlib.Path(get_test_file("sample_asos.csv"))
    result = asos.parse_file(datpath)
    expected = (
        pandas.read_csv(csvpath, parse_dates=True, index_col=["datetime"])
        .resample("5min")
        .asfreq()
    )
    pdtest.assert_frame_equal(
        result.fillna(-9999).sort_index(axis="columns"),
        expected.fillna(-9999).sort_index(axis="columns"),
    )
Example #2
0
def test_NCDCtoCSV():
    inputfile = get_test_file("sample_NCDC_data.NCD")
    knownfile = get_test_file("known_CSV_from_NCDC.csv")
    with tempfile.TemporaryDirectory() as datadir:
        outfile = os.path.join(datadir, "test_out.dat")
        exporters.NCDCtoCSV(inputfile, outfile)

        with open(knownfile, "r") as f:
            known_data = f.read()

        with open(outfile, "r") as f:
            test_data = f.read()

        assert known_data == test_data
Example #3
0
def test_dumpNCDCFormat(fivemin):
    knownfile = get_test_file("known_hourly_NCDC.dat")
    with tempfile.TemporaryDirectory() as datadir:
        outfile = os.path.join(datadir, "test_dumpNCDC.dat")
        exporters.NCDCFormat(
            fivemin.resample("1H").sum(),
            "041685",
            "California",
            col="precip",
            filename=outfile,
        )

        with open(knownfile, "r") as f:
            known_data = f.read()

        with open(outfile, "r") as f:
            test_data = f.read()

        assert known_data == test_data
Example #4
0
def test_dumpSWMM5Format_results(fivemin, freq, expected_file):
    if freq == "hourly":
        data = fivemin.resample("1H").sum()
    else:
        data = fivemin

    with tempfile.TemporaryDirectory() as datadir:
        outfile = os.path.join(datadir, "test_dumpSWMM.dat")
        data = exporters.SWMM5Format(
            data,
            "Test-Station",
            col="precip",
            freq=freq,
            dropzeros=True,
            filename=outfile,
        )
        pdtest.assert_frame_equal(
            data.reset_index(drop=True),
            pandas.read_table(get_test_file(expected_file), sep="\t"),
        )
Example #5
0
def test_parse_file(expected_hydra):
    filepath = Path(get_test_file("sample_hydra.txt"))
    result = hydra.parse_file(filepath)
    pdtest.assert_frame_equal(expected_hydra, result)
Example #6
0
def test_file_status(filename, expected):
    fn = get_test_file(filename)
    validate.file_status(fn) == expected
Example #7
0
def sample_data():
    fname = get_test_file("sample_ncdc_data.csv")
    return pandas.read_csv(fname, parse_dates=["date"])
Example #8
0
def fivemin():
    return pandas.read_csv(get_test_file("data_for_tests.csv"),
                           parse_dates=True,
                           index_col=0)
Example #9
0
def test_data():
    csvfile = get_test_file("data_for_viz_tests.csv")
    df = pandas.read_csv(csvfile, parse_dates=True, index_col=0)
    return df