nexradaws icon indicating copy to clipboard operation
nexradaws copied to clipboard

TypeError: 'NoneType' object is not iterable when trying to get available scans in range for current day

Open ajdas1 opened this issue 2 years ago • 0 comments

Hello,

I've been working with your package to retrieve a list of files for a specific radar from an AWS bucket, and ran into a problem with retrieving a list of radar scans for the current day.

Example code that throws an error:

import nexradaws as nexr
from datetime import datetime, timedelta

start_time = datetime.now().replace(hour=10, minute=0, second=0, microsecond=0)
end_time = start_time + timedelta(hours=2)
radar_id = "KEAX"

conn = nexr.NexradAwsInterface()
file_list = conn.get_avail_scans_in_range(start_time, end_time, radar_id)

>>> TypeError: 'NoneType' object is not iterable

We have linked this error to the _datetime_range() function within get_avail_scans_in_range(), which is defined as:

    def _datetime_range(self, start=None, end=None):
        span = end - start
        if span.seconds > 0:
            numdays = span.days + 1
        else:
            numdays = span.days
        for i in range(0, numdays + 1):
            yield start + timedelta(days=i)

The issue is with the +1s in the above function, and the datetime range it returns includes the current and following day to what is defined as end_time. Therefore, if the end_time is defined as the current day, it is trying to look for files from the following day, which do not exist, and returns the TypeError. The function performs as expected for all other days that are not the current day.

Thank you for looking into this.

ajdas1 avatar Oct 11 '23 21:10 ajdas1