TypeError:图像数据不能转换为浮点数 - 使用NcML数组

TypeError:图像数据不能转换为浮点数 - 使用NcML数组

问题描述:

我是一个总的python新手,所以请裸照我。TypeError:图像数据不能转换为浮点数 - 使用NcML数组

我正在尝试使用NcML阵列运行NDVI变化分析,我使用xarray和opendap从http://www.auscover.org.au/purl/lpdaac-mosaic-mod13q1-v5中取出。

我剪切了我需要的数据,并将它们分配给火灾变量之前,期间和之后。

现在,当我尝试在同一图中显示三个图时,我收到一个错误:'图像数据不能转换为浮动'。我错过了什么吗?我认为我分配的数组是xml而不是图像?

任何意见,将不胜感激,因为这份报告是明天到期。

谢谢,山姆。

import xarray as xr 
import numpy as np 
import pandas as pd 

import matplotlib.pyplot as plt 
import seaborn 
%matplotlib inline 
seaborn.set_style('dark') 

NDVI_aggr_data_url = 'http://data.auscover.org.au/thredds/dodsC/auscover/lpdaac-aggregates/c5/v2-nc4/aust/MOD13Q1.005/MOD13Q1.aggregated.aust.005.normalised_difference_vegetation_index.ncml' 

NDVI_aggr = xr.open_dataset(NDVI_aggr_data_url) 
NDVI_aggr 

lat_bounds = slice(-36.341, -36.645) 
lon_bounds = slice(146.666, 147.133) 

time_bounds = slice('2017-02-08', '2017-02-20') 

beechworth_NDVI_post = NDVI_aggr.sel(
    latitude=lat_bounds, longitude=lon_bounds, time=time_bounds) 
beechworth_NDVI_post 

beechworth_NDVI_post.load() 
plt.rcParams["figure.figsize"] = (12,10) 

beechworth_NDVI_post.ndvi.plot.imshow(col='time', cmap='viridis') 
plt.title('NDVI - 18 February 2017', y=1.1) 
plt.xlabel('Longitude') 
plt.ylabel('Latitude') 
plt.savefig("2017_NDVI_test1.png", dpi=100) 

post = beechworth_NDVI_post 

lat_bounds = slice(-36.341, -36.645) 
lon_bounds = slice(146.666, 147.133) 

time_bounds = slice('2009-02-07', '2009-02-20') 

beechworth_NDVI_during = NDVI_aggr.sel(
    latitude=lat_bounds, longitude=lon_bounds, time=time_bounds) 
beechworth_NDVI_during 
beechworth_NDVI_during.load() 
plt.rcParams["figure.figsize"] = (12,10) 

beechworth_NDVI_during.ndvi.plot.imshow(col='time', cmap='viridis') 
plt.title('NDVI - 18 February 2009', y=1.1) 
plt.xlabel('Longitude') 
plt.ylabel('Latitude') 
plt.savefig("2009_NDVI.png", dpi=100) 

during = beechworth_NDVI_during 

lat_bounds = slice(-36.341, -36.645) 
lon_bounds = slice(146.666, 147.133) 

time_bounds = slice('2008-02-07', '2008-02-20') 

beechworth_NDVI_before = NDVI_aggr.sel(
    latitude=lat_bounds, longitude=lon_bounds, time=time_bounds) 
beechworth_NDVI_before 

beechworth_NDVI_before.load() 
plt.rcParams["figure.figsize"] = (12,10) 

beechworth_NDVI_before.ndvi.plot.imshow(col='time', cmap='viridis') 
plt.title('NDVI - 18 February 2008', y=1.1) 
plt.xlabel('Longitude') 
plt.ylabel('Latitude') 
plt.savefig("2008_NDVI.png", dpi=100) 

before = beechworth_NDVI_before 

figure, ax_s = plt.subplots(ncols=3) 
plt.title('NDVI in Beechworth before, during, and after a bushfire') 
for data, ax in zip([before, during, post], ax_s): 
    ax.imshow(data, cmap='viridis', vmin=0, vmax=0.9) 

看起来像你的数据子设置有几个问题。这里是一个例子,使用适当的选择。

before = beechworth_NDVI_before.isel(time=0,nv=1).ndvi 
during = beechworth_NDVI_during.isel(time=0,nv=1).ndvi 
post = beechworth_NDVI_post.isel(time=0,nv=1).ndvi 


figure, ax_s = plt.subplots(ncols=3) 
plt.title('NDVI in Beechworth before, during, and after a bushfire') 
for data, ax in zip([before, during, post], ax_s): 
    ax.imshow(data, cmap='viridis', vmin=0, vmax=0.9) 

导致 enter image description here