【发布时间】:2021-01-21 11:39:11
【问题描述】:
我在尝试获得 Sentinel 3 图像的月平均值时遇到了一些麻烦……真的。 Python,Matlab,我们两个人都陷入了这个问题。
主要原因在于这些图像的信息不在单个 netcdf 文件中,而是整齐地与坐标和产品一起放置。相反,它们都位于一天文件夹中的单独文件中 different .nc files with different information each, about one single satellite image。据我了解,SNAP 使用 xmlxs 文件来处理所有这些单独的 .nc 文件。
现在,我认为尝试合并和创建/编辑 .nc 文件以创建一个新的每日 .nc 文件是一个好主意,其中包括叶绿素、坐标,还不如添加时间。稍后,我将合并这些新的,以便能够使用 xarray 计算每月平均值。至少那是我的想法,但我不能做第一部分。这可能是一个明显的解决方案,但这是我尝试过的,使用 xarray 模块
import os
import numpy as np
import xarray as xr
import netCDF4
from netCDF4 import Dataset
nc_folder = df_try.iloc[0] #folder where the image files are
#open dataset in xarray
nc_chl = xr.open_dataset(str(nc_folder['path']) + '/' + 'chl_nn.nc') #path to chlorophyll file
nc_chl
n_coord =xr.open_dataset(str(nc_folder['path'])+ '/'+ 'geo_coordinates.nc') #path to coordinates file
n_time = xr.open_dataset(str(nc_folder['path'])+ '/' + 'time_coordinates.nc') #path to time file
ds_grid = [[nc_chl], [n_coord], [n_time]]
combined = xr.combine_nested(ds_grid, concat_dim=[None, None])
combined #dataset with all but not recognizing coordinates
ds = combined.rename({'latitude': 'lat', 'longitude': 'lon', 'time_stamp' : 'time'}).set_coords(['lon', 'lat', 'time']) #dataset recognizing coordinates as coordinates
ds
它给出了一个数据集
维度:列 4865 行:4091
3 个坐标(纬度、经度和时间)和 chl 变量。
现在,它不会保存到 netcdf4(我尝试过,但出现错误),但我也在想是否有人知道另一种平均方法?我有三年的图像(从 2017 年开始到 2019 年结束),我需要以不同的方式(每月、季节性......)进行平均。我目前的主要问题是叶绿素值与地理坐标是分开的,因此仅直接使用叶绿素文件是行不通的,只会弄得一团糟。
有什么建议吗?
【问题讨论】:
-
更好的解决方案是向叶绿素文件添加坐标。虽然没有更多信息,但我无法建议如何
-
好吧,我一直在用 combine_nested 修补 xarray(根据代码),尝试将叶绿素和坐标合并到一个 .nc 文件中,使用 dataset.to_netcdf 保存。我设法保存了它,但是它给出了这个警告? «序列化警告:将带有浮点数据的变量 lat 保存为整数 dtype,没有任何 _FillValue 用于 NaN»该文件似乎确实适用于日常图像
-
cdo 可能更容易:code.mpimet.mpg.de/projects/cdo/wiki/…
标签: python netcdf satellite-image