xradar: Error when opening IRIS/Sigmet file

  • xradar version: 0.0.8
  • Python version: 3.9
  • Operating System: Ubuntu 22.04.1 LTS

I am trying to read an IRIS file using xradar.io.datatree and xr.open_dataset but I am having a dimension error.

import pyart
import fsspec
import xarray as xr
import xradar as xd
import boto3
import botocore
from botocore.client import Config
from datetime import datetime


def create_query(date, radar_site):
    """
    Creates a query for listing IDEAM radar files stored in AWS bucket
    :param date: date to be queried. e.g datetime(2021, 10, 3, 12). Datetime python object
    :param radar_site: radar site e.g. Guaviare
    :return: string with a
    """
    prefix = f'l2_data/{date:%Y}/{date:%m}/{date:%d}/{radar_site}/{radar_site[:3].upper()}{date:%y%m%d}'
    return prefix


def main():
    str_bucket = 's3://s3-radaresideam/'
    s3 = boto3.resource('s3',
                        config=Config(signature_version=botocore.UNSIGNED, user_agent_extra='Resource'))
    bucket = s3.Bucket('s3-radaresideam')
    query = create_query(date=datetime(2021, 10, 3, 12), radar_site='Guaviare')
    radar_files = [f'{str_bucket}{i.key}' for i in bucket.objects.filter(Prefix=f"{query}")]
    for idx, i in enumerate(radar_files[2:3]):
        file = fsspec.open_local(f'simplecache::{i}', s3={'anon': True}, filecache={'cache_storage': '.'})
       # dtree = xd.io.open_iris_datatree(file)
        ds = xr.open_dataset(file, group=1, engine="iris")

if __name__ == "__main__":
    main()

Then it rises this error,

ValueError: conflicting sizes for dimension 'range': length 580 on 'range' and length 581 on {'azimuth': 'DBTH', 'range': 'DBTH'}
python-BaseException

I have dug a little bit and I found that when creating the range dimension in iris.py file, line 3821 , it should create a NumPy array with a size of 581 but it instead creates a 580 NumPy array. I tried to solve it as follows but not sure if this is the right way .

rng = (
            np.arange(
                range_first_bin,
                range_last_bin + 1, ## ###adding 1 here
                task["step_output_bins"],
                dtype="float32",
            )[: task["number_output_bins"]]
            / 1e2
        )

Cheers,

Alfonso

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 21 (7 by maintainers)

Most upvoted comments

@kmuehlbauer I tested it and it worked! Thanks for looking at it.

@aladinor I sent some sample data for you to work with. Managed to read the volumes with no issues using Py-ART.

@kmuehlbauer I think you can use any other file in radar_files varible. I just identified the files 2, 5, 8, ... within that list are the ones that present this issue.

    for idx, i in enumerate(radar_files[2:3]): ### ------------> here you can chose any other out of 864 files 
        file = fsspec.open_local(f'simplecache::{i}', s3={'anon': True}, filecache={'cache_storage': '.'})
        dtree = xd.io.open_iris_datatree(file, reindex_angle=False)
        ds = xr.open_dataset(file, engine="iris")

Great! Your help is very much appreciated. It really helps to sort things out.

@aladinor @mgrover1 While working on this I found more inconsistencies with the metadata (eg. with longitude). I’ll issue a PR when I’m ready.

There are also some points which needs discussion in a wider audience (eg. angle reindexing). I’ll open issues as needed.

Great, I can have a look tomorrow.

@kmuehlbauer it might be. this code will run on your pc. The AWS bucket is an open dataset. You should just copy and paste. This is the complete version of my code

import pyart
import fsspec
import xarray as xr
import xradar as xd
import boto3
import botocore
from botocore.client import Config
from datetime import datetime


def create_query(date, radar_site):
    """
    Creates a query for listing IDEAM radar files stored in AWS bucket
    :param date: date to be queried. e.g datetime(2021, 10, 3, 12). Datetime python object
    :param radar_site: radar site e.g. Guaviare
    :return: string with a
    """
    prefix = f'l2_data/{date:%Y}/{date:%m}/{date:%d}/{radar_site}/{radar_site[:3].upper()}{date:%y%m%d}'
    return prefix


def main():
    str_bucket = 's3://s3-radaresideam/'
    s3 = boto3.resource('s3',
                        config=Config(signature_version=botocore.UNSIGNED, user_agent_extra='Resource'))
    bucket = s3.Bucket('s3-radaresideam')
    query = create_query(date=datetime(2021, 10, 3, 12), radar_site='Guaviare')
    radar_files = [f'{str_bucket}{i.key}' for i in bucket.objects.filter(Prefix=f"{query}")]

    # using context manager for reading radar data from guaviare radar
    of = pyart.io.prepare_for_read(radar_files[2], storage_options={'anon': True})
    with of as f:
        radar = pyart.io.read(f)
        print(radar.range['data'])
        f.close()

    for idx, i in enumerate(radar_files[2:3]):
        file = fsspec.open_local(f'simplecache::{i}', s3={'anon': True}, filecache={'cache_storage': '.'})
        dtree = xd.io.open_iris_datatree(file, reindex_angle=False)
        ds = xr.open_dataset(file, engine="iris")


if __name__ == "__main__":
    main()