Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetCDFOutputWriter: new features and bug fixes #823

Merged
merged 22 commits into from
Jul 29, 2020
Merged

Conversation

ali-ramadhan
Copy link
Member

This PR adds new features to the NetCDFOutputWriter and fixes some bugs.

  1. It now always writes useful metadata to all NetCDF files (the date the file was generated, the Julia version, and the Oceananigans version used). This is essential for reproducibility.
  2. Add a verbose flag (default is false) in case you want to track what's being to disk and how long it takes for each output to be computed.
  3. Add an include_halos flag (default is false) in case you want to use the full grid including halos to write fields and custom output. Added new tests for this.
  4. Test that the x, y, z coordinates being written to NetCDF files are correct. They were not (I think this happened when we switched to using offset arrays for grid.xC, etc.). This has been fixed.
  5. Added jldoctest examples showing how to write fields and custom output to NetCDF.
  6. There was a bug in showing/printing grid domains for bounded dimensions, e.g.
    julia> grid = RegularCartesianGrid(size=(16, 16, 16), extent=(1, 1, 1))
    RegularCartesianGrid{Float64, Periodic, Periodic, Bounded}
                       domain: x  [0.0, 1.0], y  [0.0, 1.0], z  [-1.0, 0.0625]
                     topology: (Periodic, Periodic, Bounded)
      resolution (Nx, Ny, Nz): (16, 16, 16)
       halo size (Hx, Hy, Hz): (1, 1, 1)
    grid spacing (Δx, Δy, Δz): (0.0625, 0.0625, 0.0625)
    Notice that z ∈ [-1.0, 0.0625] should be z ∈ [-1.0, 0.0]. This has been fixed now.

I'd like to start using these features in LESbrary.jl (and in PR #572) so I'll tag v0.33.0 once this PR is merged.

Resolves #683

@codecov
Copy link

codecov bot commented Jul 27, 2020

Codecov Report

Merging #823 into master will increase coverage by 0.66%.
The diff coverage is 90.10%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #823      +/-   ##
==========================================
+ Coverage   70.72%   71.38%   +0.66%     
==========================================
  Files         188      189       +1     
  Lines        5113     5270     +157     
==========================================
+ Hits         3616     3762     +146     
- Misses       1497     1508      +11     
Impacted Files Coverage Δ
benchmark/benchmark_ffts.jl 0.00% <ø> (ø)
benchmark/benchmark_forcing_functions.jl 0.00% <ø> (ø)
benchmark/benchmark_tracers.jl 0.00% <ø> (ø)
benchmark/benchmark_utils.jl 0.00% <ø> (ø)
docs/make.jl 0.00% <ø> (ø)
src/Utils/Utils.jl 100.00% <ø> (ø)
src/Grids/regular_cartesian_grid.jl 81.81% <50.00%> (-8.19%) ⬇️
src/Grids/grid_utils.jl 89.36% <54.54%> (-10.64%) ⬇️
src/Utils/versioninfo.jl 85.71% <85.71%> (ø)
src/OutputWriters/netcdf_output_writer.jl 93.42% <87.50%> (-2.95%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 40e7caf...2a19ef9. Read the comment docs.

@@ -90,7 +90,7 @@ example, to set up a 1D model with $N_z$ grid points
julia> grid = RegularCartesianGrid(topology=(Flat, Flat, Bounded),
size=(1, 1, 90), extent=(1, 1, 1000))
RegularCartesianGrid{Float64, Flat, Flat, Bounded}
domain: x ∈ [0.0, 1.0], y ∈ [0.0, 1.0], z ∈ [-1000.0, 11.111111111111086]
domain: x ∈ [0.0, 1.0], y ∈ [0.0, 1.0], z ∈ [-1000.0, -2.471452993948034e-14]
Copy link
Member

Choose a reason for hiding this comment

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

hmmm

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm yeah it's not pretty but that's just floating point arithmetic I guess. Interestingly, in this case

julia> grid = RegularCartesianGrid(topology=(Flat, Flat, Bounded),
                                   size=(10, 10, 10), x=(0, 1), y=(0, 1), z=(0, 1))
RegularCartesianGrid{Float64, Flat, Flat, Bounded}
                   domain: x  [0.0, 1.0], y  [0.0, 1.0], z  [-1.6190752442450216e-17, 0.9999999999999999]
                 topology: (Flat, Flat, Bounded)
  resolution (Nx, Ny, Nz): (10, 10, 10)
   halo size (Hx, Hy, Hz): (1, 1, 1)
grid spacing (Δx, Δy, Δz): (0.1, 0.1, 0.1)

it's because

julia> -0.1 + 1.0 + 2*1.0 * 0.1
1.1

julia> -0.1 + (1.0 + 2*1.0 * 0.1)
1.0999999999999999

so we could probably fix it by changing

xF₊, yF₊, zF₊ = XF₊ = @. XF₋ + total_extent(topology, halo, Δ, L)

to something like

xF₊, yF₊, zF₊ = XF₊ = @. right_endpoint(topology, XF₋, halo, Δ, L)

global_attributes=Dict(), output_attributes=Dict(), dimensions=Dict(),
clobber=true, compression=0, slice_kw...)
clobber=true, compression=0, include_halos=false, verbose=false, slice_kwargs...)
Copy link
Member

Choose a reason for hiding this comment

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

This keyword argument could also be with_halos. We have a function with_tracers (this might be the only with_* currently); I had imagined we might have more with_* in the futures (eg a with_boundary_conditions function for Fields. So we could use that kind of nomenclature here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Done.

Copy link
Member

@glwagner glwagner left a comment

Choose a reason for hiding this comment

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

This looks great. The only change that might be considered it to change include_halos to with_halos, if we want to start promoting the pattern with_* in the API.

On the default choice to omit halos: I think (but am not completely sure) that this is what most users prefer when interacting with data as arrays, for convenience. We have gotten a bit of feedback on this question.

I do hope that some day we have abstractions for interacting with data as fields, rather than arrays. At that point, it may make sense to have halos saved by default. The reason is that without halos, fields cannot be differentiated or interpolated across boundaries correctly.

On the other hand, omitting halos is convenient for common data analysis tasks, such as plotting or the calculation of simple statistics (by "simple", this means statistics that do not involve differentiating or interpolating fields across boundaries, since this cannot be done correctly when halos are omitted). For the sake of this convenience, I think it makes sense to omit halos when data is being interacted with as arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to NetCDFOutputWriter to include halo regions
2 participants