Skip to content

Commit

Permalink
rebrand zfactor to zscale (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle committed May 24, 2023
1 parent e058479 commit 9a0601c
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 136 deletions.
64 changes: 32 additions & 32 deletions src/geovista/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
GV_FIELD_NAME,
GV_FIELD_RADIUS,
RADIUS,
ZLEVEL_FACTOR,
ZLEVEL_SCALE,
nan_mask,
to_spherical,
wrap,
Expand Down Expand Up @@ -349,8 +349,8 @@ def from_1d(
name: str | None = None,
crs: CRSLike | None = None,
radius: float | None = None,
zfactor: float | None = None,
zlevel: int | None = None,
zscale: float | None = None,
clean: bool | None = None,
) -> pv.PolyData:
"""Build a quad-faced mesh from contiguous 1-D x-values and y-values.
Expand Down Expand Up @@ -388,12 +388,12 @@ def from_1d(
to ``EPSG:4326`` i.e., ``WGS 84``.
radius : float, optional
The radius of the sphere. Defaults to :data:`geovista.common.RADIUS`.
zfactor : float, optional
The proportional multiplier for z-axis levels/offsets. Defaults
to :data:`geovista.common.ZLEVEL_FACTOR`.
zlevel : int, default=0
The z-axis level. Used in combination with the `zfactor` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zfactor``.
The z-axis level. Used in combination with the `zscale` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zscale``.
zscale : float, optional
The proportional multiplier for z-axis `zlevel`. Defaults to
:data:`geovista.common.ZLEVEL_SCALE`.
clean : bool, optional
Specify whether to merge duplicate points, remove unused points,
and/or remove degenerate cells in the resultant mesh. Defaults to
Expand All @@ -418,8 +418,8 @@ def from_1d(
name=name,
crs=crs,
radius=radius,
zfactor=zfactor,
zlevel=zlevel,
zscale=zscale,
clean=clean,
)

Expand All @@ -432,8 +432,8 @@ def from_2d(
name: str | None = None,
crs: CRSLike | None = None,
radius: float | None = None,
zfactor: float | None = None,
zlevel: int | None = None,
zscale: float | None = None,
clean: bool | None = None,
) -> pv.PolyData:
"""Build a quad-faced mesh from 2-D x-values and y-values.
Expand Down Expand Up @@ -472,12 +472,12 @@ def from_2d(
to ``EPSG:4326`` i.e., ``WGS 84``.
radius : float, optional
The radius of the sphere. Defaults to :data:`geovista.common.RADIUS`.
zfactor : float, optional
The proportional multiplier for z-axis levels/offsets. Defaults
to :data:`geovista.common.ZLEVEL_FACTOR`.
zlevel : int, default=0
The z-axis level. Used in combination with the `zfactor` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zfactor``.
The z-axis level. Used in combination with the `zscale` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zscale``.
zscale : float, optional
The proportional multiplier for z-axis `zlevel`. Defaults to
:data:`geovista.common.ZLEVEL_SCALE`.
clean : bool, optional
Specify whether to merge duplicate points, remove unused points,
and/or remove degenerate cells in the resultant mesh. Defaults to
Expand Down Expand Up @@ -521,8 +521,8 @@ def from_2d(
name=name,
crs=crs,
radius=radius,
zfactor=zfactor,
zlevel=zlevel,
zscale=zscale,
clean=clean,
)

Expand All @@ -537,8 +537,8 @@ def from_unstructured(
name: ArrayLike | None = None,
crs: CRSLike | None = None,
radius: float | None = None,
zfactor: float | None = None,
zlevel: int | None = None,
zscale: float | None = None,
clean: bool | None = None,
) -> pv.PolyData:
"""Build a mesh from unstructured 1-D x-values and y-values.
Expand Down Expand Up @@ -591,12 +591,12 @@ def from_unstructured(
to ``EPSG:4326`` i.e., ``WGS 84``.
radius : float, optional
The radius of the mesh sphere. Defaults to :data:`geovista.common.RADIUS`.
zfactor : float, optional
The proportional multiplier for z-axis levels/offsets. Defaults
to :data:`geovista.common.ZLEVEL_FACTOR`.
zlevel : int, default=0
The z-axis level. Used in combination with the `zfactor` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zfactor``.
The z-axis level. Used in combination with the `zscale` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zscale``.
zscale : float, optional
The proportional multiplier for z-axis `zlevel`. Defaults to
:data:`geovista.common.ZLEVEL_SCALE`.
clean : bool, optional
Specify whether to merge duplicate points, remove unused points,
and/or remove degenerate cells in the resultant mesh. Defaults to
Expand Down Expand Up @@ -687,9 +687,9 @@ def from_unstructured(
xs[poles] = 0

radius = RADIUS if radius is None else abs(float(radius))
zfactor = ZLEVEL_FACTOR if zfactor is None else float(zfactor)
zscale = ZLEVEL_SCALE if zscale is None else float(zscale)
zlevel = 0 if zlevel is None else int(zlevel)
radius += radius * zlevel * zfactor
radius += radius * zlevel * zscale

# convert lat/lon to cartesian xyz
geometry = to_spherical(xs, ys, radius=radius)
Expand Down Expand Up @@ -770,8 +770,8 @@ def __init__(
start_index: int | None = None,
crs: ArrayLike | None = None,
radius: float | None = None,
zfactor: float | None = None,
zlevel: int | None = None,
zscale: float | None = None,
clean: bool | None = None,
):
"""Build a mesh from spatial points, connectivity, data and CRS metadata.
Expand Down Expand Up @@ -811,12 +811,12 @@ def __init__(
to ``EPSG:4326`` i.e., ``WGS 84``.
radius : float, optional
The radius of the mesh sphere. Defaults to :data:`geovista.common.RADIUS`.
zfactor : float, optional
The proportional multiplier for z-axis levels/offsets. Defaults
to :data:`geovista.common.ZLEVEL_FACTOR`.
zlevel : int, default=0
The z-axis level. Used in combination with the `zfactor` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zfactor``.
The z-axis level. Used in combination with the `zscale` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zscale``.
zscale : float, optional
The proportional multiplier for z-axis `zlevel`. Defaults to
:data:`geovista.common.ZLEVEL_SCALE`.
clean : bool, optional
Specify whether to merge duplicate points, remove unused points,
and/or remove degenerate cells in the resultant mesh. Defaults to
Expand All @@ -836,8 +836,8 @@ def __init__(
ys,
crs=crs,
radius=radius,
zfactor=zfactor,
zlevel=zlevel,
zscale=zscale,
clean=clean,
)
else:
Expand All @@ -846,8 +846,8 @@ def __init__(
ys,
crs=crs,
radius=radius,
zfactor=zfactor,
zlevel=zlevel,
zscale=zscale,
clean=clean,
)
else:
Expand All @@ -859,8 +859,8 @@ def __init__(
crs=crs,
radius=radius,
clean=clean,
zfactor=zfactor,
zlevel=zlevel,
zscale=zscale,
)

self._mesh = mesh
Expand Down
4 changes: 2 additions & 2 deletions src/geovista/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"REMESH_SEAM",
"VTK_CELL_IDS",
"VTK_POINT_IDS",
"ZLEVEL_FACTOR",
"ZLEVEL_SCALE",
"distance",
"from_spherical",
"nan_mask",
Expand Down Expand Up @@ -112,7 +112,7 @@
WRAP_RTOL: float = 1e-5

#: Proportional multiplier for z-axis levels/offsets.
ZLEVEL_FACTOR: float = 1e-4
ZLEVEL_SCALE: float = 1e-4


def active_kernel() -> bool:
Expand Down
18 changes: 9 additions & 9 deletions src/geovista/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
RADIUS,
REMESH_JOIN,
REMESH_SEAM,
ZLEVEL_FACTOR,
ZLEVEL_SCALE,
distance,
from_spherical,
sanitize_data,
Expand Down Expand Up @@ -604,8 +604,8 @@ def is_projected(mesh: pv.PolyData) -> bool:
def resize(
mesh: pv.PolyData,
radius: float | None = None,
zfactor: float | None = None,
zlevel: int | None = None,
zscale: float | None = None,
inplace: bool | None = False,
) -> pv.PolyData:
"""Change the radius of the spherical mesh.
Expand All @@ -616,12 +616,12 @@ def resize(
The mesh to be resized to the provided ``radius``.
radius : float, optional
The target radius of the ``mesh``. Defaults to :data:`geovista.common.RADIUS`.
zfactor : float, optional
The magnitude factor for the z-axis level (`zlevel`). Defaults to
:data:`geovista.common.ZLEVEL_FACTOR`.
zlevel : int, default=0
The z-axis level. Used in combination with the `zfactor` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zfactor``.
The z-axis level. Used in combination with the `zscale` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zscale``.
zscale : float, optional
The proportional multiplier for z-axis `zlevel`. Defaults to
:data:`geovista.common.ZLEVEL_SCALE`.
inplace : boolean, default=False
Update `mesh` in-place.
Expand All @@ -640,9 +640,9 @@ def resize(
raise ValueError(emsg)

radius = RADIUS if radius is None else abs(float(radius))
zfactor = ZLEVEL_FACTOR if zfactor is None else float(zfactor)
zscale = ZLEVEL_SCALE if zscale is None else float(zscale)
zlevel = 0 if zlevel is None else int(zlevel)
radius += radius * zlevel * zfactor
radius += radius * zlevel * zscale

if radius and not np.isclose(distance(mesh), radius):
lonlat = from_spherical(mesh)
Expand Down
31 changes: 19 additions & 12 deletions src/geovista/geodesic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
import pyproj
import pyvista as pv

from .common import RADIUS, ZLEVEL_FACTOR, distance, to_spherical, wrap
from .common import RADIUS, ZLEVEL_SCALE, distance, to_spherical, wrap
from .filters import cast_UnstructuredGrid_to_PolyData

__all__ = ["BBox", "line", "npoints", "npoints_by_idx", "panel", "wedge"]
__all__ = [
"BBox",
"GEODESIC_NPTS",
"line",
"npoints",
"npoints_by_idx",
"panel",
"wedge",
]

# Type aliases
Corners = tuple[float, float, float, float]
Expand Down Expand Up @@ -466,8 +474,7 @@ def boundary(
"""
self._generate_bbox_mesh(surface=surface, radius=radius)

# TODO: address "fudge-factor" z-level
radius = self._surface_radius + self._surface_radius * ZLEVEL_FACTOR
radius = self._surface_radius + self._surface_radius * ZLEVEL_SCALE

edge_idxs = self._bbox_face_edge_idxs()
edge_lons = self._bbox_lons[edge_idxs]
Expand Down Expand Up @@ -602,8 +609,8 @@ def line(
npts: int | None = None,
ellps: str | None = None,
close: bool | None = False,
zfactor: float | None = None,
zlevel: int | None = None,
zscale: float | None = None,
) -> pv.PolyData:
"""Geodesic line consisting of one or more connected geodesic line segments.
Expand Down Expand Up @@ -635,12 +642,12 @@ def line(
close : bool, default=False
Whether to close the geodesic line segments into a loop i.e., the last
point is connected to the first point.
zfactor : float, optional
The magnitude factor for the z-axis level (`zlevel`). Defaults to
:data:`geovista.common.ZLEVEL_FACTOR`.
zlevel : int, default=1
The z-axis level. Used in combination with the `zfactor` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zfactor``.
The z-axis level. Used in combination with the `zscale` to offset the
`radius` by a proportional amount i.e., ``radius * zlevel * zscale``.
zscale : float, optional
The proportional multiplier for z-axis `zlevel`. Defaults to
:data:`geovista.common.ZLEVEL_SCALE`.
Returns
-------
Expand All @@ -657,9 +664,9 @@ def line(
else:
radius = RADIUS if radius is None else abs(float(radius))

zfactor = ZLEVEL_FACTOR if zfactor is None else float(zfactor)
zscale = ZLEVEL_SCALE if zscale is None else float(zscale)
zlevel = 1 if zlevel is None else int(zlevel)
radius += radius * zlevel * zfactor
radius += radius * zlevel * zscale

if npts is None:
npts = GEODESIC_NPTS
Expand Down

0 comments on commit 9a0601c

Please sign in to comment.