Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calc.storm_relative_helicity "TypeError: tuple indices must be integers or slices, not tuple" #1164

Closed
ThunderRoad75 opened this issue Sep 15, 2019 · 3 comments
Labels
Area: Calc Pertains to calculations Status: Duplicate Duplicates an existing issue Type: Bug Something is not working like it should

Comments

@ThunderRoad75
Copy link

ThunderRoad75 commented Sep 15, 2019

Calling the SRH function for a single point or spatial subset (in this case, 10x10 grid) throws "TypeError: tuple indices must be integers or slices, not tuple". When attempting to operate on the full volume rather than a single point or subset, it throws a MemoryError. The full RAP volume at 13 km is (37, 337, 451) - which doesn't strike me as excessively large.

Response on Twitter was that it may be a problem with Pint and asked me to open an issue. All errors thrown are attached as a screenshot.

Code snippet below uses UCAR's siphon and THREDDS so should be very easily copied, pasted, and run. Just make sure the valid date is within the last ~30 days.
SRH_bug_output

from time import time
from datetime import datetime, timedelta
from siphon.catalog import TDSCatalog
#from netCDF4 import Dataset
from metpy.calc import storm_relative_helicity
from metpy.units import units
import numpy as np

# Use siphon to get the desired model dataset and time, and desired variable from the dataset
model_url = "http://thredds.ucar.edu/thredds/catalog/grib/NCEP/RAP/CONUS_13km/RR_CONUS_13km_20190819_1200.grib2/catalog.html?dataset=grib/NCEP/RAP/CONUS_13km/RR_CONUS_13km_20190915_1200.grib2"

# Create a datetime object for the day and FHR being used
vtime = datetime.strptime('2019091512','%Y%m%d%H')

# Get the data
model = TDSCatalog(model_url)
ds = model.datasets[0]
ncss = ds.subset()
query = ncss.query()
query.accept('netcdf4')
query.time(vtime) # Set to the analysis hour only
query.add_lonlat()
query.variables('U-Component_Storm_Motion_height_above_ground_layer', 'V-Component_Storm_Motion_height_above_ground_layer',
'u-component_of_wind_isobaric', 'v-component_of_wind_isobaric', 'Geopotential_height_isobaric')
data = ncss.get_data(query)

# Select variable(s) to plot
hgt = data.variables['Geopotential_height_isobaric'][0,:,10:20,10:20] * units.meter
uwnd = data.variables['u-component_of_wind_isobaric'][0,:,10:20,10:20] * units.meter / units.second
vwnd = data.variables['v-component_of_wind_isobaric'][0,:,10:20,10:20] * units.meter / units.second
print(np.shape(uwnd))
storm_u = data.variables['U-Component_Storm_Motion_height_above_ground_layer'][0,:,10:20,10:20] * units.meter / units.second
storm_v = data.variables['V-Component_Storm_Motion_height_above_ground_layer'][0,:,10:20,10:20] * units.meter / units.second

# Calculate SRH
SRH = storm_relative_helicity(uwnd, vwnd, hgt, 3000. * units.meter, 0 * units.meter, storm_u, storm_v) 
  • Running Anaconda on Windows
  • Python 3.7.1
  • MetPy v0.10.0
@ThunderRoad75 ThunderRoad75 added the Type: Bug Something is not working like it should label Sep 15, 2019
@jthielen
Copy link
Collaborator

This looks like the same issue as #997 and several others. Would you be able to update MetPy to v0.10.2, as in @zbruick's suggestion in #1146 (comment) and see if that resolves your issue?

This was an issue with our dependence on pint, which caused this issue with their release of pint 0.9 (#997). We released a fix in MetPy 0.10.2, so if you update MetPy (and ask students to do the same), then this issue should be resolved: pip install --upgrade metpy or conda update metpy.

@zbruick
Copy link
Contributor

zbruick commented Sep 16, 2019

Yes, if you upgrade to 0.10.2, this first problem should be resolved. The memory problem is a larger issue with how we do these calculations (see #395, #480). This is on the to-do list in the future, but it is not something we support currently. As a result, you would need to loop through your points that you want to this function to work on.

@ThunderRoad75
Copy link
Author

Yup, 0.10.2 fixed this issue for a single point. Thanks folks!

@dopplershift dopplershift added Area: Calc Pertains to calculations Status: Duplicate Duplicates an existing issue labels Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Calc Pertains to calculations Status: Duplicate Duplicates an existing issue Type: Bug Something is not working like it should
Projects
None yet
Development

No branches or pull requests

4 participants