"""Define `asccol` data specifications.""" import math import asccol def simple_time(s): """Convert an HHMM string to an (H, M) tuple.""" hhmm = int(s) return divmod(hhmm, 100) def filtered_int(s): """Like int, but ignore the special value 999.""" val = int(s) return val if val != 999 else math.nan def filtered_float(s): """Like float, but ignore the special values 444.0, 99.9, etc.""" val = float(s) return val if val not in (444.0, 99.9, 999.9, 9999.9) else math.nan ONE_HOUR = asccol.DataSpec( leading=2, # 2 lines to delete cols=( ('year', int, 4), # name, type (converter function), width ('jdate', int, 4), ('month', int, 3), ('day', int, 3), ('time', simple_time, 5), ('temp', filtered_float, 7), ('pressure', filtered_float, 7), ('wind_speed', filtered_float, 7), ('wind_dir', filtered_float, 7), ('rel_hum', filtered_float, 7), ('delta_t', filtered_float, 7), ), )