예제 #1
0
def test_load_waterlvl_measures_withxls():
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements.csv")
    delete_file(filename)
    assert not os.path.exists(filename)

    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements.xlsx")
    with xlsxwriter.Workbook(filename) as wb:
        ws = wb.add_worksheet()
        for i, line in enumerate(WLMEAS):
            ws.write_row(i, 0, line)

    # Test init_waterlvl_measures to be sure the file is not overriden.
    init_waterlvl_measures(os.getcwd())

    # Assert that it loads the right data.
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements")
    time, wl = load_waterlvl_measures(filename, 'Dummy')
    assert len(time) == 0 and isinstance(time, np.ndarray)
    assert len(wl) == 0 and isinstance(wl, np.ndarray)

    time, wl = load_waterlvl_measures(filename, 'Test')
    assert np.all(time == np.array([40623.54167, 40842.54167, 41065.54167]))
    assert np.all(wl == np.array([1.43, 1.6, 1.57]))

    time, wl = load_waterlvl_measures(filename, "é@#^'")
    assert np.all(time == np.array([41240.8125]))
    assert np.all(wl == np.array([3.75]))
예제 #2
0
def test_load_waterlvl_measures_withxls():
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements.csv")
    delete_file(filename)
    assert not os.path.exists(filename)

    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements.xlsx")
    with xlsxwriter.Workbook(filename) as wb:
        ws = wb.add_worksheet()
        for i, line in enumerate(WLMEAS):
            ws.write_row(i, 0, line)

    # Test init_waterlvl_measures to be sure the file is not overriden.
    init_waterlvl_measures(os.getcwd())

    # Assert that it loads the right data.
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements")
    time, wl = load_waterlvl_measures(filename, 'Dummy')
    assert len(time) == 0 and isinstance(time, np.ndarray)
    assert len(wl) == 0 and isinstance(wl, np.ndarray)

    time, wl = load_waterlvl_measures(filename, 'Test')
    assert np.all(time == np.array([40623.54167, 40842.54167, 41065.54167]))
    assert np.all(wl == np.array([1.43, 1.6, 1.57]))

    time, wl = load_waterlvl_measures(filename, "é@#^'")
    assert np.all(time == np.array([41240.8125]))
    assert np.all(wl == np.array([3.75]))
예제 #3
0
    def wldset_changed(self):
        """Handle when the water level dataset of the datamanager changes."""
        if self.wldset is None:
            self.clear_hydrograph()
            return
        else:
            wldset = self.wldset
            self.hydrograph.set_wldset(wldset)
            self.hydrograph.gluedf = self.wldset.get_glue_at(-1)

        # Load the manual measurements.

        fname = os.path.join(self.workdir, "Water Levels",
                             'waterlvl_manual_measurements')
        tmeas, wlmeas = load_waterlvl_measures(fname, wldset['Well'])
        wldset.set_wlmeas(tmeas, wlmeas)

        # Setup the layout of the hydrograph.

        layout = wldset.get_layout()
        if layout is not None:
            msg = 'Loading existing graph layout for well %s.' % wldset['Well']
            print(msg)
            self.ConsoleSignal.emit('<font color=black>%s</font>' % msg)
            self.load_graph_layout(layout)
        else:
            print('No graph layout exists for well %s.' % wldset['Well'])
            # Fit Water Level in Layout :
            self.__updateUI = False
            self.best_fit_waterlvl()
            self.best_fit_time()
            self.dmngr.set_closest_wxdset()
            self.__updateUI = True
예제 #4
0
    def wldset_changed(self):
        """Handle when the water level dataset of the datamanager changes."""
        if self.wldset is None:
            self.clear_hydrograph()
            return
        else:
            self.hydrograph.set_wldset(self.wldset)
            self.hydrograph.gluedf = self.wldset.get_glue_at(-1)

        # Load the manual measurements.

        fname = os.path.join(
            self.workdir, "Water Levels", 'waterlvl_manual_measurements')
        tmeas, wlmeas = load_waterlvl_measures(fname, self.wldset['Well'])
        self.wldset.set_wlmeas(tmeas, wlmeas)

        # Setup the layout of the hydrograph.

        layout = self.wldset.get_layout()
        if layout is not None:
            msg = ("Loading existing graph layout for well %s." %
                   self.wldset['Well'])
            print(msg)
            self.ConsoleSignal.emit('<font color=black>%s</font>' % msg)
            self.load_graph_layout(layout)
        else:
            print('No graph layout exists for well %s.' % self.wldset['Well'])
            # Fit Water Level in Layout :
            self.__updateUI = False
            self.best_fit_waterlvl()
            self.best_fit_time()
            if self.dmngr.set_closest_wxdset() is None:
                self.draw_hydrograph()
            self.__updateUI = True
예제 #5
0
def test_load_waterlvl_measures_withcsv():
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements.csv")
    save_content_to_csv(filename, WLMEAS)

    # Test init_waterlvl_measures to be sure the file is not overriden.
    init_waterlvl_measures(os.getcwd())

    # Assert that it loads the right data.
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements")
    time, wl = load_waterlvl_measures(filename, 'Dummy')
    assert len(time) == 0 and isinstance(time, np.ndarray)
    assert len(wl) == 0 and isinstance(wl, np.ndarray)

    time, wl = load_waterlvl_measures(filename, 'Test')
    assert np.all(time == np.array([40623.54167, 40842.54167, 41065.54167]))
    assert np.all(wl == np.array([1.43, 1.6, 1.57]))

    time, wl = load_waterlvl_measures(filename, "é@#^'")
    assert np.all(time == np.array([41240.8125]))
    assert np.all(wl == np.array([3.75]))
예제 #6
0
def test_load_waterlvl_measures_withcsv():
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements.csv")
    save_content_to_csv(filename, WLMEAS)

    # Test init_waterlvl_measures to be sure the file is not overriden.
    init_waterlvl_measures(os.getcwd())

    # Assert that it loads the right data.
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements")
    time, wl = load_waterlvl_measures(filename, 'Dummy')
    assert len(time) == 0 and isinstance(time, np.ndarray)
    assert len(wl) == 0 and isinstance(wl, np.ndarray)

    time, wl = load_waterlvl_measures(filename, 'Test')
    assert np.all(time == np.array([40623.54167, 40842.54167, 41065.54167]))
    assert np.all(wl == np.array([1.43, 1.6, 1.57]))

    time, wl = load_waterlvl_measures(filename, "é@#^'")
    assert np.all(time == np.array([41240.8125]))
    assert np.all(wl == np.array([3.75]))
예제 #7
0
def test_init_waterlvl_measures():
    # Assert that the water_level_measurement file is initialized correctly.
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements")
    assert not os.path.exists(filename+'.csv')
    time, wl = load_waterlvl_measures(filename, 'Test')
    assert os.path.exists(filename+'.csv')
    assert len(time) == 0 and isinstance(time, np.ndarray)
    assert len(wl) == 0 and isinstance(wl, np.ndarray)

    # Assert that the format of the file is correct.
    expected_result = ['Well_ID', 'Time (days)', 'Obs. (mbgs)']
    with open(filename+'.csv', 'r') as f:
        reader = list(csv.reader(f, delimiter=','))
    assert len(reader) == 1
    assert reader[0] == expected_result
예제 #8
0
def test_init_waterlvl_measures():
    # Assert that the water_level_measurement file is initialized correctly.
    filename = os.path.join(os.getcwd(), "waterlvl_manual_measurements")
    assert not os.path.exists(filename + '.csv')
    time, wl = load_waterlvl_measures(filename, 'Test')
    assert os.path.exists(filename + '.csv')
    assert len(time) == 0 and isinstance(time, np.ndarray)
    assert len(wl) == 0 and isinstance(wl, np.ndarray)

    # Assert that the format of the file is correct.
    expected_result = ['Well_ID', 'Time (days)', 'Obs. (mbgs)']
    with open(filename + '.csv', 'r') as f:
        reader = list(csv.reader(f, delimiter=','))
    assert len(reader) == 1
    assert reader[0] == expected_result