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

Plot srf map bug #253

Merged
merged 6 commits into from
Sep 21, 2021
Merged
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
25 changes: 12 additions & 13 deletions qcore/srf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@

from math import ceil, cos, floor, radians, sqrt, sin, degrees, atan
from subprocess import Popen, PIPE
import sys

import numpy as np

try:
import alphashape
except ImportError:
# only used for get_perimeter function
pass
from alphashape import alphashape, optimizealpha

from qcore.binary_version import get_unversioned_bin

Expand Down Expand Up @@ -821,18 +818,20 @@ def get_perimeter(srf_file, depth=True, plot=False):
ndip = planes[i]["ndip"]
points = np.array([get_lonlat(sf, value=None) for j in range(ndip * nstk)])

# alpha=600 worked fine with SRF, roughness 0.1
# 1000 was cutting into the plane and missing points entirely
# 800 was zigzagging a bit too much along the edge
try:
ashape = alphashape.alphashape(points, 600.0)
except NameError:
raise ImportError("install alphashape")
# The value of alpha parameter determines how tightly points are enclosed
# alpha= 0 means we get a convex-hull, but often a concave-hull represents a better fit.
# Viktor reported alpha=600 worked ok with SRF (roughness 0.1) but it is too high and often misses points entirely.
# if no alpha is given, the optimal value is to be found, but is impractically slow.
# The following will try to optimize alpha with 10 iterations (default is 1000), and if no success, alpha=0 (convex hull)

alpha = optimizealpha(points, max_iterations=10)
ashape = alphashape(points, alpha)
perimeters.append(np.dstack(ashape.exterior.coords.xy)[0])

if plot:
fig, ax = plt.subplots()
ax.scatter(*zip(*points))
ax.add_patch(PolygonPatch(alpha_shape, alpha=0.2))
ax.add_patch(PolygonPatch(ashape, alpha=0.2))
plt.show()
plt.close()

Expand Down
2 changes: 1 addition & 1 deletion qcore/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_set_up(realizations):
sys.exit("{} failed to extract data folder".format(err))

else:
print("Benchmark data folder already exits: ", data_store_path)
print("Benchmark data folder already exists: ", data_store_path)
print(test_data_save_dirs)
# Run all tests
return test_data_save_dirs
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest
pytest-black
alphashape