miniufo / xgrads

Parse and read ctl and associated binary file commonly used by GrADS into xarray
https://xgrads.readthedocs.io/
MIT License
71 stars 27 forks source link

Cannot read templated file name #34

Closed mzaglia closed 1 year ago

mzaglia commented 2 years ago

The following name template doesn't work DSET ^R13537439_%y4%m2%d2%h2%n2.raw.gz.

  File "/usr/lib/python3.8/genericpath.py", line 50, in getsize
    return os.stat(filename).st_size
FileNotFoundError: [Errno 2] No such file or directory: 'radar/R13537439_%y4%m2%d2%h2%n2.raw.gz'
miniufo commented 2 years ago

Hi, can you provide the full ctl file and a sample dataset (with a templated filename) for me to check in? I guess %n2 is not properly parsed.

mzaglia commented 2 years ago

Sure,

DSET ^R13537439_%y4%m2%d2%h2%n2.raw
UNDEF  -99
TITLE  Radar
XDEF 500 LINEAR  -49.5786   0.0099570
YDEF 500 LINEAR  -25.8386   0.0090014
ZDEF   1 LEVELS 1
TDEF  1 LINEAR   00:30Z12feb2007 30mn
VARS 1
dbz 0 99 refletividade
ENDVARS

and the files are like this:

R13537439_202112061850.raw.gz
R13537439_202112061900.raw.gz
R13537439_202112061910.raw.gz
R13537439_202112061920.raw.gz
miniufo commented 2 years ago

You have forgot to add a line of 'options template' to CTL file. The complete ctl file should be: DSET ^R13537439_%y4%m2%d2%h2%n2.raw UNDEF -99 OPTIONS template TITLE Radar XDEF 500 LINEAR -49.5786 0.0099570 YDEF 500 LINEAR -25.8386 0.0090014 ZDEF 1 LEVELS 1 TDEF 1 LINEAR 00:30Z12feb2007 30mn VARS 1 dbz 0 99 refletividade ENDVARS

Note that the file name ends with .gz, while in ctl file it ends with .raw

mzaglia commented 2 years ago

I got it working, but I wish I could partially read the dataset without editing the TDEF line. Is it possible?

miniufo commented 2 years ago

You won't need to modify the TDEF, as long as the TDEF correctly describes the data time range and there are corresponding data file in the range. Otherwise, raising error is necessary to locate the error accurately. Then the best way would be to make a ctl copy and edit the TDEF for the time range you would like to read.