TNO Intern

Commit 3f16b993 authored by Jan Diederik van Wees's avatar Jan Diederik van Wees
Browse files

changes for examples (commented) and added conversion scenarios

parent f8f696e7
Loading
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
%% Cell type:code id:initial_id tags:

``` python
#
# this example is a simple run of the doublet performance model, with a single set of input parameters.
# The input parameters are provided as an xarray Dataset
# The output is an xarray Dataset with the results of the simulation.
#
from pythermogis import calculate_doublet_performance
import xarray as xr
```

%% Cell type:code id:23cd5a9471611a5c tags:

``` python
input_data = xr.Dataset({
    "thickness": 300,
    "ntg": 0.5,
    "porosity": 0.2,
    "depth": 2000,
    "permeability": 300,
})
```

%% Cell type:code id:3c92c4f9d5890229 tags:

``` python
results = calculate_doublet_performance(input_data)
```

%% Cell type:code id:4f81387037e4ce1e tags:

``` python
print(results.data_vars.keys())
```

%% Output

    KeysView(Data variables:
        thickness                int64 8B 300
        ntg                      float64 8B 0.5
        porosity                 float64 8B 0.2
        depth                    int64 8B 2000
        permeability             int64 8B 300
        mask                     float64 8B nan
        temperature              float64 8B 76.65
        transmissivity           int64 8B 90000
        transmissivity_with_ntg  float64 8B 45.0
        power                    float64 8B 19.75
        heat_pump_power          float64 8B 0.0
        capex                    float64 8B 19.65
        opex                     float64 8B -3.127
        utc                      float64 8B 4.872
        npv                      float64 8B 1.536
        hprod                    float64 8B 2.5e+06
        cop                      float64 8B 18.01
        cophp                    float64 8B 0.0
        pres                     float64 8B 60.0
        flow_rate                float64 8B 394.9
        welld                    float64 8B 1.193e+03
        inj_temp                 float64 8B 30.0
        prd_temp                 float64 8B 75.84)

%% Cell type:code id:e5e069faebb99ebd tags:

``` python
```
+4 −0
Original line number Diff line number Diff line
%% Cell type:code id:initial_id tags:

``` python
#
# this example shows how to use the calculate_doublet_performance function with a simple xy grid as input
# The input parameters are provided as an xarray Dataset with dimensions 'x' and 'y'
#
from pythermogis import calculate_doublet_performance
import xarray as xr
import numpy as np
```

%% Cell type:code id:5eeb6f3673a3b7f1 tags:

``` python
input_data = xr.Dataset({
    "thickness": (("x", "y"), np.array([[300, 300], [200, 200]])),
    "ntg": (("x", "y"), np.array([[0.5, 0.5], [0.25, 0.25]])),
    "porosity": (("x", "y"), np.array([[0.2, 0.2], [0.3, 0.3]])),
    "depth": (("x", "y"), np.array([[5000, 5000], [4500, 4500]])),
    "permeability": (("x", "y"), np.array([[300, 300], [450, 450]])),
}, coords={"x": [0, 1], "y": [10, 20]})
```

%% Cell type:code id:a166bdda1620353d tags:

``` python
results = calculate_doublet_performance(input_data)
```

%% Cell type:code id:c0e146c5398a6e52 tags:

``` python
print(results.coords)
print(results.data_vars.keys())
```

%% Output

    Coordinates:
      * x        (x) int64 16B 0 1
      * y        (y) int64 16B 10 20
    KeysView(Data variables:
        thickness                (x, y) int64 32B 300 300 200 200
        ntg                      (x, y) float64 32B 0.5 0.5 0.25 0.25
        porosity                 (x, y) float64 32B 0.2 0.2 0.3 0.3
        depth                    (x, y) int64 32B 5000 5000 4500 4500
        permeability             (x, y) int64 32B 300 300 450 450
        mask                     float64 8B nan
        temperature              (x, y) float64 32B 169.7 169.7 152.6 152.6
        transmissivity           (x, y) int64 32B 90000 90000 90000 90000
        transmissivity_with_ntg  (x, y) float64 32B 45.0 45.0 22.5 22.5
        power                    (x, y) float64 32B 48.42 48.42 49.34 49.34
        heat_pump_power          (x, y) float64 32B 0.0 0.0 0.0 0.0
        capex                    (x, y) float64 32B 53.33 53.33 49.56 49.56
        opex                     (x, y) float64 32B -6.998 -6.998 -7.835 -7.835
        utc                      (x, y) float64 32B 4.814 4.814 4.9 4.9
        npv                      (x, y) float64 32B 27.89 27.89 26.97 26.97
        hprod                    (x, y) float64 32B 6.127e+06 ... 6.243e+06
        cop                      (x, y) float64 32B 37.34 37.34 17.69 17.69
        cophp                    (x, y) float64 32B 0.0 0.0 0.0 0.0
        pres                     (x, y) float64 32B 56.02 56.02 120.5 120.5
        flow_rate                (x, y) float64 32B 500.0 500.0 500.0 500.0
        welld                    (x, y) float64 32B 1.306e+03 ... 2.224e+03
        inj_temp                 (x, y) float64 32B 69.65 69.65 52.6 52.6
        prd_temp                 (x, y) float64 32B 166.1 166.1 149.7 149.7)

%% Cell type:code id:147a4b3a919f8486 tags:

``` python
print(results.sel(x=1, y=10))
```

%% Output

    <xarray.Dataset> Size: 200B
    Dimensions:                  ()
    Coordinates:
        x                        int64 8B 1
        y                        int64 8B 10
    Data variables: (12/23)
        thickness                int64 8B 200
        ntg                      float64 8B 0.25
        porosity                 float64 8B 0.3
        depth                    int64 8B 4500
        permeability             int64 8B 450
        mask                     float64 8B nan
        ...                       ...
        cophp                    float64 8B 0.0
        pres                     float64 8B 120.5
        flow_rate                float64 8B 500.0
        welld                    float64 8B 2.224e+03
        inj_temp                 float64 8B 52.6
        prd_temp                 float64 8B 149.7

%% Cell type:code id:6885ec69a2f8d52d tags:

``` python
```
+12 −2
Original line number Diff line number Diff line
%% Cell type:code id:initial_id tags:

``` python
#
# this example shows how to set up the UTC properties and use them in the doublet performance calculation.
#  The UTC properties are used to calculate the performance of a doublet system with a heat pump.
#  The UTC properties modified here activate the heatpump model, the goal and return temperature of the heat network
#  and the use of the Kestin viscosity model.
#
#  It also modifies the cost parameters of the heat pump, which are used to calculate the UTC cost of the system.
#
#
from pythermogis import calculate_doublet_performance
from pythermogis import instantiate_thermogis_parameters
import xarray as xr
```

%% Cell type:code id:d78e3e6f8909074d tags:

``` python
input_data = xr.Dataset({
    "thickness": 300,
    "ntg": 0.5,
    "porosity": 0.2,
    "depth": 2000,
    "permeability": 300,
})
```

%% Cell type:code id:59bb4943298aecec tags:

``` python
tg_properties = instantiate_thermogis_parameters()
tg_properties.setUseHeatpump(True)
tg_properties.setOpexPower(100)
tg_properties.setOpexBase(0)
tg_properties.setHeatPumpCapex(600)
tg_properties.setHeatPumpOpex(60)
tg_properties.setHeatPumpAlternativeHeatingPrice(2.8)
tg_properties.setGoalTemperature(100)
tg_properties.setDhReturnTemp(50)
tg_properties.setUseKestinViscosity(True)

utc_properties = tg_properties.setupUTCParameters()
```

%% Cell type:code id:8a75abccf9d7e13e tags:

``` python
results = calculate_doublet_performance(input_data, utc_properties=utc_properties)
```

%% Cell type:code id:a01bab0bd12b4a7b tags:

``` python
print(results.data_vars.keys())
```

%% Output

    KeysView(Data variables:
        thickness                int64 8B 300
        ntg                      float64 8B 0.5
        porosity                 float64 8B 0.2
        depth                    int64 8B 2000
        permeability             int64 8B 300
        mask                     float64 8B nan
        temperature              float64 8B 76.65
        transmissivity           int64 8B 90000
        transmissivity_with_ntg  float64 8B 45.0
        power                    float64 8B 22.12
        heat_pump_power          float64 8B 10.56
        capex                    float64 8B 28.09
        opex                     float64 8B -6.133
        utc                      float64 8B 7.634
        npv                      float64 8B -19.15
        hprod                    float64 8B 2.799e+06
        cop                      float64 8B 4.053
        cophp                    float64 8B 2.844
        pres                     float64 8B 60.0
        flow_rate                float64 8B 411.9
        welld                    float64 8B 1.216e+03
        inj_temp                 float64 8B 26.65
        prd_temp                 float64 8B 75.87)
+10 −0
Original line number Diff line number Diff line
%% Cell type:code id:initial_id tags:

``` python
#
#  this example shows how to use the `calculate_doublet_performance_stochastic` function to calculate the performance of a geothermal doublet while accounting for uncertainty in the input parameters
#  on thickness and ln_peremability.
#  The input parameters are defined as a dataset with mean and standard deviation values for each parameter,
#  and the function will perform a stochastic analysis to provide a range of possible outcomes for the doublet performance.
#  the sampled values correspond to p_valeus which default to p50, but can be set to any value between 0 and 100.
#  The output is an xarray Dataset with the results of the simulation, including the performance metrics for each set of sampled input parameters.
#
#  so this example only samples the p50 value of the input distributon, example show s how to use the argument p_values to sample other values of the distribution, for example p10, p90 etc.
#
from pythermogis import calculate_doublet_performance_stochastic
import xarray as xr
```

%% Cell type:code id:537f0f900884962f tags:

``` python
input_data = xr.Dataset({
    "thickness_mean": 300,
    "thickness_sd": 50,
    "ntg": 0.5,
    "porosity": 0.2,
    "depth": 2000,
    "ln_permeability_mean": 4,
    "ln_permeability_sd": 0.5,
})
```

%% Cell type:code id:97c7b6db1a1d78a0 tags:

``` python
results = calculate_doublet_performance_stochastic(input_data)
```

%% Cell type:code id:2aaa8a00cde80f7c tags:

``` python
print(results.coords)
print(results.data_vars.keys())
```

%% Output

    Coordinates:
      * p_value  (p_value) float64 8B 50.0
    KeysView(Data variables:
        temperature              (p_value) float64 8B 76.65
        thickness                (p_value) int64 8B 300
        permeability             (p_value) float64 8B 54.6
        transmissivity           (p_value) float64 8B 1.638e+04
        transmissivity_with_ntg  (p_value) float64 8B 8.19
        power                    (p_value) float64 8B 4.751
        heat_pump_power          (p_value) float64 8B 0.0
        capex                    (p_value) float64 8B 14.11
        opex                     (p_value) float64 8B -0.7586
        utc                      (p_value) float64 8B 8.646
        npv                      (p_value) float64 8B -5.756
        hprod                    (p_value) float64 8B 6.012e+05
        cop                      (p_value) float64 8B 17.14
        cophp                    (p_value) float64 8B 0.0
        pres                     (p_value) float64 8B 60.0
        flow_rate                (p_value) float64 8B 99.78
        welld                    (p_value) float64 8B 592.8
        inj_temp                 (p_value) float64 8B 30.0
        prd_temp                 (p_value) float64 8B 73.61)
+5 −0
Original line number Diff line number Diff line
%% Cell type:code id:initial_id tags:

``` python
#
# this example shows how to calculate the doublet performance for a range of p-values, from 1 to 99.
# The results are plotted as a function of the transmissivity of the aquifer.
# The transmissivity corresponding to a p-value of 50% is also highlighted with the intersection of a vertical and horizontal line.
#
from pythermogis import calculate_doublet_performance_stochastic
import xarray as xr
from matplotlib import pyplot as plt
from pathlib import Path
from os import path
output_data_path = Path( "test_output") / "example5"
output_data_path.mkdir(parents=True, exist_ok=True)
```

%% Cell type:code id:cd51875a68545954 tags:

``` python
input_data = xr.Dataset({
    "thickness_mean": 300,
    "thickness_sd": 50,
    "ntg": 0.5,
    "porosity": 0.2,
    "depth": 2000,
    "ln_permeability_mean": 5,
    "ln_permeability_sd": 0.5,
})
```

%% Cell type:code id:aa082b2f4176ffd3 tags:

``` python
results = calculate_doublet_performance_stochastic(input_data, p_values=[1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 99])
```

%% Cell type:code id:59a48ea142719d55 tags:

``` python
fig, axe = plt.subplots(figsize=(10, 5))
kh = results.transmissivity_with_ntg * 1.0
kh.plot(y="p_value", ax=axe)
axe.set_title(f"Aquifer Net transmissivity\n kH")
temp =  input_data.temperature
inj_temp = results.inj_temp.sel(p_value=50, method="nearest")
prd_temp = results.prd_temp.sel(p_value=50, method="nearest")
axe.axhline(50.0, label=f"TEMP res: {temp:.1f} inj: {inj_temp:.1f} prd: {prd_temp:.1f} ",  ls="--", c="tab:orange")
# axes.axhline(pos, label=f"probability of success: {pos:.1f}%",ls="--", c="tab:orange")
kh50 = kh.sel(p_value=50, method="nearest")
axe.axvline(kh50, ls="--", c="tab:orange" )
axe.legend()
axe.set_xlabel("kH [Dm]")
axe.set_ylabel("p-value [%]")
plt.savefig(output_data_path / "kh.png")
```

%% Output

Loading