python - 如何在python中将多个netcdf文件合并为一个数据文件

标签 python netcdf

!pip install wget
import wget
import requests
import numpy as np

days = ['01','15']
months = ['01','02','03','04','05','06','07','08','09','10','11','12']
years = np.array([2010, 2015, 2020])

for year in years:
    for month in months:
        for day in days:
            url = "https://www.ncei.noaa.gov/data/sea-surface-temperature-optimum-interpolation/v2.1/access/avhrr/"+str(year)+str(month)+"/oisst-avhrr-v02r01."+str(year)+str(month)+str(day)+".nc"
            r = requests.get(url, allow_redirects = True)
            open(str(year)+str(month)+str(day)+".nc", "wb").write(r.content)

我已经阅读了72个文件(3年中每个月的第1天和第15天:2010年、2015年、2020年)。我想将所有数据合并到一个 .nc 文件中,以便在 python 中读取我想要的数据。

最佳答案

下载所有文件后,您可以使用 xarray.open_mfdataset 自动打开并组合它们:

import xarray as xr
import os

DS = xr.open_mfdataset(os.path.join("path/to/files", "*.nc"))

关于python - 如何在python中将多个netcdf文件合并为一个数据文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70766427/

相关文章:

python - 在 python 中命名为非捕获组?

python - Python中通过散点提取二维网格场的值

python - 使用 Python 将现有 netcdf 文件中的 Nans 替换为 -9999

python - 使用 Python 对 NetCDF 文件进行循环纬度/经度裁剪

python - 在数组中执行按位左移操作时超出整数限制

python - 如何在不手动编写的情况下将障碍物分配到我的网格?

python - 在python中读取和操作多个netcdf文件

python - 如何找到netCDF数组除零之外的最小值

r - 使用 R : Manually works, download.file 下载 NetCDF 文件会产生错误

Python 单元测试无法解析导入语句