Skip to content

Commit b39408f

Browse files
authored
Remove SatelliteImage class for reading sensor metadata in favor of a Raster option (#628)
1 parent 049f39b commit b39408f

23 files changed

+321
-509
lines changed

dev-environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies:
3131
- pylint
3232
- netcdf4 # To write synthetic data with chunksizes
3333
- dask-memusage
34+
- pre-commit
3435

3536
# Doc dependencies
3637
- sphinx

doc/source/about_geoutils.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ header-rows: 1
9090
* - ```{eval-rst}
9191
.. literalinclude:: code/about_geoutils_sidebyside_raster_geoutils.py
9292
:language: python
93-
:lines: 14-29
93+
:lines: 15-30
9494
```
9595
9696
- ```{eval-rst}

doc/source/api.md

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ documentation.
3737

3838
(api-raster-attrs)=
3939

40-
### Unique attributes
40+
### Main attributes
4141

4242
```{eval-rst}
4343
.. autosummary::
@@ -60,16 +60,25 @@ documentation.
6060
Raster.height
6161
Raster.width
6262
Raster.count
63-
Raster.count_on_disk
6463
Raster.bands
65-
Raster.bands_on_disk
6664
Raster.res
6765
Raster.bounds
6866
Raster.dtype
67+
```
68+
69+
### Other attributes
70+
71+
```{eval-rst}
72+
.. autosummary::
73+
:toctree: gen_modules/
74+
75+
Raster.count_on_disk
76+
Raster.bands_on_disk
6977
Raster.is_loaded
7078
Raster.is_modified
7179
Raster.name
7280
Raster.driver
81+
Raster.tags
7382
```
7483

7584
(api-geo-handle)=
@@ -203,36 +212,6 @@ And reverse operations.
203212
Raster.__array_function__
204213
```
205214

206-
## SatelliteImage
207-
208-
```{eval-rst}
209-
.. minigallery:: geoutils.SatelliteImage
210-
:add-heading:
211-
```
212-
213-
### Opening a file
214-
215-
```{eval-rst}
216-
.. autosummary::
217-
:toctree: gen_modules/
218-
219-
SatelliteImage
220-
```
221-
222-
### Satellite image metadata
223-
224-
```{eval-rst}
225-
.. autosummary::
226-
:toctree: gen_modules/
227-
228-
SatelliteImage.datetime
229-
SatelliteImage.tile_name
230-
SatelliteImage.satellite
231-
SatelliteImage.sensor
232-
SatelliteImage.product
233-
SatelliteImage.version
234-
```
235-
236215
## Mask
237216

238217
```{eval-rst}
@@ -289,7 +268,7 @@ And reverse operations.
289268
Vector.info
290269
```
291270

292-
### Unique attributes
271+
### Main attributes
293272

294273
```{eval-rst}
295274
.. autosummary::

doc/source/code/about_geoutils_sidebyside_raster_geoutils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import warnings
1010

1111
warnings.filterwarnings("ignore", category=UserWarning, message="For reprojection, nodata must be set.*")
12+
warnings.filterwarnings("ignore", category=UserWarning, message="One raster has a pixel interpretation*")
1213
####
1314

1415
import geoutils as gu

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#
2+
#
23
# Configuration file for the Sphinx documentation builder.
34
#
45
import glob
@@ -124,7 +125,6 @@
124125
inheritance_alias = {
125126
"geoutils.raster.raster.Raster": "geoutils.Raster",
126127
"geoutils.raster.raster.Mask": "geoutils.Mask",
127-
"geoutils.raster.satimg.SatelliteImage": "geoutils.SatelliteImage",
128128
"geoutils.vector.Vector": "geoutils.Vector",
129129
"xdem.dem.DEM": "xdem.DEM",
130130
}

doc/source/core_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ core_match_ref
1111
core_py_ops
1212
core_array_funcs
1313
core_lazy_load
14+
core_parsing
1415
core_inheritance
1516
```

doc/source/core_inheritance.md

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ kernelspec:
1111
name: geoutils
1212
---
1313
(core-inheritance)=
14-
# Inheritance to geo-images and beyond
14+
# Inheritance to DEMs and beyond
1515

1616
Inheritance is practical to naturally pass down parent methods and attributes to child classes.
1717

@@ -20,12 +20,13 @@ implemented in GeoUtils.
2020

2121
## Overview of {class}`~geoutils.Raster` inheritance
2222

23-
24-
Below is a diagram showing current {class}`~geoutils.Raster` inheritance, which extends into other packages such as [xDEM](https://xdem.readthedocs.io/)
23+
Current {class}`~geoutils.Raster` inheritance extends into other packages, such as [xDEM](https://xdem.readthedocs.io/)
2524
for analyzing digital elevation models.
25+
Within GeoUtils, inheritance extends only to {class}`~geoutils.Mask` that implements overloaded methods specific to binary raster masks,
26+
as shown in the diagram below.
2627

2728
```{eval-rst}
28-
.. inheritance-diagram:: geoutils.raster.raster geoutils.raster.satimg
29+
.. inheritance-diagram:: geoutils.raster.raster
2930
:top-classes: geoutils.raster.raster.Raster
3031
```
3132

@@ -37,42 +38,11 @@ Among others, it also adds a {attr}`~xdem.DEM.vcrs` property to consistently man
3738
If you are DEM-enthusiastic, **[check-out our sister package xDEM](https://xdem.readthedocs.io/) for digital elevation models.**
3839
```
3940

40-
## The internal {class}`~geoutils.SatelliteImage` subclass
41-
42-
GeoUtils subclasses {class}`Rasters<geoutils.Raster>` to {class}`SatelliteImages<geoutils.SatelliteImage>` for remote sensing users interested in parsing
43-
metadata from space- or airborne imagery.
44-
45-
Based on the filename, or auxiliary files, the {class}`~geoutils.SatelliteImage` class attempts to automatically parse a
46-
{attr}`~geoutils.SatelliteImage.datetime`, {attr}`~geoutils.SatelliteImage.sensor`, {attr}`~geoutils.SatelliteImage.tile_name`,
47-
and other information.
48-
49-
```{code-cell} ipython3
50-
import geoutils as gu
51-
52-
# Instantiate a geo-image from an ASTER image
53-
filename_geoimg = gu.examples.get_path("exploradores_aster_dem")
54-
geoimg = gu.SatelliteImage(filename_geoimg, silent=False)
55-
```
56-
57-
```{code-cell} ipython3
58-
# Instantiate a geo-image from a Landsat 7 image
59-
filename_geoimg2 = gu.examples.get_path("everest_landsat_b4")
60-
geoimg2 = gu.SatelliteImage(filename_geoimg2, silent=False)
61-
```
62-
63-
Along these additional attributes, the {class}`~geoutils.SatelliteImage` possesses the same main attributes as a {class}`~geoutils.Raster`.
64-
65-
```{code-cell} ipython3
66-
67-
# The geo-image main attributes
68-
geoimg
69-
```
70-
7141
## And beyond
7242

7343
Many types of geospatial data can be viewed as a subclass of {class}`Rasters<geoutils.Raster>`, which have more attributes and require their own methods:
7444
**spectral images**, **velocity fields**, **phase difference maps**, etc...
7545

76-
If you are interested to build your own subclass of {class}`~geoutils.Raster`, you can take example of the structure of {class}`geoutils.SatelliteImage` and
77-
{class}`xdem.DEM`. Then, just add any of your own attributes and methods, and overload parent methods if necessary! Don't hesitate to reach out on our
46+
If you are interested to build your own subclass of {class}`~geoutils.Raster`, you can take example of the structure of {class}`xdem.DEM`.
47+
Then, just add any of your own attributes and methods, and overload parent methods if necessary! Don't hesitate to reach out on our
7848
GitHub if you have a subclassing project.

doc/source/core_parsing.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
file_format: mystnb
3+
jupytext:
4+
formats: md:myst
5+
text_representation:
6+
extension: .md
7+
format_name: myst
8+
kernelspec:
9+
display_name: geoutils-env
10+
language: python
11+
name: geoutils
12+
---
13+
(satimg-parsing)=
14+
15+
# Sensor metadata parsing
16+
17+
GeoUtils functionalities for remote sensing users interested in parsing metadata from space- or airborne imagery.
18+
19+
## Parsing metadata at raster instantiation
20+
21+
A {class}`~geoutils.Raster` can be instantiated while trying to parse metadata usint the ``parse_sensor_metadata`` argument.
22+
23+
```{code-cell} ipython3
24+
import geoutils as gu
25+
26+
# Parse metadata from an ASTER raster
27+
filename_aster = gu.examples.get_path("exploradores_aster_dem")
28+
rast_aster = gu.Raster(filename_aster, parse_sensor_metadata=True, silent=False)
29+
```
30+
31+
32+
```{code-cell} ipython3
33+
# Parse metadata from a Landsat 7 raster
34+
filename_landsat = gu.examples.get_path("everest_landsat_b4")
35+
rast_landsat = gu.Raster(filename_landsat, parse_sensor_metadata=True, silent=False)
36+
```
37+
38+
The metadata is then stored in the {attr}`~geoutils.Raster.tags` attribute of the raster.
39+
40+
```{code-cell} ipython3
41+
rast_aster.tags
42+
```
43+
44+
For tiled products such as SRTM, the tile naming is also retrieved, and converted to usable tile sizes and extents based on known metadata.
45+
46+
## Supported sensors
47+
48+
Right now are supported:
49+
- Landsat,
50+
- Sentinel-2,
51+
- SPOT,
52+
- ASTER,
53+
- ArcticDEM and REMA,
54+
- ALOS,
55+
- SRTM,
56+
- TanDEM-X, and
57+
- NASADEM.
58+
59+
```{important}
60+
Sensor metadata parsing is still in development. We hope to add the ability to parse from
61+
auxiliary files in the future (such as [here](https://github.com/jlandmann/glaciersat/blob/master/glaciersat/core/imagery.py)).
62+
```

doc/source/data_object_index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ raster_class
1010
vector_class
1111
pointcloud_class
1212
mask_class
13-
satimg_class
1413
```

doc/source/feature_overview.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ import os
241241
os.remove("myaoi.gpkg")
242242
```
243243

244-
## Parsing metadata with {class}`~geoutils.SatelliteImage`
244+
## Parsing sensor metadata
245245

246-
In our case, `rast` would be better opened using the {class}`~geoutils.Raster` object {class}`~geoutils.SatelliteImage` instead, which tentatively parses
247-
metadata recognized from the filename or auxiliary files.
246+
In our case, `rast` would be better opened using the ``parse_sensor_metadata`` argument of a `{class}`~geoutils.Raster`
247+
, which tentatively parses metadata recognized from the filename or auxiliary files.
248248

249249
```{code-cell} ipython3
250250
# Name of the image we used
@@ -254,7 +254,7 @@ print(os.path.basename(filename_rast))
254254

255255
```{code-cell} ipython3
256256
# Open while parsing metadata
257-
rast = gu.SatelliteImage(filename_rast, silent=False)
257+
rast = gu.Raster(filename_rast, parse_sensor_metadata=True, silent=False)
258258
```
259259

260260
```{admonition} Wrap-up

0 commit comments

Comments
 (0)