0

Hi there I am getting this error: ValueError: setting an array element with a sequence. When I run this code:

import metpy.calc as mpcalc

from metpy.units import units

import cartopy.crs as ccrs
import cartopy.feature as cfeat
import os

from netCDF4 import Dataset as netcdf_dataset


fname = os.path.join(config["repo_data_dir"],
                     'netcdf', "nam_218_20170625_1200_031.nc"
                     )

dataset = netcdf_dataset(fname)

lat = dataset.variables['gridlat_0'][:]
lon = dataset.variables['gridlon_0'][:]
sfct=units.degC*(np.mean(dataset.variables['TMP_P0_L103_GLC0'][:,:,:],0)-273.15)
dp=units.degC*(dataset.variables['DPT_P0_L103_GLC0'][:]-273.15)
sfcp=units.hPa*(dataset.variables['PRES_P0_L103_GLC0'][:]/100.0)

lcl_pressure=np.empty(((428),(614)))
lcl_temperature=np.empty(((428),(614)))
lclht=np.empty(((428),(614)))
for i in range(428):
    for j in range(614):
        lcl_pressure[i,j], lcl_temperature[i,j] = mpcalc.lcl(sfcp[i,j],sfct[i,j],dp[i,j])
        lclht[i,j]=mpcalc.pressure_to_height_std(lcl_pressure[i,j]).to('feet')

The line in question is this:

lcl_pressure[i,j], lcl_temperature[i,j] = mpcalc.lcl(sfcp[i,j],sfct[i,j],dp[i,j])

since I am unsure as to how that's causing it as the line in question works for a different code where it says

lcl_pressure[i,j], lcl_temperature[i,j] = mpcalc.lcl(p[0],t[0],dp[0])

as the p,t, and dp in that 2nd version are also arrays

  • The LHS of that assignment will accept two numbers (2 slots in float arrays) What is `mpcalc.lcl(sfcp[i,j],sfct[i,j],dp[i,j])`? Is that two numbers as well? Or multielement arrays? – hpaulj Jun 21 '20 at 23:44
  • https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.lcl.html#metpy.calc.lcl @hpaulj – stratusshow Jun 21 '20 at 23:57
  • Hi @stratusshow, try remove as much code as possible to get to just the error that you can see. This will help people answer the question as well. – robertlayton Jun 22 '20 at 00:59
  • I realized it was the [i,j] for the lcl_pressure and lcl_temperature as I want to plot the lclht – stratusshow Jun 22 '20 at 01:36

0 Answers0