pdemtools 1.1.2__tar.gz → 1.2.1__tar.gz

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.
Files changed (25) hide show
  1. {pdemtools-1.1.2/src/pdemtools.egg-info → pdemtools-1.2.1}/PKG-INFO +1 -1
  2. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/__init__.py +1 -1
  3. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/data.py +64 -8
  4. {pdemtools-1.1.2 → pdemtools-1.2.1/src/pdemtools.egg-info}/PKG-INFO +1 -1
  5. {pdemtools-1.1.2 → pdemtools-1.2.1}/LICENSE.md +0 -0
  6. {pdemtools-1.1.2 → pdemtools-1.2.1}/README.md +0 -0
  7. {pdemtools-1.1.2 → pdemtools-1.2.1}/pyproject.toml +0 -0
  8. {pdemtools-1.1.2 → pdemtools-1.2.1}/setup.cfg +0 -0
  9. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/_accessor.py +0 -0
  10. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/_coreg.py +0 -0
  11. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/_geomorphometry.py +0 -0
  12. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/_index_search.py +0 -0
  13. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/_utils.py +0 -0
  14. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/load.py +0 -0
  15. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/mosaic_index/ArcticDEM_Mosaic_Index_v3_gpkg.gpkg +0 -0
  16. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/mosaic_index/ArcticDEM_Mosaic_Index_v4_1_gpkg.gpkg +0 -0
  17. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/mosaic_index/REMA_Mosaic_Index_v2_gpkg.gpkg +0 -0
  18. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools/test_data/test_arcticdem_index_kiv_steenstrup.parquet +0 -0
  19. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools.egg-info/SOURCES.txt +0 -0
  20. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools.egg-info/dependency_links.txt +0 -0
  21. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools.egg-info/requires.txt +0 -0
  22. {pdemtools-1.1.2 → pdemtools-1.2.1}/src/pdemtools.egg-info/top_level.txt +0 -0
  23. {pdemtools-1.1.2 → pdemtools-1.2.1}/tests/test_download.py +0 -0
  24. {pdemtools-1.1.2 → pdemtools-1.2.1}/tests/test_processing.py +0 -0
  25. {pdemtools-1.1.2 → pdemtools-1.2.1}/tests/test_search.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pdemtools
3
- Version: 1.1.2
3
+ Version: 1.2.1
4
4
  Summary: Conveniently search, download, and preprocess ArcticDEM and REMA products.
5
5
  Author-email: Tom Chudley <thomas.r.chudley@durham.ac.uk>
6
6
  License: MIT
@@ -13,6 +13,6 @@ from . import _coreg
13
13
  from . import _geomorphometry
14
14
  from . import _utils
15
15
 
16
- __version__ = "1.1.2"
16
+ __version__ = "1.2.1"
17
17
 
18
18
  __all__ = ["search", "DemAccessor"]
@@ -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, Literal
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(bm_fpath: str, target_rxd: DataArray) -> DataArray:
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
- geoid_crs = geoid.rio.crs
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(fpath: str, target_rxd: DataArray = None) -> DataArray:
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
- geoid_crs = geoid.rio.crs
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, target_rxd: DataArray
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(bm_fpath: str, target_rxd: DataArray) -> DataArray:
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 = mask.rio.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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pdemtools
3
- Version: 1.1.2
3
+ Version: 1.2.1
4
4
  Summary: Conveniently search, download, and preprocess ArcticDEM and REMA products.
5
5
  Author-email: Tom Chudley <thomas.r.chudley@durham.ac.uk>
6
6
  License: MIT
File without changes
File without changes
File without changes
File without changes