!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/