Skip to content

Commit

Permalink
Merge pull request #110 from EcoJulia/claireh93/fix-windows
Browse files Browse the repository at this point in the history
Remove some tests from Windows - doesn't have enough memory to cope
  • Loading branch information
claireh93 authored Mar 10, 2023
2 parents 02fce5a + ca31c37 commit 9dc048e
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 180 deletions.
269 changes: 135 additions & 134 deletions test/test_AbioticEnv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,152 +5,153 @@ using EcoSISTEM.Units
using EcoSISTEM.ClimatePref
using AxisArrays
using RasterDataSources
if !Sys.iswindows()
if !isdir("assets")
mkdir("assets")
end
ENV["RASTERDATASOURCES_PATH"] = "assets"

if !isdir("assets")
mkdir("assets")
end
ENV["RASTERDATASOURCES_PATH"] = "assets"
temp = getraster(WorldClim{BioClim}, :bio1)
getraster(EarthEnv{LandCover})
grid = (5, 5)
area = 25.0km^2
totalK = 10000.0kJ/km^2
numNiches = 4
active = fill(true, grid)

temp = getraster(WorldClim{BioClim}, :bio1)
getraster(EarthEnv{LandCover})
grid = (5, 5)
area = 25.0km^2
totalK = 10000.0kJ/km^2
numNiches = 4
active = fill(true, grid)
@testset "simple habitat" begin
# TEST simplehabitatAE
fillval = 0.0
abenv = simplehabitatAE(fillval, grid, totalK, area)
@test_nowarn simplehabitatAE(fillval, grid, totalK, area)
@test_nowarn simplehabitatAE(fillval, grid, totalK, area, active)
@test all(abenv.habitat.matrix .== fillval)
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)

@testset "simple habitat" begin
# TEST simplehabitatAE
fillval = 0.0
abenv = simplehabitatAE(fillval, grid, totalK, area)
@test_nowarn simplehabitatAE(fillval, grid, totalK, area)
@test_nowarn simplehabitatAE(fillval, grid, totalK, area, active)
@test all(abenv.habitat.matrix .== fillval)
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)
@test EcoSISTEM._getsubcommunitynames(abenv) == abenv.names
@test EcoSISTEM.getavailableenergy(abenv) == sum(abenv.budget.matrix)
end

@test EcoSISTEM._getsubcommunitynames(abenv) == abenv.names
@test EcoSISTEM.getavailableenergy(abenv) == sum(abenv.budget.matrix)
end
@testset "temperature gradient" begin
# TEST tempgradAE
abenv = tempgradAE(-10.0K, 10.0K, grid, totalK, area, 0.01K/month)
@test_nowarn tempgradAE(-10.0K, 10.0K, grid, totalK, area, 0.01K/month)
@test minimum(abenv.habitat.matrix) == -10.0K
@test maximum(abenv.habitat.matrix) == 10.0K
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)
end

@testset "temperature gradient" begin
# TEST tempgradAE
abenv = tempgradAE(-10.0K, 10.0K, grid, totalK, area, 0.01K/month)
@test_nowarn tempgradAE(-10.0K, 10.0K, grid, totalK, area, 0.01K/month)
@test minimum(abenv.habitat.matrix) == -10.0K
@test maximum(abenv.habitat.matrix) == 10.0K
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)
end
@testset "peaked temperature gradient" begin
# TEST peakedgradAE
abenv = peakedgradAE(-10.0K, 10.0K, grid, totalK, area, 0.01K/month)
@test_nowarn peakedgradAE(-10.0K, 10.0K, grid, totalK, area, 0.01K/month)
@test minimum(abenv.habitat.matrix) == -10.0K
@test maximum(abenv.habitat.matrix) == 10.0K
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)
end

@testset "peaked temperature gradient" begin
# TEST peakedgradAE
abenv = peakedgradAE(-10.0K, 10.0K, grid, totalK, area, 0.01K/month)
@test_nowarn peakedgradAE(-10.0K, 10.0K, grid, totalK, area, 0.01K/month)
@test minimum(abenv.habitat.matrix) == -10.0K
@test maximum(abenv.habitat.matrix) == 10.0K
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)
end
@testset "rainfall gradient" begin
# TEST raingradAE
abenv = raingradAE(0.0mm, 100.0mm, grid, totalK, area, 0.01mm/month)
@test_nowarn raingradAE(0.0mm, 100.0mm, grid, totalK, area, 0.01mm/month)
@test minimum(abenv.habitat.matrix) == 0.0mm
@test maximum(abenv.habitat.matrix) == 100.0mm
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)
end

@testset "rainfall gradient" begin
# TEST raingradAE
abenv = raingradAE(0.0mm, 100.0mm, grid, totalK, area, 0.01mm/month)
@test_nowarn raingradAE(0.0mm, 100.0mm, grid, totalK, area, 0.01mm/month)
@test minimum(abenv.habitat.matrix) == 0.0mm
@test maximum(abenv.habitat.matrix) == 100.0mm
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)
end
@testset "niche habitat" begin
# TEST simplenicheAE
abenv = simplenicheAE(numNiches, grid, totalK, area)
@test_nowarn simplenicheAE(numNiches, grid, totalK, area)
@test_nowarn simplenicheAE(numNiches, grid, totalK, area, active)
@test maximum(abenv.habitat.matrix) <= numNiches
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)
end

@testset "niche habitat" begin
# TEST simplenicheAE
abenv = simplenicheAE(numNiches, grid, totalK, area)
@test_nowarn simplenicheAE(numNiches, grid, totalK, area)
@test_nowarn simplenicheAE(numNiches, grid, totalK, area, active)
@test maximum(abenv.habitat.matrix) <= numNiches
@test size(abenv.habitat.matrix) == grid
@test sum(abenv.budget.matrix) == totalK * area
@test abenv.active == active
@test all(abenv.active)
end
@testset "ERA data" begin
# TEST eraAE
temp = AxisArray(fill(1.0K, 10, 10, 3), Axis{:latitude}(1:10), Axis{:longitude}(1:10), Axis{:time}(collect(1:3) .* s))
eratemp = ERA(temp)
active = fill(true, 10, 10)
totalK = 1000.0kJ/m^2; area = 100.0km^2
ea = eraAE(eratemp, totalK, area)
@test_nowarn eraAE(eratemp, totalK, area)
@test_nowarn eraAE(eratemp, totalK, area, active)
@test size(ea.habitat.matrix) == size(temp)
@test EcoSISTEM.getavailableenergy(ea) == totalK * area
@test ea.active == active
@test all(ea.active)

@testset "ERA data" begin
# TEST eraAE
temp = AxisArray(fill(1.0K, 10, 10, 3), Axis{:latitude}(1:10), Axis{:longitude}(1:10), Axis{:time}(collect(1:3) .* s))
eratemp = ERA(temp)
active = fill(true, 10, 10)
totalK = 1000.0kJ/m^2; area = 100.0km^2
ea = eraAE(eratemp, totalK, area)
@test_nowarn eraAE(eratemp, totalK, area)
@test_nowarn eraAE(eratemp, totalK, area, active)
@test size(ea.habitat.matrix) == size(temp)
@test EcoSISTEM.getavailableenergy(ea) == totalK * area
@test ea.active == active
@test all(ea.active)
solar = SolarTimeBudget(fill(10.0kJ, 10, 10, 3), 1)
ea = eraAE(eratemp, solar, active)
end

solar = SolarTimeBudget(fill(10.0kJ, 10, 10, 3), 1)
ea = eraAE(eratemp, solar, active)
end
@testset "Worldclim data" begin
# TEST worldclimAE
temp = AxisArray(fill(1.0K, 10, 10, 12), Axis{:latitude}(collect(1:10) .* m), Axis{:longitude}(collect(1:10) .* m), Axis{:time}(collect(1:12) .* month))
wctemp = Worldclim_monthly(temp)
active = fill(true, 10, 10)
totalK = 1000.0kJ/m^2; area = 100.0km^2
wc = worldclimAE(wctemp, totalK, area)
@test_nowarn worldclimAE(wctemp, totalK, area)
@test_nowarn worldclimAE(wctemp, totalK, area, active)
@test size(wc.habitat.matrix) == size(temp)
@test EcoSISTEM.getavailableenergy(wc) == totalK * area
@test wc.active == active
@test all(wc.active)

@testset "Worldclim data" begin
# TEST worldclimAE
temp = AxisArray(fill(1.0K, 10, 10, 12), Axis{:latitude}(collect(1:10) .* m), Axis{:longitude}(collect(1:10) .* m), Axis{:time}(collect(1:12) .* month))
wctemp = Worldclim_monthly(temp)
active = fill(true, 10, 10)
totalK = 1000.0kJ/m^2; area = 100.0km^2
wc = worldclimAE(wctemp, totalK, area)
@test_nowarn worldclimAE(wctemp, totalK, area)
@test_nowarn worldclimAE(wctemp, totalK, area, active)
@test size(wc.habitat.matrix) == size(temp)
@test EcoSISTEM.getavailableenergy(wc) == totalK * area
@test wc.active == active
@test all(wc.active)
solar = SolarTimeBudget(fill(10.0kJ, 10, 10, 3), 1)
wc = worldclimAE(wctemp, solar, active)
end

solar = SolarTimeBudget(fill(10.0kJ, 10, 10, 3), 1)
wc = worldclimAE(wctemp, solar, active)
end
@testset "Bioclim data" begin
bio_africa = readbioclim("assets/WorldClim/BioClim/")
bio_africa = Worldclim_bioclim(bio_africa.array[:,:,1])
active = fill(true, size(bio_africa.array))
totalK = 1000.0kJ/km^2; area = 100.0km^2
bc = bioclimAE(bio_africa, totalK, area)
@test_nowarn bioclimAE(bio_africa, totalK, area)
@test_nowarn bioclimAE(bio_africa, totalK, area, active)
@test size(bc.habitat.matrix) == size(bio_africa.array)
@test isapprox(EcoSISTEM.getavailableenergy(bc), totalK * area)
solar = SolarBudget(fill(10.0kJ, size(bio_africa.array)))
bc = bioclimAE(bio_africa, solar, active)
end

@testset "Bioclim data" begin
bio_africa = readbioclim("assets/WorldClim/BioClim/")
bio_africa = Worldclim_bioclim(bio_africa.array[:,:,1])
active = fill(true, size(bio_africa.array))
totalK = 1000.0kJ/km^2; area = 100.0km^2
bc = bioclimAE(bio_africa, totalK, area)
@test_nowarn bioclimAE(bio_africa, totalK, area)
@test_nowarn bioclimAE(bio_africa, totalK, area, active)
@test size(bc.habitat.matrix) == size(bio_africa.array)
@test isapprox(EcoSISTEM.getavailableenergy(bc), totalK * area)
solar = SolarBudget(fill(10.0kJ, size(bio_africa.array)))
bc = bioclimAE(bio_africa, solar, active)
end
@testset "Lancover data" begin
world = readlc("assets/EarthEnv/LandCover/without_DISCover/")
world_lc = compressLC(world)
world_lc = Landcover(world_lc)
active = fill(true, size(world_lc.array))
totalK = 1000.0kJ/km^2; area = 100.0km^2
lc = lcAE(world_lc, totalK, area)
@test_nowarn lcAE(world_lc, totalK, area)
@test_nowarn lcAE(world_lc, totalK, area, active)
@test size(lc.habitat.matrix) == size(world_lc.array)
@test isapprox(EcoSISTEM.getavailableenergy(lc), totalK * area)
solar = SolarBudget(fill(10.0kJ, size(world_lc.array)))
lc = lcAE(world_lc, solar, active)
end

@testset "Lancover data" begin
world = readlc("assets/EarthEnv/LandCover/without_DISCover/")
world_lc = compressLC(world)
world_lc = Landcover(world_lc)
active = fill(true, size(world_lc.array))
totalK = 1000.0kJ/km^2; area = 100.0km^2
lc = lcAE(world_lc, totalK, area)
@test_nowarn lcAE(world_lc, totalK, area)
@test_nowarn lcAE(world_lc, totalK, area, active)
@test size(lc.habitat.matrix) == size(world_lc.array)
@test isapprox(EcoSISTEM.getavailableenergy(lc), totalK * area)
solar = SolarBudget(fill(10.0kJ, size(world_lc.array)))
lc = lcAE(world_lc, solar, active)
end

if isdir("assets/WorldClim")
rm("assets/WorldClim", recursive = true)
end
if isdir("assets/EarthEnv")
rm("assets/EarthEnv", recursive = true)
if isdir("assets/WorldClim")
rm("assets/WorldClim", recursive = true)
end
if isdir("assets/EarthEnv")
rm("assets/EarthEnv", recursive = true)
end
end
2 changes: 1 addition & 1 deletion test/test_MPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ using JLD2
end

# Only test on linux for now - bug in Windows machine testing
if Sys.islinux()
if !Sys.iswindows()
@testset "mpirun" begin
# Keep outputs all one folder
isdir("data") || mkdir("data")
Expand Down
92 changes: 47 additions & 45 deletions test/test_ReadData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,51 @@ using Unitful.DefaultSymbols
using RasterDataSources
using Test

if !isdir("assets")
mkdir("assets")
end
ENV["RASTERDATASOURCES_PATH"] = "assets"
# Download layers of bioclim data and test on all read functions
# (essentially all the same file type)
temp = getraster(WorldClim{BioClim}, 1:12)
lc = getraster(EarthEnv{LandCover})

@testset "Reading functions" begin
@test_nowarn readbioclim("assets/WorldClim/BioClim/")
@test_nowarn readworldclim("assets/WorldClim/BioClim/")
@test_nowarn readCRUTS("assets/WorldClim/BioClim/", "tavg")
@test_nowarn readCHELSA_monthly("assets/WorldClim/BioClim/", "tavg")
@test_nowarn readCHELSA_bioclim("assets/WorldClim/BioClim/")
@test_nowarn readlc("assets/EarthEnv/LandCover/without_DISCover/")
@test_nowarn readfile("assets/WorldClim/BioClim/wc2.1_10m_bio_1.tif")
end

@testset "Output data" begin
bc = readbioclim("assets/WorldClim/BioClim/")
rf = readfile("assets/WorldClim/BioClim/wc2.1_10m_bio_1.tif")
wc = readworldclim("assets/WorldClim/BioClim/")
ch_b = readCHELSA_bioclim("assets/WorldClim/BioClim/")

@test unit(bc.array[1]) == unit(wc.array[1]) == unit(rf[1]) == unit(ch_b.array[1]) == NoUnits
end

@testset "Output data 2" begin
lc = readlc("assets/EarthEnv/LandCover/without_DISCover/")
@test unit(lc[1])== NoUnits
end

@testset "Output data 3" begin
cr = readCRUTS("assets/WorldClim/BioClim/", "tavg")
ch_m = readCHELSA_monthly("assets/WorldClim/BioClim/", "tavg")

@test unit(cr.array[1]) == unit(ch_m.array[1]) == K
end

if isdir("assets/WorldClim")
rm("assets/WorldClim", recursive = true)
end
if isdir("assets/EarthEnv")
rm("assets/EarthEnv", recursive = true)
if !Sys.iswindows()
if !isdir("assets")
mkdir("assets")
end
ENV["RASTERDATASOURCES_PATH"] = "assets"
# Download layers of bioclim data and test on all read functions
# (essentially all the same file type)
temp = getraster(WorldClim{BioClim}, 1:12)
lc = getraster(EarthEnv{LandCover})

@testset "Reading functions" begin
@test_nowarn readbioclim("assets/WorldClim/BioClim/")
@test_nowarn readworldclim("assets/WorldClim/BioClim/")
@test_nowarn readCRUTS("assets/WorldClim/BioClim/", "tavg")
@test_nowarn readCHELSA_monthly("assets/WorldClim/BioClim/", "tavg")
@test_nowarn readCHELSA_bioclim("assets/WorldClim/BioClim/")
@test_nowarn readlc("assets/EarthEnv/LandCover/without_DISCover/")
@test_nowarn readfile("assets/WorldClim/BioClim/wc2.1_10m_bio_1.tif")
end

@testset "Output data" begin
bc = readbioclim("assets/WorldClim/BioClim/")
rf = readfile("assets/WorldClim/BioClim/wc2.1_10m_bio_1.tif")
wc = readworldclim("assets/WorldClim/BioClim/")
ch_b = readCHELSA_bioclim("assets/WorldClim/BioClim/")

@test unit(bc.array[1]) == unit(wc.array[1]) == unit(rf[1]) == unit(ch_b.array[1]) == NoUnits
end

@testset "Output data 2" begin
lc = readlc("assets/EarthEnv/LandCover/without_DISCover/")
@test unit(lc[1])== NoUnits
end

@testset "Output data 3" begin
cr = readCRUTS("assets/WorldClim/BioClim/", "tavg")
ch_m = readCHELSA_monthly("assets/WorldClim/BioClim/", "tavg")

@test unit(cr.array[1]) == unit(ch_m.array[1]) == K
end

if isdir("assets/WorldClim")
rm("assets/WorldClim", recursive = true)
end
if isdir("assets/EarthEnv")
rm("assets/EarthEnv", recursive = true)
end
end

0 comments on commit 9dc048e

Please sign in to comment.