-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into albert-de-montserrat-patch-1
- Loading branch information
Showing
23 changed files
with
67,905 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
MOR = "MOR" | ||
dum = "dum" | ||
Shepard = "Shepard" | ||
nin = "nin" | ||
|
||
[files] | ||
extend-exclude = ["tutorials/*.pvsm"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# These are routes to perform waterflow calculations (upstream area etc.) on a DEM | ||
|
||
using WhereTheWaterFlows | ||
import WhereTheWaterFlows: waterflows | ||
|
||
export waterflows | ||
|
||
""" | ||
dlon, dlat = spacing(lon,lat) | ||
Computes the spacing with central differences | ||
""" | ||
function spacing(lon,lat) | ||
dlon = zeros(size(lon.val)[1:2]) | ||
dlat = zeros(size(lat.val)[1:2]) | ||
@views dlon[2:end-1,:] = (lon.val[3:end,:,1] - lon.val[1:end-2,:,1])/2 | ||
dlon[1,:] = dlon[2,:] | ||
dlon[end,:] = dlon[end-1,:] | ||
dlat[:,2:end-1] = (lat.val[:,3:end,1] - lat.val[:,1:end-2,1])/2 | ||
dlat[:,1] = dlat[:,2] | ||
dlat[:,end] = dlat[:,end-1] | ||
|
||
return dlon, dlat | ||
end | ||
|
||
""" | ||
area_m2 = cell_area(Topo::GeoData) | ||
Returns the cell area for a Topographic dataset in m² (required for upstream area calculation) | ||
""" | ||
function cell_area(Topo::GeoData) | ||
|
||
proj = ProjectionPoint(Lon=mean(Topo.lon.val[:]), Lat=mean(Topo.lat.val[:])) | ||
Topo_cart = convert2CartData(Topo, proj) | ||
dx, dy = spacing(Topo_cart.x, Topo_cart.y) | ||
|
||
area_m2 = dx.*dy*1e6 | ||
return area_m2 | ||
end | ||
|
||
|
||
""" | ||
Topo_water, sinks, pits, bnds = waterflows(Topo::GeoData; | ||
flowdir_fn=WhereTheWaterFlows.d8dir_feature, feedback_fn=nothing, drain_pits=true, bnd_as_sink=true, | ||
rainfall = nothing, | ||
minsize=300) | ||
Takes a GMG GeoData object of a topographic map and routes water through the grid. Optionally, | ||
you can specify `rainfall` in which case we accumulate the rain as specified in this 2D array instead of the cellarea. | ||
This allows you to, for example, sum, up water if you have variable rainfall in the area. | ||
The other options are as in the `waterflows` function of the package `WhereTheWaterFlows`. | ||
Example | ||
=== | ||
```julia | ||
# Download some topographic data | ||
julia> Topo = import_topo([6.5,7.3,50.2,50.6], file="@earth_relief_03s"); | ||
# Flow the water through the area: | ||
julia> Topo_water, sinks, pits, bnds = waterflows(Topo) | ||
julia> Topo_water | ||
GeoData | ||
size : (961, 481, 1) | ||
lon ϵ [ 6.5 : 7.3] | ||
lat ϵ [ 50.2 : 50.59999999999999] | ||
depth ϵ [ 0.045 : 0.724] | ||
fields : (:Topography, :area, :slen, :dir, :nout, :nin, :c) | ||
``` | ||
""" | ||
function waterflows(Topo::GeoData, flowdir_fn= WhereTheWaterFlows.d8dir_feature; feedback_fn=nothing, drain_pits=true, bnd_as_sink=true, rainfall=nothing, minsize=300) | ||
|
||
cellarea = cell_area(Topo) | ||
cellarea_m2 = cellarea | ||
if !isnothing(rainfall) | ||
@assert typeof(rainfall) == Array{Float64,2} | ||
cellarea = rainfall | ||
end | ||
|
||
dem = Topo.depth.val[:,:,1] | ||
|
||
ni = size(Topo.depth.val) | ||
area = zeros(ni) | ||
slen = zeros(Int64, ni) | ||
dir = zeros(Int8, ni) | ||
nout = zeros(Int8, ni) | ||
nin = zeros(Int8, ni) | ||
c = zeros(Int64, ni) | ||
|
||
area[:,:,1], slen[:,:,1], dir[:,:,1], nout[:,:,1], nin[:,:,1], sinks, pits, c[:,:,1], bnds = waterflows(dem, cellarea, flowdir_fn; | ||
feedback_fn=feedback_fn, drain_pits=drain_pits, bnd_as_sink=bnd_as_sink) | ||
|
||
catchment_large = prune_catchments(c, minsize; val=0) | ||
largest_catchment = catchment_large .== maximum(catchment_large) | ||
largest_area = copy(area) | ||
largest_area[.!largest_catchment] .= NaN | ||
|
||
log10_area = log10.(area) | ||
|
||
Topo_water = addfield(Topo,(;area, slen, dir, nout, nin, c, cellarea_m2, catchment_large, log10_area, largest_catchment, largest_area)) | ||
return Topo_water, sinks, pits, bnds | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export sea_level_files, SeaLevel, load_sea_level, curve_name | ||
|
||
const sea_level_path = "sea_level_data" | ||
|
||
const sea_level_files = Dict( | ||
:Spratt_800ka => "Spratt2016-800ka.txt", | ||
:Spratt_450ka => "Spratt2016-450ka.txt", | ||
:Bintanja_3Ma => "Bintanja-3Ma.txt", | ||
:Grant_153ka => "Grant2012_153ka.txt", | ||
:Rohl_Bint_3Ma => "Rohl-Bint-3Ma.txt", | ||
:Rohling2009_516ka => "Rohling2009-516ka.txt", | ||
:Siddall2003_379ka => "Siddall2003-379ka.txt", | ||
:Waelbroeck2002 => "Waelbroeck2002.txt", | ||
) | ||
|
||
struct SeaLevel{T} | ||
elevation::Vector{T} | ||
age::Vector{T} | ||
name::Symbol | ||
|
||
function SeaLevel(name::Symbol; flip_elevation = false, flip_age = false) | ||
age, elevation = load_sea_level( | ||
name; | ||
flip_age = flip_age, | ||
flip_elevation = flip_elevation | ||
) | ||
new{eltype(age)}(age, elevation, name) | ||
end | ||
end | ||
|
||
Base.getindex(x::SeaLevel, i::Int64) = x.elevation[i] | ||
Base.getindex(x::SeaLevel, i::Int64, j::Int64) = x.elevation[i], x.age[j] | ||
Base.getindex(x::SeaLevel, i::Tuple{Int64}) = x.elevation[i...], x.age[i...] | ||
Base.size(x::SeaLevel) = size(x.elevation) | ||
Base.eachindex(x::SeaLevel) = eachindex(x.elevation) | ||
Base.axes(x::SeaLevel) = axes(x.elevation) | ||
Base.length(x::SeaLevel) = length(x.elevation) | ||
curve_name(x::SeaLevel) = x.name | ||
|
||
function load_sea_level(name::Symbol; flip_elevation = false, flip_age = false) | ||
fname = sea_level_files[name] | ||
data = readdlm(joinpath(sea_level_path, fname)) | ||
h = data[:, 1] | ||
age = data[:, 2] | ||
flip_elevation && reverse!(h) | ||
flip_age && reverse!(age) | ||
return h, age | ||
end |
Oops, something went wrong.