传单速度-无法读取null的属性“数据" [英] leaflet-velocity - cannot read property 'data' of null

查看:186
本文介绍了传单速度-无法读取null的属性“数据"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过使用leaflet-velocity.js来制作风动画,可以在npm或github中找到它(

I am working on the wind animation by using leaflet-velocity.js, which can be found in either npm or github (https://github.com/danwild/leaflet-velocity) from my own atmospheric model output (WRF).

要执行风动画,我写下了自己的python代码,以将模型输出从netCDF格式转换为json格式.代码如下所示

To perform the wind animation, I wrote down my own python code to convert the model output from netCDF format to json format. The code is showing below

import os, sys, json, numpy as np
from glob import glob
from netCDF4 import Dataset, num2date, date2num

#- header templete
header = {  
    'parameterUnit': 'm.s-1',
    'parameterNumber': 2,
    'dx': 1.0,
    'dy': 1.0,
    'parameterNumberName': 'eastward_wind',
    'la1': 90.0,
    'la2': -90.0,
    'parameterCategory': 2,
    'lo1': 0.0,
    'nx': 360,
    'ny': 181,
    'refTime': '2016-04-30T06:00:00.000Z',
    'lo2': 359.0,
    }

lists = glob('TXGLO.surf_wind4json.nc')
ntimes= 8
for fid in lists[:1]:
    nc = Dataset(fid)
    tm = nc.variables['Times'][:]
    dim1, dim2 = nc.variables['XLAT'][0].shape
    nPoints = dim1*dim2
    lat= np.flipud(nc.variables['XLAT'][0]).flatten().tolist()
    lon= np.flipud(nc.variables['XLONG'][0]+360.).flatten().tolist()
    header['nx'] = dim1
    header['ny'] = dim2
    header['la1']= lat[0]
    header['la2']= lat[-1]
    header['lo1']= lon[0]
    header['lo2']= lon[-1]
    numPoints = nPoints
    for num, tim in enumerate(tm[:1]):
        refTime = ''.join(tim).replace('_',' ')
        print(' Processing file : '+fid+' , time : '+str(num)+' '+refTime)
        header['refTime'] = refTime
        with open('cresm_atmos_surf.json','w') as outfile:  
            outfile.write('[')
            #-  U10
            header['parameterNumberName'] = 'eastward_wind'
            u10 = np.flipud(nc.variables['U10'][num]).flatten().tolist()
            json.dump({'data':u10,'header':header}, outfile)
            outfile.write(',')
            #- V10
            header['parameterNumberName'] = 'northward_wind'
            v10 = np.flipud(nc.variables['V10'][num]).flatten().tolist()
            json.dump({'data':v10,'header':header}, outfile)
            outfile.write(']')

json输出的结果与演示json文件类似,例如wind-gbr.json(

The results of json output looks like similar with the demo json file, such as wind-gbr.json (https://github.com/danwild/leaflet-velocity/blob/master/demo/wind-gbr.json)

完成转换器后,我刷新了网页,发现读取json文件时出错.

Once I completed the converter, I refreshed my web page and found out there is an error on reading my json file.

有人可以帮我弄清楚什么是错误的吗?

Could someone please help me to figure out what is the error?

谢谢

我的netcdf文件: https://www.dropbox .com/s/tmyrrinraetvcxs/TXGLO.surf_wind4json.nc?dl = 0

my netcdf file : https://www.dropbox.com/s/tmyrrinraetvcxs/TXGLO.surf_wind4json.nc?dl=0

我的json文件: https://www.dropbox.com/s/huiffld05zmldrs/cresm_atmos_surf. json?dl = 0

my json file : https://www.dropbox.com/s/huiffld05zmldrs/cresm_atmos_surf.json?dl=0

演示json文件: https://www.dropbox.com/s/17pr3vdkl1v3bq7/wind_gbr. json?dl = 0

the demo json file : https://www.dropbox.com/s/17pr3vdkl1v3bq7/wind_gbr.json?dl=0

推荐答案

如果您退出错误调用堆栈,则将检查

If you step down the error call stack, you will inspect createBuilder function which shows you how it extracts uComp and vComp from your provided JSON data.

您将看到它使用记录头parameterCategoryparameterNumber字段来确定应将记录数据分配给uComp还是vComp:

You will see that it uses your records header parameterCategory and parameterNumber fields to determine whether the record data should be assigned to uComp or vComp:

switch (record.header.parameterCategory + "," + record.header.parameterNumber) {
  case "1,2":
  case "2,2":
    uComp = record;
    break;
  case "1,3":
  case "2,3":
    vComp = record;
    break;
  default:
    scalar = record;
}

您的数据似乎有2条记录,这2个字段的值完全相同:

It looks like your data has 2 records with exactly the same values for these 2 fields:

"parameterNumber": 2,
"parameterCategory": 2

因此,您似乎没有提供vComp类型的记录.

Therefore you do not seem to provide vComp type record.

通过使用"parameterNumber": 3强制您的一条记录,传单速度脚本不再会引发错误并在地图上显示某些内容,尽管它可能不是适当的显示方式.

By forcing one of your records with "parameterNumber": 3, leaflet-velocity script no longer throws an error and displays something on the map, although it might not be the appropriate display.

这篇关于传单速度-无法读取null的属性“数据"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆