TNO Intern

Commit 73990f08 authored by Hen Brett's avatar Hen Brett 🐔
Browse files

Cleaning up the module removing the docker implementation

parent 83af4df6
Loading
Loading
Loading
Loading
+0 −198
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<project ATES="false">
	<application_version>1.6.0</application_version>
	<application_name>ThermoGIS</application_name>
	<input_data_directory>/data/InputData</input_data_directory>
	<maps_prefix__can_be_empty_></maps_prefix__can_be_empty_>
	<results_directory>/data/Results</results_directory>
	<compare_results>0.0</compare_results>
	<comparison_directory></comparison_directory>
	<output_maps_for_petrel>0</output_maps_for_petrel>
	<max_number_of_processors_for_calculations>10</max_number_of_processors_for_calculations>
	<aquifer_list__comma_separated__excluding_stacked_aquifers_>test, </aquifer_list__comma_separated__excluding_stacked_aquifers_>
	<property_grids__in_input_data_directory__stacked_grids_will_be_created_>
		<row_1>Permeability;no;_perm.zmap</row_1>
		<row_2>PermeabilityLNSD;no;_ln_perm_sd.zmap</row_2>
		<row_3>Porosity;no;_poro.zmap</row_3>
		<row_4>Thickness;no;_thick.zmap</row_4>
		<row_5>ThicknessSD;no;_thick_sd.zmap</row_5>
		<row_6>Depth;no;_top.zmap</row_6>
		<row_7>NetToGross;no;_ntg.zmap</row_7>
		<row_8>Temperature;yes;__temperature.zmap</row_8>
		<row_9>HCAccum;yes;_hc_accum.zmap</row_9>
		<row_10>BoundaryShapefile;yes;__BoundaryShapefile.shp</row_10>
	</property_grids__in_input_data_directory__stacked_grids_will_be_created_>
	<calculate_stacked_aquifers>0</calculate_stacked_aquifers>
	<thickness_correlation_factor___1_to_1__0__no_corr_>0.0</thickness_correlation_factor___1_to_1__0__no_corr_>
	<permeability_correlation_factor___1_to_1__0__no_corr_>0.0</permeability_correlation_factor___1_to_1__0__no_corr_>
	<stacked_aquifers></stacked_aquifers>
	<copy_aquifer_files>0</copy_aquifer_files>
	<aquifer_files__in_input_data_directory_>
		<row_1>__ntg_points.shp;__ntg_points.shp</row_1>
		<row_2>__poro_points.shp;__poro_points.shp</row_2>
		<row_3>__perm_points.shp;__perm_points.shp</row_3>
	</aquifer_files__in_input_data_directory_>
	<output_scenario_name>BaseCase</output_scenario_name>
	<aquifers_to_calculate>test, </aquifers_to_calculate>
	<pvalues_to_calculate>50</pvalues_to_calculate>
	<xy_grid_size_factor_for_thickness_grid__integer_>1</xy_grid_size_factor_for_thickness_grid__integer_>
	<max_undefined_cells__of_surrounding_4__for_interp>3.0</max_undefined_cells__of_surrounding_4__for_interp>
	<scale_factor_for_h_and_lnk_standard_deviations>1.0</scale_factor_for_h_and_lnk_standard_deviations>
	<minimum_production_temperature>20.0</minimum_production_temperature>
	<heating_return_temperature>30.0</heating_return_temperature>
	<maximum_cooling_temperature_range>100.0</maximum_cooling_temperature_range>
	<exclude_hydrocarbon_areas>1.0</exclude_hydrocarbon_areas>
	<use_boundary_shapefile>0.0</use_boundary_shapefile>
	<validate_input_grids>0</validate_input_grids>
	<validate_output_grids>0</validate_output_grids>
	<optimize_well_distance>1.0</optimize_well_distance>
	<minimum_well_distance>100.0</minimum_well_distance>
	<maximum_well_distance>3000.0</maximum_well_distance>
	<lifetime>50.0</lifetime>
	<max_tvd_stepout_factor>1.0</max_tvd_stepout_factor>
	<rock_density>2700.0</rock_density>
	<rock_heat_capacity>1000.0</rock_heat_capacity>
	<allowed_temperature_drop_as_fraction_of_deltat>0.1</allowed_temperature_drop_as_fraction_of_deltat>
	<maximum_flow>500.0</maximum_flow>
	<well_distance>1500.0</well_distance>
	<hydraulic_gradient_injection_water__sodm_max_inj_pres_>0.105</hydraulic_gradient_injection_water__sodm_max_inj_pres_>
	<minimum_pump_pressure>1.0</minimum_pump_pressure>
	<maximum_pump_pressure>300.0</maximum_pump_pressure>
	<tolerance_of_utc_increase___bar_>0.0</tolerance_of_utc_increase___bar_>
	<temperature_from_input_grids>0.0</temperature_from_input_grids>
	<use_3d_temperature_voxet_model>1.0</use_3d_temperature_voxet_model>
	<temperature_voxet_file>/data/InputTemperatureModel/restart.vo</temperature_voxet_file>
	<temp_gradient__surface_temp__below__also_used_>31.0</temp_gradient__surface_temp__below__also_used_>
	<surface_temperature>10.0</surface_temperature>
	<kh_cutoff__speed_up_calculation_>1.0</kh_cutoff__speed_up_calculation_>
	<anistropy__kv_kh__for_doubletcalc1d>3.0</anistropy__kv_kh__for_doubletcalc1d>
	<salinity_at_surface__ppm_>0.0</salinity_at_surface__ppm_>
	<salinity_gradient__ppm_m_>46.67</salinity_gradient__ppm_m_>
	<pump_efficiency>0.6</pump_efficiency>
	<pump_depth>300.0</pump_depth>
	<calculation_segment_length>50.0</calculation_segment_length>
	<outer_diameter__open_aquifer_section_>8.5</outer_diameter__open_aquifer_section_>
	<inner_diameter__cased_surface_top_aquifer_section_>8.5</inner_diameter__cased_surface_top_aquifer_section_>
	<casing_roughness>1.38</casing_roughness>
	<well_trajectory_curvature_scaling_factor__0__vert_wells_>1.1</well_trajectory_curvature_scaling_factor__0__vert_wells_>
	<injector_skin>-1.0</injector_skin>
	<producer_skin>-1.0</producer_skin>
	<economic_lifetime>30.0</economic_lifetime>
	<drilling_time>2.0</drilling_time>
	<annual_load_hours>6000.0</annual_load_hours>
	<annual_opex_base>0.0</annual_opex_base>
	<annual_opex_per_unit_power>100.0</annual_opex_per_unit_power>
	<annual_opex_per_unit_energy_produced>0.19</annual_opex_per_unit_energy_produced>
	<annual_opex_based_on_capex>0.0</annual_opex_based_on_capex>
	<opex_electricity_purchase_price_for_operations>8.0</opex_electricity_purchase_price_for_operations>
	<well_costs_base>0.25</well_costs_base>
	<well_costs_depth__along_hole__factor>700.0</well_costs_depth__along_hole__factor>
	<well_costs_depth_2__along_hole__factor>0.2</well_costs_depth_2__along_hole__factor>
	<well_costs_scaling>1.3</well_costs_scaling>
	<capex_base_expenses__excl_wells_>3.0</capex_base_expenses__excl_wells_>
	<capex_variable_expenses__excl_wells_>300.0</capex_variable_expenses__excl_wells_>
	<capex_contingency>15.0</capex_contingency>
	<tax_rate>25.0</tax_rate>
	<interest_on_loan>5.0</interest_on_loan>
	<inflation>1.5</inflation>
	<required_return_on_equity>14.5</required_return_on_equity>
	<debt_equity>80.0</debt_equity>
	<use_orc>0.0</use_orc>
	<heat_conversion_efficiency>1.0</heat_conversion_efficiency>
	<parasitic_power_fraction_of_net_power>0.0</parasitic_power_fraction_of_net_power>
	<base_temperature>10.0</base_temperature>
	<use_kestin_viscosity>0.0</use_kestin_viscosity>
	<maximum_depth_for_calculations>6000.0</maximum_depth_for_calculations>
	<stimulate_well_s_>0.0</stimulate_well_s_>
	<added_skin_injector__negative_increases_flow_>-3.0</added_skin_injector__negative_increases_flow_>
	<added_skin_producer__negative_increases_flow_>-3.0</added_skin_producer__negative_increases_flow_>
	<maximum_kh_value_for_stimulation>20.0</maximum_kh_value_for_stimulation>
	<stimulation_capex__for_both_wells_>0.5</stimulation_capex__for_both_wells_>
	<use_heat_pump>0.0</use_heat_pump>
	<calculate_cop>1.0</calculate_cop>
	<_minimum__injection_temperature>20.0</_minimum__injection_temperature>
	<goal_temperature>70.0</goal_temperature>
	<coefficient_of_performance>4.0</coefficient_of_performance>
	<heat_pump_capex>200.0</heat_pump_capex>
	<heat_pump_annual_opex>10.0</heat_pump_annual_opex>
	<include__non_sde__electric_power_in_output>0.0</include__non_sde__electric_power_in_output>
	<alternative_heating_price>2.8</alternative_heating_price>
	<application_mode>0.0</application_mode>
	<rosim_settings_file__must_contain__aquifer__layer_></rosim_settings_file__must_contain__aquifer__layer_>
	<ates_aquifer_anisotropy>5.0</ates_aquifer_anisotropy>
	<thermal_radius_factor>2.0</thermal_radius_factor>
	<ates_charge_temperature>80.0</ates_charge_temperature>
	<ates_injection_production_period__max_182_days_>120.0</ates_injection_production_period__max_182_days_>
	<rosim_simulation_time__constant_power_after_>5.0</rosim_simulation_time__constant_power_after_>
	<use_power_from_last_rosim_year_for_all_years>0.0</use_power_from_last_rosim_year_for_all_years>
	<ates_minimum_flow_rate__speed_up_calculation_>0.0</ates_minimum_flow_rate__speed_up_calculation_>
	<ates_minimum_depth__speed_up_calculation_>0.0</ates_minimum_depth__speed_up_calculation_>
	<ates_maximum_depth__speed_up_calculation_>500.0</ates_maximum_depth__speed_up_calculation_>
	<ates_filter_fraction__of_aquifer_thickness_>0.8</ates_filter_fraction__of_aquifer_thickness_>
	<ates_clogging_velocity>0.3</ates_clogging_velocity>
	<ates_membrane_filter_index>1.0</ates_membrane_filter_index>
	<ates_depth_multiplication_factor>0.01</ates_depth_multiplication_factor>
	<input__power_utc__scenario_name__must_exist_>BaseCase</input__power_utc__scenario_name__must_exist_>
	<aquifers_for_potential_calculation>test, </aquifers_for_potential_calculation>
	<probability_maps__basename__treshold_value_>npv:0, utc:5, power:1, cop:10, kh:5, flowr:100, h:20</probability_maps__basename__treshold_value_>
	<unit_technical_cost_cutoff>5.1</unit_technical_cost_cutoff>
	<unit_technical_cost_cutoff_deep>6.5</unit_technical_cost_cutoff_deep>
	<depth_for_deep_unit_technical_cost_cutoff>4000.0</depth_for_deep_unit_technical_cost_cutoff>
	<p_value_potential_category_1>50.0</p_value_potential_category_1>
	<p_value_potential_category_2__0__not_used_>30.0</p_value_potential_category_2__0__not_used_>
	<p_value_potential_category_3__0__not_used_>10.0</p_value_potential_category_3__0__not_used_>
	<p_value_potential_category_4__0__not_used_>0.0</p_value_potential_category_4__0__not_used_>
	<additional_p_values_for_the_power_probability_map_and_the_recoverable_heat_maps>90</additional_p_values_for_the_power_probability_map_and_the_recoverable_heat_maps>
	<power_value_for_power_probability_map>10.0</power_value_for_power_probability_map>
	<surface_temperature_hip>10.0</surface_temperature_hip>
	<rock_density_hip>2700.0</rock_density_hip>
	<rock_heat_capacity_hip>1000.0</rock_heat_capacity_hip>
	<exclude_hc_areas_for_recov_heat>1.0</exclude_hc_areas_for_recov_heat>
	<min_prod_temperature__potential__recoverable_heat>0.0</min_prod_temperature__potential__recoverable_heat>
	<aquifer_identifier_for_overview_resources__empty__all_>stacked</aquifer_identifier_for_overview_resources__empty__all_>
	<well_distance__0__from__calc_power_utc_>0.0</well_distance__0__from__calc_power_utc_>
	<doublet_geographical_sorting_factor>1.0</doublet_geographical_sorting_factor>
	<annual_resource_load_hours>6000.0</annual_resource_load_hours>
	<doublet_lifetime>30.0</doublet_lifetime>
	<delete_resources_within_shapefile_s___per_aquifer_>0.0</delete_resources_within_shapefile_s___per_aquifer_>
	<delete_shapefiles__in_input_grids_directory_>
		<row_1>shapefile.shp;license header;aquifer name header</row_1>
	</delete_shapefiles__in_input_grids_directory_>
	<classify_resources_by_shapefile_s_>0.0</classify_resources_by_shapefile_s_>
	<classify_shapefiles__in_input_grids_directory_>
		<row_1>shapefile.shp;output name</row_1>
	</classify_shapefiles__in_input_grids_directory_>
	<stochastic_resources__p90_p50_p10_needed_>0.0</stochastic_resources__p90_p50_p10_needed_>
	<number_of_stochastic_realisations>1000.0</number_of_stochastic_realisations>
	<minimum_unit_technical_cost_cutoff>3.0</minimum_unit_technical_cost_cutoff>
	<maximum_unit_technical_cost_cutoff>8.0</maximum_unit_technical_cost_cutoff>
	<minimum_unit_technical_cost_cutoff_deep>4.0</minimum_unit_technical_cost_cutoff_deep>
	<maximum_unit_technical_cost_cutoff_deep>10.0</maximum_unit_technical_cost_cutoff_deep>
	<stochastic_calculation_parameters>
		<row_1>aquiferName;10;0;1</row_1>
	</stochastic_calculation_parameters>
	<input__calc_potential__scenario_name__must_exist_>BaseCase</input__calc_potential__scenario_name__must_exist_>
	<aquifers_to_use_in_overview_calculation></aquifers_to_use_in_overview_calculation>
	<mask_file__for_output_geometry_>/data/InputData/ahn2_250m_filled.nc</mask_file__for_output_geometry_>
	<xy_grid_size_factor_for_mask_grid>1</xy_grid_size_factor_for_mask_grid>
	<max_undefined_cells__of_surrounding_4__for_interp_overview>3.0</max_undefined_cells__of_surrounding_4__for_interp_overview>
	<p_value_overview_potential_category_1>50.0</p_value_overview_potential_category_1>
	<p_value_overview_potential_category_2__0__not_used_>30.0</p_value_overview_potential_category_2__0__not_used_>
	<p_value_overview_potential_category_3__0__not_used_>10.0</p_value_overview_potential_category_3__0__not_used_>
	<p_value_overview_potential_category_4__0__not_used_>0.0</p_value_overview_potential_category_4__0__not_used_>
	<power_category_1>5.0</power_category_1>
	<power_category_2__0__not_used_>7.5</power_category_2__0__not_used_>
	<power_category_3__0__not_used_>10.0</power_category_3__0__not_used_>
	<power_category_4__0__not_used_>20.0</power_category_4__0__not_used_>
	<additional_p_values_for_the_overview_power_probability_map_and_recoverable_heat_maps>90</additional_p_values_for_the_overview_power_probability_map_and_recoverable_heat_maps>
	<power_value_for_overview_power_probability_map>10.0</power_value_for_overview_power_probability_map>
	<input_scenario_name>BaseCase</input_scenario_name>
	<aquifers_to_use_in_voi_calculation>RO_STACKED</aquifers_to_use_in_voi_calculation>
	<minimum_npv_for_portfolio_repeat>1.0</minimum_npv_for_portfolio_repeat>
	<upward_and_downward_change_of_pos>15.0</upward_and_downward_change_of_pos>
	<general_upward_change_of_pos>5.0</general_upward_change_of_pos>
	<maximum_number_of_failures>2.0</maximum_number_of_failures>
	<repeat_potential_in_portfolio>10.0</repeat_potential_in_portfolio>
	<output_grid_file_type___zmap___asc___nc__beta__>.zmap</output_grid_file_type___zmap___asc___nc__beta__>
	<remove_padding_from_input_grids>0</remove_padding_from_input_grids>
</project>
 No newline at end of file

src/datamodels/__init__.py

deleted100644 → 0
+0 −0

Empty file deleted.

src/datamodels/configuration.py

deleted100644 → 0
+0 −26
Original line number Diff line number Diff line
import os
from pathlib import Path
from git import Repo
from pydantic import BaseModel, model_validator



class WP5Parameters(BaseModel):
    aquifers: list[str]
    stacked_aquifers: list[str]
    data_path: Path | None = None
    docker_image_tag: str


class Config(BaseModel):
    model_path: Path | None
    model_name: str
    grid_extension: str
    WP5: WP5Parameters

    @model_validator(mode="after")
    def set_paths(self):
        if not self.model_path:
            repo_path = Path(Repo(".", search_parent_directories=True).working_tree_dir)
            self.model_path = repo_path / "models" / self.model_name
        return self
+0 −112
Original line number Diff line number Diff line
import copy
from pathlib import Path

from src.datamodels.configuration import Config
import docker
import xmltodict

from src.utils.docker_util import docker_run


def edit_wp5_configuration_file(config: Config, xml_file: Path):
    """Take the configuration xml files from the App settings directory, edit them to reflect the path of the container, and overwrite the original files"""
    #   Editing the configuration files for the java code is ugly:
    #   -there are 12 variables we need to change just to say we only calculate P10, P30, P50, P90
    #   -Likewise we need to change 5 variables to set the aquifers we want to calculate.
    #   -A string "1" or "0" denotes true or false.
    stacked_aquifer_combinations = {
        "TR_STACKED": "TR_STACKED;RBMDL, RBMDU, RBMH, RBMVL, RBMVU, RBSHN, RNROF, RNSOB",
        "SLDN_STACKED": "SLDN_STACKED;SLDNA, SLDND",
        "KN_STACKED": "KN_STACKED;KNNSY, KNNSR, KNNSL, KNNSG, KNNSF_KNNSP, KNNSB, KNGLG_KNGLS",
        "RO_STACKED": "RO_STACKED;ROSL_ROSLU, ROSLL",
        "DC_STACKED": "DC_STACKED;DCH, DCD",
        "N_STACKED": "N_STACKED;NMVESO, NMVEVO, NMRUST, NMRUBE, NLDOBR, NLDOOO, NLLARE, NLLAOR"
    }

    # Read xml file as a python dictionary
    with open(xml_file, "r") as file:
        xml_content = file.read()
    wp5_config_dictionary = xmltodict.parse(xml_content)
    project_dict = wp5_config_dictionary["project"]
    is_ates = project_dict["@ATES"] == "true"

    # General parameters
    project_dict["copy_aquifer_files"] = "0"
    project_dict["calculate_stacked_aquifers"] = "0"
    project_dict["input_data_directory"] = "/data/InputData"
    project_dict["results_directory"] = "/data/Results"
    project_dict["max_number_of_processors_for_calculations"] = "10"
    project_dict["validate_input_grids"] = "0"
    project_dict["validate_output_grids"] = "0"
    project_dict["output_maps_for_petrel"] = "0"
    project_dict["output_grid_file_type___zmap___asc___nc__beta__"] = config.grid_extension
    project_dict["remove_padding_from_input_grids"] = "0"
    project_dict["xy_grid_size_factor_for_thickness_grid__integer_"] = "1"
    project_dict["xy_grid_size_factor_for_mask_grid"] = "1"

    # grid names: change to using the user inputted suffix
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_1"] = f"Permeability;no;_perm{config.grid_extension}"
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_2"] = f"PermeabilityLNSD;no;_ln_perm_sd{config.grid_extension}"
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_3"] = f"Porosity;no;_poro{config.grid_extension}"
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_4"] = f"Thickness;no;_thick{config.grid_extension}"
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_5"] = f"ThicknessSD;no;_thick_sd{config.grid_extension}"
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_6"] = f"Depth;no;_top{config.grid_extension}"
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_7"] = f"NetToGross;no;_ntg{config.grid_extension}"
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_8"] = f"Temperature;yes;__temperature{config.grid_extension}"
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_9"] = f"HCAccum;yes;_hc_accum{config.grid_extension}"
    project_dict["property_grids__in_input_data_directory__stacked_grids_will_be_created_"]["row_10"] = "BoundaryShapefile;yes;__BoundaryShapefile.shp"

    # p-values to process
    #   UTC
    project_dict["pvalues_to_calculate"] = "50"

    # Aquifers to Process
    aquifers_and_stacked_aquifers_string, stacked_aquifers_string, aquifers_string = generate_aquifer_strings(config.WP5.aquifers, config.WP5.stacked_aquifers)
    project_dict["aquifers_to_calculate"] = aquifers_and_stacked_aquifers_string
    project_dict["aquifer_list__comma_separated__excluding_stacked_aquifers_"] = aquifers_string
    project_dict["aquifers_for_potential_calculation"] = aquifers_and_stacked_aquifers_string
    project_dict["stacked_aquifers"] = {}
    for i in range(len(config.WP5.stacked_aquifers)):
        project_dict["stacked_aquifers"][f"row_{i}"] = stacked_aquifer_combinations[config.WP5.stacked_aquifers[i]]
    project_dict["aquifers_to_use_in_overview_calculation"] = stacked_aquifers_string

    # Temperature voxet and mask file
    project_dict["temperature_voxet_file"] = "/data/InputTemperatureModel/restart.vo"
    project_dict["mask_file__for_output_geometry_"] = "/data/InputData/mask.nc"


    # Overwrite the original xml file
    xml_output = xmltodict.unparse(wp5_config_dictionary, pretty=True)
    with open(xml_file, "w") as file:
        file.write(xml_output)


def generate_aquifer_strings(aquifers, aquifers_stacked):
    aquifers_string = ""
    for s in aquifers:
        aquifers_string += s + ", "

    aquifers_stacked_string = ""
    aquifers_and_stacked_aquifers_string = copy.deepcopy(aquifers_string)
    for s in aquifers_stacked:
        aquifers_stacked_string += s + ", "
        aquifers_and_stacked_aquifers_string += s + ", "

    return aquifers_and_stacked_aquifers_string, aquifers_stacked_string, aquifers_string


def run_wp5_docker_image(config: Config):
    """using docker create the python environment and run the code"""
    print("copy & edit configuration xml files")
    app_settings_path = config.model_path / "xml"
    wp5_scenario_xmls = list(app_settings_path.glob("*.xml"))
    [edit_wp5_configuration_file(config, xml_file) for xml_file in wp5_scenario_xmls]

    print(f"run docker image on {len(wp5_scenario_xmls)} scenarios")
    for xml_file in wp5_scenario_xmls:
        run_scenario(config, xml_file)


def run_scenario(config: Config, xml_file: Path):
    client = docker.from_env()
    docker_run(client, config.WP5.docker_image_tag, command=[f"/data/xml/{xml_file.name}"], volumes=[f'{str(config.model_path)}:/data'])
 No newline at end of file

src/thermogis/__init__.py

deleted100644 → 0
+0 −0

Empty file deleted.