Skip to content

Commit 9050724

Browse files
authored
coastlines and tide stations (#51)
* coastlines and tide stations * add fiona to deps * ruff format
1 parent 047a21a commit 9050724

5 files changed

Lines changed: 370 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies = [
2828
'numpy>1.24',
2929
'pyproj>3.6.1',
3030
'rasterio>1.4.0',
31+
'fiona',
3132
'fetchez>=0.5.0',
3233
'scipy',
3334
'click',

src/transformez/api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def generate_grid(
116116
decay_pixels: int = 100,
117117
out_fn: Optional[str] = None,
118118
cache_dir: Optional[str] = None,
119+
use_stations: bool = False,
119120
verbose: bool = False,
120121
) -> Optional[np.ndarray]:
121122
"""Generate a vertical shift grid for a specific region.
@@ -168,6 +169,7 @@ def generate_grid(
168169
geoid_out=geoid_out,
169170
decay_pixels=decay_pixels,
170171
cache_dir=cache_dir,
172+
use_stations=use_stations,
171173
verbose=verbose,
172174
)
173175

@@ -193,6 +195,7 @@ def transform_raster(
193195
cache_dir: Optional[str] = None,
194196
z_unit_in: Optional[str] = "auto",
195197
z_unit_out: Optional[str] = "auto",
198+
use_stations: bool = False,
196199
verbose: bool = False,
197200
) -> Optional[str]:
198201
"""Apply a vertical datum transformation directly to an existing raster file.
@@ -253,6 +256,7 @@ def transform_raster(
253256
geoid_out=geoid_out,
254257
decay_pixels=decay_pixels,
255258
cache_dir=cache_dir,
259+
use_stations=use_stations,
256260
verbose=verbose,
257261
)
258262

src/transformez/cli.py

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,22 @@ def transformez_cli():
6868
default=100,
6969
help="Number of pixels to decay tidal shifts inland.",
7070
)
71+
@click.option(
72+
"--use-stations",
73+
is_flag=True,
74+
help="Force RBF interpolation using live tide stations instead of global satellite models.",
75+
)
7176
@click.option("--preview", is_flag=True, help="Preview the transformation output.")
7277
def transform_run(
73-
input_file, region, increment, input_datum, output_datum, out, decay_pixels, preview
78+
input_file,
79+
region,
80+
increment,
81+
input_datum,
82+
output_datum,
83+
out,
84+
decay_pixels,
85+
use_stations,
86+
preview,
7487
):
7588
"""Transform a raster's vertical datum or generate a standalone shift grid.
7689
@@ -92,6 +105,7 @@ def transform_run(
92105
datum_out=output_datum,
93106
decay_pixels=decay_pixels,
94107
output_raster=out,
108+
use_stations=use_stations,
95109
verbose=True,
96110
)
97111

@@ -162,11 +176,23 @@ def transform_run(
162176
@click.option(
163177
"--decay-pixels", type=int, default=100, help="Pixels to decay tidal shifts inland."
164178
)
179+
@click.option(
180+
"--use-stations",
181+
is_flag=True,
182+
help="Force RBF interpolation using live tide stations instead of global satellite models.",
183+
)
165184
@click.option(
166185
"--preview", is_flag=True, help="Show matplotlib preview instead of saving."
167186
)
168187
def transform_grid(
169-
region, increment, input_datum, output_datum, out, decay_pixels, preview
188+
region,
189+
increment,
190+
input_datum,
191+
output_datum,
192+
out,
193+
decay_pixels,
194+
use_stations,
195+
preview,
170196
):
171197
"""Generate a standalone vertical shift grid for a specified region."""
172198

@@ -187,6 +213,7 @@ def transform_grid(
187213
datum_out=output_datum,
188214
decay_pixels=decay_pixels,
189215
out_fn=out_fn,
216+
use_stations=use_stations,
190217
verbose=True,
191218
)
192219

@@ -227,8 +254,20 @@ def transform_grid(
227254
@click.option(
228255
"--decay-pixels", type=int, default=100, help="Pixels to decay tidal shifts inland."
229256
)
257+
@click.option(
258+
"--use-stations",
259+
is_flag=True,
260+
help="Force RBF interpolation using live tide stations instead of global satellite models.",
261+
)
230262
def transform_raster(
231-
input_file, input_datum, output_datum, in_units, out_units, out, decay_pixels
263+
input_file,
264+
input_datum,
265+
output_datum,
266+
in_units,
267+
out_units,
268+
out,
269+
decay_pixels,
270+
use_stations,
232271
):
233272
"""Apply a vertical datum shift (and optional unit conversion) to an existing DEM."""
234273

@@ -243,6 +282,7 @@ def transform_raster(
243282
output_raster=out,
244283
z_unit_in=in_units,
245284
z_unit_out=out_units,
285+
use_stations=use_stations,
246286
verbose=True,
247287
)
248288

@@ -253,27 +293,24 @@ def transform_raster(
253293
sys.exit(1)
254294

255295

296+
# --- LIST DATUMS, ETC. ---
256297
@transformez_cli.command("list")
257298
def transform_list():
258299
"""List all supported vertical datums, EPSG codes, and geoids."""
259300
try:
260301
from transformez.definitions import Datums
261302

262303
click.secho("\n🌊 Supported Tidal Surfaces:", fg="cyan", bold=True)
263-
# For tidal datums, the user types the dictionary key (e.g., 'mllw')
264304
for key, v in Datums.SURFACES.items():
265305
region_str = v.get("region", "global").upper()
266306
click.echo(f" {key:<12} : {v.get('name', key):<30} [{region_str}]")
267307

268308
click.secho("\n🌐 Ellipsoidal / Frame Datums (EPSG):", fg="cyan", bold=True)
269-
# For ellipsoidal, explicitly list the EPSG codes
270309
click.echo(f" {'4979':<12} : WGS84 - World Geodetic System 1984")
271310
click.echo(f" {'6319':<12} : NAD83 - North American Datum 1983")
272311

273312
click.secho("\n🏔️ Orthometric / Geoid-Based (EPSG):", fg="cyan", bold=True)
274-
# For orthometric, the key in Datums.CDN is typically the EPSG code (e.g., '5703')
275313
for epsg_key, v in Datums.CDN.items():
276-
# Fallback to the key if 'epsg' isn't explicitly defined in the dict
277314
epsg_code = v.get("epsg", epsg_key)
278315
geoid_str = v.get("default_geoid", "None")
279316
click.echo(
@@ -283,6 +320,26 @@ def transform_list():
283320
click.secho("\n🌍 Available Geoids:", fg="cyan", bold=True)
284321
click.echo(f" {', '.join(Datums.GEOIDS.keys())}")
285322

323+
# ---> HIERARCHY DOCUMENTATION <---
324+
click.secho(
325+
"\n🔄 Dynamic Fallback Hierarchy (Coastal/Tidal):", fg="magenta", bold=True
326+
)
327+
click.echo(
328+
" 1. NOAA VDatum : High-res regional hydrodynamics (USA Base)."
329+
)
330+
click.echo(
331+
" 2. FES2014 / Global : Satellite altimetry proxy for offshore/international."
332+
)
333+
click.echo(
334+
" 3. Tide Station RBF : Live CO-OPS splines (Activated via --use-stations)."
335+
)
336+
click.echo(
337+
" 4. Constant Offset : Safety fallback for sparse coverage (< 3 stations)."
338+
)
339+
click.echo(
340+
" 5. Inland Decay : Vector-masked spatial decay for rivers/estuaries going inland."
341+
)
342+
286343
click.secho("\n💡 Pro-Tip:", fg="yellow", bold=True, nl=False)
287344
click.echo(
288345
" Combine an EPSG and a specific Geoid using a colon (e.g., -O 5703:g2012b)\n"

0 commit comments

Comments
 (0)