diff --git a/LICENSE b/LICENSE.md similarity index 96% rename from LICENSE rename to LICENSE.md index 80119cd..c0b2909 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Benoit Pasquier +Copyright (c) 2021 Benoit Pasquier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Project.toml b/Project.toml index f4a2689..0c6ca22 100644 --- a/Project.toml +++ b/Project.toml @@ -1,12 +1,13 @@ name = "WorldOceanAtlasTools" uuid = "04f20302-f1b9-11e8-29d9-7d841cb0a64a" authors = ["Benoit Pasquier "] -version = "0.4.4" +version = "0.5.0" [deps] DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe" +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" Match = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf" -MetadataArrays = "49441bc9-da82-574f-b07c-a0d10dd4ac13" NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab" NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce" OceanGrids = "cfe838f4-859f-11e9-2ea1-df7d4e7c3537" @@ -16,11 +17,11 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] DataDeps = "0.7" +DataFrames = "1" Match = "1" -MetadataArrays = "0.1" NCDatasets = "0.9, 0.10, 0.11" NearestNeighbors = "0.4" -OceanGrids = "0.1, 0.2, 0.3" +OceanGrids = "0.1, 0.2, 0.3, 0.4" StatsBase = "0.33" Unitful = "1" julia = "1" diff --git a/src/WorldOceanAtlasTools.jl b/src/WorldOceanAtlasTools.jl index 3068d2e..c8bf245 100644 --- a/src/WorldOceanAtlasTools.jl +++ b/src/WorldOceanAtlasTools.jl @@ -1,7 +1,15 @@ module WorldOceanAtlasTools -using DataDeps, NCDatasets, Match, Statistics, StatsBase, Unitful -using OceanGrids, NearestNeighbors +using DataDeps +using Downloads +using NCDatasets +using DataFrames +using Match +using Statistics +using StatsBase +using Unitful +using OceanGrids +using NearestNeighbors include("names.jl") include("citations.jl") diff --git a/src/functions.jl b/src/functions.jl index 1b9734a..20f392f 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -161,33 +161,19 @@ end -#================================== -More general API functions -==================================# -# GEOTRACES.jl inspired functions. -# Maybe faster that what I previously had. -# Anyway it would be better to compare interpolated model to obs, -# rather than interpolated obs to model. -# So this is the format of obs I should use. -# obs, MD -# with obs and units -# and MD a named tuple with fields Depth, Latitude, and Longitude -# If MD is used a lot, maybe use depth, lat, lon? -# TODO make this the basic API and let AIBECS use it -# TODO push new version with new API - - +#========================================= +observations function returns a DataFrames +=========================================# -using MetadataArrays function observations(ds::Dataset, tracer::String; metadatakeys) var, v, ikeep = indices_and_var(ds, tracer) u = _unit(var) WOAmetadatakeys = varname.(metadatakeys) - metadata = [metadatakeyvaluepair(ds[k], ikeep) for k in WOAmetadatakeys] - metadata = (name="Observed $(WOA_path_varname(tracer))", WOAvarname=name(var), metadata...) - return MetadataVector(float.(v[ikeep]) .* u, metadata) + metadata = (metadatakeyvaluepair(ds[k], ikeep) for k in WOAmetadatakeys) + df = DataFrame(metadata..., Symbol(tracer)=>float.(view(v, ikeep))*u) + return df end """ observations(tracer::String; metadatakeys=("lat", "lon", "depth")) @@ -216,9 +202,9 @@ end _unit(v) = convert_to_Unitful(get(v.attrib, "units", "nothing")) _fillvalue(v) = get(v.attrib, "_FillValue", NaN) metadatakeyvaluepair(v, idx) = @match name(v) begin - "lon" => (:lon, float.(v.var[:][[i.I[1] for i in idx]]) * u"°") - "lat" => (:lat, float.(v.var[:][[i.I[2] for i in idx]]) * u"°") - "depth" => (:depth, float.(v.var[:][[i.I[3] for i in idx]]) * u"m") + "lon" => (:lon => float.(v.var[:][[i.I[1] for i in idx]])) + "lat" => (:lat => float.(v.var[:][[i.I[2] for i in idx]])) + "depth" => (:depth => float.(v.var[:][[i.I[3] for i in idx]]) * u"m") end diff --git a/src/names.jl b/src/names.jl index 5b8eeb2..39602c0 100644 --- a/src/names.jl +++ b/src/names.jl @@ -7,7 +7,7 @@ function fallback_download(remotepath, localdir) @assert(isdir(localdir)) filename = basename(remotepath) # only works for URLs with filename as last part of name localpath = joinpath(localdir, filename) - Base.download(remotepath, localpath) + Downloads.download(remotepath, localpath) return localpath end diff --git a/test/test_functions.jl b/test/test_functions.jl index 3f310b5..f993653 100644 --- a/test/test_functions.jl +++ b/test/test_functions.jl @@ -54,7 +54,8 @@ # new functionality @testset "observations function" begin σSW = 1.035u"kg/L" # approximate mean sea water density to convert mol/kg to mol/m^3 - PO₄obs = WorldOceanAtlasTools.observations(tracer) * σSW - @test 0.1u"μM" < mean(PO₄obs) < 10u"μM" + obs = WorldOceanAtlasTools.observations(tracer) + obs.value = obs.p .* σSW .|> u"μM" + @test 0.1u"μM" < mean(obs.value) < 10u"μM" end end