diff options
-rw-r--r-- | windy/point_forecast.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/windy/point_forecast.py b/windy/point_forecast.py index f840d97..844cef3 100644 --- a/windy/point_forecast.py +++ b/windy/point_forecast.py @@ -172,6 +172,7 @@ class Response: for parameter in levels: levels[parameter] = tuple(sorted(levels[parameter])) units = {x: registry(_convert_notation(raw['units'][f'{x}-{levels[x][0]}'])) for x in parameters} + pressure_sort = [] if 'pressure' in parameters: for level in all_levels: if level is Level.SURFACE: @@ -179,6 +180,13 @@ class Response: pressure = (level.pressure() * registry.hPa).m_as(units['pressure']) raw[f'pressure-{level}'] = [pressure for _ in range(len(self.timestamps))] levels['pressure'] = all_levels + for index in range(len(self.timestamps)): + surface = raw[f'pressure-{Level.SURFACE}'][index] + new_index = 0 + for new_index, level in enumerate(all_levels[1:], start=0): + if surface > raw[f'pressure-{level}'][index]: + break + pressure_sort.append(new_index) self.raw_predictions = {} for parameter in parameters: profiles = [] @@ -189,6 +197,9 @@ class Response: profile.append(raw[f'{parameter}-{level}'][index]) except KeyError: pass + if pressure_sort: + new_index = pressure_sort[index] + profile[0], profile[new_index] = profile[new_index], profile[0] profiles.append(np.array(profile) * units[parameter]) self.raw_predictions[parameter] = profiles |