Skip to content

Commit 0bb6953

Browse files
Merge pull request #87 from TUDelftGeodesy/fix_76
Add doc for enrich_from_dataset
2 parents ea29f5b + 82f87b6 commit 0bb6953

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

docs/operations.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ STMTools supports various operations on an STM.
44

55
## Enrich an STM
66

7-
Contextual data can be added to an STM by enrichment. At present, STMTools supports enriching an STM by static polygons.
7+
Contextual data can be added to an STM by enrichment. STMTools supports enriching an STM by static polygons or a dataset.
88

9-
For example, if soil type data (`soil_map.gpkg`) is available together with an STM, one can first read `soil_map.gpkg` using the `GeoPandas` library as a `GeoDataFrame`, then add the soil type and corresponding type ID to the STM, using the `enrich_from_polygon` function.
9+
### Enrich from a polygon
10+
11+
STMTools supports enriching an STM by static polygons. For example, if soil type
12+
data (`soil_map.gpkg`) is available together with an STM, one can first read
13+
`soil_map.gpkg` using the `GeoPandas` library as a `GeoDataFrame`, then add the
14+
soil type and corresponding type ID to the STM, using the `enrich_from_polygon`
15+
function.
1016

1117
```python
1218
import geopandas as gpd
@@ -24,6 +30,34 @@ fields_to_query = ['soil_type', 'type_id']
2430
stmat_enriched = stmat.stm.enrich_from_polygon(path_polygon, fields_to_query)
2531
```
2632

33+
### Enrich from a dataset
34+
35+
STMTools supports enriching an STM by a dataset or a data array. For example, if
36+
a dataset (`meteo_data.nc`) is available together with an STM, one can first
37+
read `meteo_data.nc` using the `Xarray` library, then add the dataset to the
38+
STM, using the `enrich_from_dataset` function.
39+
40+
```python
41+
import xarray as xr
42+
dataset = xr.open_dataset('meteo_data.nc')
43+
44+
# one field
45+
stmat_enriched = stmat.stm.enrich_from_dataset(dataset, 'temperature')
46+
47+
# multiple fields
48+
stmat_enriched = stmat.stm.enrich_from_dataset(dataset, ['temperature', 'precipitation'])
49+
```
50+
51+
By default `"nearest"` is used for the interpolation. But you can choose [any
52+
method provided by
53+
Xarray](https://docs.xarray.dev/en/stable/generated/xarray.Dataset.interp.html).
54+
For example, if you want to use `"linear"` interpolation, you can do it like
55+
this:
56+
57+
```python
58+
stmat_enriched = stmat.stm.enrich_from_dataset(dataset, 'temperature', method='linear')
59+
```
60+
2761
## Subset an STM
2862

2963
A subset of an STM can be obtained based on 1) thresholding on an attribute, or 2) intersection with a background polygon.
@@ -42,7 +76,7 @@ This is equivalent to Xarray filtering:
4276
mask = stmat['pnt_enscoh'] > 0.7
4377
mask = mask.compute()
4478
stmat_subset = stmat.where(mask, drop=True)
45-
```
79+
```
4680

4781
### Subset by a polygon
4882

0 commit comments

Comments
 (0)