Skip to content

Commit

Permalink
fixed point distibution for the poles
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsail committed Jul 18, 2024
1 parent a017890 commit e2e4fda
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
6 changes: 3 additions & 3 deletions oceanmesh/geodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,9 @@ 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
) # set the no-data value to 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

0 comments on commit e2e4fda

Please sign in to comment.