Skip to content

Upgrade NetCDF output writer to write arbitrary outputs for LESbrary use #643

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

Merged
merged 10 commits into from
Feb 26, 2020

Conversation

ali-ramadhan
Copy link
Member

This PR allows NetCDFOutputWriter to write arbitrary outputs, similar to how we pass functions that return data to be saved to disk with the JLD2 output writer, but now with metadata! The dimensions kwarg allows you to pass a dictionary of dimensions to apply to any outputs.

I also cleaned up the NetCDFOutputWriter a bit and changed the name of the time dimension from "Time" to "time".

@suyashbire1 Let me know if I did anything wrong.

I added a pretty comprehensive test that shows how you might write a mix of scalars, profiles, and slices to a NetCDF file with grid/unit/name metadata and global attributes.

Here's what the API looks like right now:

# Define scalar, vector, 2D slice, and 3D field outputs
f(model) = model.clock.time^2
g(model) = @. model.clock.time * exp(model.grid.zC)
h(model) = @. model.clock.time * sin(model.grid.xC) * cos(model.grid.yC')

outputs = Dict("scalar" => f, "profile" => g, "slice" => h)
dims = Dict("scalar" => (), "profile" => ("zC",), "slice" => ("xC", "yC"))

output_attributes = Dict(
    "scalar"  => Dict("longname" => "Some scalar", "units" => "bananas"),
    "profile" => Dict("longname" => "Some vertical profile", "units" => "watermelons"),
    "slice"   => Dict("longname" => "Some slice", "units" => "mushrooms")
)

global_attributes = Dict("location" => "Bay of Fundy", "onions" => 7)

simulation.output_writers[:fruits] =
    NetCDFOutputWriter(
        model, outputs; frequency=1, filename="test_function_outputs.nc", dimensions=dims,
        global_attributes=global_attributes, output_attributes=output_attributes)

run!(simulation)

@ali-ramadhan ali-ramadhan added feature 🌟 Something new and shiny cleanup 🧹 Paying off technical debt abstractions 🎨 Whatever that means labels Feb 24, 2020
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.

Beautiful. Is this documented? Is there an example? The two_dimensional_turbulence.jl example could be appended to output vorticity, perhaps... or one of the three-dimensional examples might be modified.

@ali-ramadhan
Copy link
Member Author

The NetCDF tests fail on GPU so gotta look into that.

Is this documented? Is there an example?

No and no, but yeah we should update model setup documentation and show an example of how to use it. Vorticity example might be good. Might also be nice to have the example save a horizontal average to NetCDF so we can also show how to save outputs with different dimensions.

@codecov
Copy link

codecov bot commented Feb 25, 2020

Codecov Report

Merging #643 into master will decrease coverage by 2.9%.
The diff coverage is 97.22%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #643      +/-   ##
=========================================
- Coverage   78.11%   75.2%   -2.91%     
=========================================
  Files         119     119              
  Lines        2326    2267      -59     
=========================================
- Hits         1817    1705     -112     
- Misses        509     562      +53
Impacted Files Coverage Δ
src/OutputWriters/OutputWriters.jl 100% <ø> (ø) ⬆️
src/OutputWriters/checkpointer.jl 90.9% <ø> (-0.62%) ⬇️
src/OutputWriters/netcdf_output_writer.jl 87.5% <100%> (-12.5%) ⬇️
src/OutputWriters/output_writer_utils.jl 61.53% <50%> (-0.63%) ⬇️
src/Coriolis/no_rotation.jl 0% <0%> (-100%) ⬇️
src/Forcing/Forcing.jl 50% <0%> (-50%) ⬇️
src/SurfaceWaves.jl 0% <0%> (-47.06%) ⬇️
src/AbstractOperations/interpolation_utils.jl 63.33% <0%> (-33.34%) ⬇️
src/AbstractOperations/AbstractOperations.jl 33.33% <0%> (-33.34%) ⬇️
src/Forcing/simple_forcing.jl 50% <0%> (-33.34%) ⬇️
... and 38 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 9f72d84...7809b1e. Read the comment docs.

@glwagner
Copy link
Member

No and no, but yeah we should update model setup documentation and show an example of how to use it. Vorticity example might be good. Might also be nice to have the example save a horizontal average to NetCDF so we can also show how to save outputs with different dimensions.

Maybe just get this merged and open an issue?

\ Outdated
"w" => Dict("longname" => "Velocity in the z-direction", "units" => "m/s"),
"b" => Dict("longname" => "Buoyancy", "units" => "m/s²"),
"T" => Dict("longname" => "Conservative temperature", "units" => "K"),
"S" => Dict("longname" => "Absolute aalinity", "units" => "g/kg")
Copy link
Member

Choose a reason for hiding this comment

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

typo

"w" => Dict("longname" => "Velocity in the z-direction", "units" => "m/s"),
"b" => Dict("longname" => "Buoyancy", "units" => "m/s²"),
"T" => Dict("longname" => "Conservative temperature", "units" => "K"),
"S" => Dict("longname" => "Absolute aalinity", "units" => "g/kg")
Copy link
Member

Choose a reason for hiding this comment

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

Typo here. There is also a spurious file called / above.

@glwagner
Copy link
Member

@ali-ramadhan a spurious file should be deleted before this is merged.

@ali-ramadhan
Copy link
Member Author

Ah thanks for catching that, no idea how it happened.

@ali-ramadhan
Copy link
Member Author

Maybe just get this merged and open an issue?

Yeah sure, there are a few other things that need updating too.

@ali-ramadhan ali-ramadhan merged commit 705158b into master Feb 26, 2020
@ali-ramadhan ali-ramadhan deleted the ar/netcdf-improvements branch February 26, 2020 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abstractions 🎨 Whatever that means cleanup 🧹 Paying off technical debt feature 🌟 Something new and shiny
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants