Example #1
0
def test_write_file():
    """ Test write_file functionality """

    # create water use totals
    wateruse_totals = {
        'January': 2.0,
        'February': 2.0,
        'March': 2.0,
        'April': 3.0,
        'May': 3.0,
        'June': 0.0,
        'July': 4.0,
        'August': 4.0,
        'September': 4.0,
        'October': 5.0,
        'November': 5.0,
        'December': 5.0
    }  


    # write water formatted file   
    data = fixture["sample_data_dict"]
    watertxt.write_file(watertxt_data = data, save_path = os.path.join(os.getcwd(), "tests"))

    # write water formatted file with new values set in discharge
    data = fixture["sample_data_dict"]
    new_discharge_data = np.array([230, 240, 280])
    data = watertxt.set_parameter_values(watertxt_data = data, name = "Discharge", values = new_discharge_data)
    watertxt.write_file(watertxt_data = data , save_path = os.path.join(os.getcwd(), "tests"), filename = "_WATER-with-new-discharge.txt")
    
    # apply water use
    data = fixture["sample_data_dict"]
    data = watertxt.apply_wateruse(watertxt_data = data, wateruse_totals = wateruse_totals)     
    watertxt.write_file(watertxt_data = data , save_path = os.path.join(os.getcwd(), "tests"), filename = "_WATER-with-wateruse.txt") 
Example #2
0
def test_write_timeseries_file_stationid():
    """ Test write_timeseries_file_wisconsin functionality part 3 - Discharge + Water Use; water use is applied """

    # create water use totals
    wateruse_totals = {
        'January': 2.0,
        'February': 2.0,
        'March': 2.0,
        'April': 3.0,
        'May': 3.0,
        'June': 0.0,
        'July': 4.0,
        'August': 4.0,
        'September': 4.0,
        'October': 5.0,
        'November': 5.0,
        'December': 5.0
    }  
      
    # create test data
    data = fixture["sample_data_dict"]
    
    # apply water use
    data = watertxt.apply_wateruse(watertxt_data = data, wateruse_totals = wateruse_totals)     
    
    # write file
    watertxt.write_timeseries_file_stationid(watertxt_data = data, name = "Discharge + Water Use", save_path = os.path.join(os.getcwd(), "tests"), filename = "", stationid = data["stationid"])  
Example #3
0
def test_apply_wateruse():
    """ Test apply_wateruse() functionality """

    # create water use totals
    wateruse_totals = {
        'January': 2.0,
        'February': 2.0,
        'March': 2.0,
        'April': 3.0,
        'May': 3.0,
        'June': 3.0,
        'July': 4.0,
        'August': 4.0,
        'September': 4.0,
        'October': -5.0,
        'November': -5.0,
        'December': -5.0
    }  

    wateruse_totals_data = np.array([2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -5.0, -5.0, -5.0])

    discharge_and_wateruse_data = np.array([5.0, 8.0, 12.0, 15.0, 18.0, 19.0, 22.0, 19.0, 15.0, 2.0, 0.0, -3.0])

    # expected values to test with actual values
    expected_wateruse_totals = {"name": "Water Use (cfs)", "index": 2, "data": wateruse_totals_data, "mean": np.mean(wateruse_totals_data), "max": np.max(wateruse_totals_data), "min": np.min(wateruse_totals_data)}    
    expected_discharge_and_wateruse = {"name": "Discharge + Water Use (cfs)", "index": 3, "data": discharge_and_wateruse_data, "mean": np.mean(discharge_and_wateruse_data), "max": np.max(discharge_and_wateruse_data), "min": np.min(discharge_and_wateruse_data)}

    # apply water use
    data = watertxt.apply_wateruse(watertxt_data = fixture["sample_data_dict_all_months"], wateruse_totals = wateruse_totals) 
    
    # actual values
    actual_wateruse_totals = watertxt.get_parameter(watertxt_data = data, name = "Water Use")
    actual_discharge_and_wateruse = watertxt.get_parameter(watertxt_data = data, name = "Discharge + Water Use") 

    # make assertions for wateruse_totals
    nose.tools.assert_almost_equals(actual_wateruse_totals["name"], expected_wateruse_totals["name"])
    nose.tools.assert_almost_equals(actual_wateruse_totals["index"], expected_wateruse_totals["index"])
    
    nose.tools.assert_almost_equals(actual_wateruse_totals["mean"], expected_wateruse_totals["mean"])          
    nose.tools.assert_almost_equals(actual_wateruse_totals["max"], expected_wateruse_totals["max"])
    nose.tools.assert_almost_equals(actual_wateruse_totals["min"], expected_wateruse_totals["min"])

    nose.tools.assert_almost_equals(actual_wateruse_totals["data"].all(), expected_wateruse_totals["data"].all())
    
    # make assertions for discharge and wateruse_totals
    nose.tools.assert_almost_equals(actual_discharge_and_wateruse["name"], expected_discharge_and_wateruse["name"])
    nose.tools.assert_almost_equals(actual_discharge_and_wateruse["index"], expected_discharge_and_wateruse["index"])
    
    nose.tools.assert_almost_equals(actual_discharge_and_wateruse["mean"], expected_discharge_and_wateruse["mean"])          
    nose.tools.assert_almost_equals(actual_discharge_and_wateruse["max"], expected_discharge_and_wateruse["max"])
    nose.tools.assert_almost_equals(actual_discharge_and_wateruse["min"], expected_discharge_and_wateruse["min"])

    nose.tools.assert_almost_equals(actual_discharge_and_wateruse["data"].all(), expected_discharge_and_wateruse["data"].all())