1

I have got this error with metpy:

AttributeError: module 'metpy' has no attribute 'calc'

The code is as follows;

import metpy as mp
import numpy as np
from metpy.units import units

df = pd.read_csv('wind.csv', header = 0)
u = (df['u10'].to_numpy()) *units("m/s")
v = (df['v10'].to_numpy()) *units("m/s")
df['speed'] = mp.calc.wind_speed(u, v) 

Versions: numpy 1.23.5 metpy 1.5.0

Any idea how to solve it? Thank you.

sbottingota
  • 533
  • 1
  • 3
  • 18
tok
  • 13
  • 3

1 Answers1

0

To keep imports as quick as possible and streamlined, import metpy does not import the subpackages, it essentially only sets up xarray intergrations. If you want to use metpy.calc, you need to do import metpy.calc:

    import metpy.calc as mpcalc
    from metpy.units import units
    import pandas as pd

    df = pd.read_csv('wind.csv', header = 0)
    u = (df['u10'].to_numpy()) * units("m/s")
    v = (df['v10'].to_numpy()) * units("m/s")
    speed = mpcalc.wind_speed(u, v) 
DopplerShift
  • 5,472
  • 1
  • 21
  • 20