TNO Intern

Commit c59e6d53 authored by Hen Brett's avatar Hen Brett 🐔
Browse files

Testing the speed of the doublet calculations

parent 785b4096
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
import timeit
from os import path
from pathlib import Path
from unittest.case import TestCase
@@ -14,37 +15,35 @@ class PyThermoGIS(TestCase):
    test_files_out_path = Path(path.dirname(path.dirname(__file__)), "resources") / "test_output" / "SLDNA"

    def setUp(self):
        outpath = Path(self.test_files_out_path)
        if outpath.exists():
            shutil.rmtree(outpath)
        if self.test_files_out_path.exists():
            shutil.rmtree(self.test_files_out_path)
        shutil.copytree(self.test_files_path / "SLDNA", self.test_files_out_path)

    def tearDown(self):
        shutil.rmtree(self.test_files_out_path)

    def test_run_SLDNA(self):
        print("SLDNA")
        input_grids = self.read_input_grids()
        p_values = [10,50,90]

        data = input_grids["thickness_mean"].data.flatten()
        non_nan_data = data[~np.isnan(data)]
        print(f"Non Nan Values: {len(non_nan_data)}")
        print(f"Running Performance calculation for SLDNA, Pvalues: {p_values}, The number of Non Nan Cells: {len(non_nan_data)}")

        # Run calculation across all dimensions of input_grids, and all provided P_values: The Equivalent calculation with 10 cores takes 43 seconds in the Java code
        output_grids = calculate_doublet_performance(input_grids, input_params={"rng_seed": 123}, p_values=p_values)

        start = timeit.default_timer()
        calculate_doublet_performance(input_grids, input_params={"rng_seed": 123}, p_values=p_values)
        time_elapsed = timeit.default_timer() - start
        print(f"Python calculation took {time_elapsed:.1f} seconds. Java Calculation takes 40seconds (10 Cores)")


    def read_input_grids(self):
        input_grids = read_grid(self.test_files_out_path / "SLDNA__thick.nc").to_dataset(
            name="thickness_mean")
        input_grids = read_grid(self.test_files_out_path / "SLDNA__thick.nc").to_dataset(name="thickness_mean")
        input_grids["thickness_sd"] = read_grid(self.test_files_out_path / "SLDNA__thick_sd.nc")
        input_grids["ntg"] = read_grid(self.test_files_out_path / "SLDNA__ntg.nc")
        input_grids["porosity"] = read_grid(self.test_files_out_path / "SLDNA__phi.nc") / 100
        input_grids["depth"] = read_grid(self.test_files_out_path / "SLDNA__top.nc")
        input_grids["mask"] = read_grid(self.test_files_out_path / "SLDNA__hc_accum.nc")
        input_grids["ln_permeability_mean"] = np.log(
            read_grid(self.test_files_out_path / "SLDNA__k.nc"))
        input_grids["ln_permeability_mean"] = np.log(read_grid(self.test_files_out_path / "SLDNA__k.nc"))
        input_grids["ln_permeability_sd"] = read_grid(self.test_files_out_path / "SLDNA__k_ln_sd.nc")
        return input_grids
 No newline at end of file