diff --git a/modules/icing/pireps.py b/modules/icing/pireps.py index 54599f9001eb18d5e4bbe169d5dc45b02edbe7d4..293b9233265d05eb16a135d73927b12ea46bb723 100644 --- a/modules/icing/pireps.py +++ b/modules/icing/pireps.py @@ -164,12 +164,47 @@ def pirep_icing_from_boeing(dirname='/ships19/cloud/scratch/ICING/BOEING/icing/2 for path in Path(dirname).rglob('*.nc'): flist.append(path) - cnt = 0 + ice_dict = {} + no_ice_dict = {} + + cnt_ice = 0 + cnt_no_ice = 0 + for fname in flist: - print(fname) - h5f = h5py.File(fname, 'r') - ice_bool = h5f['ice_bool'][:] - cnt += ice_bool.shape[0] - print('num_icing: ', cnt) + try: + h5f = h5py.File(fname, 'r') + ice_bool = h5f['ice_bool'][:] + lons = h5f['longitude'][:] + lats = h5f['latitude'][:] + years = h5f['year'][:] + mons = h5f['month'][:] + days = h5f['day'][:] + hours = h5f['hour'][:] + mins = h5f['minute'][:] + secs = h5f['second'][:] + flt_levs = h5f + except Exception as e: + print(e) + h5f.close() + continue + nrpts = ice_bool.shape[0] + if nrpts > 0: + for k in range(nrpts): + dto = datetime.datetime(year=years[k], month=mons[k], day=days[k], hour=hours[k], minute=mins[k], second=secs[k]) + dto = dto.replace(tzinfo=timezone.utc) + ts = dto.timestamp() + + if ice_bool[k]: + tup = (lats[k], lons[k], flt_levs[k], 1, 0, 'None') + ice_dict[ts] = tup + cnt_ice += 1 + else: + tup = (lats[k], lons[k], flt_levs[k], 0, 0, 'None') + no_ice_dict[ts] = tup + cnt_no_ice += 1 + h5f.close() - print('num icing: ', cnt) \ No newline at end of file + + print('num icing/no icing: ', cnt_ice, cnt_no_ice) + + return ice_dict, no_ice_dict, None \ No newline at end of file