pySTEPS / pysteps

Python framework for short-term ensemble prediction systems.
https://pysteps.github.io/
BSD 3-Clause "New" or "Revised" License
466 stars 168 forks source link

Error: aggregate_fields_space #310

Closed eltonrobaina closed 2 years ago

eltonrobaina commented 2 years ago

Hello guys!

I've been redoing the ERAD2022 examples that I participated and found a little problem when using this function.

import os

from pysteps.datasets import load_dataset from pysteps.utils.dimension import aggregate_fields_space

precip, metadata, timestep = load_dataset('fmi', frames=16) precip, metadata = aggregate_fields_space(precip, metadata, (2*metadata["xpixelsize"], 2*metadata["ypixelsize"]))

The error is:

`--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_9862/2000621040.py in <cell line: 7>() 5 6 precip, metadata, timestep = load_dataset('fmi', frames=16) ----> 7 precip, metadata = aggregate_fields_space(precip, metadata, (2metadata["xpixelsize"], 2metadata["ypixelsize"])) 8 #precip, metadata = aggregate_fields_space(precip, metadata, space_window=(None))

~/miniconda3/envs/teste/lib/python3.9/site-packages/pysteps/utils/dimension.py in aggregate_fields_space(R, metadata, space_window, ignore_nan) 181 if ypixelsize == space_window and xpixelsize == space_window: 182 return R, metadata --> 183 if (R.shape[axes[0]] ypixelsize) % space_window or ( 184 R.shape[axes[1]] xpixelsize 185 ) % space_window:

TypeError: unsupported operand type(s) for %: 'float' and 'tuple'`

To continue my studies I used: precip, metadata = aggregate_fields_space(precip, metadata, space_window=(None))

But in the future, I may need to adjust the size, so I would like to help understand this error better. An example application of the function can be seen here: https://github.com/pySTEPS/ERAD-nowcasting-course-2022/blob/main/hands-on-session-users/notebooks/helper_input_data.ipynb

Thanks!!

aperezhortal commented 2 years ago

Hi @eltonrobaina,

This bug was fixed in 94a11b3adf5281f04a537201d80edb856bbef3f and it will be included in the next release. I

Try updating the pysteps package to the latest commit by running:: pip install git+https://github.com/pySTEPS/pysteps

dnerini commented 2 years ago

To be a bit more precise, this was a new feature rather than a bug, introduced for the ERAD short course, but not yet available in a release. So as already pointed out, running the ERAD tutorials with pysteps versions <= 1.7.1 will fail.

@eltonrobaina I'm closing the issue, feel free to reopen it if the fix suggested by @aperezhortal doesn't work.