Skip to content

Commit

Permalink
avoid non-standard indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Aug 4, 2023
1 parent 4f77c8b commit 340a3af
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/NCODV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function load(T, fname, long_name; qv_flags = ["good_value", "probably_good_valu
ncvar_LOCAL_CDI_ID = varbyattrib_first(ds, long_name = "LOCAL_CDI_ID")

if ndims(ncvar_LOCAL_CDI_ID) == 2
LOCAL_CDI_ID = chararray2strings(ncvar_LOCAL_CDI_ID.var[:])
LOCAL_CDI_ID = chararray2strings(Array(ncvar_LOCAL_CDI_ID.var))
else
@warn """The variable with the long_name attribute \'LOCAL_CDI_ID\' is expected to have two dimensions. For example the output of 'ncdump -h' of $fname should contain:
[...]
Expand All @@ -348,13 +348,13 @@ We use the empty string for LOCAL_CDI_ID instead.
end

EDMO_CODE = if length(varbyattrib(ds; long_name = "EDMO_code")) > 0
varbyattrib_first(ds, long_name = "EDMO_code")[:]
Array(varbyattrib_first(ds, long_name = "EDMO_code"))
else
varbyattrib_first(ds, long_name = "EDMO_CODE")[:]
Array(varbyattrib_first(ds, long_name = "EDMO_CODE"))
end

obsproflon = varbyattrib_first(ds, standard_name = "longitude")[:]
obsproflat = varbyattrib_first(ds, standard_name = "latitude")[:]
obsproflon = Array(varbyattrib_first(ds, standard_name = "longitude"))
obsproflat = Array(varbyattrib_first(ds, standard_name = "latitude"))

# time for time series
ncvar_time = nothing
Expand All @@ -369,7 +369,7 @@ We use the empty string for LOCAL_CDI_ID instead.
@assert ndims(ncvar_time) == 2
else
# profile
obsproftime = varbyattrib_first(ds, standard_name = "time")[:]
obsproftime = Array(varbyattrib_first(ds, standard_name = "time"))
@assert ndims(obsproftime) == 1
end

Expand Down
10 changes: 5 additions & 5 deletions src/NCSDN.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ function loadvar(
return T[]
end

dataarray = ds[param][:]
dataarray = Array(ds[param])
data = nomissing(dataarray, fillvalue)

if qfname in ds
qf = ds[qfname].var[:]
qf = Array(ds[qfname].var)

keep_data = falses(size(qf))

Expand Down Expand Up @@ -176,7 +176,7 @@ function load(
)

if ndims(lon) == 1
#@show fname,param,size(lon),size(data)
@debug "check size",fname,param,size(lon),size(data)
@assert size(lon, 1) == size(data, 2)
lon = repeat(reshape(lon, 1, size(lon, 1)), inner = (size(data, 1), 1))
end
Expand Down Expand Up @@ -207,8 +207,8 @@ function load(
time = repeat(reshape(time, 1, size(time, 1)), inner = (size(data, 1), 1))
end

edmo = ds["SDN_EDMO_CODE"][:]
cdiid = ds["SDN_LOCAL_CDI_ID"][:]
edmo = Array(ds["SDN_EDMO_CODE"])
cdiid = Array(ds["SDN_LOCAL_CDI_ID"])

@assert size(edmo, 1) == size(data, 2)
@assert size(cdiid, 2) == size(data, 2)
Expand Down
12 changes: 6 additions & 6 deletions test/test_ncodv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,14 @@ obsvalue,obslon,obslat,obsdepth,obstime,obsids = NCODV.load(T,fname_TS,long_name
almostgood(qf) = !ismissing(qf) && ((qf == 49) || (qf == 50))

nc = NCDataset(fname_TS)
ox = nc["var3"][:];
ox_qf = nc["var3_qc"][:];
ox = nc["var3"][:,:];
ox_qf = nc["var3_qc"][:,:];

z = nc["var2"][:];
z_qf = nc["var2_qc"][:];
z = nc["var2"][:,:];
z_qf = nc["var2_qc"][:,:];

time = nc["var1_qc"].var[:];
time_qf = nc["var1_qc"][:];
time = nc["var1_qc"].var[:,:];
time_qf = nc["var1_qc"][:,:];

good = almostgood.(ox_qf) .& .!ismissing.(ox) .& almostgood.(z_qf) .& .!ismissing.(z) .& almostgood.(time_qf) .& .!ismissing.(time)

Expand Down
2 changes: 1 addition & 1 deletion test/test_save.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ relerr = rand(T, sz)
DIVAnd.save(filename, xyi, fi, varname; type_save = T, relerr = relerr)

ds = Dataset(filename)
fi2 = ds[varname][:]
fi2 = ds[varname][:,:,:,:]
close(ds)

@test fi2[mask] == fi[mask]
Expand Down

0 comments on commit 340a3af

Please sign in to comment.