Skip to content
Snippets Groups Projects
Commit 60d68f30 authored by tomrink's avatar tomrink
Browse files

add new method to time sort icing dicts, use it in `pirep_icing`

parent 3d8d3557
No related branches found
No related tags found
No related merge requests found
import datetime import datetime
from datetime import timezone from datetime import timezone
from dateutil import tz import numpy as np
import re import re
from pathlib import Path from pathlib import Path
import h5py import h5py
...@@ -22,6 +22,34 @@ ATYPE = '/TP' ...@@ -22,6 +22,34 @@ ATYPE = '/TP'
RMK = '/RM' RMK = '/RM'
def time_sort_pirep_dict(the_dict):
new_dict = {}
keys = []
tidx = []
for ts in list(the_dict.keys()):
rpts = the_dict[ts]
for idx, tup in enumerate(rpts):
keys.append(ts)
tidx.append(idx)
sidxs = np.argsort(keys)
ice_keys = keys[sidxs]
ice_tidx = tidx[sidxs]
for idx, key in enumerate(ice_keys):
rpts = the_dict[key]
tup = rpts[ice_tidx[idx]]
n_rpts = new_dict.get(key)
if n_rpts is None:
n_rpts = []
new_dict[key] = n_rpts
n_rpts.append(tup)
return new_dict
# Returns icing, no_icing (no icing observed), neg-icing (icing expected, but not observed) # Returns icing, no_icing (no icing observed), neg-icing (icing expected, but not observed)
def pirep_icing(filename, lon_range=[-180, 180], lat_range=[-63, 63]): def pirep_icing(filename, lon_range=[-180, 180], lat_range=[-63, 63]):
...@@ -158,6 +186,10 @@ def pirep_icing(filename, lon_range=[-180, 180], lat_range=[-63, 63]): ...@@ -158,6 +186,10 @@ def pirep_icing(filename, lon_range=[-180, 180], lat_range=[-63, 63]):
else: else:
rpts.append(tup) rpts.append(tup)
ice_dict = time_sort_pirep_dict(ice_dict)
no_ice_dict = time_sort_pirep_dict(no_ice_dict)
neg_ice_dict = time_sort_pirep_dict(neg_ice_dict)
return ice_dict, no_ice_dict, neg_ice_dict return ice_dict, no_ice_dict, neg_ice_dict
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment