pdemtools 1.1.2__py3-none-any.whl → 1.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pdemtools/__init__.py +1 -1
- pdemtools/data.py +64 -8
- {pdemtools-1.1.2.dist-info → pdemtools-1.2.1.dist-info}/METADATA +1 -1
- {pdemtools-1.1.2.dist-info → pdemtools-1.2.1.dist-info}/RECORD +7 -7
- {pdemtools-1.1.2.dist-info → pdemtools-1.2.1.dist-info}/WHEEL +0 -0
- {pdemtools-1.1.2.dist-info → pdemtools-1.2.1.dist-info}/licenses/LICENSE.md +0 -0
- {pdemtools-1.1.2.dist-info → pdemtools-1.2.1.dist-info}/top_level.txt +0 -0
pdemtools/__init__.py
CHANGED
pdemtools/data.py
CHANGED
|
@@ -3,7 +3,7 @@ processing (geoids, masks, etc), resampled to match the DEM xarray object.
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
import datetime
|
|
6
|
-
from typing import Optional,
|
|
6
|
+
from typing import Optional, Union
|
|
7
7
|
from warnings import warn
|
|
8
8
|
|
|
9
9
|
import rioxarray as rxr
|
|
@@ -24,7 +24,9 @@ from ._utils import clip, get_resolution
|
|
|
24
24
|
# from shapely.geometry.polygon import Polygon
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
def geoid_from_bedmachine(
|
|
27
|
+
def geoid_from_bedmachine(
|
|
28
|
+
bm_fpath: str, target_rxd: DataArray, geoid_crs: Optional[Union[str, int]] = None
|
|
29
|
+
) -> DataArray:
|
|
28
30
|
"""Extracts the BedMachine geoid (EIGEN-6C4), bilinearly resampled to match the
|
|
29
31
|
target dataset.
|
|
30
32
|
|
|
@@ -32,12 +34,23 @@ def geoid_from_bedmachine(bm_fpath: str, target_rxd: DataArray) -> DataArray:
|
|
|
32
34
|
:type bm_fpath: str
|
|
33
35
|
:param target_rxd: (rio)xarray dataset that BedMachine will be resampled to match
|
|
34
36
|
:type target_rxd: DataArray
|
|
37
|
+
:param geoid_crs: CRS of the geoid raster, if not stored in the geoid file metadata.
|
|
38
|
+
Optional, defaults to None
|
|
39
|
+
:type geoid_crs: Optional[Union[str, int]]
|
|
35
40
|
|
|
36
41
|
:returns: geoid for the target_rxd region as an xarray DataArray
|
|
37
42
|
:rtype: DataArray"""
|
|
38
43
|
|
|
39
44
|
geoid = rxr.open_rasterio(f"{bm_fpath}")["geoid"]
|
|
40
|
-
|
|
45
|
+
|
|
46
|
+
if geoid_crs is None:
|
|
47
|
+
geoid_crs = geoid.rio.crs
|
|
48
|
+
if geoid_crs is None:
|
|
49
|
+
raise ValueError(
|
|
50
|
+
"Geoid CRS could not be determined from file metadata. "
|
|
51
|
+
"Please provide `geoid_crs` parameter (e.g. 3413 or 'EPSG:3413')."
|
|
52
|
+
)
|
|
53
|
+
|
|
41
54
|
geoid = geoid.squeeze().astype("float32").rio.write_crs(geoid_crs)
|
|
42
55
|
geoid = geoid.rio.reproject_match(
|
|
43
56
|
match_data_array=target_rxd, resampling=Resampling.bilinear
|
|
@@ -46,7 +59,11 @@ def geoid_from_bedmachine(bm_fpath: str, target_rxd: DataArray) -> DataArray:
|
|
|
46
59
|
return geoid.squeeze()
|
|
47
60
|
|
|
48
61
|
|
|
49
|
-
def geoid_from_raster(
|
|
62
|
+
def geoid_from_raster(
|
|
63
|
+
fpath: str,
|
|
64
|
+
target_rxd: DataArray = None,
|
|
65
|
+
geoid_crs: Optional[Union[str, int]] = None,
|
|
66
|
+
) -> DataArray:
|
|
50
67
|
"""Extracts an arbritary geoid stored as a raster dataset, bilinearly resampled to
|
|
51
68
|
match the target dataset.
|
|
52
69
|
|
|
@@ -55,13 +72,24 @@ def geoid_from_raster(fpath: str, target_rxd: DataArray = None) -> DataArray:
|
|
|
55
72
|
:param target_rxd: (rio)xarray dataset/array that the raster will be resampled to
|
|
56
73
|
match. Optional, defaults to None
|
|
57
74
|
:type target_rxd: DataArray
|
|
75
|
+
:param geoid_crs: CRS of the geoid raster, if not stored in the geoid file metadata.
|
|
76
|
+
Optional, defaults to None
|
|
77
|
+
:type geoid_crs: Optional[Union[str, int]]
|
|
58
78
|
|
|
59
79
|
:returns: geoid for the target_rxd region as an xarray DataArray
|
|
60
80
|
:rtype: DataArray
|
|
61
81
|
"""
|
|
62
82
|
|
|
63
83
|
geoid = rxr.open_rasterio(f"{fpath}")
|
|
64
|
-
|
|
84
|
+
|
|
85
|
+
if geoid_crs is None:
|
|
86
|
+
geoid_crs = geoid.rio.crs
|
|
87
|
+
if geoid_crs is None:
|
|
88
|
+
raise ValueError(
|
|
89
|
+
"Geoid CRS could not be determined from file metadata. "
|
|
90
|
+
"Please provide `geoid_crs` parameter (e.g. 3413 or 'EPSG:3413')."
|
|
91
|
+
)
|
|
92
|
+
|
|
65
93
|
geoid = geoid.squeeze().astype("float32").rio.write_crs(geoid_crs)
|
|
66
94
|
|
|
67
95
|
if target_rxd != None:
|
|
@@ -73,7 +101,9 @@ def geoid_from_raster(fpath: str, target_rxd: DataArray = None) -> DataArray:
|
|
|
73
101
|
|
|
74
102
|
|
|
75
103
|
def bedrock_mask_from_vector(
|
|
76
|
-
vector: str | GeoDataFrame,
|
|
104
|
+
vector: str | GeoDataFrame,
|
|
105
|
+
target_rxd: DataArray,
|
|
106
|
+
mask_crs: Optional[Union[str, int]] = None,
|
|
77
107
|
) -> DataArray:
|
|
78
108
|
"""Construct boolean bedrock mask from a Geopandas vector file of bedrock areas and
|
|
79
109
|
a given target rioxarray dataset. Returns mask where bedrock values are 1 and
|
|
@@ -84,6 +114,9 @@ def bedrock_mask_from_vector(
|
|
|
84
114
|
:type vector_fpath: str | GeoDataFrame
|
|
85
115
|
:param target_rxd: (rio)xarray dataset that BedMachine will be resampled to match
|
|
86
116
|
:type target_rxd: DataArray
|
|
117
|
+
:param mask_crs: CRS of the vector file, if not stored in the file metadata.
|
|
118
|
+
Optional, defaults to None
|
|
119
|
+
:type mask_crs: Optional[Union[str, int]]
|
|
87
120
|
|
|
88
121
|
:returns: bedrock mask for the target_rxd region as a (rio)xarray DataArray
|
|
89
122
|
:rtype: DataArray
|
|
@@ -97,12 +130,26 @@ def bedrock_mask_from_vector(
|
|
|
97
130
|
raise ValueError(
|
|
98
131
|
"Input `vector` must be either a filepath string or GeoPandas GeoDataFrame"
|
|
99
132
|
)
|
|
133
|
+
|
|
134
|
+
if mask_crs is None:
|
|
135
|
+
mask_crs = gdf_clip.crs
|
|
136
|
+
if mask_crs is None:
|
|
137
|
+
raise ValueError(
|
|
138
|
+
"Vector CRS could not be determined from file metadata. "
|
|
139
|
+
"Please provide `mask_crs` parameter (e.g. 3413 or 'EPSG:3413')."
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
if gdf_clip.crs != target_rxd.rio.crs:
|
|
143
|
+
gdf_clip = gdf_clip.to_crs(target_rxd.rio.crs)
|
|
144
|
+
|
|
100
145
|
target_rxd = target_rxd.rio.write_nodata(-9999) # Enforce -9999 as nodata value
|
|
101
146
|
target_clip = target_rxd.rio.clip(gdf_clip.geometry.values, drop=False)
|
|
102
147
|
return (target_clip.where(target_clip != -9999) * 0 + 1).fillna(0).squeeze()
|
|
103
148
|
|
|
104
149
|
|
|
105
|
-
def bedrock_mask_from_bedmachine(
|
|
150
|
+
def bedrock_mask_from_bedmachine(
|
|
151
|
+
bm_fpath: str, target_rxd: DataArray, mask_crs: Optional[Union[str, int]] = None
|
|
152
|
+
) -> DataArray:
|
|
106
153
|
"""Construct boolean bedrock mask from bedmachine and a given target rioxarray
|
|
107
154
|
dataset. Returns mask where bedrock values are 1 and outside are 0.
|
|
108
155
|
|
|
@@ -110,6 +157,9 @@ def bedrock_mask_from_bedmachine(bm_fpath: str, target_rxd: DataArray) -> DataAr
|
|
|
110
157
|
:type bm_fpath: str
|
|
111
158
|
:param target_rxd: (rio)xarray dataset that BedMachine will be resampled to match
|
|
112
159
|
:type target_rxd: DataArray
|
|
160
|
+
:param mask_crs: CRS of the BedMachine dataset, if not stored in the file metadata.
|
|
161
|
+
Optional, defaults to None
|
|
162
|
+
:type mask_crs: Optional[Union[str, int]]
|
|
113
163
|
|
|
114
164
|
:returns: bedrock mask for the target_rxd region as a (rio)xarray DataArray
|
|
115
165
|
:rtype: DataArray
|
|
@@ -117,7 +167,13 @@ def bedrock_mask_from_bedmachine(bm_fpath: str, target_rxd: DataArray) -> DataAr
|
|
|
117
167
|
|
|
118
168
|
# Open geoid
|
|
119
169
|
mask = rxr.open_rasterio(f"{bm_fpath}")["mask"]
|
|
120
|
-
mask_crs
|
|
170
|
+
if mask_crs is None:
|
|
171
|
+
mask_crs = mask.rio.crs
|
|
172
|
+
if mask_crs is None:
|
|
173
|
+
raise ValueError(
|
|
174
|
+
"BedMachine CRS could not be determined from file metadata. "
|
|
175
|
+
"Please provide `mask_crs` parameter (e.g. 3413 or 'EPSG:3413')."
|
|
176
|
+
)
|
|
121
177
|
|
|
122
178
|
# Get geoid-projected geometry of the extent of the target dataset,
|
|
123
179
|
# with a bit of a buffer for safety
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
pdemtools/__init__.py,sha256=
|
|
1
|
+
pdemtools/__init__.py,sha256=aOo61W2rtFpdiNWBIc5UWF3GmVMhZkDtvIWPSuLbIqU,368
|
|
2
2
|
pdemtools/_accessor.py,sha256=RNxts9ruziueo3-sZBruU2DmDmaZumBA7Kac9w_Zn3Y,36387
|
|
3
3
|
pdemtools/_coreg.py,sha256=n6idsTsCeATzxrD4foeLJ4-QqUM-4HkfCX8OKIUDY3c,16577
|
|
4
4
|
pdemtools/_geomorphometry.py,sha256=NyGb-z2_ZrEuiwi37zjI7z-J0Zr-Wnt2KMkiVP1NxAw,8739
|
|
5
5
|
pdemtools/_index_search.py,sha256=KLbU1GIezrumL4nMaLe0C074uKThbnprdDnPw2yYLfk,20180
|
|
6
6
|
pdemtools/_utils.py,sha256=Bym7p9yKOy3lHpGGaMEdYxD8dvpZ8CO_MCWXCuc4CRk,2280
|
|
7
|
-
pdemtools/data.py,sha256=
|
|
7
|
+
pdemtools/data.py,sha256=2yIEEC0lIb9MIvyrVIP2yWo64la4sa85uyuXu10SPdU,16023
|
|
8
8
|
pdemtools/load.py,sha256=wrIQ2JOxR-nhms1dDPb6JBh2i5irwsvO4jhTngofwGw,18483
|
|
9
9
|
pdemtools/mosaic_index/ArcticDEM_Mosaic_Index_v3_gpkg.gpkg,sha256=15f2IEo0mnz8LAamm_UG_x_2e0q7k8HnVd_dUSg_O3Y,8540160
|
|
10
10
|
pdemtools/mosaic_index/ArcticDEM_Mosaic_Index_v4_1_gpkg.gpkg,sha256=vDrBdlLtmy0dcKYvaORCOWTkWzYtwK5B3JnQiCThL8s,8552448
|
|
11
11
|
pdemtools/mosaic_index/REMA_Mosaic_Index_v2_gpkg.gpkg,sha256=HrRKp5lWpbCOmpHwANHSVc_eO0qo11J42CGuQEmmUQc,5177344
|
|
12
12
|
pdemtools/test_data/test_arcticdem_index_kiv_steenstrup.parquet,sha256=Nzg3HXPbef4VgrnZXiAAa8RxmhBcFoqMNiFpm3_u99Y,91756
|
|
13
|
-
pdemtools-1.1.
|
|
14
|
-
pdemtools-1.1.
|
|
15
|
-
pdemtools-1.1.
|
|
16
|
-
pdemtools-1.1.
|
|
17
|
-
pdemtools-1.1.
|
|
13
|
+
pdemtools-1.2.1.dist-info/licenses/LICENSE.md,sha256=JbOkncS9jKLCvDWUpTApk8QhBLtfy-pRs74Gw6mVVPk,1068
|
|
14
|
+
pdemtools-1.2.1.dist-info/METADATA,sha256=5MwKCDVuR09m0l2z5paR-1OEOo1Grk9rCW9nqDEkXzQ,7214
|
|
15
|
+
pdemtools-1.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
+
pdemtools-1.2.1.dist-info/top_level.txt,sha256=nTm0PsXQSEKsrI9f5XKoiQor9c_pLGgxuuWt5l425GM,10
|
|
17
|
+
pdemtools-1.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|