ioos / ioos_qc

:ballot_box_with_check: :ocean: IOOS QARTOD and other Quality Control tests implemented in Python
https://ioos.github.io/ioos_qc/
Apache License 2.0
46 stars 27 forks source link

Climatology test errors when period is specified #66

Open lgarzio opened 2 years ago

lgarzio commented 2 years ago

I'm using the latest version of ioos_qc (2.0.1), and I get the following error when period is specified in the climatology test configuration:

Traceback (most recent call last): File "/Users/garzio/opt/anaconda3/envs/ioos_qc_test/lib/python3.9/site-packages/ioos_qc/qartod.py", line 384, in check flag_arr[(values_idx & ~fail_idx & suspect_idx)] = QartodFlags.SUSPECT File "/Users/garzio/opt/anaconda3/envs/ioos_qc_test/lib/python3.9/site-packages/numpy/ma/core.py", line 3375, in setitem _data[indx] = dval IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

Here is my example code:

import numpy as np from ioos_qc.qartod import ClimatologyConfig, climatology_test

c = ClimatologyConfig() c.add(tspan=[150, 270], period='dayofyear', vspan=[3.4, 5], zspan=[0, 1000])

inp = np.array([0. , np.nan, 0. , np.nan, np.nan, np.nan, 4.16743, 4.23101, 4.23322]) t = np.array(['2021-07-16T19:01:01.313999872', '2021-07-16T19:01:02.315000064', '2021-07-16T19:01:02.903000064', '2021-07-16T19:01:03.903000064', '2021-07-16T19:01:04.903000064', '2021-07-16T19:01:05.903000064', '2021-07-16T19:01:06.903000064', '2021-07-16T19:01:07.336000000', '2021-07-16T19:01:07.903000064'], dtype='datetime64[ns]') z = np.array([0. , np.nan, 0. , np.nan, np.nan, np.nan, 0.08931513, 0.15878244, 0.11908684])

results = climatology_test(config=c, inp=inp, tinp=t, zinp=z)

When I debug this error, it looks like the issues is with line 345 of qartod.py https://github.com/ioos/ioos_qc/blob/master/ioos_qc/qartod.py#L345

I changed tinp_copy = getattr(tinp, m.period).to_series() to tinp_copy = getattr(tinp, m.period) on my local machine, and the test ran correctly.

kwilcox commented 2 years ago

Thanks for the test case/data, I'll plug it in and check it out!