Exemplo n.º 1
0
def test_get_timeseries_data_file2():

    expected = {"q_dates": [np.array([datetime.datetime(2014, 1, 1, 0, 0), datetime.datetime(2014, 1, 2, 0, 0)]), np.array([datetime.datetime(2014, 1, 1, 0, 0), datetime.datetime(2014, 1, 2, 0, 0)])],
                "p_dates": [np.array([datetime.datetime(2014, 1, 1, 0, 0), datetime.datetime(2014, 1, 2, 0, 0)]), np.array([datetime.datetime(2014, 1, 1, 0, 0), datetime.datetime(2014, 1, 2, 0, 0)])],
                "t_dates": [np.array([datetime.datetime(2014, 1, 1, 0, 0), datetime.datetime(2014, 1, 2, 0, 0)]), np.array([datetime.datetime(2014, 1, 1, 0, 0), datetime.datetime(2014, 1, 2, 0, 0)])],
                
                "q_values": [np.array([100.0, 110.0]), np.array([100.0, 110.0])],
                "p_values": [np.array([3, 4.5]), np.array([3, 4.5])],
                "t_values": [np.array([11.1, 12.2]), np.array([11.1, 12.2])],           
            
                "q_units": ["mm per day", "mm per day"],
                "p_units": ["mm", "mm"],
                "t_units": ["Celsius", "Celsius"]
                }
    
    simulation = waterxml.create_simulation_dict()

    simulation = waterxml.fill_simulation_dict(waterxml_tree = fixture["xml_tree2"], simulation_dict = simulation)

    actual = {}
    actual["q_dates"], actual["q_values"], actual["q_units"] = waterxml.get_timeseries_data(simulation_dict = simulation, timeseries_key = "StudyUnitDischargeSeries")
    actual["p_dates"], actual["p_values"], actual["p_units"] = waterxml.get_timeseries_data(simulation_dict = simulation, timeseries_key = "ClimaticPrecipitationSeries")
    actual["t_dates"], actual["t_values"], actual["t_units"] = waterxml.get_timeseries_data(simulation_dict = simulation, timeseries_key = "ClimaticTemperatureSeries")

    nose.tools.assert_equals(len(expected["q_dates"]), len(actual["q_dates"]))
    nose.tools.assert_equals(len(expected["p_dates"]), len(actual["p_dates"]))
    nose.tools.assert_equals(len(expected["t_dates"]), len(actual["t_dates"]))

    np.testing.assert_equal(actual["q_dates"][0], expected["q_dates"][0])
    np.testing.assert_equal(actual["p_dates"][0], expected["p_dates"][0])
    np.testing.assert_equal(actual["t_dates"][0], expected["t_dates"][0])

    np.testing.assert_equal(actual["q_values"][0], expected["q_values"][0])
    np.testing.assert_equal(actual["p_values"][0], expected["p_values"][0])
    np.testing.assert_equal(actual["t_values"][0], expected["t_values"][0])

    np.testing.assert_equal(actual["q_units"][0], expected["q_units"][0])
    np.testing.assert_equal(actual["p_units"][0], expected["p_units"][0])
    np.testing.assert_equal(actual["t_units"][0], expected["t_units"][0])

    np.testing.assert_equal(actual["q_dates"][1], expected["q_dates"][1])
    np.testing.assert_equal(actual["p_dates"][1], expected["p_dates"][1])
    np.testing.assert_equal(actual["t_dates"][1], expected["t_dates"][1])

    np.testing.assert_equal(actual["q_values"][1], expected["q_values"][1])
    np.testing.assert_equal(actual["p_values"][1], expected["p_values"][1])
    np.testing.assert_equal(actual["t_values"][1], expected["t_values"][1])

    np.testing.assert_equal(actual["q_units"][1], expected["q_units"][1])
    np.testing.assert_equal(actual["p_units"][1], expected["p_units"][1])
    np.testing.assert_equal(actual["t_units"][1], expected["t_units"][1])
Exemplo n.º 2
0
def test_apply_factors():
    
    expected = {"q_dates": [np.array([datetime.datetime(2014, 1, 1, 0, 0), datetime.datetime(2014, 1, 2, 0, 0)])],
                "p_dates": [np.array([datetime.datetime(2014, 1, 1, 0, 0), datetime.datetime(2014, 1, 2, 0, 0)])],
                "t_dates": [np.array([datetime.datetime(2014, 1, 1, 0, 0), datetime.datetime(2014, 1, 2, 0, 0)])],
                
                "q_values": [np.array([200.0, 220.0])],
                "p_values": [np.array([6, 9.])],
                "t_values": [np.array([13.1, 14.2])],           
            
                "q_units": ["mm per day"],
                "p_units": ["mm"],
                "t_units": ["Celsius"]
                }
    
    simulation = waterxml.create_simulation_dict()

    simulation = waterxml.fill_simulation_dict(waterxml_tree = fixture["xml_tree1"], simulation_dict = simulation)

    q_dates, q_values, q_units = waterxml.get_timeseries_data(simulation_dict = simulation, timeseries_key = "StudyUnitDischargeSeries")
    p_dates, p_values, p_units = waterxml.get_timeseries_data(simulation_dict = simulation, timeseries_key = "ClimaticPrecipitationSeries")
    t_dates, t_values, t_units = waterxml.get_timeseries_data(simulation_dict = simulation, timeseries_key = "ClimaticTemperatureSeries")
    
    waterxml.apply_factors(waterxml_tree = fixture["xml_tree1"], element = "StudyUnitDischargeSeries", factors = fixture["factors"])
    waterxml.apply_factors(waterxml_tree = fixture["xml_tree1"], element = "ClimaticPrecipitationSeries", factors = fixture["factors"])
    waterxml.apply_factors(waterxml_tree = fixture["xml_tree1"], element = "ClimaticTemperatureSeries", factors = fixture["factors"])

    simulation_updated = waterxml.create_simulation_dict()

    simulation_updated = waterxml.fill_simulation_dict(waterxml_tree = fixture["xml_tree1"], simulation_dict = simulation_updated)
    
    actual = {}
    actual["q_dates"], actual["q_values"], actual["q_units"] = waterxml.get_timeseries_data(simulation_dict = simulation_updated, timeseries_key = "StudyUnitDischargeSeries")
    actual["p_dates"], actual["p_values"], actual["p_units"] = waterxml.get_timeseries_data(simulation_dict = simulation_updated, timeseries_key = "ClimaticPrecipitationSeries")
    actual["t_dates"], actual["t_values"], actual["t_units"] = waterxml.get_timeseries_data(simulation_dict = simulation_updated, timeseries_key = "ClimaticTemperatureSeries")

    nose.tools.assert_equals(len(expected["q_dates"]), len(actual["q_dates"]))
    nose.tools.assert_equals(len(expected["p_dates"]), len(actual["p_dates"]))
    nose.tools.assert_equals(len(expected["t_dates"]), len(actual["t_dates"]))

    np.testing.assert_equal(actual["q_dates"][0], expected["q_dates"][0])
    np.testing.assert_equal(actual["p_dates"][0], expected["p_dates"][0])
    np.testing.assert_equal(actual["t_dates"][0], expected["t_dates"][0])

    np.testing.assert_equal(actual["q_values"][0], expected["q_values"][0])
    np.testing.assert_equal(actual["p_values"][0], expected["p_values"][0])
    np.testing.assert_equal(actual["t_values"][0], expected["t_values"][0])

    np.testing.assert_equal(actual["q_units"][0], expected["q_units"][0])
    np.testing.assert_equal(actual["p_units"][0], expected["p_units"][0])
    np.testing.assert_equal(actual["t_units"][0], expected["t_units"][0])
Exemplo n.º 3
0
def test_apply_factors():

    expected = {
        "q_dates": [
            np.array([
                datetime.datetime(2014, 1, 1, 0, 0),
                datetime.datetime(2014, 1, 2, 0, 0)
            ])
        ],
        "p_dates": [
            np.array([
                datetime.datetime(2014, 1, 1, 0, 0),
                datetime.datetime(2014, 1, 2, 0, 0)
            ])
        ],
        "t_dates": [
            np.array([
                datetime.datetime(2014, 1, 1, 0, 0),
                datetime.datetime(2014, 1, 2, 0, 0)
            ])
        ],
        "q_values": [np.array([200.0, 220.0])],
        "p_values": [np.array([6, 9.])],
        "t_values": [np.array([13.1, 14.2])],
        "q_units": ["mm per day"],
        "p_units": ["mm"],
        "t_units": ["Celsius"]
    }

    simulation = waterxml.create_simulation_dict()

    simulation = waterxml.fill_simulation_dict(
        waterxml_tree=fixture["xml_tree1"], simulation_dict=simulation)

    q_dates, q_values, q_units = waterxml.get_timeseries_data(
        simulation_dict=simulation, timeseries_key="StudyUnitDischargeSeries")
    p_dates, p_values, p_units = waterxml.get_timeseries_data(
        simulation_dict=simulation,
        timeseries_key="ClimaticPrecipitationSeries")
    t_dates, t_values, t_units = waterxml.get_timeseries_data(
        simulation_dict=simulation, timeseries_key="ClimaticTemperatureSeries")

    waterxml.apply_factors(waterxml_tree=fixture["xml_tree1"],
                           element="StudyUnitDischargeSeries",
                           factors=fixture["factors"])
    waterxml.apply_factors(waterxml_tree=fixture["xml_tree1"],
                           element="ClimaticPrecipitationSeries",
                           factors=fixture["factors"])
    waterxml.apply_factors(waterxml_tree=fixture["xml_tree1"],
                           element="ClimaticTemperatureSeries",
                           factors=fixture["factors"])

    simulation_updated = waterxml.create_simulation_dict()

    simulation_updated = waterxml.fill_simulation_dict(
        waterxml_tree=fixture["xml_tree1"], simulation_dict=simulation_updated)

    actual = {}
    actual["q_dates"], actual["q_values"], actual[
        "q_units"] = waterxml.get_timeseries_data(
            simulation_dict=simulation_updated,
            timeseries_key="StudyUnitDischargeSeries")
    actual["p_dates"], actual["p_values"], actual[
        "p_units"] = waterxml.get_timeseries_data(
            simulation_dict=simulation_updated,
            timeseries_key="ClimaticPrecipitationSeries")
    actual["t_dates"], actual["t_values"], actual[
        "t_units"] = waterxml.get_timeseries_data(
            simulation_dict=simulation_updated,
            timeseries_key="ClimaticTemperatureSeries")

    nose.tools.assert_equals(len(expected["q_dates"]), len(actual["q_dates"]))
    nose.tools.assert_equals(len(expected["p_dates"]), len(actual["p_dates"]))
    nose.tools.assert_equals(len(expected["t_dates"]), len(actual["t_dates"]))

    np.testing.assert_equal(actual["q_dates"][0], expected["q_dates"][0])
    np.testing.assert_equal(actual["p_dates"][0], expected["p_dates"][0])
    np.testing.assert_equal(actual["t_dates"][0], expected["t_dates"][0])

    np.testing.assert_equal(actual["q_values"][0], expected["q_values"][0])
    np.testing.assert_equal(actual["p_values"][0], expected["p_values"][0])
    np.testing.assert_equal(actual["t_values"][0], expected["t_values"][0])

    np.testing.assert_equal(actual["q_units"][0], expected["q_units"][0])
    np.testing.assert_equal(actual["p_units"][0], expected["p_units"][0])
    np.testing.assert_equal(actual["t_units"][0], expected["t_units"][0])
Exemplo n.º 4
0
def test_get_timeseries_data_file2():

    expected = {
        "q_dates": [
            np.array([
                datetime.datetime(2014, 1, 1, 0, 0),
                datetime.datetime(2014, 1, 2, 0, 0)
            ]),
            np.array([
                datetime.datetime(2014, 1, 1, 0, 0),
                datetime.datetime(2014, 1, 2, 0, 0)
            ])
        ],
        "p_dates": [
            np.array([
                datetime.datetime(2014, 1, 1, 0, 0),
                datetime.datetime(2014, 1, 2, 0, 0)
            ]),
            np.array([
                datetime.datetime(2014, 1, 1, 0, 0),
                datetime.datetime(2014, 1, 2, 0, 0)
            ])
        ],
        "t_dates": [
            np.array([
                datetime.datetime(2014, 1, 1, 0, 0),
                datetime.datetime(2014, 1, 2, 0, 0)
            ]),
            np.array([
                datetime.datetime(2014, 1, 1, 0, 0),
                datetime.datetime(2014, 1, 2, 0, 0)
            ])
        ],
        "q_values": [np.array([100.0, 110.0]),
                     np.array([100.0, 110.0])],
        "p_values": [np.array([3, 4.5]),
                     np.array([3, 4.5])],
        "t_values": [np.array([11.1, 12.2]),
                     np.array([11.1, 12.2])],
        "q_units": ["mm per day", "mm per day"],
        "p_units": ["mm", "mm"],
        "t_units": ["Celsius", "Celsius"]
    }

    simulation = waterxml.create_simulation_dict()

    simulation = waterxml.fill_simulation_dict(
        waterxml_tree=fixture["xml_tree2"], simulation_dict=simulation)

    actual = {}
    actual["q_dates"], actual["q_values"], actual[
        "q_units"] = waterxml.get_timeseries_data(
            simulation_dict=simulation,
            timeseries_key="StudyUnitDischargeSeries")
    actual["p_dates"], actual["p_values"], actual[
        "p_units"] = waterxml.get_timeseries_data(
            simulation_dict=simulation,
            timeseries_key="ClimaticPrecipitationSeries")
    actual["t_dates"], actual["t_values"], actual[
        "t_units"] = waterxml.get_timeseries_data(
            simulation_dict=simulation,
            timeseries_key="ClimaticTemperatureSeries")

    nose.tools.assert_equals(len(expected["q_dates"]), len(actual["q_dates"]))
    nose.tools.assert_equals(len(expected["p_dates"]), len(actual["p_dates"]))
    nose.tools.assert_equals(len(expected["t_dates"]), len(actual["t_dates"]))

    np.testing.assert_equal(actual["q_dates"][0], expected["q_dates"][0])
    np.testing.assert_equal(actual["p_dates"][0], expected["p_dates"][0])
    np.testing.assert_equal(actual["t_dates"][0], expected["t_dates"][0])

    np.testing.assert_equal(actual["q_values"][0], expected["q_values"][0])
    np.testing.assert_equal(actual["p_values"][0], expected["p_values"][0])
    np.testing.assert_equal(actual["t_values"][0], expected["t_values"][0])

    np.testing.assert_equal(actual["q_units"][0], expected["q_units"][0])
    np.testing.assert_equal(actual["p_units"][0], expected["p_units"][0])
    np.testing.assert_equal(actual["t_units"][0], expected["t_units"][0])

    np.testing.assert_equal(actual["q_dates"][1], expected["q_dates"][1])
    np.testing.assert_equal(actual["p_dates"][1], expected["p_dates"][1])
    np.testing.assert_equal(actual["t_dates"][1], expected["t_dates"][1])

    np.testing.assert_equal(actual["q_values"][1], expected["q_values"][1])
    np.testing.assert_equal(actual["p_values"][1], expected["p_values"][1])
    np.testing.assert_equal(actual["t_values"][1], expected["t_values"][1])

    np.testing.assert_equal(actual["q_units"][1], expected["q_units"][1])
    np.testing.assert_equal(actual["p_units"][1], expected["p_units"][1])
    np.testing.assert_equal(actual["t_units"][1], expected["t_units"][1])