Loading src/pythermogis/doublet_simulation/deterministic_doublet.py +6 −2 Original line number Diff line number Diff line Loading @@ -6,8 +6,12 @@ import xarray as xr from pythermogis import simulate_doublet from pythermogis.dask_utils.auto_chunk import auto_chunk_dataset from pythermogis.physics.temperature_grid_calculation import calculate_temperature_from_gradient from pythermogis.thermogis_classes.utc_properties import instantiate_utc_properties_builder from pythermogis.physics.temperature_grid_calculation import ( calculate_temperature_from_gradient, ) from pythermogis.thermogis_classes.utc_properties import ( instantiate_utc_properties_builder, ) def calculate_doublet_performance(reservoir_properties: xr.Dataset, utc_properties = None, rng_seed: int = None, chunk_size: int = None, print_execution_duration: bool = False, mask_value: float = np.nan) -> xr.Dataset: Loading src/pythermogis/thermogis_classes/doublet.py +9 −14 Original line number Diff line number Diff line Loading @@ -119,13 +119,13 @@ def calculate_performance_of_single_location(mask: float, depth: float, thicknes ) # The Java routine which calculates DoubletPerformance, for more detail on the simulation inspect the Java source code try: results = doublet.calculateDoubletPerformance(input) # If calculation was not successful, return mask value if results is None: except: return (mask_value,) * 14 if results.utc() == -9999.0: # If calculation was not successful, return mask value if results is None or results.utc() == -9999.0: return (mask_value,) * 14 # calculate net-present-value using the utc-cutoffs Loading Loading @@ -167,15 +167,10 @@ def validate_input(depth: float, transmissivity: float, transmissivity_with_ntg: float, ) -> bool: if np.any(np.isnan([depth, ntg, porosity, temperature, thickness, transmissivity, transmissivity_with_ntg])): return False return True """ Check that none of the input is nan """ return not np.any(np.isnan([depth, ntg, porosity, temperature, thickness, transmissivity, transmissivity_with_ntg])) def instantiate_thermogis_doublet(utc_properties, rng_seed: int = None) -> JClass: """ Loading tests/documentation/test_define_calculation_limits.py 0 → 100644 +50 −0 Original line number Diff line number Diff line from pathlib import Path import numpy as np import xarray as xr from pythermogis import calculate_doublet_performance import pytest test_files_path = Path(__file__).parent.parent / "resources" def print_min_max(variable: xr.DataArray): print(f"{variable.name}, {np.min(variable):.2f}, {np.max(variable):.2f}") @pytest.mark.skip("Useful for understanding the range of possible input values, not for pipeline testing") def test_define_calculation_limits(): recalculate_results = False if recalculate_results: # generate simulation samples across desired reservoir properties Nsamples = 1000 thickness_samples = np.random.uniform(low=1, high=10e3, size=Nsamples) porosity_samples = np.random.uniform(low=0.01, high=0.99, size=Nsamples) ntg_samples = np.random.uniform(low=0.01, high=0.99, size=Nsamples) depth_samples = np.random.uniform(low=1, high=10e3, size=Nsamples) permeability_samples = np.random.uniform(low=1, high=10e3, size=Nsamples) reservoir_properties = xr.Dataset( { "thickness": (["sample"], thickness_samples), "porosity": (["sample"], porosity_samples), "ntg": (["sample"], ntg_samples), "depth": (["sample"], depth_samples), "permeability": (["sample"], permeability_samples), }, coords={"sample": np.arange(Nsamples)}, ) results = calculate_doublet_performance( reservoir_properties, chunk_size=100, print_execution_duration=True ) results.to_netcdf(test_files_path / "calculation_limits_result.nc") else: results = xr.load_dataset(test_files_path / "calculation_limits_result.nc") # drop the values which returned nan: results = results.dropna(dim="sample", subset=["power"]) # print the min and max values of all the inputs for var in ["thickness", "porosity", "ntg", "depth", "permeability", "temperature"]: print_min_max(results[var]) No newline at end of file tests/test_doc_examples.py→tests/documentation/test_doc_examples.py +6 −7 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ def test_example_5(): from matplotlib import pyplot as plt from pathlib import Path from os import path output_data_path = Path(path.dirname(__file__), "resources") / "test_output" / "example_data" output_data_path = Path(__file__).parent.parent / "resources" / "test_output" / "example_data" output_data_path.mkdir(parents=True, exist_ok=True) input_data = xr.Dataset({ Loading Loading @@ -108,10 +108,10 @@ def test_example_6(): from os import path # the location of the input data: the data can be found in the resources/example_data directory of the repo input_data_path = Path(path.dirname(__file__), "resources") / "test_input" / "example_data" input_data_path = Path(__file__).parent.parent / "resources" / "test_input" / "example_data" # create a directory to write the output files to output_data_path = Path(path.dirname(__file__), "resources") / "test_output" / "example_data" output_data_path = Path(__file__).parent.parent / "resources" / "test_output" / "example_data" output_data_path.mkdir(parents=True, exist_ok=True) # if set to True then simulation is always run, otherwise pre-calculated results are read (if available) Loading Loading @@ -176,10 +176,9 @@ def test_example_7(): import numpy as np import xarray as xr from pathlib import Path from os import path input_data_path = Path(path.dirname(__file__), "resources") / "test_input" / "example_data" output_data_path = Path(path.dirname(__file__), "resources") / "test_output" / "example_data" input_data_path = Path(__file__).parent.parent / "resources" / "test_input" / "example_data" output_data_path = Path(__file__).parent.parent / "resources" / "test_output" / "example_data" output_data_path.mkdir(parents=True, exist_ok=True) # read in reservoir property maps Loading Loading @@ -276,7 +275,7 @@ def test_example8(): # output directory to write output to output_data_path = Path(path.dirname(__file__), "resources") / "test_output" / "exceedance_example" output_data_path = Path(__file__).parent.parent / "resources" / "test_output" / "exceedance_example" output_data_path.mkdir(parents=True, exist_ok=True) # generate simulation samples across desired reservoir properties Loading tests/test_mkdown_utctable.py→tests/documentation/test_mkdown_utctable.py +10 −11 Original line number Diff line number Diff line from os import path from pythermogis import * # Create the Markdown table scenarios_file_path = Path(path.dirname(__file__), "resources") / "test_input" / "scenarios" scenarios_file_path = Path(__file__).parent.parent / "resources" / "test_input" / "scenarios" def test_markdown_table(): # create correspondence table with xml names scenario_files = { "TG basecase": path.join(scenarios_file_path, "doublet_techno-econ_basecase.xml") "TG basecase": scenarios_file_path / "doublet_techno-econ_basecase.xml" } scenarios_data = {name: xml_to_dict(file) for name, file in scenario_files.items()} comparison_table = create_comparison_table(scenarios_data, skipparametername=False) Loading @@ -17,10 +16,10 @@ def test_markdown_table(): def test_markdown_table_TG(): scenario_files = { "TG basecase": path.join(scenarios_file_path , "doublet_techno-econ_basecase.xml"), "TG HP": path.join(scenarios_file_path ,"doublet_techno-econ_HP.xml"), "TG STIM": path.join(scenarios_file_path , "doublet_techno-econ_STIM.xml"), "TG STIM HP": path.join(scenarios_file_path , "doublet_techno-econ_STIM_HP.xml"), "TG basecase": scenarios_file_path / "doublet_techno-econ_basecase.xml", "TG HP": scenarios_file_path / "doublet_techno-econ_HP.xml", "TG STIM": scenarios_file_path / "doublet_techno-econ_STIM.xml", "TG STIM HP": scenarios_file_path / "doublet_techno-econ_STIM_HP.xml", } scenarios_data = {name: xml_to_dict(file) for name, file in scenario_files.items()} # Create the comparison table Loading @@ -32,10 +31,10 @@ def test_markdown_table_TG(): def test_markdown_table_GA4A(): scenario_files = { "Direct Heat": path.join(scenarios_file_path, "ga4a_directheat_new_config.xml"), "Direct Heat HP": path.join(scenarios_file_path, "ga4a_directheatHP_new_config.xml"), "Chill": path.join(scenarios_file_path, "ga4a_chiller_new_config.xml"), "ORC": path.join(scenarios_file_path, "ga4a_ORC_new_config.xml") "Direct Heat": scenarios_file_path / "ga4a_directheat_new_config.xml", "Direct Heat HP": scenarios_file_path / "ga4a_directheatHP_new_config.xml", "Chill": scenarios_file_path / "ga4a_chiller_new_config.xml", "ORC": scenarios_file_path / "ga4a_ORC_new_config.xml" } scenarios_data = {name: xml_to_dict(file) for name, file in scenario_files.items()}; # Create the comparison table Loading Loading
src/pythermogis/doublet_simulation/deterministic_doublet.py +6 −2 Original line number Diff line number Diff line Loading @@ -6,8 +6,12 @@ import xarray as xr from pythermogis import simulate_doublet from pythermogis.dask_utils.auto_chunk import auto_chunk_dataset from pythermogis.physics.temperature_grid_calculation import calculate_temperature_from_gradient from pythermogis.thermogis_classes.utc_properties import instantiate_utc_properties_builder from pythermogis.physics.temperature_grid_calculation import ( calculate_temperature_from_gradient, ) from pythermogis.thermogis_classes.utc_properties import ( instantiate_utc_properties_builder, ) def calculate_doublet_performance(reservoir_properties: xr.Dataset, utc_properties = None, rng_seed: int = None, chunk_size: int = None, print_execution_duration: bool = False, mask_value: float = np.nan) -> xr.Dataset: Loading
src/pythermogis/thermogis_classes/doublet.py +9 −14 Original line number Diff line number Diff line Loading @@ -119,13 +119,13 @@ def calculate_performance_of_single_location(mask: float, depth: float, thicknes ) # The Java routine which calculates DoubletPerformance, for more detail on the simulation inspect the Java source code try: results = doublet.calculateDoubletPerformance(input) # If calculation was not successful, return mask value if results is None: except: return (mask_value,) * 14 if results.utc() == -9999.0: # If calculation was not successful, return mask value if results is None or results.utc() == -9999.0: return (mask_value,) * 14 # calculate net-present-value using the utc-cutoffs Loading Loading @@ -167,15 +167,10 @@ def validate_input(depth: float, transmissivity: float, transmissivity_with_ntg: float, ) -> bool: if np.any(np.isnan([depth, ntg, porosity, temperature, thickness, transmissivity, transmissivity_with_ntg])): return False return True """ Check that none of the input is nan """ return not np.any(np.isnan([depth, ntg, porosity, temperature, thickness, transmissivity, transmissivity_with_ntg])) def instantiate_thermogis_doublet(utc_properties, rng_seed: int = None) -> JClass: """ Loading
tests/documentation/test_define_calculation_limits.py 0 → 100644 +50 −0 Original line number Diff line number Diff line from pathlib import Path import numpy as np import xarray as xr from pythermogis import calculate_doublet_performance import pytest test_files_path = Path(__file__).parent.parent / "resources" def print_min_max(variable: xr.DataArray): print(f"{variable.name}, {np.min(variable):.2f}, {np.max(variable):.2f}") @pytest.mark.skip("Useful for understanding the range of possible input values, not for pipeline testing") def test_define_calculation_limits(): recalculate_results = False if recalculate_results: # generate simulation samples across desired reservoir properties Nsamples = 1000 thickness_samples = np.random.uniform(low=1, high=10e3, size=Nsamples) porosity_samples = np.random.uniform(low=0.01, high=0.99, size=Nsamples) ntg_samples = np.random.uniform(low=0.01, high=0.99, size=Nsamples) depth_samples = np.random.uniform(low=1, high=10e3, size=Nsamples) permeability_samples = np.random.uniform(low=1, high=10e3, size=Nsamples) reservoir_properties = xr.Dataset( { "thickness": (["sample"], thickness_samples), "porosity": (["sample"], porosity_samples), "ntg": (["sample"], ntg_samples), "depth": (["sample"], depth_samples), "permeability": (["sample"], permeability_samples), }, coords={"sample": np.arange(Nsamples)}, ) results = calculate_doublet_performance( reservoir_properties, chunk_size=100, print_execution_duration=True ) results.to_netcdf(test_files_path / "calculation_limits_result.nc") else: results = xr.load_dataset(test_files_path / "calculation_limits_result.nc") # drop the values which returned nan: results = results.dropna(dim="sample", subset=["power"]) # print the min and max values of all the inputs for var in ["thickness", "porosity", "ntg", "depth", "permeability", "temperature"]: print_min_max(results[var]) No newline at end of file
tests/test_doc_examples.py→tests/documentation/test_doc_examples.py +6 −7 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ def test_example_5(): from matplotlib import pyplot as plt from pathlib import Path from os import path output_data_path = Path(path.dirname(__file__), "resources") / "test_output" / "example_data" output_data_path = Path(__file__).parent.parent / "resources" / "test_output" / "example_data" output_data_path.mkdir(parents=True, exist_ok=True) input_data = xr.Dataset({ Loading Loading @@ -108,10 +108,10 @@ def test_example_6(): from os import path # the location of the input data: the data can be found in the resources/example_data directory of the repo input_data_path = Path(path.dirname(__file__), "resources") / "test_input" / "example_data" input_data_path = Path(__file__).parent.parent / "resources" / "test_input" / "example_data" # create a directory to write the output files to output_data_path = Path(path.dirname(__file__), "resources") / "test_output" / "example_data" output_data_path = Path(__file__).parent.parent / "resources" / "test_output" / "example_data" output_data_path.mkdir(parents=True, exist_ok=True) # if set to True then simulation is always run, otherwise pre-calculated results are read (if available) Loading Loading @@ -176,10 +176,9 @@ def test_example_7(): import numpy as np import xarray as xr from pathlib import Path from os import path input_data_path = Path(path.dirname(__file__), "resources") / "test_input" / "example_data" output_data_path = Path(path.dirname(__file__), "resources") / "test_output" / "example_data" input_data_path = Path(__file__).parent.parent / "resources" / "test_input" / "example_data" output_data_path = Path(__file__).parent.parent / "resources" / "test_output" / "example_data" output_data_path.mkdir(parents=True, exist_ok=True) # read in reservoir property maps Loading Loading @@ -276,7 +275,7 @@ def test_example8(): # output directory to write output to output_data_path = Path(path.dirname(__file__), "resources") / "test_output" / "exceedance_example" output_data_path = Path(__file__).parent.parent / "resources" / "test_output" / "exceedance_example" output_data_path.mkdir(parents=True, exist_ok=True) # generate simulation samples across desired reservoir properties Loading
tests/test_mkdown_utctable.py→tests/documentation/test_mkdown_utctable.py +10 −11 Original line number Diff line number Diff line from os import path from pythermogis import * # Create the Markdown table scenarios_file_path = Path(path.dirname(__file__), "resources") / "test_input" / "scenarios" scenarios_file_path = Path(__file__).parent.parent / "resources" / "test_input" / "scenarios" def test_markdown_table(): # create correspondence table with xml names scenario_files = { "TG basecase": path.join(scenarios_file_path, "doublet_techno-econ_basecase.xml") "TG basecase": scenarios_file_path / "doublet_techno-econ_basecase.xml" } scenarios_data = {name: xml_to_dict(file) for name, file in scenario_files.items()} comparison_table = create_comparison_table(scenarios_data, skipparametername=False) Loading @@ -17,10 +16,10 @@ def test_markdown_table(): def test_markdown_table_TG(): scenario_files = { "TG basecase": path.join(scenarios_file_path , "doublet_techno-econ_basecase.xml"), "TG HP": path.join(scenarios_file_path ,"doublet_techno-econ_HP.xml"), "TG STIM": path.join(scenarios_file_path , "doublet_techno-econ_STIM.xml"), "TG STIM HP": path.join(scenarios_file_path , "doublet_techno-econ_STIM_HP.xml"), "TG basecase": scenarios_file_path / "doublet_techno-econ_basecase.xml", "TG HP": scenarios_file_path / "doublet_techno-econ_HP.xml", "TG STIM": scenarios_file_path / "doublet_techno-econ_STIM.xml", "TG STIM HP": scenarios_file_path / "doublet_techno-econ_STIM_HP.xml", } scenarios_data = {name: xml_to_dict(file) for name, file in scenario_files.items()} # Create the comparison table Loading @@ -32,10 +31,10 @@ def test_markdown_table_TG(): def test_markdown_table_GA4A(): scenario_files = { "Direct Heat": path.join(scenarios_file_path, "ga4a_directheat_new_config.xml"), "Direct Heat HP": path.join(scenarios_file_path, "ga4a_directheatHP_new_config.xml"), "Chill": path.join(scenarios_file_path, "ga4a_chiller_new_config.xml"), "ORC": path.join(scenarios_file_path, "ga4a_ORC_new_config.xml") "Direct Heat": scenarios_file_path / "ga4a_directheat_new_config.xml", "Direct Heat HP": scenarios_file_path / "ga4a_directheatHP_new_config.xml", "Chill": scenarios_file_path / "ga4a_chiller_new_config.xml", "ORC": scenarios_file_path / "ga4a_ORC_new_config.xml" } scenarios_data = {name: xml_to_dict(file) for name, file in scenario_files.items()}; # Create the comparison table Loading