Skip to content

Error when using both calendar_time_points and frequency_hz

Steps to reproduce:

import datetime

import robofish.io

f = robofish.io.File(
    world_size_cm=(100, 100),
    sampling_name="25",
    frequency_hz=25,
    calendar_time_points=[
        datetime.datetime.now(
            tz=datetime.timezone(
                offset=datetime.timedelta(0),
            ),
        )
    ],
)

Output:

WARNING:root:local variable 'time_points' referenced before assignment

It looks like the logger is hiding an error there so I can not give you a stack trace.

When calling robofish.io.validate(f) on the created file, I do get a stack trace:

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-2-d2c289ba089e> in <module>
----> 1 robofish.io.validate(f)

~/.venv/brl/lib/python3.8/site-packages/robofish/io/validation.py in validate(iofile, strict_validate)
    295     except Exception as e:
    296         if strict_validate:
--> 297             raise e
    298         else:
    299             logging.warning(e)

~/.venv/brl/lib/python3.8/site-packages/robofish/io/validation.py in validate(iofile, strict_validate)
    140                 )
    141                 assert_validate(
--> 142                     calendar_points.shape[0] == time_points.shape[0],
    143                     "The length of calendar points (%d) does not match the length of monotonic points (%d)"
    144                     % (calendar_points.shape[0], time_points.shape[0]),

UnboundLocalError: local variable 'time_points' referenced before assignment

Hopefully this is the same error. In src/robofish/io/validation.py::validate, the lines 116f:

if "frequency_hz" in sampling.attrs:
    pass

are preventing time_points from being initialized.