Skip to content

Commit

Permalink
Expose "raw" data with # of obs
Browse files Browse the repository at this point in the history
  • Loading branch information
briochemc committed Dec 9, 2019
1 parent e2f7686 commit 953785a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
@@ -1,7 +1,7 @@
name = "WorldOceanAtlasTools"
uuid = "04f20302-f1b9-11e8-29d9-7d841cb0a64a"
authors = ["Benoit Pasquier <pasquieb@uci.edu>"]
version = "0.3.4"
version = "0.3.5"

[deps]
DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe"
Expand Down
31 changes: 22 additions & 9 deletions src/functions.jl
Expand Up @@ -86,6 +86,19 @@ end
get_unit(ds, tracer, field) = convert_to_Unitful(ds[WOA_varname(tracer, field)].attrib["units"])

function mean_and_variance_gridded_3d_field(grid::OceanGrid, field3D, lat, lon, depth)
χ_3D, σ²_3D, n_3D = raw_mean_and_variance_gridded_3d_field(grid, field3D, lat, lon, depth)
# Enforce μ = 0 and σ = ∞ where no observations
# (Instead of NaNs)
println(" Setting μ = 0 and σ² = ∞ where no obs")
χ_3D[findall(n_3D .== 0)] .= 0.0
σ²_3D[findall(n_3D .== 0)] .= Inf
println(" Setting a realistic minimum for σ²")
meanχ = mean(χ_3D, weights(n_3D))
σ²_3D .= max.(σ²_3D, 1e-4meanχ^2)
return χ_3D, σ²_3D
end

function raw_mean_and_variance_gridded_3d_field(grid::OceanGrid, field3D, lat, lon, depth)
fieldvec, latvec, lonvec, depthvec, CI = filter_gridded_3D_field(field3D, lat, lon, depth)
println(" Averaging data over each grid box")
χ_3D = zeros(size(grid))
Expand All @@ -103,15 +116,7 @@ function mean_and_variance_gridded_3d_field(grid::OceanGrid, field3D, lat, lon,
end
χ_3D .= χ_3D ./ n_3D # μ = Σᵢ μᵢ / n
σ²_3D .= σ²_3D ./ n_3D .- χ_3D.^2 # σ² = Σᵢ μᵢ² / n - μ²
# Enforce μ = 0 and σ = ∞ where no observations
# (Instead of NaNs)
println(" Setting μ = 0 and σ² = ∞ where no obs")
χ_3D[findall(n_3D .== 0)] .= 0.0
σ²_3D[findall(n_3D .== 0)] .= Inf
println(" Setting a realistic minimum for σ²")
meanχ = mean(χ_3D, weights(n_3D))
σ²_3D .= max.(σ²_3D, 1e-4meanχ^2)
return χ_3D, σ²_3D
return χ_3D, σ²_3D, n_3D
end

function convert_to_SI_unit!(χ_3D, σ²_3D, ds, tracer, field)
Expand All @@ -129,6 +134,14 @@ function fit_to_grid(grid::OceanGrid, product_year, tracer, period, resolution,
return χ_3D, σ²_3D
end

function raw_to_grid(grid::OceanGrid, product_year, tracer, period, resolution, field)
ds = WOA_Dataset(product_year, tracer, period, resolution)
field3D, lat, lon, depth = get_gridded_3D_field(ds, tracer, field)
χ_3D, σ²_3D, n_3D = raw_mean_and_variance_gridded_3d_field(grid, field3D, lat, lon, depth)
convert_to_SI_unit!(χ_3D, σ²_3D, ds, tracer, field)
return χ_3D, n_3D
end

#==================================
Helper functions
==================================#
Expand Down

2 comments on commit 953785a

@briochemc
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/6434

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.5 -m "<description of version>" 953785a2ee82e02a3094a2c74c18052c5e8890a2
git push origin v0.3.5

Please sign in to comment.