-
Notifications
You must be signed in to change notification settings - Fork 13
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
Read ECCO-Darwin field from NASA Earthdata #328
Open
seamanticscience
wants to merge
9
commits into
CliMA:main
Choose a base branch
from
seamanticscience:jml/climaocean-oceanbgc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+131
−14
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
af59f98
Use ECCODarwin (binary) data to initialize ClimaOcean runs
seamanticscience fb0217e
add `MeshArrays` dependency
seamanticscience 7b9d642
add `scale_factor` to allow conversion of `ECCODarwin` units to `Clim…
seamanticscience e291e17
avoid `Method overwriting` warning by removing duplicate `metadata_fi…
seamanticscience 6f3e0db
Fix another `method overwrite` warning
seamanticscience 9d178b7
review suggestions
seamanticscience c6f176c
Refactor ECCO Darwin code
seamanticscience 7b7eba6
refine inpainting
seamanticscience 074da93
apply mask on the native grid in `ECCO_darwin_model_data`.
seamanticscience File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using MeshArrays | ||
|
||
Base.size(::ECCOMetadata{<:AbstractCFDateTime, <:ECCO4DarwinMonthly}) = (720, 360, 50, 1) | ||
Base.size(data::ECCOMetadata{<:Any, <:ECCO4DarwinMonthly}) = (720, 360, 50, length(data.dates)) | ||
|
||
# File name generation specific to each Dataset version | ||
function metadata_filename(metadata::ECCOMetadata{<:AbstractCFDateTime, <:ECCO4DarwinMonthly}) | ||
shortname = short_name(metadata) | ||
|
||
reference_date = DateTimeProlepticGregorian(1992, 1, 1, 12, 0, 0) | ||
timestep_size = 3600 | ||
|
||
iternum = Dates.value((metadata.dates - reference_date) / (timestep_size * 1e3)) | ||
iterstr = string(iternum, pad=10) | ||
|
||
return shortname * "." * iterstr * ".data" | ||
end | ||
|
||
# Convenience functions | ||
short_name(data::ECCOMetadata{<:Any, <:ECCO4DarwinMonthly}) = ECCO_darwin_short_names[data.name] | ||
|
||
metadata_url(prefix, m::ECCOMetadata{<:Any, <:ECCO4DarwinMonthly}) = prefix * "/" * short_name(m) * "/" * metadata_filename(m) | ||
|
||
location(::ECCOMetadata{<:Any, <:ECCO4DarwinMonthly}) = (Center, Center, Center) | ||
|
||
variable_is_three_dimensional(::ECCOMetadata{<:Any, <:ECCO4DarwinMonthly}) = true | ||
|
||
ECCO_darwin_short_names = Dict( | ||
:DIC => "DIC", | ||
:ALK => "ALK", | ||
:PO₄ => "PO4", | ||
:NO₃ => "NO3", | ||
:DOP => "DOP", | ||
:POP => "POP", | ||
:Fe => "FeT", | ||
:Siᵀ => "SiO2", | ||
) | ||
|
||
ECCO_darwin_scale_factor = Dict( | ||
:DIC => 1e-3, | ||
:ALK => 1e-3, | ||
:PO₄ => 1e-3, | ||
:NO₃ => 1e-3, | ||
:DOP => 1e-3, | ||
:POP => 1e-3, | ||
:Fe => 1e-3, | ||
:Siᵀ => 1e-3, | ||
) | ||
|
||
# URLs for the ECCO datasets specific to each version | ||
urls(::ECCOMetadata{<:Any, <:ECCO4DarwinMonthly}) = "https://ecco.jpl.nasa.gov/drive/files/ECCO2/LLC90/ECCO-Darwin/monthly/" | ||
|
||
ECCO_darwin_native_grid(::ECCO4DarwinMonthly) = GridSpec("LatLonCap", MeshArrays.GRID_LLC90) | ||
ECCO_darwin_native_size(::ECCO4DarwinMonthly) = (90, 1170, 50) | ||
|
||
""" | ||
ECCO_darwin_model_data(metafile) | ||
|
||
Read a ECCO4DarwinMonthly data file and regrid using MeshArrays on to regular lat-lon grid | ||
""" | ||
function ECCO_darwin_model_data(metadata, path) | ||
native_size = ECCO_darwin_native_size(metadata.version) | ||
native_grid = ECCO_darwin_native_grid(metadata.version) | ||
native_data = zeros(Float32, prod(native_size)) # Native LLC90 grid at precision of the input binary file | ||
|
||
read!(path, native_data) | ||
native_data = bswap.(native_data) | ||
|
||
meshed_data = read(reshape(native_data, native_size...), native_grid) | ||
Nx, Ny, Nz, _ = size(metadata) | ||
coeffs = interpolation_setup() | ||
data = zeros(Float32, Nx, Ny, Nz) # Native LLC90 grid at precision of the input binary file | ||
|
||
# Interpolate each layer | ||
for k in 1:Nz | ||
i, j, c = Interpolate(meshed_data[:, k], coeffs) | ||
data[:, :, k] = c | ||
end | ||
|
||
# Reverse the z-axis | ||
data = reverse(data, dims=3) | ||
|
||
# Fill NaNs in Antarctica with zeros | ||
data[isnan.(data)] .= 0.f0 | ||
|
||
scale_factor = ECCO_darwin_scale_factor[metadata.name] | ||
# Scale data according to metadata.scale_factor | ||
return data .* scale_factor | ||
end | ||
|
||
retrieve_data(metadata::ECCOMetadata{<:Any, <:ECCO4DarwinMonthly}, path) = ECCO_darwin_model_data(metadata, path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Will be slightly cleaner to use abstract type or type union to express this. This pattern does not generalize well; this makes it more work to change how we express
version
for example.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.
as in
if metadata.version isa Union{ECCO4Monthly, ECCO4DarwinMonthly}
?