Skip to content

Commit

Permalink
try it now
Browse files Browse the repository at this point in the history
  • Loading branch information
simone-silvestri committed Nov 28, 2024
1 parent 51aff06 commit d22edc9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
5 changes: 2 additions & 3 deletions src/Bathymetry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Bathymetry
export regrid_bathymetry, retrieve_bathymetry

using ImageMorphology
using ..DataWrangling: DownloadProgress
using ..DataWrangling: download_progress

using Oceananigans
using Oceananigans.Architectures: architecture, on_architecture
Expand Down Expand Up @@ -96,8 +96,7 @@ function regrid_bathymetry(target_grid;
fileurl = url * "/" * filename # joinpath on windows creates the wrong url

@root if !isfile(filepath) # perform all this only on rank 0, aka the "root" rank
progress = DownloadProgress(filename)
Downloads.download(fileurl, filepath; progress)
Downloads.download(fileurl, filepath; progress=download_progress)
end

dataset = Dataset(filepath)
Expand Down
23 changes: 7 additions & 16 deletions src/DataWrangling/DataWrangling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,20 @@ using Oceananigans: pretty_filesize, location
using Oceananigans.Utils: launch!
using KernelAbstractions: @kernel, @index

struct DownloadProgress <: Function
fileurl :: String
messages :: Int
next_fraction :: Ref{Float64}
download_start_time :: Ref{UInt64}
end

DownloadProgress(fileurl) = DownloadProgress(fileurl, 10, Ref(0.0), Ref(time_ns()))
next_fraction = Ref(0.0)
download_start_time = Ref(time_ns())

"""
DowloadProgress(total, now; filename="")
a graceful progres for downloading files
download_progress(total, now; filename="")
"""
function (d::DownloadProgress)(total, now; filename="")
messages = d.messages
next_fraction = d.next_fraction
download_start_time = d.download_start_time
function download_progress(total, now; filename="")
messages = 10

if total > 0
fraction = now / total

if fraction < 1 / messages && next_fraction[] == 0
@info @sprintf("Downloading %s (size: %s)...", d.fileurl, pretty_filesize(total))
@info @sprintf("Downloading %s (size: %s)...", filename, pretty_filesize(total))
next_fraction[] = 1 / messages
download_start_time[] = time_ns()
end
Expand All @@ -50,6 +40,7 @@ function (d::DownloadProgress)(total, now; filename="")
end
else
if now > 0 && next_fraction[] == 0
@info "Downloading $filename..."
next_fraction[] = 1 / messages
download_start_time[] = time_ns()
end
Expand Down
2 changes: 1 addition & 1 deletion src/DataWrangling/ECCO/ECCO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export ECCORestoring, LinearlyTaperedPolarMask

using ClimaOcean
using ClimaOcean.DataWrangling
using ClimaOcean.DataWrangling: inpaint_mask!, NearestNeighborInpainting, DownloadProgress
using ClimaOcean.DataWrangling: inpaint_mask!, NearestNeighborInpainting, download_progress
using ClimaOcean.InitialConditions: three_dimensional_regrid!, interpolate!

using Oceananigans
Expand Down
4 changes: 2 additions & 2 deletions src/DataWrangling/ECCO/ECCO_metadata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ function download_dataset(metadata::ECCOMetadata; url = urls(metadata))
and setting your ECCO_USERNAME and ECCO_PASSWORD." * instructions_msg
throw(ArgumentError(msg))
end
progress = DownloadProgress("$(summary(metadata))")
Downloads.download(fileurl, filepath; downloader, progress)

Downloads.download(fileurl, filepath; downloader, progerss=download_progress)
end
end

Expand Down
7 changes: 2 additions & 5 deletions src/DataWrangling/JRA55.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using Oceananigans.Fields: interpolate!
using Oceananigans.OutputReaders: Cyclical, TotallyInMemory, AbstractInMemoryBackend, FlavorOfFTS, time_indices

using ClimaOcean
using ClimaOcean.DataWrangling: DownloadProgress
using ClimaOcean.DataWrangling: download_progress

using ClimaOcean.OceanSeaIceModels:
PrescribedAtmosphere,
Expand Down Expand Up @@ -391,10 +391,7 @@ function JRA55_field_time_series(variable_name;

# Note, we don't re-use existing jld2 files.
@root begin
if isfile(filepath)
progress = DownloadProgress("JRA55 $variable_name data", 50)
Downloads.download(url, filepath; progress)
end
isfile(filepath) || download(url, filepath; progress=download_progress)
isfile(jld2_filepath) && rm(jld2_filepath)
end

Expand Down

0 comments on commit d22edc9

Please sign in to comment.