From ebb1b43bfb04f1cc274a1e041ac5ca67c5ce43b5 Mon Sep 17 00:00:00 2001 From: Julia Sloan Date: Thu, 30 Nov 2023 09:20:04 -0800 Subject: [PATCH] NCD updates --- .../AMIP/modular/user_io/ncep_visualizer.jl | 10 +++++----- src/Regridder.jl | 14 +++++++------- test/TestHelper.jl | 2 +- test/regridder_tests.jl | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/experiments/AMIP/modular/user_io/ncep_visualizer.jl b/experiments/AMIP/modular/user_io/ncep_visualizer.jl index c31e7ec435..99ab5d2d68 100644 --- a/experiments/AMIP/modular/user_io/ncep_visualizer.jl +++ b/experiments/AMIP/modular/user_io/ncep_visualizer.jl @@ -87,16 +87,16 @@ function download_read_nc(data_source::NCEPMonthlyDataSource, https::String, nce local_file = joinpath(data_source.tmp_dir, ncep_vname * ".nc") Downloads.download(https, local_file) NCDataset(local_file) do ds - t_i = findall(x -> Dates.yearmonth(x) == Dates.yearmonth(data_source.month_date[1]), ds["time"][:]) # time index of month in file - d_i = length(size(ds[ncep_vname][:])) # index of time in the dimension list - lev = "level" in keys(ds) ? ds["level"][:] : [Float64(-999)] - data = dropdims(selectdim(ds[ncep_vname][:], d_i, t_i), dims = d_i) + t_i = findall(x -> Dates.yearmonth(x) == Dates.yearmonth(data_source.month_date[1]), Array(ds["time"])) # time index of month in file + d_i = length(size(Array(ds[ncep_vname]))) # index of time in the dimension list + lev = "level" in keys(ds) ? Array(ds["level"]) : [Float64(-999)] + data = dropdims(selectdim(Array(ds[ncep_vname]), d_i, t_i), dims = d_i) if length(size(data)) == 3 data .= data[:, end:-1:1, end:-1:1] else data .= data[:, end:-1:1] end - coords = (; lon = ds["lon"][:], lat = ds["lat"][:][end:-1:1], lev = lev[end:-1:1]) + coords = (; lon = Array(ds["lon"]), lat = Array(ds["lat"])[end:-1:1], lev = lev[end:-1:1]) (Array(data), coords) end end diff --git a/src/Regridder.jl b/src/Regridder.jl index 55920a7d23..ee97319ba3 100644 --- a/src/Regridder.jl +++ b/src/Regridder.jl @@ -263,7 +263,7 @@ determined by the space type. """ function get_coords(ds, ::Spaces.ExtrudedFiniteDifferenceSpace) data_dates = get_time(ds) - z = ds["z"][:] + z = Array(ds["z"]) return (data_dates, z) end function get_coords(ds, ::Spaces.SpectralElementSpace2D) @@ -278,9 +278,9 @@ Extracts the time information from a NetCDF file `ds`. """ function get_time(ds) if "time" in ds - data_dates = Dates.DateTime.(ds["time"][:]) + data_dates = Dates.DateTime.(Array(ds["time"])) elseif "date" in ds - data_dates = TimeManager.strdate_to_datetime.(string.(Int.(ds["date"][:]))) + data_dates = TimeManager.strdate_to_datetime.(string.(Int.(Array(ds["date"])))) else @warn "No dates available in input data file" data_dates = [Dates.DateTime(0)] @@ -585,10 +585,10 @@ Extract data and coordinates from `datafile_latlon`. """ function read_remapped_field(name::Symbol, datafile_latlon::String, lev_name = "z") out = NCDataset(datafile_latlon, "r") do nc - lon = nc["lon"][:] - lat = nc["lat"][:] - lev = lev_name in keys(nc) ? nc[lev_name][:] : Float64(-999) - var = nc[name][:] + lon = Array(nc["lon"]) + lat = Array(nc["lat"]) + lev = lev_name in keys(nc) ? Array(nc[lev_name]) : Float64(-999) + var = Array(nc[name]) coords = (; lon = lon, lat = lat, lev = lev) (var, coords) diff --git a/test/TestHelper.jl b/test/TestHelper.jl index 34577997b4..1610d4fe7e 100644 --- a/test/TestHelper.jl +++ b/test/TestHelper.jl @@ -13,7 +13,7 @@ using NCDatasets export create_space, gen_ncdata """ - create_space(FT; comms_ctx = ClimaComms.SingletonCommsContext(), + create_space(FT; comms_ctx = ClimaComms.SingletonCommsContext(), R = FT(6371e3), ne = 4, polynomial_degree = 3, nz = 1) Initialize a space on a sphere with the given parameters. diff --git a/test/regridder_tests.jl b/test/regridder_tests.jl index b8dbf50698..db56f3d32c 100644 --- a/test/regridder_tests.jl +++ b/test/regridder_tests.jl @@ -294,7 +294,7 @@ for FT in (Float32, Float64) T_rll, _ = Regridder.cgll2latlonz(T_cgll) # check consistency across z-levels - @test T_rll[:, :, 1] == T_rll[:, :, 2] + @test Array(T_rll)[:, :, 1] == Array(T_rll)[:, :, 2] # check consistency of CGLL remapped data with original data @test all(isapprox.(extrema(data), extrema(parent(T_cgll)), atol = 1e-2)) @@ -304,7 +304,7 @@ for FT in (Float32, Float64) # visual inspection # Plots.plot(T_cgll) # using ClimaCorePlots - # Plots.contourf(T_rll[:,:,1]) + # Plots.contourf(Array(T_rll)[:,1]) # Delete testing directory and files rm(REGRID_DIR; recursive = true, force = true)