Skip to content

Commit fdd842d

Browse files
committed
event_counts.jl
1 parent df1b6c5 commit fdd842d

File tree

8 files changed

+47
-47
lines changed

8 files changed

+47
-47
lines changed

docs/src/man/Tutorial_FaultDensity.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ Data_Faults = GeoData(Lon3D,Lat3D,Faults,(Faults=Faults,))
8282
```
8383

8484
## 2. Create Density Map
85-
Create a density map of the fault data. This is done with the `CountMap` function. This function takes a specified field of a 2D `GeoData` struct and counts the entries in all control areas which are defined by steplon (number of control areas in lon direction) and steplat (number of control areas in lat direction). The field should only consist of 0.0 and 1.0 and the steplength. The final result is normalized by the highest count.
85+
Create a density map of the fault data. This is done with the `countMap` function. This function takes a specified field of a 2D `GeoData` struct and counts the entries in all control areas which are defined by steplon (number of control areas in lon direction) and steplat (number of control areas in lat direction). The field should only consist of 0.0 and 1.0 and the steplength. The final result is normalized by the highest count.
8686

8787
```julia
8888
steplon = 188
8989
steplat = 104
90-
cntmap = CountMap(Data_Faults,"Faults",steplon,steplat)
90+
cntmap = countMap(Data_Faults,"Faults",steplon,steplat)
9191
```
9292

9393
Plot the density map with coastlines
@@ -103,7 +103,7 @@ Plot this using `Plots.jl`:
103103

104104
```julia
105105
heatmap(lon,lat,coastlinesEurope',colormap=cgrad(:gray1,rev=true),alpha=1.0);
106-
heatmap!(lon,lat,cntmap.fields.CountMap[:,:,1]',colormap=cgrad(:batlowW,rev=true),alpha = 0.8,legend=true,title="Fault Density Map Europe",ylabel="Lat",xlabel="Lon")
106+
heatmap!(lon,lat,cntmap.fields.countMap[:,:,1]',colormap=cgrad(:batlowW,rev=true),alpha = 0.8,legend=true,title="Fault Density Map Europe",ylabel="Lat",xlabel="Lon")
107107
```
108108

109109
![tutorial_Fault_Map](../assets/img/FaultDensity.png)

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 =pointData2NearestGrid(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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ interpolateDataOnSurface
1414
InterpolateTopographyOnPlane
1515
ParseColumns_CSV_File
1616
RotateTranslateScale!
17-
PointData2NearestGrid
17+
pointData2NearestGrid
1818
Convert2UTMzone
1919
Convert2CartData
2020
projectCartData
2121
drape_on_topo
2222
LithostaticPressure!
23-
CountMap
23+
countMap
2424
```

src/event_counts.jl

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

3-
export PointData2NearestGrid, CountMap
3+
export pointData2NearestGrid, countMap
44

55

66
"""
7-
Grid_counts = PointData2NearestGrid(Point::CartData, Grid::CartData; radius_factor=1)
7+
Grid_counts = pointData2NearestGrid(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 pointData2NearestGrid(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 = pointData2NearestGrid(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 = pointData2NearestGrid(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 pointData2NearestGrid(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 = pointData2NearestGrid(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 = pointData2NearestGrid(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 pointData2NearestGrid(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 = pointData2NearestGrid(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 = pointData2NearestGrid(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 pointData2NearestGrid(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 = pointData2NearestGrid(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 = pointData2NearestGrid(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 pointData2NearestGrid(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[:]
@@ -115,7 +115,7 @@ function PointData2NearestGrid(pt_x,pt_y,pt_z, X,Y,Z; radius_factor=1)
115115
end
116116

117117
"""
118-
DatasetCountMap = CountMap(DataSet::GeoData,field::String,stepslon::Int64,stepslat::Int64)
118+
DatasetcountMap = countMap(DataSet::GeoData,field::String,stepslon::Int64,stepslat::Int64)
119119
120120
Takes a 2D GeoData struct and counts entries of `field` per predefined control area. `field` should only consist of 1.0s and 0.0s. The control area is defined by `steplon` and `steplat`.
121121
`steplon` is the number of control areas in longitude direction and `steplat` the number of control areas in latitude direction.
@@ -132,18 +132,18 @@ GeoData
132132
133133
julia> steplon = 125
134134
julia> steplat = 70
135-
julia> countmap = CountMap(Data_Faults,"Faults",steplon,steplat)
135+
julia> countMap = countMap(Data_Faults,"Faults",steplon,steplat)
136136
137137
GeoData
138138
size : (124, 69, 1)
139139
lon ϵ [ -9.751471789279 : 34.75891471959677]
140140
lat ϵ [ 35.26604656731949 : 59.73926004602028]
141141
depth ϵ [ 0.0 : 1.0]
142-
fields : (:CountMap,)
142+
fields : (:countMap,)
143143
```julia
144144
145145
"""
146-
function CountMap(DataSet::GeoData,field::String,stepslon::Int64,stepslat::Int64)
146+
function countMap(DataSet::GeoData,field::String,stepslon::Int64,stepslat::Int64)
147147

148148
lon = unique(DataSet.lon.val)
149149
lat = unique(DataSet.lat.val)
@@ -155,7 +155,7 @@ function CountMap(DataSet::GeoData,field::String,stepslon::Int64,stepslat::Int64
155155
dlat = abs(latstep[2]-latstep[1])
156156
loncen = lonstep[1]+dlon/2:dlon:lonstep[end]-dlon/2
157157
latcen = latstep[1]+dlat/2:dlat:latstep[end]-dlat/2
158-
countmap = zeros(length(loncen),length(latcen))
158+
countMap = zeros(length(loncen),length(latcen))
159159

160160
expr = Meta.parse(field)
161161
if !haskey(DataSet.fields,expr[1])
@@ -169,18 +169,18 @@ function CountMap(DataSet::GeoData,field::String,stepslon::Int64,stepslat::Int64
169169
indj = findall((lat .>= latstep[j]) .& (lat .<= latstep[j+1]))
170170
dataint = DataSet.fields[expr[1]][indi,indj,1]
171171
count = sum(dataint)
172-
countmap[i,j] = count
172+
countMap[i,j] = count
173173
end
174174
end
175175

176176
# normalize count in every control area
177-
maxcount = maximum(countmap)
178-
countmap = countmap ./ maxcount
177+
maxcount = maximum(countMap)
178+
countMap = countMap ./ maxcount
179179

180180
# create new GeoData
181181
Lon3D,Lat3D, Data = LonLatDepthGrid(loncen,latcen,0);
182-
Data[:,:,1] .= countmap
183-
DatasetCountMap = GeoData(Lon3D,Lat3D,Data,(CountMap=Data,))
182+
Data[:,:,1] .= countMap
183+
DatasetcountMap = GeoData(Lon3D,Lat3D,Data,(countMap=Data,))
184184

185-
return DatasetCountMap
185+
return DatasetcountMap
186186
end

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# few utils that are useful
22

33
export meshgrid, CrossSection, CrossSectionVolume, CrossSectionSurface, CrossSectionPoints, ExtractSubvolume, SubtractHorizontalMean
4-
export ParseColumns_CSV_File, VoteMap, CountMap
4+
export ParseColumns_CSV_File, VoteMap, countMap
55
export InterpolateDataFields2D, InterpolateDataFields, InterpolateTopographyOnPlane
66
export RotateTranslateScale
77
export LithostaticPressure!

test/test_event_counts.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@ 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 = pointData2NearestGrid(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 = pointData2NearestGrid(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 = pointData2NearestGrid(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 = pointData2NearestGrid(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 = pointData2NearestGrid(EQ_geo, Grid_geo; radius_factor=2)
4848
@test extrema(Grid_Count.fields.Count) == (0, 85)
4949

50-
# Test CountMap
51-
Data_CountMap = CountMap(Data_set2D,"Count",5,5)
52-
@test Data_CountMap.fields.CountMap[1,1] == 1.0
53-
@test Data_CountMap.fields.CountMap[2,2] == 0.4444444444444444
54-
@test Data_CountMap.fields.CountMap[4,4] == 0.0
50+
# Test countMap
51+
Data_countMap = countMap(Data_set2D,"Count",5,5)
52+
@test Data_countMap.fields.countMap[1,1] == 1.0
53+
@test Data_countMap.fields.countMap[2,2] == 0.4444444444444444
54+
@test Data_countMap.fields.countMap[4,4] == 0.0

tutorials/Tutorial_FaultDensity.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ Faults[:,:,1] = data
5050
Data_Faults = GeoData(Lon3D,Lat3D,Faults,(Faults=Faults,))
5151

5252
# ## 2. Create Density Map
53-
# Create a density map of the fault data. This is done with the `CountMap` function. This function takes a specified field of a 2D `GeoData` struct and counts the entries in all control areas which are defined by steplon (number of control areas in lon direction) and steplat (number of control areas in lat direction). The field should only consist of 0.0 and 1.0 and the steplength. The final result is normalized by the highest count.
53+
# Create a density map of the fault data. This is done with the `countMap` function. This function takes a specified field of a 2D `GeoData` struct and counts the entries in all control areas which are defined by steplon (number of control areas in lon direction) and steplat (number of control areas in lat direction). The field should only consist of 0.0 and 1.0 and the steplength. The final result is normalized by the highest count.
5454
steplon = 188
5555
steplat = 104
56-
cntmap = CountMap(Data_Faults,"Faults",steplon,steplat)
56+
cntmap = countMap(Data_Faults,"Faults",steplon,steplat)
5757

5858
# Plot the density map with coastlines
5959
lon = unique(cntmap.lon.val)
@@ -63,7 +63,7 @@ coastlinesEurope = map(y -> y > 1 ? 1 : y, coastlinesEurope)
6363

6464
# Plot this using `Plots.jl`:
6565
heatmap(lon,lat,coastlinesEurope',colormap=cgrad(:gray1,rev=true),alpha=1.0);
66-
heatmap!(lon,lat,cntmap.fields.CountMap[:,:,1]',colormap=cgrad(:batlowW,rev=true),alpha = 0.8,legend=true,title="Fault Density Map Europe",ylabel="Lat",xlabel="Lon")
66+
heatmap!(lon,lat,cntmap.fields.countMap[:,:,1]',colormap=cgrad(:batlowW,rev=true),alpha = 0.8,legend=true,title="Fault Density Map Europe",ylabel="Lat",xlabel="Lon")
6767
# ![tutorial_Fault_Map](../assets/img/FaultDensity.png)
6868

6969

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 =pointData2NearestGrid(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)