使用xarray或satpy的多个netcdf的空间合并/合并

问题描述

我有两个netcdf格式的空间数据集。它们具有相同的时间,尺寸,坐标和数据变量。但是它们用于不同的空间坐标。在下面,我尝试通过多边形显示我的两个数据集:

@app.route('/',methods=['GET','POST'])
def index():
    loadform = LoadDataForm()
    session['dataset'] = toy_data.get_empty_df()

    if loadform.validate_on_submit():
        dataset,headers = toy_data.get_dataset(int(loadform.selectToyData.data))
        session['dataset'] = dataset
        session.modified = True
        return render_template('DataTable.html',dataset=dataset)

    return render_template('LoadData.html',form=loadform)

@app.route('/DataTable','POST'])
def index_data():
    dataset = session.get('dataset',None)

    return render_template('DataTable.html',dataset=dataset)

一个数据集图:

import glob
import xarray as xr 
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

file1 = '20190109T071048.nc'
file2 = '20190109T085117.nc'

ds1 = xr.open_dataset(file1,group='PRODUCT')
ds2 = xr.open_dataset(file2,group='PRODUCT')

PATH_TO_GPK = 'Study_Area.gpkg'
SA = gpd.read_file(PATH_TO_GPK,layer='Study_Area')

enter image description here

第二个数据集图:

plt.figure(figsize=(12,8))
ax = plt.axes()
ds1.qa_value.isel(time = 0).plot(ax = ax,x='longitude',y='latitude')
SA.plot(ax = ax,alpha = 0.8,facecolor = 'none')

enter image description here

我想将这两个netcdf文件与xarray合并。

plt.figure(figsize=(12,8))
ax = plt.axes()
ds2.qa_value.isel(time = 0).plot(ax = ax,facecolor = 'none')

错误

combined = xr.merge([ds1,ds2],compat='no_conflicts')

尝试:

MergeError: conflicting values for variable 'latitude' on objects to be combined. You can skip this check by specifying compat='override'.

但是combined = xr.merge([ds1,compat='override') 的图与上面的第一图相同。 然后尝试:

combined

错误

combined = xr.combine_by_coords([ds1,compat='no_conflicts')

然后尝试:

Could not find any dimension coordinates to use to order the datasets for concatenation

combined = xr.combine_nested([ds1,concat_dim=["time"]) 的情节与第一个情节相同。 根据{{​​3}}的建议,我使用了以下代码

combined

但是它返回此错误

ds = xr.open_mfdataset([file1,file2],combine='nested')

结果中没有任何数据

ThomasNicolas

一个数据集的打印(例如)显示

AttributeError: 'Dataset' object has no attribute 'qa_value'

是否有合并或合并这些文件的建议?

已更新

基于

enter image description here

的建议,我使用print (ds1) <xarray.Dataset> Dimensions: (corner: 4,ground_pixel: 450,scanline: 3245,time: 1) Coordinates: * scanline (scanline) float64 0.0 1.0 ... 3.244e+03 * ground_pixel (ground_pixel) float64 0.0 1.0 ... 449.0 * time (time) datetime64[ns] 2019-01-03 * corner (corner) float64 0.0 1.0 2.0 3.0 latitude (time,scanline,ground_pixel) float32 ... longitude (time,ground_pixel) float32 ... Data variables: delta_time (time,scanline) timedelta64[ns] 08:07:0... time_utc (time,scanline) object '2019-01-03T08:0... qa_value (time,ground_pixel) float32 ... 解决了我的问题,看来它可以合并两个netcdf文件,但不能完全合并,在合并时会看到不正确的部分(红色边界)图片satpy可以正确执行吗?

satpy

@dl.meteo

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)