NetCDF Python 无法将 ufunc 'multiply' 输出从 dtype('<U32') 转换为 dtype('float32')

问题描述

我正在尝试使用 xarray 或 netCDF4 库将 netCDF 加载到数据帧中。通常这不会成为问题,因为我的 netCDF 大部分带有 Float32 中的纬度、经度和数据值。我假设我的错误是因为我有一些数据类型被作为 Float64 传递。

我目前在加载时从两个库中收到相同的错误,大概是因为它们都使用了 numpy。我没有做任何数学运算 - 只是加载。

numpy.core._exceptions.UFuncTypeError: Cannot cast ufunc 'multiply' output from dtype('<U32') 
to dtype('float32') with casting rule 'same_kind'

使用 print(netCDF4.Dataset("d:\netdcdf.nc") 产生以下描述:

dimensions(sizes): time(1),lon(841),lat(681)
variables(dimensions): float64 time(time),float64 lon(lon),float64 lat(lat),int32 crs(),float32 deadpool(time,lat,lon)

我的脚本如下,包括 xarray 和 netCDF4 的加载示例。

#This file is designed to convert netcdf files to the BOM standard format. 

import netCDF4
import pandas as pd
import xarray as xr

def main():
    pass

if __name__ == '__main__':
    inputfile = 'D:\\Temp\\WeatherDownloads\\Weather\\deadpool.aus.nc'

    #xarray setup,debug and load
    ncx = xr.open_dataset(inputfile)
    ncdf = ncx.deadpool.to_dataframe() #fails here if we use xarray

    print(ncdf.head(10))


    #NetCDF4 setup,debug and load
    nc = netCDF4.Dataset(inputfile,mode='r')
    nc.variables.keys()

    lat = nc.variables['lat'][:]
    lon = nc.variables['lon'][:]
    time = nc.variables['time']
    datavar = nc.variables['deadpool'][:] #fails here if we use netCDF4

    print("The dtype of lat is: " + str(dtype(lat)))
    print("The dtype of lon is: " + str(dtype(lon)))
    print("The dtype of time is: " + str(dtype(time)))
    print("The dtype of datavar is: " + str(dtype(datavar)))

    data_ts = pd.Series(datavar,index=time)

    print(data_ts.head(10))

解决方法

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

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...