GEUS-Glaciology-and-Climate / pypromice

Process AWS data from L0 (raw logger) through Lx (end user)
https://pypromice.readthedocs.io
GNU General Public License v2.0
14 stars 4 forks source link

Getting an error in resampling step (L2toL3) #93

Closed BaptisteVandecrux closed 1 year ago

BaptisteVandecrux commented 1 year ago

I'm running this simple scritpt:

from aws import AWS
import matplotlib.pyplot as plt

path_to_l0 = 'C:/Users/bav/OneDrive - Geological survey of Denmark and Greenland/Code/PROMICE/aws-l0/'

## Test an individual station
test_station = 'NSE'
config_file = path_to_l0 + '/raw/config/{}.toml'.format(test_station)
inpath= path_to_l0 + '/raw/{}/'.format(test_station)
vari = 'variables.csv'
pAWS_gc = AWS(config_file, inpath, var_file=vari)
pAWS_gc.getL1()
pAWS_gc.getL2()
pAWS_gc.getL3()

And get the following error

  File "C:\Users\bav\AppData\Local\Temp\ipykernel_20248\2534486318.py", line 1, in <module>
    pAWS_gc.getL3()

  File "C:\Users\bav\OneDrive - Geological survey of Denmark and Greenland\Code\PROMICE\pypromice\src\pypromice\aws.py", line 105, in getL3
    self.L3 = toL3(self.L2)

  File "C:\Users\bav\OneDrive - Geological survey of Denmark and Greenland\Code\PROMICE\pypromice\src\pypromice\L2toL3.py", line 33, in toL3
    df_h = ds.to_dataframe().resample("1H").mean(numeric_only=True)                             # Resample xarray (quick with pandas)

  File "C:\Users\bav\Anaconda3\lib\site-packages\pandas\core\resample.py", line 1038, in g
    nv.validate_resampler_func(_method, args, kwargs)

  File "C:\Users\bav\Anaconda3\lib\site-packages\pandas\compat\numpy\function.py", line 384, in validate_resampler_func
    raise UnsupportedFunctionCall(

UnsupportedFunctionCall: numpy operations are not valid with resample. Use .resample(...).mean() instead

The error disappears when I use

    df_h = ds.to_dataframe().resample("1H").mean()                             # Resample xarray (quick with pandas)

instead of

    df_h = ds.to_dataframe().resample("1H").mean(numeric_only=True)                             # Resample xarray (quick with pandas)
PennyHow commented 1 year ago

What versions of xarray and pandas are you using?

I am using xarray==2022.6.0 and pandas==1.5.0 and it works okay for me.

BaptisteVandecrux commented 1 year ago

Just updated pandas from 1.4.4 to 1.5.3 and the error disappeared!

PennyHow commented 1 year ago

Okay. I think it is to do with the pandas versioning then. I'll make a note in the pip install that pandas should be version 1.5.0 or above.