Beispiel #1
0
    def test_is_supy_running_multi_grid_par(self):
        df_state_init, df_forcing_tstep = sp.load_SampleData()
        df_state_init = pd.concat([df_state_init for x in range(6)])
        df_forcing_part = df_forcing_tstep.iloc[:]
        t_start = time()
        df_output, df_state = sp.run_supy(
            df_forcing_part, df_state_init)
        t_end = time()

        # only print to screen on macOS due incompatibility on Windows
        if platform.system() == 'Darwin':
            capturedOutput = io.StringIO()  # Create StringIO object
            sys.stdout = capturedOutput  # and redirect stdout.
            # Call function.
            n_grid = df_state_init.index.size
            print(f'Running time: {t_end-t_start:.2f} s for {n_grid} grids')
            sys.stdout = sys.__stdout__                     # Reset redirect.
            # Now works as before.
            print('Captured:\n', capturedOutput.getvalue())

        test_non_empty = np.all(
            [
                not df_output.empty,
                not df_state.empty,
            ]
        )
        self.assertTrue(test_non_empty)
Beispiel #2
0
    def test_is_supy_save_working(self):
        df_state_init, df_forcing_tstep = sp.load_SampleData()
        # df_state_init = pd.concat([df_state_init for x in range(6)])
        df_forcing_part = df_forcing_tstep.iloc[:288*2]
        t_start = time()
        df_output, df_state = sp.run_supy(
            df_forcing_part, df_state_init)
        t_end = time()
        with tempfile.TemporaryDirectory() as dir_temp:
            list_outfile = sp.save_supy(
                df_output, df_state, path_dir_save=dir_temp)

        # only print to screen on macOS due incompatibility on Windows
        if platform.system() == 'Darwin':
            capturedOutput = io.StringIO()  # Create StringIO object
            sys.stdout = capturedOutput  # and redirect stdout.
            # Call function.
            n_grid = df_state_init.index.size
            print(f'Running time: {t_end-t_start:.2f} s for {n_grid} grids')
            sys.stdout = sys.__stdout__                     # Reset redirect.
            # Now works as before.
            print('Captured:\n', capturedOutput.getvalue())

        test_non_empty = np.all(
            [isinstance(fn, Path) for fn in list_outfile]
        )
        self.assertTrue(test_non_empty)
Beispiel #3
0
 def test_is_supy_running_single_step(self):
     df_state_init, df_forcing_tstep = sp.load_SampleData()
     df_forcing_part = df_forcing_tstep.iloc[: 288 * 1]
     df_output, df_state = sp.run_supy(
         df_forcing_part, df_state_init, save_state=True
     )
     test_non_empty = np.all([not df_output.empty, not df_state.empty,])
     self.assertTrue(test_non_empty)
Beispiel #4
0
    def test_is_supy_running_multi_step(self):
        df_state_init, df_forcing_tstep = sp.load_SampleData()
        df_forcing_part = df_forcing_tstep.iloc[:]
        df_output, df_state = sp.run_supy(
            df_forcing_part, df_state_init, check_input=True
        )

        # # only print to screen on macOS due incompatibility on Windows
        # if platform.system() == "Darwin":
        #     # capturedOutput = io.StringIO()  # Create StringIO object
        #     # sys.stdout = capturedOutput  # and redirect stdout.
        #     # Call function.
        #     print(f"Running time: {t_end-t_start:.2f} s")
        #     # sys.stdout = sys.__stdout__  # Reset redirect.
        #     # Now works as before.
        #     # print("Captured:\n", capturedOutput.getvalue())

        test_non_empty = np.all([not df_output.empty, not df_state.empty,])
        self.assertTrue(test_non_empty)
Beispiel #5
0
import os
try:
    os.chdir(os.path.join(os.getcwd(), 'docs/source/data-structure'))
    print(os.getcwd())
except:
    pass
#%% [markdown]
# # Key IO Data Structures in SuPy
#%% [markdown]
# ## Introduction
#%% [markdown]
# The Cell below demonstrates a minimal case of SuPy simulation with all key IO data structures included:

#%%
import supy as sp
df_state_init, df_forcing = sp.load_SampleData()
df_output, df_state_final = sp.run_supy(df_forcing.iloc[:288], df_state_init)

#%% [markdown]
# * Input:
#	* `df_state_init`: model initial states
#	* `df_forcing`: forcing data
# * Output:
#   * `df_state_final`: model final states
#	* `df_output`: model output results

#%% [markdown]
# ## Input
#%% [markdown]
# ### `df_state_init`: model initial states