Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ClimaArtifactsHelper.jl/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.0.1"
[deps]
ArtifactUtils = "8b73e784-e7d8-4ea5-973d-377fed4e3bce"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Expand Down
51 changes: 49 additions & 2 deletions ClimaArtifactsHelper.jl/src/ClimaArtifactsHelper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module ClimaArtifactsHelper
using ArtifactUtils
using REPL.TerminalMenus
using Pkg.Artifacts
using NCDatasets

import SHA: sha1
import Downloads: download

export create_artifact_guided,
create_artifact_guided_one_file,
download_rate_callback
create_artifact_guided_one_file, download_rate_callback, thin_NCDataset!

const MB = 1024 * 1024
const GB = 1024 * MB
Expand Down Expand Up @@ -261,4 +261,51 @@ function create_artifact_guided_one_file(
create_artifact_guided(output_dir; artifact_name, append)
end

"""
thin_NCDataset!(ds_out::NCDataset, ds_in::NCDataset, thinning_factor=6, dims...)

Fills `ds_out` with a thinned version of `ds_in` by a factor of `thinning_factor` in the dimensions `dims`.
If no dimensions are provided, all dimensions are thinned.
"""
function thin_NCDataset!(ds_out::NCDataset, ds_in::NCDataset, thinning_factor = 6, dims...)
# check that requested regrid dimensions are in the dataset.
all(in.(dims, Ref(keys(ds_in.dim)))) || error("Not all of $dims are in the dataset")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why we need a Ref here? Can you add a comment explaining this or find an alternative solution?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ref prevents broadcasting over the list of dimensions in the input file. I think this is done pretty commonly.

@show typeof(ds_out.attrib)
@show ds_in.attrib
old_history = get(ds_out.attrib, "history", "")
ds_out.attrib["history"] =
old_history * "; Thinned by a factor of $thinning_factor in dimensions $dims"
for (dim_name, dim_length) in ds_in.dim
if dim_name in dims
defDim(ds_out, dim_name, Int(ceil(ds_in.dim[dim_name] // thinning_factor)))
else
defDim(ds_out, dim_name, ds_in.dim[dim_name])
end
end
for (varname, var) in ds_in
var_dims = dimnames(var)
input_indices = map(var_dims) do dim_name
dim_name in dims ? range(1, ds_in.dim[dim_name]; step = thinning_factor) : Colon()
end
defVar(ds_out, varname, var[input_indices...], dimnames(var), attrib = var.attrib)
end
end

"""
thin_NCDataset!(ouput_path, input_path, thinning_factor=6, dims...)

Create and thin a new NetCDF file at `ouput_path` from the file at `input_path` by a factor of
`thinning_factor` in the dimensions `dims`. This method also copies the global attributes.
"""
function thin_NCDataset!(ouput_path, input_path, thinning_factor = 6, dims...)
ds_in = NCDataset(input_path)
ds_out = NCDataset(ouput_path, "c"; attrib = copy(ds_in.attrib))
thin_NCDataset!(ds_out, ds_in, thinning_factor, dims...)
close(ds_out)
close(ds_in)
end

thin_NCDataset!(ds_out::NCDataset, ds_in::NCDataset, thinning_factor = 6) =
thin_NCDataset!(ds_out, ds_in, thinning_factor, keys(ds_in.dim)...)

end
2 changes: 1 addition & 1 deletion aerosol_concentrations/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ weakdeps = ["SparseArrays"]
ChainRulesCoreSparseArraysExt = "SparseArrays"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion bedrock_depth/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion bonan_richards_eqn/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.9"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion clm_data/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.9"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion co2_dataset/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.9"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion era5_cloud/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion era5_lai_covers/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ weakdeps = ["GeoMakie", "Makie"]
ClimaAnalysisMakieExt = "Makie"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion era5_monthly_averages_2008/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion era5_monthly_averages_single_level_1979_2024/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion forty_yrs_era5_land_forcing_data/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion historical_sst_sic/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion landsea_mask/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"
version = "0.2.6"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion lehmann2008_evaporation/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.9"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion merra2_AOD/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.4"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion merra2_aerosols/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ weakdeps = ["SparseArrays"]
ChainRulesCoreSparseArraysExt = "SparseArrays"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion ozone_concentrations/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion precipitation_obs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.8"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion radiation_obs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.9"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion soil_ic_2008_50m/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.4"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion surface_temperatures/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion sw_albedo/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.3"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion topo_drag/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.9"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion water_conservation_test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.9"

[[deps.ClimaArtifactsHelper]]
deps = ["ArtifactUtils", "Downloads", "Pkg", "REPL", "SHA"]
deps = ["ArtifactUtils", "Downloads", "NCDatasets", "Pkg", "REPL", "SHA"]
path = "../ClimaArtifactsHelper.jl"
uuid = "6ffa2572-8378-4377-82eb-ea11db28b255"
version = "0.0.1"
Expand Down