首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:图像数据无法转换为浮点型-使用NcML数组

TypeError:图像数据无法转换为浮点型-使用NcML数组
EN

Stack Overflow用户
提问于 2017-06-01 14:42:38
回答 1查看 112关注 0票数 1

我正在尝试使用我使用xarray和opendap获得的NcML数组来运行NDVI变化分析。

我已经对所需的数据进行了切片,并将它们分配给了之前、期间和之后的fire变量。

现在,当我试图在同一张图中显示这三个图时,我收到一个错误:“图像数据无法转换为浮点数”。我错过了什么吗?我以为我分配的数组是xml而不是图像?

任何建议都将不胜感激,因为这份报告明天就到期了。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2017-06-06 08:03:07

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

代码语言:javascript
复制
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)

通向

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44300260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档