Skip to content

IGRAUpperAir returns wrong release time in the header due to excess padding of string in _ctime function #982

@awalkermag

Description

@awalkermag

The _ctime function in igra2.py is supposed to work for both MMMSS and HHMM formats, but is always padding the input string to 5 characters, which causes the hour and minute substrings of the HHMM format to be wrong. This can be seen by running the following copy of the _ctime code, with some print statements added.:

# Copy of _ctime function from igra2.py, with print statements added
def _ctime(strformat='MMMSS'):
    """Return a function converting a string from MMMSS or HHMM to seconds."""
    def _ctime_strformat(val):
        print('val',val)
        time = val.strip().zfill(5)
        print('time',time)
        if int(time) < 0 or int(time) == 9999:
            return np.nan
        else:
            if strformat == 'MMMSS':
                minutes = int(time[0:3])
                seconds = int(time[3:5])
                time_seconds = minutes * 60 + seconds
            elif strformat == 'HHMM':
                hours = int(time[0:2])
                minutes = int(time[2:4])
                print('hours minutes', hours,minutes)
                time_seconds = hours * 3600 + minutes * 60
            else:
                sys.exit('Unrecognized time format')

        return time_seconds
    return _ctime_strformat

# Call the function and print the result
func = _ctime(strformat='HHMM')
print(func('1142'))

The result is this:

val 1142
time 01142
hours minutes 1 14
4440

You can see the hours and minutes are not being correctly extracted from the input, so the resulting number of seconds computed is wrong. To fix this, the 5-char padding should be applied only when the format is MMMSS, and 4-char padding should be applied when the format is HHMM.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions