Skip to content

Commit

Permalink
add nc_crop
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Jul 12, 2024
1 parent 39d2816 commit ce37d9c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/NetCDFTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ include("ncdim_def.jl")
include("ncatt_put.jl")
include("tools_rbase.jl")

include("utilize/nc_aggregate.jl")
include("utilize/nc_combine.jl")
include("utilize/nc_subset.jl")
include("utilize/utilize.jl")

include("MFDataset/MFDataset.jl")
# CMIP
Expand Down
2 changes: 1 addition & 1 deletion src/utilize/nc_aggregate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ function nc_aggregate_dir(indir;
end


export nc_aggregate, nc_aggregate_dir

21 changes: 21 additions & 0 deletions src/utilize/nc_crop.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
nc_crop(f::String, range, fout::String;
compress=false, overwrite=false, kw...)
只有一个变量的情况。
"""
function nc_crop(f::String, range::Vector, fout::String;
compress=false, overwrite=false, kw...)

lon, lat = st_dims(f)
ilon = findall(range[1] .<= lon .<= range[2]) |> zip
ilat = findall(range[3] .<= lat .<= range[4]) |> zip

A = nc_read(f, ind=(ilon, ilat, :));
var = nc_bands(f)[1]
_dims = ncvar_dim(f)
_dims["lon"] = _dims["lon"][ilon]
_dims["lat"] = _dims["lat"][ilat]

nc_write(fout, var, A, _dims; compress, overwrite, kw...)
end
1 change: 0 additions & 1 deletion src/utilize/nc_subset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,3 @@ function nc_subset(d::AbstractDataFrame, range;
end


export nc_subset
8 changes: 8 additions & 0 deletions src/utilize/utilize.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include("nc_aggregate.jl")
include("nc_combine.jl")
include("nc_subset.jl")
include("nc_crop.jl")

export nc_aggregate, nc_aggregate_dir
export nc_combine
export nc_subset, nc_crop

0 comments on commit ce37d9c

Please sign in to comment.