Skip to content

Commit 9d519e9

Browse files
committed
nearest_points.jl
1 parent 425b51b commit 9d519e9

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

docs/src/man/Tutorial_LaPalma.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Grid_3D = CartData(xyzGrid(-35:.3:30,-15:.25:45,-50:.5:5))
108108
Next we check how many earthquakes are around the grid points:
109109

110110
```julia
111-
Grid_3D =pointData2NearestGrid(EQ_cart, Grid_3D, radius_factor=3)
111+
Grid_3D =point_to_nearest_grid(EQ_cart, Grid_3D, radius_factor=3)
112112
```
113113

114114
And we can define an array with rock types:

docs/src/man/tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interpolate_data_surface
1414
interpolate_topography_plane
1515
parse_columns_CSV
1616
rotate_translate_scale!
17-
pointData2NearestGrid
17+
point_to_nearest_grid
1818
convert2UTMzone
1919
convert2CartData
2020
project_CartData

src/event_counts.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using NearestNeighbors
22

3-
export pointData2NearestGrid, countmap
3+
export point_to_nearest_grid, countmap
44

55

66
"""
7-
Grid_counts = pointData2NearestGrid(Point::CartData, Grid::CartData; radius_factor=1)
7+
Grid_counts = point_to_nearest_grid(Point::CartData, Grid::CartData; radius_factor=1)
88
99
Uses nearest neighbour interpolation to count how many points (given by `Point`) are in the vicinity of a 3D `Grid`.
1010
The search radius is `R=radius_factor*(Δx² + Δy² + Δz²)^(1/3)`
@@ -13,38 +13,38 @@ The search radius is `R=radius_factor*(Δx² + Δy² + Δz²)^(1/3)`
1313
1414
`Grid_counts` is `Grid` but with an additional field `Count` that has the number of hits
1515
"""
16-
function pointData2NearestGrid(Point::CartData, Grid::CartData; radius_factor=1)
16+
function point_to_nearest_grid(Point::CartData, Grid::CartData; radius_factor=1)
1717

1818
@assert length(size(Point.x)) == 1
1919

2020
# call routine
21-
Count = pointData2NearestGrid(NumValue(Point.x),NumValue(Point.y), NumValue(Point.z), NumValue(Grid.x),NumValue(Grid.y),NumValue(Grid.z); radius_factor=radius_factor)
21+
Count = point_to_nearest_grid(NumValue(Point.x),NumValue(Point.y), NumValue(Point.z), NumValue(Grid.x),NumValue(Grid.y),NumValue(Grid.z); radius_factor=radius_factor)
2222

2323
# return CartGrid with added field
2424
return addfield(Grid,"Count",Count);
2525
end
2626

2727

2828
"""
29-
Grid_counts = pointData2NearestGrid(pt_x,pt_y,pt_z, Grid::CartData; radius_factor=1)
29+
Grid_counts = point_to_nearest_grid(pt_x,pt_y,pt_z, Grid::CartData; radius_factor=1)
3030
3131
Uses nearest neighbour interpolation to count how many points (given by `pt_x`,`pt_y`,`pt_z` coordinate vectors) are in the
3232
vicinity of 3D `CartGrid` specified by `Grid`. The search radius is `R=radius_factor*(Δx² + Δy² + Δz²)^(1/3)`
3333
3434
`Grid_counts` is `Grid` but with an additional field `Count` that has the number of hits
3535
"""
36-
function pointData2NearestGrid(pt_x,pt_y,pt_z, Grid::CartData; radius_factor=1)
36+
function point_to_nearest_grid(pt_x,pt_y,pt_z, Grid::CartData; radius_factor=1)
3737

3838
# call routine
39-
Count = pointData2NearestGrid(pt_x,pt_y,pt_z, NumValue(Grid.x),NumValue(Grid.y),NumValue(Grid.z); radius_factor=radius_factor)
39+
Count = point_to_nearest_grid(pt_x,pt_y,pt_z, NumValue(Grid.x),NumValue(Grid.y),NumValue(Grid.z); radius_factor=radius_factor)
4040

4141
# return CartGrid with added field
4242
return addfield(Grid,"Count",Count);
4343
end
4444

4545

4646
"""
47-
Grid_counts = pointData2NearestGrid(Point::GeoData, Grid::GeoData; radius_factor=1)
47+
Grid_counts = point_to_nearest_grid(Point::GeoData, Grid::GeoData; radius_factor=1)
4848
4949
Uses nearest neighbour interpolation to count how many points (given by `Point`) are in the vicinity of a 3D `Grid`.
5050
The search radius is `R=radius_factor*(Δx² + Δy² + Δz²)^(1/3)`
@@ -53,44 +53,44 @@ The search radius is `R=radius_factor*(Δx² + Δy² + Δz²)^(1/3)`
5353
5454
`Grid_counts` is `Grid` but with an additional field `Count` that has the number of hits
5555
"""
56-
function pointData2NearestGrid(Point::GeoData, Grid::GeoData; radius_factor=1)
56+
function point_to_nearest_grid(Point::GeoData, Grid::GeoData; radius_factor=1)
5757

5858
@assert length(size(Point.lon)) == 1
5959

6060
# call routine
61-
Count = pointData2NearestGrid(NumValue(Point.lon),NumValue(Point.lat), NumValue(Point.depth), NumValue(Grid.lon),NumValue(Grid.lat),NumValue(Grid.depth); radius_factor=radius_factor)
61+
Count = point_to_nearest_grid(NumValue(Point.lon),NumValue(Point.lat), NumValue(Point.depth), NumValue(Grid.lon),NumValue(Grid.lat),NumValue(Grid.depth); radius_factor=radius_factor)
6262

6363
# return CartGrid with added field
6464
return addfield(Grid,"Count",Count);
6565
end
6666

6767

6868
"""
69-
Grid_counts = pointData2NearestGrid(pt_x,pt_y,pt_z, Grid::GeoData; radius_factor=1)
69+
Grid_counts = point_to_nearest_grid(pt_x,pt_y,pt_z, Grid::GeoData; radius_factor=1)
7070
7171
Uses nearest neighbour interpolation to count how many points (given by `pt_x`,`pt_y`,`pt_z` coordinate vectors) are in the
7272
vicinity of 3D `GeoData` specified by `Grid`. The search radius is `R=radius_factor*(Δx² + Δy² + Δz²)^(1/3)`
7373
7474
`Grid_counts` is `Grid` but with an additional field `Count` that has the number of hits
7575
"""
76-
function pointData2NearestGrid(pt_x,pt_y,pt_z, Grid::GeoData; radius_factor=1)
76+
function point_to_nearest_grid(pt_x,pt_y,pt_z, Grid::GeoData; radius_factor=1)
7777

7878
# call routine
79-
Count = pointData2NearestGrid(pt_x,pt_y,pt_z, NumValue(Grid.lon),NumValue(Grid.lat),NumValue(Grid.depth); radius_factor=radius_factor)
79+
Count = point_to_nearest_grid(pt_x,pt_y,pt_z, NumValue(Grid.lon),NumValue(Grid.lat),NumValue(Grid.depth); radius_factor=radius_factor)
8080

8181
# return CartGrid with added field
8282
return addfield(Grid,"Count",Count);
8383
end
8484

8585
"""
86-
count = pointData2NearestGrid(pt_x,pt_y,pt_z, X,Y,Z; radius_factor=1)
86+
count = point_to_nearest_grid(pt_x,pt_y,pt_z, X,Y,Z; radius_factor=1)
8787
8888
This uses nearest neighbour interpolation to count how many points (given by `pt_x`,`pt_y`,`pt_z` coordinate vectors) are in the
8989
vicinity of 3D grid point specified by `X`,`Y`,`Z` 3D coordinate arrays, with regular spacing `(Δx,Δy,Δz)`.
9090
The search radius is `R=radius_factor*(Δx² + Δy² + Δz²)^(1/3)`
9191
9292
"""
93-
function pointData2NearestGrid(pt_x,pt_y,pt_z, X,Y,Z; radius_factor=1)
93+
function point_to_nearest_grid(pt_x,pt_y,pt_z, X,Y,Z; radius_factor=1)
9494

9595
data = zeros(3,length(pt_x));
9696
data[1,:],data[2,:],data[3,:] = pt_x[:], pt_y[:], pt_z[:]

src/stl.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using LinearAlgebra
1010
#using TriangleIntersect
1111

1212
export Ray, Intersection, IntersectRayTriangle, load, TriangleNormal, Point, IntersectRayMesh, coordinates
13-
export STLToSurface, isInsideClosedSTL
13+
export STLToSurface, isinside_closed_STL
1414

1515
#=
1616
# Conversion routines from GeometryBasics triangles to TriangleIntersect triangles:
@@ -163,7 +163,7 @@ end
163163

164164

165165
"""
166-
inside = isInsideClosedSTL(mesh::Mesh, Pt, eps=1e-3)
166+
inside = isinside_closed_STL(mesh::Mesh, Pt, eps=1e-3)
167167
168168
Determine whether a point `Pt` is inside a 3D closed triangular `*.stl` surface or not.
169169
@@ -172,7 +172,7 @@ https://github.com/marmakoide/inside-3d-mesh
172172
173173
This again is described in the following [paper](https://igl.ethz.ch/projects/winding-number/) by Alec Jacobson, Ladislav Kavan and Olga Sorkine-Hornung.
174174
"""
175-
function isInsideClosedSTL(mesh::Mesh, Pt::Vector, eps=1e-3)
175+
function isinside_closed_STL(mesh::Mesh, Pt::Vector, eps=1e-3)
176176

177177
# Compute triangle vertices and their norms relative to X
178178
M_vec = [mesh.position[i]-Pt[:] for i in eachindex(mesh.position)];

test/test_event_counts.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ R = (sum(pt.^2,dims=2)).^(1/3)
2828
ind = findall(R.< 5);
2929

3030
# test the basic routine
31-
counts = pointData2NearestGrid(pt[:,1],pt[:,2],pt[:,3], NumValue(Grid_cart.x),NumValue(Grid_cart.y), NumValue(Grid_cart.z); radius_factor=2)
31+
counts = point_to_nearest_grid(pt[:,1],pt[:,2],pt[:,3], NumValue(Grid_cart.x),NumValue(Grid_cart.y), NumValue(Grid_cart.z); radius_factor=2)
3232
@test extrema(counts) == (0, 85)
3333

3434
# Test if the grid is on a CartData grid
35-
Grid_Count = pointData2NearestGrid(pt[:,1],pt[:,2],pt[:,3], Grid_cart; radius_factor=2)
35+
Grid_Count = point_to_nearest_grid(pt[:,1],pt[:,2],pt[:,3], Grid_cart; radius_factor=2)
3636
@test extrema(Grid_Count.fields.Count) == (0, 85)
3737

3838
# Test in case the EQ data is also specified as CartData
39-
Grid_Count = pointData2NearestGrid(EQ_cart, Grid_cart; radius_factor=2)
39+
Grid_Count = point_to_nearest_grid(EQ_cart, Grid_cart; radius_factor=2)
4040
@test extrema(Grid_Count.fields.Count) == (0, 85)
4141

4242
# Test if the grid is on a GeoData grid
43-
Grid_Count = pointData2NearestGrid(pt[:,1],pt[:,2],pt[:,3], Grid_geo; radius_factor=2)
43+
Grid_Count = point_to_nearest_grid(pt[:,1],pt[:,2],pt[:,3], Grid_geo; radius_factor=2)
4444
@test extrema(Grid_Count.fields.Count) == (0, 85)
4545

4646
# Test in case the EQ data is also specified as GeoData
47-
Grid_Count = pointData2NearestGrid(EQ_geo, Grid_geo; radius_factor=2)
47+
Grid_Count = point_to_nearest_grid(EQ_geo, Grid_geo; radius_factor=2)
4848
@test extrema(Grid_Count.fields.Count) == (0, 85)
4949

5050
# Test countmap

test/test_stl.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ using Test, GeophysicalModelGenerator
55
mesh = load("./test_files/cat.stl")
66
X,Y,Z = xyzGrid(150:180, -15:2:15, 10:5:60) # Create mesh
77

8-
# Test isInsideClosedSTL routine for individual points (note: bit slow)
8+
# Test isinside_closed_STL routine for individual points (note: bit slow)
99
Phase = zeros(size(X));
1010
for i in eachindex(X)
1111

12-
inside = isInsideClosedSTL(mesh, [X[i], Y[i], Z[i]])
12+
inside = isinside_closed_STL(mesh, [X[i], Y[i], Z[i]])
1313
if inside
1414
Phase[i] = 1;
1515
end

tutorials/Tutorial_LaPalma.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ write_Paraview(Topo_model,"Topo_model")
6565
Grid_3D = CartData(xyzGrid(-35:.3:30,-15:.25:45,-50:.5:5))
6666

6767
# Next we check how many earthquakes are around the grid points:
68-
Grid_3D =pointData2NearestGrid(EQ_cart, Grid_3D, radius_factor=3)
68+
Grid_3D =point_to_nearest_grid(EQ_cart, Grid_3D, radius_factor=3)
6969

7070
# And we can define an array with rock types:
7171
Phases = zeros(Int64,size(Grid_3D.x))

0 commit comments

Comments
 (0)