pdemtools 1.1.1__py3-none-any.whl → 1.2.0__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 +65 -7
- pdemtools/load.py +1 -1
- {pdemtools-1.1.1.dist-info → pdemtools-1.2.0.dist-info}/METADATA +1 -1
- {pdemtools-1.1.1.dist-info → pdemtools-1.2.0.dist-info}/RECORD +8 -8
- {pdemtools-1.1.1.dist-info → pdemtools-1.2.0.dist-info}/WHEEL +0 -0
- {pdemtools-1.1.1.dist-info → pdemtools-1.2.0.dist-info}/licenses/LICENSE.md +0 -0
- {pdemtools-1.1.1.dist-info → pdemtools-1.2.0.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,25 @@ 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"]
|
|
45
|
+
|
|
40
46
|
geoid_crs = geoid.rio.crs
|
|
47
|
+
|
|
48
|
+
if geoid_crs is None:
|
|
49
|
+
geoid_crs = geoid.rio.crs
|
|
50
|
+
if geoid_crs is None:
|
|
51
|
+
raise ValueError(
|
|
52
|
+
"Geoid CRS could not be determined from file metadata. "
|
|
53
|
+
"Please provide `geoid_crs` parameter (e.g. 3413 or 'EPSG:3413')."
|
|
54
|
+
)
|
|
55
|
+
|
|
41
56
|
geoid = geoid.squeeze().astype("float32").rio.write_crs(geoid_crs)
|
|
42
57
|
geoid = geoid.rio.reproject_match(
|
|
43
58
|
match_data_array=target_rxd, resampling=Resampling.bilinear
|
|
@@ -46,7 +61,11 @@ def geoid_from_bedmachine(bm_fpath: str, target_rxd: DataArray) -> DataArray:
|
|
|
46
61
|
return geoid.squeeze()
|
|
47
62
|
|
|
48
63
|
|
|
49
|
-
def geoid_from_raster(
|
|
64
|
+
def geoid_from_raster(
|
|
65
|
+
fpath: str,
|
|
66
|
+
target_rxd: DataArray = None,
|
|
67
|
+
geoid_crs: Optional[Union[str, int]] = None,
|
|
68
|
+
) -> DataArray:
|
|
50
69
|
"""Extracts an arbritary geoid stored as a raster dataset, bilinearly resampled to
|
|
51
70
|
match the target dataset.
|
|
52
71
|
|
|
@@ -55,13 +74,24 @@ def geoid_from_raster(fpath: str, target_rxd: DataArray = None) -> DataArray:
|
|
|
55
74
|
:param target_rxd: (rio)xarray dataset/array that the raster will be resampled to
|
|
56
75
|
match. Optional, defaults to None
|
|
57
76
|
:type target_rxd: DataArray
|
|
77
|
+
:param geoid_crs: CRS of the geoid raster, if not stored in the geoid file metadata.
|
|
78
|
+
Optional, defaults to None
|
|
79
|
+
:type geoid_crs: Optional[Union[str, int]]
|
|
58
80
|
|
|
59
81
|
:returns: geoid for the target_rxd region as an xarray DataArray
|
|
60
82
|
:rtype: DataArray
|
|
61
83
|
"""
|
|
62
84
|
|
|
63
85
|
geoid = rxr.open_rasterio(f"{fpath}")
|
|
64
|
-
|
|
86
|
+
|
|
87
|
+
if geoid_crs is None:
|
|
88
|
+
geoid_crs = geoid.rio.crs
|
|
89
|
+
if geoid_crs is None:
|
|
90
|
+
raise ValueError(
|
|
91
|
+
"Geoid CRS could not be determined from file metadata. "
|
|
92
|
+
"Please provide `geoid_crs` parameter (e.g. 3413 or 'EPSG:3413')."
|
|
93
|
+
)
|
|
94
|
+
|
|
65
95
|
geoid = geoid.squeeze().astype("float32").rio.write_crs(geoid_crs)
|
|
66
96
|
|
|
67
97
|
if target_rxd != None:
|
|
@@ -73,7 +103,9 @@ def geoid_from_raster(fpath: str, target_rxd: DataArray = None) -> DataArray:
|
|
|
73
103
|
|
|
74
104
|
|
|
75
105
|
def bedrock_mask_from_vector(
|
|
76
|
-
vector: str | GeoDataFrame,
|
|
106
|
+
vector: str | GeoDataFrame,
|
|
107
|
+
target_rxd: DataArray,
|
|
108
|
+
mask_crs: Optional[Union[str, int]] = None,
|
|
77
109
|
) -> DataArray:
|
|
78
110
|
"""Construct boolean bedrock mask from a Geopandas vector file of bedrock areas and
|
|
79
111
|
a given target rioxarray dataset. Returns mask where bedrock values are 1 and
|
|
@@ -84,6 +116,9 @@ def bedrock_mask_from_vector(
|
|
|
84
116
|
:type vector_fpath: str | GeoDataFrame
|
|
85
117
|
:param target_rxd: (rio)xarray dataset that BedMachine will be resampled to match
|
|
86
118
|
:type target_rxd: DataArray
|
|
119
|
+
:param mask_crs: CRS of the vector file, if not stored in the file metadata.
|
|
120
|
+
Optional, defaults to None
|
|
121
|
+
:type mask_crs: Optional[Union[str, int]]
|
|
87
122
|
|
|
88
123
|
:returns: bedrock mask for the target_rxd region as a (rio)xarray DataArray
|
|
89
124
|
:rtype: DataArray
|
|
@@ -97,12 +132,26 @@ def bedrock_mask_from_vector(
|
|
|
97
132
|
raise ValueError(
|
|
98
133
|
"Input `vector` must be either a filepath string or GeoPandas GeoDataFrame"
|
|
99
134
|
)
|
|
135
|
+
|
|
136
|
+
if mask_crs is None:
|
|
137
|
+
mask_crs = gdf_clip.crs
|
|
138
|
+
if mask_crs is None:
|
|
139
|
+
raise ValueError(
|
|
140
|
+
"Vector CRS could not be determined from file metadata. "
|
|
141
|
+
"Please provide `mask_crs` parameter (e.g. 3413 or 'EPSG:3413')."
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
if gdf_clip.crs != target_rxd.rio.crs:
|
|
145
|
+
gdf_clip = gdf_clip.to_crs(target_rxd.rio.crs)
|
|
146
|
+
|
|
100
147
|
target_rxd = target_rxd.rio.write_nodata(-9999) # Enforce -9999 as nodata value
|
|
101
148
|
target_clip = target_rxd.rio.clip(gdf_clip.geometry.values, drop=False)
|
|
102
149
|
return (target_clip.where(target_clip != -9999) * 0 + 1).fillna(0).squeeze()
|
|
103
150
|
|
|
104
151
|
|
|
105
|
-
def bedrock_mask_from_bedmachine(
|
|
152
|
+
def bedrock_mask_from_bedmachine(
|
|
153
|
+
bm_fpath: str, target_rxd: DataArray, mask_crs: Optional[Union[str, int]] = None
|
|
154
|
+
) -> DataArray:
|
|
106
155
|
"""Construct boolean bedrock mask from bedmachine and a given target rioxarray
|
|
107
156
|
dataset. Returns mask where bedrock values are 1 and outside are 0.
|
|
108
157
|
|
|
@@ -110,6 +159,9 @@ def bedrock_mask_from_bedmachine(bm_fpath: str, target_rxd: DataArray) -> DataAr
|
|
|
110
159
|
:type bm_fpath: str
|
|
111
160
|
:param target_rxd: (rio)xarray dataset that BedMachine will be resampled to match
|
|
112
161
|
:type target_rxd: DataArray
|
|
162
|
+
:param mask_crs: CRS of the BedMachine dataset, if not stored in the file metadata.
|
|
163
|
+
Optional, defaults to None
|
|
164
|
+
:type mask_crs: Optional[Union[str, int]]
|
|
113
165
|
|
|
114
166
|
:returns: bedrock mask for the target_rxd region as a (rio)xarray DataArray
|
|
115
167
|
:rtype: DataArray
|
|
@@ -117,7 +169,13 @@ def bedrock_mask_from_bedmachine(bm_fpath: str, target_rxd: DataArray) -> DataAr
|
|
|
117
169
|
|
|
118
170
|
# Open geoid
|
|
119
171
|
mask = rxr.open_rasterio(f"{bm_fpath}")["mask"]
|
|
120
|
-
mask_crs
|
|
172
|
+
if mask_crs is None:
|
|
173
|
+
mask_crs = mask.rio.crs
|
|
174
|
+
if mask_crs is None:
|
|
175
|
+
raise ValueError(
|
|
176
|
+
"BedMachine CRS could not be determined from file metadata. "
|
|
177
|
+
"Please provide `mask_crs` parameter (e.g. 3413 or 'EPSG:3413')."
|
|
178
|
+
)
|
|
121
179
|
|
|
122
180
|
# Get geoid-projected geometry of the extent of the target dataset,
|
|
123
181
|
# with a bit of a buffer for safety
|
pdemtools/load.py
CHANGED
|
@@ -403,7 +403,7 @@ def mosaic(
|
|
|
403
403
|
|
|
404
404
|
if len(tiles) < 1:
|
|
405
405
|
raise ValueError(
|
|
406
|
-
f"No {dataset} mosaic tiles found to intersect with bounds {
|
|
406
|
+
f"No {dataset} mosaic tiles found to intersect with bounds {bounds}"
|
|
407
407
|
)
|
|
408
408
|
|
|
409
409
|
# get aws filepaths from the tiles dataframe
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
pdemtools/__init__.py,sha256=
|
|
1
|
+
pdemtools/__init__.py,sha256=IOaQkVDZ-SJ4IEvAqeUzz9eadcKQLeoHGzHnFyxOvVQ,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=
|
|
8
|
-
pdemtools/load.py,sha256=
|
|
7
|
+
pdemtools/data.py,sha256=WAvFAuu0JFv8yNkv89yhfxFG71fizVS5NaCGtkqjIPo,16054
|
|
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.
|
|
14
|
-
pdemtools-1.
|
|
15
|
-
pdemtools-1.
|
|
16
|
-
pdemtools-1.
|
|
17
|
-
pdemtools-1.
|
|
13
|
+
pdemtools-1.2.0.dist-info/licenses/LICENSE.md,sha256=JbOkncS9jKLCvDWUpTApk8QhBLtfy-pRs74Gw6mVVPk,1068
|
|
14
|
+
pdemtools-1.2.0.dist-info/METADATA,sha256=Hc6dgAadQ5oiKIFUH4I2Oqf7NODRY1StvQdhW9XpYJ0,7214
|
|
15
|
+
pdemtools-1.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
+
pdemtools-1.2.0.dist-info/top_level.txt,sha256=nTm0PsXQSEKsrI9f5XKoiQor9c_pLGgxuuWt5l425GM,10
|
|
17
|
+
pdemtools-1.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|