#+begin_src python :results output :exports both :session s1
import h5py
import matplotlib.pyplot as plt
import numpy as np
#+end_src

* Чтение файла
#+begin_src python :results output :exports both :session s1
with h5py.File('train/2021-01-train.hdf5', mode='r') as dataset:
    print(list(dataset.keys())[:10])
#+end_src

#+RESULTS:
: ['1609459200', '1609459800', '1609460400', '1609461000', '1609461600', '1609462200', '1609462800', '1609463400', '1609464000', '1609464600']


#+begin_src python :results output :exports both :session s1
with h5py.File('train/2021-01-train.hdf5', mode='r') as dataset:
    print(list(dataset['1609459200'].keys()))
#+end_src

#+RESULTS:
: ['events', 'intensity', 'radial_velocity', 'reflectivity']


#+begin_src python :results output :exports both :session s1
with h5py.File('train/2021-01-train.hdf5', mode='r') as dataset:
    print(f"events shape: {dataset['1609459200']['events'].shape}")
    print(f"intensity shape: {dataset['1609459200']['intensity'].shape}")
    print(f"radial_velocity shape: {dataset['1609459200']['radial_velocity'].shape}")
    print(f"reflectivity shape: {dataset['1609459200']['reflectivity'].shape}")
#+end_src

#+RESULTS:
: events shape: (252, 252)
: intensity shape: (252, 252)
: radial_velocity shape: (10, 252, 252)
: reflectivity shape: (10, 252, 252)


* Визуализация
#+begin_src python :results output :exports both :session s1
events = []
intensity = []
radial_velocity = []
reflectivity = []

with h5py.File('train/2021-01-train.hdf5', mode='r') as dataset:
    timestamps = sorted(dataset.keys())[:6]
    for timestamp in timestamps:
        events.append(np.array(dataset[timestamp]['events']))
        intensity.append(np.array(dataset[timestamp]['intensity']))
        radial_velocity.append(np.array(dataset[timestamp]['radial_velocity']))
        reflectivity.append(np.array(dataset[timestamp]['reflectivity']))

events = np.array(events)
intensity = np.array(intensity)
radial_velocity = np.array(radial_velocity)
reflectivity = np.array(reflectivity)

events[events == -2e6] = -2
events[events == -1e6] = -1
intensity[intensity == -2e6] = -2
intensity[intensity == -1e6] = -1
radial_velocity[radial_velocity == -2e6] = -2
radial_velocity[radial_velocity == -1e6] = -1
reflectivity[reflectivity == -2e6] = -2
reflectivity[reflectivity == -1e6] = -1
#+end_src

** Погодные события
#+begin_src python :results file graphics :file ./autoimgs/8_0.png :exports both :session s1
_, axs = plt.subplots(1, len(events), figsize=(20, 2))
for index in range(len(events)):
    axs[index].imshow(events[index])
    axs[index].set_title(timestamps[index])
#+end_src

#+RESULTS:
[[file:./autoimgs/8_0.png]] <Figure size 1440x144 with 6 Axes>

** Интенсивность осадков
#+begin_src python :results file graphics :file ./autoimgs/10_0.png :exports both :session s1
_, axs = plt.subplots(1, len(intensity), figsize=(20, 2))
for index in range(len(intensity)):
    axs[index].imshow(intensity[index])
    axs[index].set_title(timestamps[index])
#+end_src

#+RESULTS:
[[file:./autoimgs/10_0.png]] <Figure size 1440x144 with 6 Axes>

** Радиальная скорость по высотам
#+begin_src python :results file graphics :file ./autoimgs/12_0.png :exports both :session s1
_, axs = plt.subplots(10, len(radial_velocity), figsize=(20, 20))
for index in range(len(radial_velocity)):
    for row in range(10):
        if index == 0:
            axs[row, index].set_ylabel(f'{row + 1} км')
        axs[row, index].imshow(radial_velocity[index, row])
    axs[0, index].set_title(timestamps[index])
#+end_src

#+RESULTS:
[[file:./autoimgs/12_0.png]] <Figure size 1440x1440 with 60 Axes>

** Отражаемость по высотам
#+begin_src python :results file graphics :file ./autoimgs/14_0.png :exports both :session s1
_, axs = plt.subplots(10, len(reflectivity), figsize=(20, 20))
for index in range(len(reflectivity)):
    for row in range(10):
        if index == 0:
            axs[row, index].set_ylabel(f'{row + 1} км')
        axs[row, index].imshow(reflectivity[index, row])
    axs[0, index].set_title(timestamps[index])
#+end_src

#+RESULTS:
[[file:./autoimgs/14_0.png]] <Figure size 1440x1440 with 60 Axes>

