2017-06-01 4 views
1

私は完全なpython初心者ですので、私と一緒に裸にしてください。TypeError:画像データをfloatに変換できません - NcML配列を使用しています

NcMLアレイを使用してNDVI変更解析を実行しようとしていますが、xarrayとopendapを使用してhttp://www.auscover.org.au/purl/lpdaac-mosaic-mod13q1-v5を削除しました。

私は必要なデータをスライスし、それらを火災変量の前、中、後に割り当てました。

私が同じ図の3つのプロットを表示しようとすると、「画像データをフロートに変換できません」というエラーが表示されます。私は何かを逃したか?私が割り当てていた配列は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) 

答えて

0

のように見えます。データのサブセットにはいくつかの問題があります。ここでは例を示し、適切な選択を使用します。

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

につながります
関連する問題