corp_guy
corp_guy

Reputation: 45

How to solve Metpy ('numpy.ndarray' object has no attribute 'to') error when calculating heat index?

I am writing a code to calculate the heat index using Metpy 1.0 library. However, when running the code I am getting this error : 'numpy.ndarray' object has no attribute 'to'

How to solve this error. I thoroughly follow the instructions on a tutorial (https://www.youtube.com/watch?v=l71dlYe3enM&ab_channel=Unidata) about metpy to calculate the heat index but it still gives me the same error. Here is a piece of my code:

climate_data = "C:/Users/princ/Documents/python code/heatindex/climate.csv" 

dataset = pd.read_csv(climate_data, index_col=0, parse_dates=True)

hu_index = calc.heat_index (dataset["temperature"].values * units.degC, dataset["humidity"].values * units.percent, mask_undefined = False)

enter image description here

Upvotes: 1

Views: 539

Answers (1)

dcamron
dcamron

Reputation: 175

MetPy takes advantage of the NumPy default __array_function__ interface for applying calculations to pint quantities (units!). This check became default as of NumPy 1.17 and was optional with the environment variable NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=1 set in NumPy 1.16.

The quickest way for you to fix this would be to update NumPy to 1.17 or newer, but if you need NumPy<1.17 then set the above environment variable to get this working!

Upvotes: 1

Related Questions