-
-
Notifications
You must be signed in to change notification settings - Fork 8
Add interpolations #16
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
Changes from all commits
be18720
252aeef
2907c3e
5ff2a24
96bf996
1c51a24
7edd5c3
d0516ba
7a670c3
0e56e2a
b9c63e0
eed5c64
0c7d17d
2c6ad84
d418c4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ on: | |
| push: | ||
| branches: | ||
| - master | ||
| - AddInterpolations | ||
| tags: '*' | ||
| pull_request: | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ on: | |
| push: | ||
| branches: | ||
| - master | ||
| - AddInterpolations | ||
| tags: '*' | ||
| pull_request: | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # # Using Interpolation On The Fly | ||
|
|
||
| using Tyler, GLMakie | ||
| using Interpolations: interpolate, Gridded, Linear | ||
|
|
||
| f(lon,lat)=cosd(16*lon)+sind(16*lat) | ||
|
|
||
| f_in_0_1_range(lon,lat)=0.5+0.25*f(lon,lat) | ||
|
|
||
| nodes=(-180.0:180.0, -90.0:90.0) | ||
| array=[f(lon,lat) for lon in nodes[1], lat in nodes[2]] | ||
| array=(array.-minimum(array))./(maximum(array)-minimum(array)) | ||
| itp = interpolate(nodes, array, Gridded(Linear())) | ||
| cols=Makie.to_colormap(:viridis) | ||
| col(i)=RGBAf(Makie.interpolated_getindex(cols,i)) | ||
| fun(x,y) = col(itp(x,y)) | ||
|
|
||
| options = Dict(:min_zoom => 1,:max_zoom => 19) | ||
| p1=Tyler.Interpolator(f_in_0_1_range,options) | ||
| p2=Tyler.Interpolator(fun,options) | ||
|
|
||
| b = Rect2f(-20.0, -20.0, 40.0, 40.0) | ||
| m = Tyler.Map(b, provider=p1) | ||
|
|
||
| # !!! info | ||
| # Sine Waves | ||
|
|
||
| # !!! tip | ||
| # Try `b = Rect2f(-180.0, -89.9, 360.0, 179.8)` | ||
|
|
||
| # !!! tip | ||
| # `interpolated_getindex` requires input `i` to be in the 0-1 range | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ using OrderedCollections | |
| using HTTP | ||
| using ImageMagick | ||
|
|
||
| include("for_interpolations.jl") | ||
| using Tyler.ForInterpolations: tile2positions, Interpolator | ||
|
|
||
| const TileImage = Matrix{RGB{N0f8}} | ||
|
|
||
| struct Map | ||
|
|
@@ -211,14 +214,34 @@ function create_tile_plot!(tyler::Map, tile::Tile, image::TileImage) | |
| place_tile!(tile, mplot, tyler.coordinate_system) | ||
| end | ||
|
|
||
| ## | ||
|
|
||
| function fetch_tile(tyler::Map, tile::Tile) | ||
| return get!(tyler.fetched_tiles, tile) do | ||
| url = TileProviders.geturl(tyler.provider, tile.x, tile.y, tile.z) | ||
| result = HTTP.get(url; retry=false, readtimeout=4, connect_timeout=4) | ||
| return ImageMagick.readblob(result.body) | ||
| fetch_tile(tyler.provider,tile) | ||
| end | ||
| end | ||
|
|
||
| function fetch_tile(provider::AbstractProvider, tile::Tile) | ||
| url = TileProviders.geturl(provider, tile.x, tile.y, tile.z) | ||
| result = HTTP.get(url; retry=false, readtimeout=4, connect_timeout=4) | ||
| return ImageMagick.readblob(result.body) | ||
| end | ||
|
|
||
| cols=Makie.to_colormap(:thermal) | ||
| col(i)=RGBAf(Makie.interpolated_getindex(cols,i)) | ||
| col(i::RGBAf)=i | ||
|
|
||
| function fetch_tile(provider::Interpolator, tile::Tile) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could go in the interpolator module |
||
| itp=provider.url | ||
| (lon,lat) = tile2positions(tile) | ||
| z = permutedims(itp.(lon,lat)) | ||
| return [col(i) for i in z] | ||
| end | ||
|
|
||
|
|
||
| ## | ||
|
|
||
| function queue_tile!(tyler::Map, tile) | ||
| queue = tyler.tiles_being_added | ||
| # NO need to start a need task! | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| module ForInterpolations | ||
rafaqz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| using MapTiles | ||
| using TileProviders: AbstractProvider | ||
| export tile2positions, Interpolator | ||
|
|
||
| lng2tile(lng, zoom) = floor((lng+180)/360*2^zoom) | ||
| lat2tile(lat, zoom) = floor((1-log(tan(lat*pi/180)+1/cos(lat*pi/180))/pi)/2*2^zoom) | ||
|
|
||
| tile2lng(x, z) = (x/2^z*360)-180 | ||
| tile2lat(y, z) = - 180/pi*atan(0.5*(exp(pi-2*pi*y/2^z)-exp(2*pi*y/2^z-pi))) | ||
|
|
||
| tile2positions(tile::Tile) = tile2positions(tile.x,tile.y,tile.z) | ||
|
|
||
| function tile2positions(x,y,z) | ||
| rng=range(0.5/232,231.5/232,232) | ||
| lons=[tile2lng(x+i,z) for i in rng, j in rng] | ||
| lats=[tile2lat(y+j,z) for i in rng, j in rng] | ||
| (lons,lats) | ||
| end | ||
|
|
||
| struct Interpolator <: AbstractProvider | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could do with some docs? I know the rest of the package is pretty short on docs, but it would be good to know what |
||
| url::Function | ||
| options::Dict{Symbol,Any} | ||
| end | ||
|
|
||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't these be part of
Interpolator? It seems like some unnecessary work to set it up.They could be keywords if people did need to customise?