Skip to content

Commit

Permalink
fix nc_aggregate_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Dec 3, 2023
1 parent 62c6b20 commit d22e073
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/BiasCorrection/QDM.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# > 测试如何做偏差矫正更有效,时间序列可能出现不连续的现象
using StatsBase: ecdf, quantile


Expand Down
4 changes: 2 additions & 2 deletions src/nc_info.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function nc_bands(ds::NCdata)
# v_id = NCDatasets.nc_inq_varids(ds.ncid)
# vars = NCDatasets.nc_inq_varname.(ds.ncid, v_id)
vars = keys(ds)
dims = ["lon", "long", "longitude",
"lat", "latitude",
dims = ["x", "lon", "long", "longitude",
"y", "lat", "latitude",
"lev", "level", "mlev", "plev",
"height",
"crs",
Expand Down
11 changes: 6 additions & 5 deletions src/utilize/nc_aggregate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
$(METHODLIST)
"""
function nc_aggregate(f::AbstractString, fout=nothing; by="year", fun=nanmean,
outdir=".", overwrite=false, verbose=true)
function nc_aggregate(f::AbstractString, fout=nothing; by="year", fun=mean,
outdir="./OUTPUT", overwrite=false, verbose=true)

fout === nothing && (fout = "$outdir/$(basename(f))")
if isfile(fout) && !overwrite
Expand Down Expand Up @@ -42,7 +42,7 @@ function nc_aggregate(f::AbstractString, fout=nothing; by="year", fun=nanmean,

printstyled("Writing data...\n")
@time nc_write(fout, band, vals, dims, Dict(nc[band].attrib);
compress=0, goal_attrib=Dict(nc.attrib))
compress=0, global_attrib=Dict(nc.attrib))

nc_close(nc)
end
Expand All @@ -58,15 +58,16 @@ scenario = "historical"
indir = "Z:/ChinaHW/CMIP6_cluster_HItasmax_adjchunk/HI_tasmax/historical"
outdir = "Z:/ChinaHW/CMIP6_cluster_HItasmax_adjchunk/HI_tasmax_year/historical"
nc_aggregate_dir(indir; by="year", outdir)
nc_aggregate_dir(indir; by="year", replacement="day"=>"year", outdir)
```
$(METHODLIST)
"""
function nc_aggregate_dir(indir;
by="year", replacement="day"=>by, outdir=".", kw...)
by="year", replacement="day"=>by, outdir="./OUTPUT", kw...)

fs = dir(indir, "nc\$")
check_dir(outdir)

for f in fs
file = str_replace(basename(f), replacement[1], replacement[2])
Expand Down
2 changes: 1 addition & 1 deletion src/utilize/nc_combine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function nc_combine(fs, fout; compress=0)

printstyled("Writing data...\n")
@time nc_write(fout, band, vals, dims, Dict(v.attrib);
compress, goal_attrib=Dict(nc.attrib))
compress, global_attrib=Dict(nc.attrib))
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/utilize/nc_subset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function nc_subset(f, range::Vector, fout=nothing;

printstyled("Writing data...\n")
@time nc_write(fout, band, vals, dims, Dict(v.attrib);
compress=1, goal_attrib=Dict(nc.attrib))
compress=1, global_attrib=Dict(nc.attrib))
# ncatt_put(fout, Dict(nc.attrib))
end

Expand Down

0 comments on commit d22e073

Please sign in to comment.