Is there a way to crop a NETCDF file?

前端 未结 3 685
盖世英雄少女心
盖世英雄少女心 2021-02-09 02:55

Imagine that you have a file example.nc, that has wind data defined in 90N, 90S, 180E, 180W region. Is there anyway I could in linux, with a simple nc-type command

3条回答
  •  無奈伤痛
    2021-02-09 03:50

    If you are on Linux or macOS, you can do this easily using nctoolkit (https://nctoolkit.readthedocs.io/en/latest/) on Python.

    import nctoolkit as nc
    nc.options(lazy = True)
    data = nc.open_data("example.nc")
    data.clip(lon = [25, 50], lat = [30, 40])
    data.write_nc("output.nc")
    

    Under the hood, nctoolkit uses CDO. So the above is the equivalent of the CDO approach mentioned above:

    cdo sellonlatbox,lon1,lon2,lat1,lat2 infile.nc outfile.nc
    

提交回复
热议问题