Skip to content

Commit 93b4d47

Browse files
Merge pull request #88 from TUDelftGeodesy/add_api_doc
Add api doc
2 parents 0bb6953 + adea1b8 commit 93b4d47

File tree

5 files changed

+131
-83
lines changed

5 files changed

+131
-83
lines changed

docs/api_reference.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
hide:
3+
- navigation
4+
---
5+
#
6+
7+
Here is the API reference for the `stmtools` package.
8+
9+
## **Space Time Matrix module**
10+
11+
::: stmtools.stm.SpaceTimeMatrix
12+
13+
## **I/O module**
14+
15+
::: stmtools._io.from_csv
16+
17+
## **Metadata schema module**
18+
19+
::: stmtools.metadata.STMMetaData
20+
21+
## **Utility**
22+
23+
::: stmtools.utils.crop
24+
25+
::: stmtools.utils.monotonic_coords

mkdocs.yml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ repo_url: https://github.com/tudelftgeodesy/stmtools/
33
repo_name: STM Tools
44

55
nav:
6-
- Getting Started:
6+
- Getting Started:
77
- About STM Tools: index.md
88
- Installation: setup.md
9-
- Usage:
9+
- Usage:
1010
- Initiate an STM: stm_init.md
1111
- Operations on STM: operations.md
1212
- Ordering an STM: order.md
@@ -17,6 +17,7 @@ nav:
1717
- Contributing Guidelines: CONTRIBUTING.md
1818
- Code of Conduct: CODE_OF_CONDUCT.md
1919
- Change Log: CHANGELOG.md
20+
- API Reference: api_reference.md
2021

2122

2223
theme:
@@ -44,7 +45,7 @@ theme:
4445
- navigation.tabs
4546
- navigation.tabs.sticky
4647
- content.code.copy
47-
48+
4849
plugins:
4950
- mkdocs-jupyter:
5051
include_source: True
@@ -53,16 +54,31 @@ plugins:
5354
handlers:
5455
python:
5556
options:
56-
docstring_style: google
57+
docstring_style: numpy
5758
docstring_options:
58-
ignore_init_summary: no
59-
merge_init_into_class: yes
60-
show_submodules: no
59+
ignore_init_summary: true
60+
merge_init_into_class: true
61+
docstring_section_style: list
62+
show_submodules: true
63+
show_root_heading: true
64+
show_source: true
65+
heading_level: 3
66+
relative_crossrefs: true
67+
parameter_headings: false
68+
separate_signature: true
69+
show_bases: true
70+
show_signature_annotations: true
71+
show_symbol_type_heading: true
72+
signature_crossrefs: true
73+
summary: true
74+
backlinks: tree
75+
scoped_crossrefs: true
6176

6277
markdown_extensions:
6378
- pymdownx.highlight:
6479
anchor_linenums: true
6580
- pymdownx.superfences
81+
- pymdownx.highlight
6682

6783
extra:
6884
generator: false

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,6 @@ line-ending = "auto"
152152

153153
[tool.ruff.per-file-ignores]
154154
"tests/**" = ["D"]
155+
156+
[tool.ruff.pydocstyle]
157+
convention = "numpy"

stmtools/_io.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,47 @@ def from_csv(
2525
"""Initiate an STM instance from a csv file.
2626
2727
The specified csv file will be loaded using `dask.dataframe.read_csv` with a fixed blocksize.
28-
2928
The columns of the csv file will be classified into coordinates, and data variables.
30-
3129
This classification is performed by Regular Expression (RE) pattern matching according to
32-
three variables: `space_pattern`, `spacetime_pattern` and `coords_cols`.
33-
30+
three variables: `space_pattern`, `spacetime_pattern` and `coords_cols`.
3431
The following assumptions are made to the column names of the csv file:
35-
1. All columns with space-only attributes share the same RE pattern in the column names.
36-
E.g. Latitude, Longitude and height columns are named as "pnt_lat", "pnt_lon" and
37-
"pnt_height", sharing the same RE pattern "^pnt_";
38-
2. Per space-time attribute, a common RE pattern is shared by all columns. E.g. for the
39-
time-series of amplitude data, the column names are "a_20100101", "a_20100110",
40-
"a_20100119" ..., where "^a_" is the common RE pattern;
41-
3. There is no temporal-only (i.e. 1-row attribute) attribute present in the csv file.
42-
43-
`from_csv` does not retrieve time stamps based on column names. The `time` coordinate of
44-
the output STM will be a monotonic integer series starting from 0.
45-
46-
Args:
47-
----
48-
file (str | Path): Path to the csv file.
49-
space_pattern (str, optional): RE pattern to match space attribute columns.
50-
Defaults to "^pnt_".
51-
spacetime_pattern (dict | None, optional): A dictionay mapping RE patterns of each
52-
space-time attribute to corresponding variable names. Defaults to None, which means
53-
the following map will be applied:
54-
{"^d_": "deformation", "^a_": "amplitude", "^h2ph_": "h2ph"}.
55-
coords_cols (list | dict, optional): List of columns to be used as space coordinates.
56-
When `coords_cols` is a dictionary, a reaming will be performed per coordinates.
57-
Defaults to None, then the following renaming will be performed:
58-
"{"pnt_lat": "lat", "pnt_lon": "lon"}"
59-
output_chunksize (dict | None, optional): Chunksize of the output. Defaults to None,
60-
then the size of the first chunk in the DaskDataFrame will be used, up-rounding to
61-
the next 5000.
62-
blocksize (int | str | None, optional): Blocksize to load the csv.
63-
Defaults to 200e6 (in bytes). See the documentation of
64-
[dask.dataframe.read_csv](https://docs.dask.org/en/stable/generated/dask.dataframe.read_csv.html)
65-
66-
Returns:
32+
33+
1. All columns with space-only attributes share the same RE pattern in the column names.
34+
E.g. Latitude, Longitude and height columns are named as "pnt_lat", "pnt_lon" and
35+
"pnt_height", sharing the same RE pattern "^pnt_";
36+
2. Per space-time attribute, a common RE pattern is shared by all columns. E.g. for the
37+
time-series of amplitude data, the column names are "a_20100101", "a_20100110",
38+
"a_20100119" ..., where "^a_" is the common RE pattern;
39+
3. There is no temporal-only (i.e. 1-row attribute) attribute present in the csv file.
40+
41+
Parameters
42+
----------
43+
file: str | Path
44+
Path to the csv file.
45+
space_pattern: str, optional
46+
RE pattern to match space attribute columns. Defaults to "^pnt_".
47+
spacetime_pattern: dict | None, optional
48+
A dictionay mapping RE patterns of each space-time attribute to
49+
corresponding variable names. Defaults to None, which means the
50+
following map will be applied: {"^d_": "deformation", "^a_":
51+
"amplitude", "^h2ph_": "h2ph"}.
52+
coords_cols: list | dict, optional
53+
List of columns to be used as space coordinates. When `coords_cols` is a
54+
dictionary, a reaming will be performed per coordinates. Defaults to
55+
None, then the following renaming will be performed: "{"pnt_lat": "lat",
56+
"pnt_lon": "lon"}"
57+
output_chunksize: dict | None, optional
58+
Chunksize of the output. Defaults to None, then the size of the first
59+
chunk in the DaskDataFrame will be used, up-rounding to the next 5000.
60+
blocksize: int | str | None, optional
61+
Blocksize to load the csv. Defaults to 200e6 (in bytes). See the
62+
documentation of
63+
[dask.dataframe.read_csv](https://docs.dask.org/en/stable/generated/dask.dataframe.read_csv.html)
64+
65+
Returns
6766
-------
68-
xr.Dataset: Output STM instance
67+
xr.Dataset
68+
Output STM instance
6969
7070
"""
7171
# Load csv as Dask DataFrame

stmtools/stm.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,15 @@ def add_metadata(self, metadata):
4848
def regulate_dims(self, space_label=None, time_label=None):
4949
"""Regulate the dimension of a Space-Time Matrix instance.
5050
51-
An STM should have two dimensions: "space" and "time".
52-
53-
If the inupt argument `space_label` or `time_label` is specified,
54-
and that dimension exists, the function will rename that dimension to "space" or "time".
55-
56-
If either `space_label` or `time_label` are None, a "space" or "time" dimension with
57-
size 1 will be created.
58-
59-
If both `space_label` or `time_label` are None. Data variables will also be regulated.
60-
61-
For data variables with a name started with "pnt_", they are regared as
62-
point-only attribute and will not be affected by "time" dimension expansion.
51+
An STM should have two dimensions: `"space"` and `"time"`. If the inupt
52+
argument `space_label` or `time_label` is specified, and that dimension
53+
exists, the function will rename that dimension to "space" or "time". If
54+
either `space_label` or `time_label` are None, a "space" or "time"
55+
dimension with size 1 will be created. If both `space_label` or
56+
`time_label` are None. Data variables will also be regulated. For data
57+
variables with a name started with "pnt_", they are regared as
58+
point-only attribute and will not be affected by "time" dimension
59+
expansion.
6360
6461
Parameters
6562
----------
@@ -113,16 +110,23 @@ def subset(self, method: str, **kwargs):
113110
----------
114111
method : str
115112
Method of subsetting. Choose from "threshold", "density" and "polygon".
113+
116114
- threshold: select all space entries with a threshold criterion, e.g.
115+
```python
117116
data_xr.stm.subset(method="threshold", var="thres", threshold='>1')
117+
```
118118
- density: select one point in every [dx, dy] cell, e.g.
119+
```python
119120
data_xr.stm.subset(method="density", dx=0.1, dy=0.1)
121+
```
120122
- polygon: select all space entries inside a given polygon, e.g.
123+
```python
121124
data_xr.stm.subset(method='polygon', polygon=path_polygon_file)
122-
or
125+
# or
123126
import geopandas as gpd
124127
polygon = gpd.read_file(path_polygon_file)
125128
data_xr.stm.subset(method='polygon', polygon=polygon)
129+
```
126130
**kwargs:
127131
- when method="threshold": data variable "var" and threshold "threshold"
128132
- when method="density": x and y density size: "dx" and "dy"
@@ -187,11 +191,9 @@ def enrich_from_polygon(self, polygon, fields, xlabel="lon", ylabel="lat"):
187191
"""Enrich the SpaceTimeMatrix from one or more attribute fields of a (multi-)polygon.
188192
189193
Each attribute in fields will be assigned as a data variable to the STM.
190-
191-
If a point of the STM falls into the given polygon, the value of the specified field will
192-
be added.
193-
194-
For space entries outside the (multi-)polygon, the value will be None.
194+
If a point of the STM falls into the given polygon, the value of the
195+
specified field will be added. For space entries outside the
196+
(multi-)polygon, the value will be None.
195197
196198
Parameters
197199
----------
@@ -200,9 +202,9 @@ def enrich_from_polygon(self, polygon, fields, xlabel="lon", ylabel="lat"):
200202
fields : str or list of str
201203
Field name(s) in the (multi-)polygon for enrichment
202204
xlabel : str, optional
203-
Name of the x-coordinates of the STM, by default "lon"
205+
Name of the x-coordinates of the STM, by default `"lon"`
204206
ylabel : str, optional
205-
Name of the y-coordinates of the STM, by default "lat"
207+
Name of the y-coordinates of the STM, by default `"lat"`
206208
207209
Returns
208210
-------
@@ -332,7 +334,7 @@ def register_datatype(self, keys: str | Iterable, datatype: DataVarTypes):
332334
keys : Union[str, Iterable]
333335
Keys of the data variables to register
334336
datatype : str in DataVarTypes
335-
String of the datatype. Choose from ["obsData", "auxData", "pntAttrib", "epochAttrib"].
337+
String of the datatype. Choose from `["obsData", "auxData", "pntAttrib", "epochAttrib"]`.
336338
337339
Returns
338340
-------
@@ -353,12 +355,12 @@ def register_datatype(self, keys: str | Iterable, datatype: DataVarTypes):
353355
def get_order(self, xlabel="azimuth", ylabel="range", xscale=1.0, yscale=1.0):
354356
"""Compute an ordering on the points based on coordinates with xlabel and ylabel.
355357
356-
This order is stored in a (new) point attribute "order".
357-
358-
Note that this ordering is most intuitive for integer coordinates (e.g. pixel coordinates).
359-
For float coordinates (e.g. lat-lon), the coordinates should be scaled to determine the
360-
resolution of the ordering: only the whole-number part influences the order.
361-
While coordinates could also be offset, this has limited effect on the relative order.
358+
This order is stored in a (new) point attribute "order". Note that this
359+
ordering is most intuitive for integer coordinates (e.g. pixel
360+
coordinates). For float coordinates (e.g. lat-lon), the coordinates
361+
should be scaled to determine the resolution of the ordering: only the
362+
whole-number part influences the order. While coordinates could also be
363+
offset, this has limited effect on the relative order.
362364
363365
Parameters
364366
----------
@@ -388,13 +390,14 @@ def get_order(self, xlabel="azimuth", ylabel="range", xscale=1.0, yscale=1.0):
388390
def reorder(self, xlabel="azimuth", ylabel="range", xscale=1.0, yscale=1.0):
389391
"""Compute and apply an ordering on the points based on coordinates with xlabel and ylabel.
390392
391-
Note that this ordering is most intuitive for integer coordinates (e.g. pixel coordinates).
392-
For float coordinates (e.g. lat-lon), the coordinates should be scaled to determine the
393-
resolution of the ordering: only the whole-number part influences the order.
394-
While coordinates could also be offset, this has limited effect on the relative order.
395-
396-
Also note that reordering a dataset may be an expensive operation. Because it is applied
397-
lazily, this preformance cost will only manifest once the elements are evaluated.
393+
Note that this ordering is most intuitive for integer coordinates (e.g.
394+
pixel coordinates). For float coordinates (e.g. lat-lon), the
395+
coordinates should be scaled to determine the resolution of the
396+
ordering: only the whole-number part influences the order. While
397+
coordinates could also be offset, this has limited effect on the
398+
relative order. Also note that reordering a dataset may be an expensive
399+
operation. Because it is applied lazily, this preformance cost will only
400+
manifest once the elements are evaluated.
398401
399402
Parameters
400403
----------
@@ -411,7 +414,7 @@ def reorder(self, xlabel="azimuth", ylabel="range", xscale=1.0, yscale=1.0):
411414
412415
"""
413416
self._obj = self.get_order(xlabel, ylabel, xscale, yscale)
414-
417+
415418
# Sorting may split up the chunks, which may interfere with later operations
416419
# so we immediately restore the chunk sizes.
417420
chunks = {"space": self._obj.chunksizes["space"][0]}
@@ -440,8 +443,8 @@ def enrich_from_dataset(self,
440443
"""Enrich the SpaceTimeMatrix from one or more fields of a dataset.
441444
442445
scipy is required. if dataset is raster, it uses
443-
_enrich_from_raster_block to do interpolation using method. if dataset
444-
is point, it uses _enrich_from_points_block to find the nearest points
446+
`_enrich_from_raster_block` to do interpolation using method. if dataset
447+
is point, it uses `_enrich_from_points_block` to find the nearest points
445448
in space and time using Euclidean distance.
446449
447450
Parameters
@@ -451,8 +454,9 @@ def enrich_from_dataset(self,
451454
fields : str or list of str
452455
Field name(s) in the dataset for enrichment
453456
method : str, optional
454-
Method of interpolation, by default "nearest", see
455-
https://docs.xarray.dev/en/stable/generated/xarray.Dataset.interp.html
457+
Method of interpolation, by default `"nearest"`, see [xarray
458+
interpolation
459+
methods](https://docs.xarray.dev/en/stable/generated/xarray.Dataset.interp.html)
456460
457461
Returns
458462
-------

0 commit comments

Comments
 (0)