-
Notifications
You must be signed in to change notification settings - Fork 254
Improvements and fixes to NetCDFWriter
#4890
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
Conversation
ext/OceananigansNCDatasetsExt.jl
Outdated
|
|
||
| function squeeze_reduced_dimensions(data, reduced_dims) | ||
| # Fill missing indices from the right with 1s | ||
| indices = Any[:,:,:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| indices = Any[:,:,:] | |
| indices = Any[:, : ,:] |
what does this mean exactly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is meant for the whole algorithm, not just that line. Basically it gets Fields that have Nothing in any of the locations and it gets rid of that dimension. (I'm calling these reduced_dims but there's probably a better name.)
So for example, if data comes from an array that has loc = Center, Center, Nothing, it'll reduce its parent data by indexing it as data[:, :, 1]; i.e. a 2D array in this case.
I'm testing this out (hence a draft PR) after some discussions with @ali-ramadhan. Basically we want to keep all NetCDF arrays 3D (to mimic Oceananigans' behavior) as much as possible, but in NetCDF there's no concept of location, so we can't easily pass LZ = Nothing to NetCDF. In these cases it probably makes sense to squeeze that dimension (or whatever the verb for this is) so that we know that dimension is reduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add attributes that indicate the location? We can add custom attributes to data even if they are not built in, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can (and in fact I probably will do it regardless), but that doesn't affect calculations with any of the software (that I'm aware of) which reads NetCDF. So broadcasting and other useful things wouldn't work. Without the singleton dimensions (i.e. with the change that I'm exploring here), those things will work out of the box for most software.
Also if we include the singleton reduced dimension, we still would need to pick a value for that length-1 coordinate. In Oceananigans, that value is nothing I think, but there's no analog to that for NetCDF, so we'd need to pick an arbitrary value like 1 or 0, which I'd like to avoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also to be clear, this PR would move the NetCDF behavior closer to Oceananigans' behavior. Currently the NetCDF writer also drops singleton dimensions whenever we slice a field, even though that sliced dimension (or length 1) has a proper value. This PR would change the behavior and keep that sliced length-1 dimension in the NetCDF, just like Oceananigans does.
…ans.jl into tc/simpler-initialize_nc
|
I think this PR is ready to be reviewed (the only failure is some keyring docs thing). I updated the top post to include a description of what was done. The most important thing is that slices with a singleton dimension now keep the singleton dimension, which is what Oceanigans does. I'm only removing singleton dimensions in the data when there isn't a well-defined coordinate value associated with it. Namely when the dimension is For the record, if I try to replace |
|
@glwagner @ali-ramadhan one thing I'd like to discuss is whether we should make the spatial dimensions always Float64. I've faced alignment problems before when working with two separate NetCDF files from the same simulation: one in Float64 for calculations, and another in Float32 for plotting. We already enforce Float64 with the time dimension, so I think it'd be natural to do it with xyz as well. |
happy for that. You could also make it user choice, with default Float64? That would be the Oceananigans Way. |
Sounds good! Just added that option with a Float64 default, plus a test :) |
This PR contains:
ImmersedBoundaryGridreconstruction using NetCDF #4848 easier.dimension_typetoNetCDFWriterwhich controls the precision type for dimensions, with a default value ofFloat64.NetCDFWritercloser to what Oceananigans does. In particular singleton dimensions are kept if the location has a well-defined value (i.e. the value is notnothing, which NetCDF can't handle). This means will remove singleton dimensions only when:FlatTo- do list:
NetCDFOutputWritersometimes outputs twice at approximately the same time step #3056).NetCDFWriteris different frommodel.grid