Skip to content

Commit f4f84cb

Browse files
committed
more more more more more smoothing compatibility updates
1 parent bba1fd5 commit f4f84cb

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/seismicity/smoothing.jl

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,36 @@ if !@isdefined h3GetResolution
1515
end
1616

1717

18+
if !@isdefined h3IsValid
19+
@info "Defining h3IsValid"
20+
function h3IsValid(h3)
21+
isValidCell(h3)
22+
end
23+
end
24+
25+
26+
@static if !@isdefined(GeoCoord)
27+
@info "Defining GeoCoord compatibility struct"
28+
struct GeoCoord
29+
lat::Float64 # in radians
30+
lon::Float64 # in radians
31+
end
32+
end
33+
34+
# Runtime conditional method definition (always allowed)
35+
if !(@isdefined geoToH3) && (@isdefined latLngToCell)
36+
@info "Defining geoToH3 compatibility shim"
37+
function geoToH3(coord::GeoCoord, res::Integer)
38+
return latLngToCell(LatLng(coord.lat, coord.lon), res)
39+
end
40+
41+
function h3ToGeo(cell_id)
42+
lat_lng_rad = cellToLatLng(cell_id)
43+
GeoCoord(lat_lng_rad.lat, lat_lng_rad.lng)
44+
end
45+
end
46+
47+
1848
# the function and api have changed; the H3.jl library as of 3.2 is not defined correctly
1949
edge_length_check = edgeLengthKm(3)
2050
if edge_length_check isa Number
@@ -74,7 +104,8 @@ julia> smoothing('count.csv', [[1.0, 20]], 50)
74104
h3res = h3GetResolution(df.h3idx[1])
75105
edge_length = get_avg_edge_length_km(h3res)
76106
println(@sprintf("Edge resolution : %d", h3res))
77-
println(@sprintf("Edge length : %.3f km", edgeLengthKm(h3res)))
107+
#println(@sprintf("Edge length : %.3f km", edgeLengthKm(h3res)))
108+
println(@sprintf("Edge length : %.3f km", edge_length))
78109

79110
maxdistk = Int(ceil(maxdistkm / edge_length))
80111
println(@sprintf("Max dist k : %d ", maxdistk))
@@ -105,7 +136,7 @@ julia> smoothing('count.csv', [[1.0, 20]], 50)
105136
dsts = zeros(Float32, length(idxs))
106137
for idx in enumerate(idxs)
107138
d = h3Distance(base, idx[2])
108-
dsts[idx[1]] = d * edgeLengthKm(h3res)
139+
dsts[idx[1]] = d * edge_length
109140
if dsts[idx[1]] < 1.0
110141
dsts[idx[1]] = 1.0
111142
end

0 commit comments

Comments
 (0)