Skip to content

Commit

Permalink
Merge pull request #15 from ckingdon95/release-3.8
Browse files Browse the repository at this point in the history
Add c# validation testing for version 3.8
  • Loading branch information
davidanthoff authored Apr 1, 2019
2 parents b83c52d + a629927 commit 1744ed5
Show file tree
Hide file tree
Showing 27 changed files with 231,069 additions and 42 deletions.
1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climateco2cycle.acco2.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climatedynamics.temp.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climateforcing.radforc.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climateforcing.rfch4.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climateforcing.rfco2.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climateforcing.rfemf22.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climateforcing.rfn2o.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climateforcing.rfsf6.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climateforcing.rfso2.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/climateso2cycle.acso2.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/emissions.cumglobso2.csv

Large diffs are not rendered by default.

1,050 changes: 1,050 additions & 0 deletions test/c#_validation_data/emissions.globso2.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/emissions.mitigationcost.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/emissions.rcei.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/emissions.reei.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/emissions.ryg.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/emissions.scei.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/emissions.seei.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/emissions.so2.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/emissions.so2withseeiandscei.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/impactaggregation.eloss.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/impactaggregation.loss.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/impactaggregation.sloss.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/impactcooling.cooling.csv

Large diffs are not rendered by default.

16,800 changes: 16,800 additions & 0 deletions test/c#_validation_data/scenariouncertainty.pgrowth.csv

Large diffs are not rendered by default.

45 changes: 3 additions & 42 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,10 @@ global new_nsteps = 10
end #fund-model testset

#------------------------------------------------------------------------------
# 2. Run tests to make sure integration version (Mimi v0.5.0)
# values match Mimi 0.4.0 values # CANNOT TEST THIS WITH VERSION 3.8
# 2. Run tests to compare Mimi output to C# output from version 3.8
#------------------------------------------------------------------------------
# @testset "test-integration" begin

# Mimi.reset_compdefs()

# global m = getfund()
# run(m)

# missingvalue = -999.999
# err_number = 1.0e-9
# err_array = 0.0

# for c in map(name, Mimi.compdefs(m)), v in Mimi.variable_names(m, c)

# #load data for comparison
# filename = joinpath(@__DIR__, "../contrib/validation_data_v040/$c-$v.csv")
# results = m[c, v]

# df = load(filename) |> DataFrame
# if typeof(results) <: Number
# validation_results = df[1,1]
# @test results ≈ validation_results atol = err_number #slight imprecision with these values due to rounding

# else
# validation_results = convert(Array, df)

# #replace missings with missingvalue so they can be compared
# results[ismissing.(results)] .= missingvalue
# validation_results[ismissing.(validation_results)] .= missingvalue

# #match dimensions
# if size(validation_results,1) == 1
# validation_results = validation_results'
# end

# @test results ≈ validation_results atol = err_array

# end
# end

# end #fund-integration testset

include("validation.jl")

#------------------------------------------------------------------------------
# 3. Test marginal damages functions (test that each function does not error)
Expand Down
66 changes: 66 additions & 0 deletions test/validation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Validation for the Julia version of FUND 3.8 by comparing it to 25 saved output values from the C# 3.8 version

using Test
using DelimitedFiles
using Mimi
using MimiFUND

Precision = 1.0e-10
cs_data_dir = joinpath(@__DIR__, "c#_validation_data") # holds the saved output files from the C# version


"""
Converts c# data files into arrays.
If the data has a region index, the data is converted from long to wide format.
"""
function convertcsdata(inputfile::String)
d = readdlm(inputfile, ',')
if size(d)[2]==3 # has a region index
numcols = 16
numrows = Int(size(d)[1]/16)
d = convert(Array, reshape(d[:, end], numcols, numrows)')
elseif size(d)[2]==2 # only has one index
d = d[:, end]
else
error("unknown parameter file structure")
end
return d
end


@testset "C# 3.8 Validation" begin

# Get the mimi version and run it
m = getfund()
run(m)

cs_files = readdir(cs_data_dir)

for f in cs_files
# println(f)
cs_data = convertcsdata(joinpath(cs_data_dir, f))

comp, var, _ = split(f, ".") # each file name is formatted as "compname.varname.csv"
var = var == "so2withseeiandscei" ? "so2WithSeeiAndScei" : var # just one variable has different capitalization between the C# and Mimi version

mimi_data = m[Symbol(comp), Symbol(var)]
if length(size(mimi_data)) == 2
mimi_data = mimi_data[1:end-1, :] # because C# version has one less timestep
else
mimi_data = mimi_data[1:end-1] # because C# version has one less timestep
end
mimi_data[ismissing.(mimi_data)] .= 0 # the "missings" in the julia version when the first step isn't calculated are zeros in the C# version

@testset "$comp $var" begin
if comp == "impactaggregation"
@test all(isapprox.(cs_data, mimi_data, rtol = Precision)) # Test relative tolerance for the variables in impactaggregation component because they are large (and only saved to two decimal places in the C# files)
else
@test all(isapprox.(cs_data, mimi_data, atol = Precision)) # Test absolute tolerance for the rest of the values
end
end

end

end

nothing

0 comments on commit 1744ed5

Please sign in to comment.