Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added parametric law for stereo distortion (north pole) #76

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions oceanmesh/geodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,7 @@ def __init__(self, dem, crs="EPSG:4326", bbox=None, extrapolate=False):
topobathy = np.transpose(topobathy, (1, 0))
# Ensure its a floating point array
topobathy = topobathy.astype(np.float64)
topobathy[
topobathy == nodata_value
] = np.nan # set the no-data value to nan
topobathy[topobathy == nodata_value] = np.nan
elif not dem.exists():
raise FileNotFoundError(f"File {dem} could not be located.")

Expand Down
1 change: 1 addition & 0 deletions oceanmesh/idw.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" invdisttree.py: inverse-distance-weighted interpolation using KDTree
fast, solid, local
"""

from __future__ import division

import numpy as np
Expand Down
29 changes: 13 additions & 16 deletions oceanmesh/mesh_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,39 +678,36 @@ def _deps_vec(i):
return p


def _stereo_distortion(lat):
# we use here Stereographic projection of the sphere
# from the north pole onto the plane
# https://en.wikipedia.org/wiki/Stereographic_projection
lat0 = 90
ll = lat + lat0
lrad = ll / 180 * np.pi
res = 2 / (1 + np.sin(lrad))
return res


def _stereo_distortion_dist(lat):
lrad = np.radians(lat)
# Calculate the scale factor for the stereographic projection
res = 2 / (1 + np.sin(lrad)) / 180 * np.pi
return res


def _edge_length_wgs84(lat):
lrad = np.radians(lat)
return 1 / np.cos(lrad) ** (1 / 2)


def _generate_initial_points(min_edge_length, geps, bbox, fh, fd, pfix, stereo=False):
"""Create initial distribution in bounding box (equilateral triangles)"""
if stereo:
bbox = np.array([[-180, 180], [-89, 89]])
p = np.mgrid[
tuple(slice(min, max + min_edge_length, min_edge_length) for min, max in bbox)
].astype(float)
bbox = np.array([[-180, 180], [-90, 90]])
p = np.mgrid[tuple(slice(min, max, min_edge_length) for min, max in bbox)].astype(
float
)
if stereo:
# for global meshes in stereographic projections,
# we need to reproject the points from lon/lat to stereo projection
# then, we need to rectify their coordinates to lat/lon for the sizing function
p += (
np.random.rand(*p.shape) * min_edge_length / 2
) # randomise the distribution
p0 = p.reshape(2, -1).T
x, y = to_stereo(p0[:, 0], p0[:, 1])
p = np.asarray([x, y]).T
r0 = fh(to_lat_lon(p[:, 0], p[:, 1])) * _stereo_distortion(p0[:, 1])
r0 = fh(to_lat_lon(x, y)) * _edge_length_wgs84(p0[:, 1])
else:
p = p.reshape(2, -1).T
r0 = fh(p)
Expand Down
Loading