# Neural Network Sounding Integration¶

David John Gagne

The goal of this notebook is to provide an introductory example showing how deep learning could be used to calculate information on a thermodynamic diagram.

In [290]:
%matplotlib inline
import numpy as np
import pandas as pd
from metpy.calc import dry_lapse, moist_lapse, saturation_mixing_ratio
from metpy.plots import SkewT
import pint
import matplotlib.pyplot as plt
from keras.layers import Dense, Input, Activation, Conv1D, AveragePooling1D, Reshape, Flatten, Dropout, AlphaDropout, LeakyReLU
from keras.models import Model
from keras.regularizers import l2
from keras.optimizers import SGD
from metpy.constants import Cp_d, epsilon, g, kappa, Lv, P0, Rd
from metpy.calc.thermo import *


The moist adiabat or pseudo-adiabat is the temperature trajectory taken by a saturated parcel as it ascends in the atmosphere. The change in temperature with pressue, or moist adiabatic lapse rate is

$$\frac{dT}{dP} = \frac{1}{P} \frac{R_d T + L_v r_s}{C_{pd} + \frac{L_v^2 r_s \epsilon}{R_d T^2}}$$

The equation does not have an analytic solution and must be integrated numerically. We do this below for a range of temperatures and a fixed set of pressure values.

In [12]:
ureg = pint.UnitRegistry()
train_temps = np.arange(230, 330, 2) * ureg.K
test_temps = np.arange(231, 331, 2) * ureg.K
pressures = np.arange(100, 1020, 20)[::-1] * ureg.hPa
print(train_temps.shape, pressures.shape)

(50,) (46,)

In [83]:
train_data = np.zeros((train_temps.size, pressures.size))
test_data = np.zeros((test_temps.size, pressures.size))
for t, temp in enumerate(train_temps):
print(temp)
train_data[t] = moist_lapse(pressures, temp)
for t, temp in enumerate(test_temps):
print(temp)
test_data[t] = moist_lapse(pressures, temp)

230 kelvin
232 kelvin
234 kelvin
236 kelvin
238 kelvin
240 kelvin
242 kelvin
244 kelvin
246 kelvin
248 kelvin
250 kelvin
252 kelvin
254 kelvin
256 kelvin
258 kelvin
260 kelvin
262 kelvin
264 kelvin
266 kelvin
268 kelvin
270 kelvin
272 kelvin
274 kelvin
276 kelvin
278 kelvin
280 kelvin
282 kelvin
284 kelvin
286 kelvin
288 kelvin
290 kelvin
292 kelvin
294 kelvin
296 kelvin
298 kelvin
300 kelvin
302 kelvin
304 kelvin
306 kelvin
308 kelvin
310 kelvin
312 kelvin
314 kelvin
316 kelvin
318 kelvin
320 kelvin
322 kelvin
324 kelvin
326 kelvin
328 kelvin
231 kelvin
233 kelvin
235 kelvin
237 kelvin
239 kelvin
241 kelvin
243 kelvin
245 kelvin
247 kelvin
249 kelvin
251 kelvin
253 kelvin
255 kelvin
257 kelvin
259 kelvin
261 kelvin
263 kelvin
265 kelvin
267 kelvin
269 kelvin
271 kelvin
273 kelvin
275 kelvin
277 kelvin
279 kelvin
281 kelvin
283 kelvin
285 kelvin
287 kelvin
289 kelvin
291 kelvin
293 kelvin
295 kelvin
297 kelvin
299 kelvin
301 kelvin
303 kelvin
305 kelvin
307 kelvin
309 kelvin
311 kelvin
313 kelvin
315 kelvin
317 kelvin
319 kelvin
321 kelvin
323 kelvin
325 kelvin
327 kelvin
329 kelvin

In [14]:
l_mean = train_data.mean(axis=0)
l_sd = train_data.std(axis=0)
t_mean = train_temps.m.mean()
t_sd = train_temps.m.std()
norm_train_data = (train_data - l_mean) / l_sd
norm_train_input = (train_temps.m.reshape(-1, 1) - t_mean) / t_sd
norm_test_input = (test_temps.m.reshape(-1, 1) - t_mean) / t_sd

In [296]:
nn_moist_in = Input(shape=(1,))
nn_moist_lapse = Dense(46 * 4,)(nn_moist_in)
nn_moist_lapse = LeakyReLU(0.1)(nn_moist_lapse)
nn_moist_lapse = Reshape((46 * 4, 1))(nn_moist_lapse)
nn_moist_lapse = LeakyReLU(0.1)(nn_moist_lapse)
nn_moist_lapse = AveragePooling1D()(nn_moist_lapse)
nn_moist_lapse = LeakyReLU(0.1)(nn_moist_lapse)
nn_moist_lapse = AveragePooling1D()(nn_moist_lapse)
nn_moist_lapse = LeakyReLU(0.1)(nn_moist_lapse)
nn_moist_lapse = Flatten()(nn_moist_lapse)
nn_moist_mod = Model(nn_moist_in, nn_moist_lapse)
opt = SGD(lr=0.001, momentum=0.99, decay=1e-6, nesterov=True)

In [285]:
nn_moist_mod.summary()

_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
input_42 (InputLayer)        (None, 1)                 0
_________________________________________________________________
dense_90 (Dense)             (None, 184)               368
_________________________________________________________________
reshape_17 (Reshape)         (None, 184, 1)            0
_________________________________________________________________
conv1d_45 (Conv1D)           (None, 184, 16)           96
_________________________________________________________________
average_pooling1d_28 (Averag (None, 92, 16)            0
_________________________________________________________________
conv1d_46 (Conv1D)           (None, 92, 24)            1944
_________________________________________________________________
average_pooling1d_29 (Averag (None, 46, 24)            0
_________________________________________________________________
conv1d_47 (Conv1D)           (None, 46, 32)            3872
_________________________________________________________________
conv1d_48 (Conv1D)           (None, 46, 1)             161
_________________________________________________________________
flatten_11 (Flatten)         (None, 46)                0
=================================================================
Total params: 6,441
Trainable params: 6,441
Non-trainable params: 0
_________________________________________________________________

In [297]:
nn_moist_mod.fit(norm_train_input, norm_train_data, epochs=500,batch_size=5)

Epoch 1/500
50/50 [==============================] - 0s - loss: 1.0025
Epoch 2/500
50/50 [==============================] - 0s - loss: 0.9908
Epoch 3/500
50/50 [==============================] - 0s - loss: 0.9686
Epoch 4/500
50/50 [==============================] - 0s - loss: 0.8758
Epoch 5/500
50/50 [==============================] - 0s - loss: 0.6228
Epoch 6/500
50/50 [==============================] - 0s - loss: 0.3613
Epoch 7/500
50/50 [==============================] - 0s - loss: 0.1985
Epoch 8/500
50/50 [==============================] - 0s - loss: 0.1369
Epoch 9/500
50/50 [==============================] - 0s - loss: 0.0917
Epoch 10/500
50/50 [==============================] - 0s - loss: 0.0664
Epoch 11/500
50/50 [==============================] - 0s - loss: 0.0537
Epoch 12/500
50/50 [==============================] - 0s - loss: 0.0507
Epoch 13/500
50/50 [==============================] - 0s - loss: 0.0455
Epoch 14/500
50/50 [==============================] - 0s - loss: 0.0379
Epoch 15/500
50/50 [==============================] - 0s - loss: 0.0321
Epoch 16/500
50/50 [==============================] - 0s - loss: 0.0294
Epoch 17/500
50/50 [==============================] - 0s - loss: 0.0243
Epoch 18/500
50/50 [==============================] - 0s - loss: 0.0211
Epoch 19/500
50/50 [==============================] - 0s - loss: 0.0187
Epoch 20/500
50/50 [==============================] - 0s - loss: 0.0172
Epoch 21/500
50/50 [==============================] - 0s - loss: 0.0160
Epoch 22/500
50/50 [==============================] - 0s - loss: 0.0148
Epoch 23/500
50/50 [==============================] - 0s - loss: 0.0140
Epoch 24/500
50/50 [==============================] - 0s - loss: 0.0133
Epoch 25/500
50/50 [==============================] - 0s - loss: 0.0135
Epoch 26/500
50/50 [==============================] - 0s - loss: 0.0127
Epoch 27/500
50/50 [==============================] - 0s - loss: 0.0126
Epoch 28/500
50/50 [==============================] - 0s - loss: 0.0115
Epoch 29/500
50/50 [==============================] - 0s - loss: 0.0107
Epoch 30/500
50/50 [==============================] - 0s - loss: 0.0104
Epoch 31/500
50/50 [==============================] - 0s - loss: 0.0102
Epoch 32/500
50/50 [==============================] - 0s - loss: 0.0092
Epoch 33/500
50/50 [==============================] - 0s - loss: 0.0086
Epoch 34/500
50/50 [==============================] - 0s - loss: 0.0083
Epoch 35/500
50/50 [==============================] - 0s - loss: 0.0080
Epoch 36/500
50/50 [==============================] - 0s - loss: 0.0079
Epoch 37/500
50/50 [==============================] - 0s - loss: 0.0075
Epoch 38/500
50/50 [==============================] - 0s - loss: 0.0072
Epoch 39/500
50/50 [==============================] - 0s - loss: 0.0075
Epoch 40/500
50/50 [==============================] - 0s - loss: 0.0077
Epoch 41/500
50/50 [==============================] - 0s - loss: 0.0069
Epoch 42/500
50/50 [==============================] - 0s - loss: 0.0065
Epoch 43/500
50/50 [==============================] - 0s - loss: 0.0060
Epoch 44/500
50/50 [==============================] - 0s - loss: 0.0058
Epoch 45/500
50/50 [==============================] - 0s - loss: 0.0056
Epoch 46/500
50/50 [==============================] - 0s - loss: 0.0054
Epoch 47/500
50/50 [==============================] - 0s - loss: 0.0054
Epoch 48/500
50/50 [==============================] - 0s - loss: 0.0056
Epoch 49/500
50/50 [==============================] - 0s - loss: 0.0050
Epoch 50/500
50/50 [==============================] - 0s - loss: 0.0052
Epoch 51/500
50/50 [==============================] - 0s - loss: 0.0046
Epoch 52/500
50/50 [==============================] - 0s - loss: 0.0044
Epoch 53/500
50/50 [==============================] - 0s - loss: 0.0042
Epoch 54/500
50/50 [==============================] - 0s - loss: 0.0040
Epoch 55/500
50/50 [==============================] - 0s - loss: 0.0039
Epoch 56/500
50/50 [==============================] - 0s - loss: 0.0038
Epoch 57/500
50/50 [==============================] - 0s - loss: 0.0037
Epoch 58/500
50/50 [==============================] - 0s - loss: 0.0038
Epoch 59/500
50/50 [==============================] - 0s - loss: 0.0034
Epoch 60/500
50/50 [==============================] - 0s - loss: 0.0035
Epoch 61/500
50/50 [==============================] - 0s - loss: 0.0036
Epoch 62/500
50/50 [==============================] - 0s - loss: 0.0034
Epoch 63/500
50/50 [==============================] - 0s - loss: 0.0031
Epoch 64/500
50/50 [==============================] - 0s - loss: 0.0031
Epoch 65/500
50/50 [==============================] - 0s - loss: 0.0028
Epoch 66/500
50/50 [==============================] - 0s - loss: 0.0027
Epoch 67/500
50/50 [==============================] - 0s - loss: 0.0025
Epoch 68/500
50/50 [==============================] - 0s - loss: 0.0028
Epoch 69/500
50/50 [==============================] - 0s - loss: 0.0026
Epoch 70/500
50/50 [==============================] - 0s - loss: 0.0026
Epoch 71/500
50/50 [==============================] - 0s - loss: 0.0024
Epoch 72/500
50/50 [==============================] - 0s - loss: 0.0025
Epoch 73/500
50/50 [==============================] - 0s - loss: 0.0023
Epoch 74/500
50/50 [==============================] - 0s - loss: 0.0021
Epoch 75/500
50/50 [==============================] - 0s - loss: 0.0021     - ETA: 0s - loss: 0.002
Epoch 76/500
50/50 [==============================] - 0s - loss: 0.0022
Epoch 77/500
50/50 [==============================] - 0s - loss: 0.0032
Epoch 78/500
50/50 [==============================] - 0s - loss: 0.0071
Epoch 79/500
50/50 [==============================] - 0s - loss: 0.0109
Epoch 80/500
50/50 [==============================] - 0s - loss: 0.0062
Epoch 81/500
50/50 [==============================] - 0s - loss: 0.0036
Epoch 82/500
50/50 [==============================] - 0s - loss: 0.0032
Epoch 83/500
50/50 [==============================] - 0s - loss: 0.0033
Epoch 84/500
50/50 [==============================] - 0s - loss: 0.0031
Epoch 85/500
50/50 [==============================] - 0s - loss: 0.0018
Epoch 86/500
50/50 [==============================] - 0s - loss: 0.0016
Epoch 87/500
50/50 [==============================] - 0s - loss: 0.0016
Epoch 88/500
50/50 [==============================] - 0s - loss: 0.0016
Epoch 89/500
50/50 [==============================] - 0s - loss: 0.0014
Epoch 90/500
50/50 [==============================] - 0s - loss: 0.0014
Epoch 91/500
50/50 [==============================] - 0s - loss: 0.0013
Epoch 92/500
50/50 [==============================] - 0s - loss: 0.0013
Epoch 93/500
50/50 [==============================] - 0s - loss: 0.0013
Epoch 94/500
50/50 [==============================] - 0s - loss: 0.0013
Epoch 95/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 96/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 97/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 98/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 99/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 100/500
50/50 [==============================] - 0s - loss: 0.0011
Epoch 101/500
50/50 [==============================] - 0s - loss: 0.0011
Epoch 102/500
50/50 [==============================] - 0s - loss: 0.0010
Epoch 103/500
50/50 [==============================] - 0s - loss: 9.9540e-04
Epoch 104/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 105/500
50/50 [==============================] - 0s - loss: 0.0010
Epoch 106/500
50/50 [==============================] - 0s - loss: 9.3900e-04
Epoch 107/500
50/50 [==============================] - 0s - loss: 8.6306e-04
Epoch 108/500
50/50 [==============================] - 0s - loss: 9.7012e-04
Epoch 109/500
50/50 [==============================] - 0s - loss: 8.7211e-04
Epoch 110/500
50/50 [==============================] - 0s - loss: 8.2063e-04
Epoch 111/500
50/50 [==============================] - 0s - loss: 8.4548e-04
Epoch 112/500
50/50 [==============================] - 0s - loss: 8.4234e-04
Epoch 113/500
50/50 [==============================] - 0s - loss: 8.3152e-04
Epoch 114/500
50/50 [==============================] - 0s - loss: 7.2001e-04
Epoch 115/500
50/50 [==============================] - 0s - loss: 7.1898e-04
Epoch 116/500
50/50 [==============================] - 0s - loss: 7.3957e-04
Epoch 117/500
50/50 [==============================] - 0s - loss: 6.6625e-04
Epoch 118/500
50/50 [==============================] - 0s - loss: 6.4070e-04
Epoch 119/500
50/50 [==============================] - 0s - loss: 6.3508e-04
Epoch 120/500
50/50 [==============================] - 0s - loss: 6.2142e-04
Epoch 121/500
50/50 [==============================] - 0s - loss: 6.2765e-04
Epoch 122/500
50/50 [==============================] - 0s - loss: 5.8295e-04
Epoch 123/500
50/50 [==============================] - 0s - loss: 6.0148e-04
Epoch 124/500
50/50 [==============================] - 0s - loss: 6.2649e-04
Epoch 125/500
50/50 [==============================] - 0s - loss: 6.5747e-04
Epoch 126/500
50/50 [==============================] - 0s - loss: 5.8412e-04
Epoch 127/500
50/50 [==============================] - 0s - loss: 5.8410e-04
Epoch 128/500
50/50 [==============================] - 0s - loss: 5.7684e-04
Epoch 129/500
50/50 [==============================] - 0s - loss: 5.5215e-04
Epoch 130/500
50/50 [==============================] - 0s - loss: 5.0752e-04
Epoch 131/500
50/50 [==============================] - 0s - loss: 6.2825e-04
Epoch 132/500
50/50 [==============================] - 0s - loss: 5.9073e-04
Epoch 133/500
50/50 [==============================] - 0s - loss: 5.2371e-04
Epoch 134/500
50/50 [==============================] - 0s - loss: 5.3094e-04
Epoch 135/500
50/50 [==============================] - 0s - loss: 5.5685e-04
Epoch 136/500
50/50 [==============================] - 0s - loss: 6.0214e-04
Epoch 137/500
50/50 [==============================] - 0s - loss: 5.5475e-04
Epoch 138/500
50/50 [==============================] - 0s - loss: 6.0385e-04
Epoch 139/500
50/50 [==============================] - 0s - loss: 6.2732e-04
Epoch 140/500
50/50 [==============================] - 0s - loss: 5.3687e-04
Epoch 141/500
50/50 [==============================] - 0s - loss: 4.6819e-04
Epoch 142/500
50/50 [==============================] - 0s - loss: 4.2603e-04
Epoch 143/500
50/50 [==============================] - 0s - loss: 4.3863e-04
Epoch 144/500
50/50 [==============================] - 0s - loss: 4.7734e-04
Epoch 145/500
50/50 [==============================] - 0s - loss: 4.7682e-04
Epoch 146/500
50/50 [==============================] - 0s - loss: 6.8893e-04
Epoch 147/500
50/50 [==============================] - 0s - loss: 6.0450e-04
Epoch 148/500
50/50 [==============================] - 0s - loss: 7.4836e-04
Epoch 149/500
50/50 [==============================] - 0s - loss: 6.4839e-04
Epoch 150/500
50/50 [==============================] - 0s - loss: 4.3505e-04
Epoch 151/500
50/50 [==============================] - 0s - loss: 4.6765e-04
Epoch 152/500
50/50 [==============================] - 0s - loss: 7.7781e-04
Epoch 153/500
50/50 [==============================] - 0s - loss: 4.4484e-04
Epoch 154/500
50/50 [==============================] - 0s - loss: 3.9103e-04
Epoch 155/500
50/50 [==============================] - 0s - loss: 3.6901e-04
Epoch 156/500
50/50 [==============================] - 0s - loss: 3.9295e-04
Epoch 157/500
50/50 [==============================] - 0s - loss: 5.4332e-04
Epoch 158/500
50/50 [==============================] - 0s - loss: 5.0417e-04
Epoch 159/500
50/50 [==============================] - 0s - loss: 3.8884e-04
Epoch 160/500
50/50 [==============================] - 0s - loss: 5.1077e-04
Epoch 161/500
50/50 [==============================] - 0s - loss: 5.1659e-04
Epoch 162/500
50/50 [==============================] - 0s - loss: 4.2155e-04
Epoch 163/500
50/50 [==============================] - 0s - loss: 4.1924e-04
Epoch 164/500
50/50 [==============================] - 0s - loss: 4.5399e-04
Epoch 165/500
50/50 [==============================] - 0s - loss: 4.4368e-04
Epoch 166/500
50/50 [==============================] - 0s - loss: 6.7781e-04
Epoch 167/500
50/50 [==============================] - 0s - loss: 8.0861e-04
Epoch 168/500
50/50 [==============================] - 0s - loss: 7.2386e-04
Epoch 169/500
50/50 [==============================] - 0s - loss: 6.6802e-04
Epoch 170/500
50/50 [==============================] - 0s - loss: 7.4168e-04
Epoch 171/500
50/50 [==============================] - 0s - loss: 7.4797e-04
Epoch 172/500
50/50 [==============================] - 0s - loss: 8.7365e-04
Epoch 173/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 174/500
50/50 [==============================] - 0s - loss: 0.0015
Epoch 175/500
50/50 [==============================] - 0s - loss: 9.7627e-04
Epoch 176/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 177/500
50/50 [==============================] - 0s - loss: 0.0030
Epoch 178/500
50/50 [==============================] - 0s - loss: 0.0049
Epoch 179/500
50/50 [==============================] - 0s - loss: 0.0048
Epoch 180/500
50/50 [==============================] - 0s - loss: 0.0040
Epoch 181/500
50/50 [==============================] - 0s - loss: 0.0018
Epoch 182/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 183/500
50/50 [==============================] - 0s - loss: 6.2884e-04
Epoch 184/500
50/50 [==============================] - 0s - loss: 5.2463e-04
Epoch 185/500
50/50 [==============================] - 0s - loss: 4.0351e-04
Epoch 186/500
50/50 [==============================] - 0s - loss: 4.0223e-04
Epoch 187/500
50/50 [==============================] - 0s - loss: 3.1661e-04
Epoch 188/500
50/50 [==============================] - 0s - loss: 2.9531e-04
Epoch 189/500
50/50 [==============================] - 0s - loss: 3.2701e-04
Epoch 190/500
50/50 [==============================] - 0s - loss: 3.2263e-04
Epoch 191/500
50/50 [==============================] - 0s - loss: 2.8106e-04
Epoch 192/500
50/50 [==============================] - 0s - loss: 3.2185e-04
Epoch 193/500
50/50 [==============================] - 0s - loss: 3.5287e-04
Epoch 194/500
50/50 [==============================] - 0s - loss: 4.5820e-04
Epoch 195/500
50/50 [==============================] - 0s - loss: 4.4261e-04
Epoch 196/500
50/50 [==============================] - 0s - loss: 2.9419e-04
Epoch 197/500
50/50 [==============================] - 0s - loss: 3.0149e-04
Epoch 198/500
50/50 [==============================] - 0s - loss: 3.0429e-04
Epoch 199/500
50/50 [==============================] - 0s - loss: 3.2660e-04
Epoch 200/500
50/50 [==============================] - 0s - loss: 3.3344e-04
Epoch 201/500
50/50 [==============================] - 0s - loss: 3.1503e-04
Epoch 202/500
50/50 [==============================] - 0s - loss: 3.2051e-04
Epoch 203/500
50/50 [==============================] - 0s - loss: 3.4153e-04
Epoch 204/500
50/50 [==============================] - 0s - loss: 2.9351e-04
Epoch 205/500
50/50 [==============================] - 0s - loss: 2.9367e-04
Epoch 206/500
50/50 [==============================] - 0s - loss: 4.2652e-04
Epoch 207/500
50/50 [==============================] - 0s - loss: 3.2714e-04
Epoch 208/500
50/50 [==============================] - 0s - loss: 2.5145e-04
Epoch 209/500
50/50 [==============================] - 0s - loss: 2.4544e-04
Epoch 210/500
50/50 [==============================] - 0s - loss: 2.3658e-04
Epoch 211/500
50/50 [==============================] - 0s - loss: 2.5982e-04
Epoch 212/500
50/50 [==============================] - 0s - loss: 2.5750e-04
Epoch 213/500
50/50 [==============================] - 0s - loss: 2.6585e-04
Epoch 214/500
50/50 [==============================] - 0s - loss: 2.3055e-04
Epoch 215/500
50/50 [==============================] - 0s - loss: 2.3492e-04
Epoch 216/500
50/50 [==============================] - 0s - loss: 2.6619e-04
Epoch 217/500
50/50 [==============================] - 0s - loss: 3.6358e-04
Epoch 218/500
50/50 [==============================] - 0s - loss: 3.1374e-04
Epoch 219/500
50/50 [==============================] - 0s - loss: 3.2507e-04
Epoch 220/500
50/50 [==============================] - 0s - loss: 3.0830e-04
Epoch 221/500
50/50 [==============================] - 0s - loss: 5.8492e-04
Epoch 222/500
50/50 [==============================] - 0s - loss: 0.0011
Epoch 223/500
50/50 [==============================] - 0s - loss: 4.5097e-04
Epoch 224/500
50/50 [==============================] - 0s - loss: 3.2624e-04
Epoch 225/500
50/50 [==============================] - 0s - loss: 4.2638e-04
Epoch 226/500
50/50 [==============================] - 0s - loss: 6.6101e-04
Epoch 227/500
50/50 [==============================] - 0s - loss: 4.8701e-04
Epoch 228/500
50/50 [==============================] - 0s - loss: 2.9974e-04
Epoch 229/500
50/50 [==============================] - 0s - loss: 3.0616e-04
Epoch 230/500
50/50 [==============================] - 0s - loss: 3.3078e-04
Epoch 231/500
50/50 [==============================] - 0s - loss: 3.0372e-04
Epoch 232/500
50/50 [==============================] - 0s - loss: 2.8556e-04
Epoch 233/500
50/50 [==============================] - 0s - loss: 2.3768e-04
Epoch 234/500
50/50 [==============================] - 0s - loss: 2.3714e-04
Epoch 235/500
50/50 [==============================] - 0s - loss: 2.0852e-04
Epoch 236/500
50/50 [==============================] - 0s - loss: 2.1143e-04
Epoch 237/500
50/50 [==============================] - 0s - loss: 2.1716e-04
Epoch 238/500
50/50 [==============================] - 0s - loss: 2.2629e-04
Epoch 239/500
50/50 [==============================] - 0s - loss: 2.4910e-04
Epoch 240/500
50/50 [==============================] - 0s - loss: 2.3781e-04
Epoch 241/500
50/50 [==============================] - 0s - loss: 2.0425e-04
Epoch 242/500
50/50 [==============================] - 0s - loss: 1.9270e-04
Epoch 243/500
50/50 [==============================] - 0s - loss: 1.8579e-04
Epoch 244/500
50/50 [==============================] - 0s - loss: 1.9801e-04
Epoch 245/500
50/50 [==============================] - 0s - loss: 2.1311e-04
Epoch 246/500
50/50 [==============================] - 0s - loss: 2.9330e-04
Epoch 247/500
50/50 [==============================] - 0s - loss: 3.4217e-04
Epoch 248/500
50/50 [==============================] - 0s - loss: 3.3469e-04
Epoch 249/500
50/50 [==============================] - 0s - loss: 6.2751e-04
Epoch 250/500
50/50 [==============================] - 0s - loss: 0.0010
Epoch 251/500
50/50 [==============================] - 0s - loss: 0.0019
Epoch 252/500
50/50 [==============================] - 0s - loss: 0.0018
Epoch 253/500
50/50 [==============================] - 0s - loss: 8.2607e-04
Epoch 254/500
50/50 [==============================] - 0s - loss: 9.7295e-04
Epoch 255/500
50/50 [==============================] - 0s - loss: 8.9717e-04
Epoch 256/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 257/500
50/50 [==============================] - 0s - loss: 4.6826e-04
Epoch 258/500
50/50 [==============================] - 0s - loss: 5.2367e-04
Epoch 259/500
50/50 [==============================] - 0s - loss: 4.3869e-04
Epoch 260/500
50/50 [==============================] - 0s - loss: 3.1204e-04
Epoch 261/500
50/50 [==============================] - 0s - loss: 2.8442e-04
Epoch 262/500
50/50 [==============================] - 0s - loss: 3.4017e-04
Epoch 263/500
50/50 [==============================] - 0s - loss: 2.3892e-04
Epoch 264/500
50/50 [==============================] - 0s - loss: 1.6401e-04
Epoch 265/500
50/50 [==============================] - 0s - loss: 1.7688e-04
Epoch 266/500
50/50 [==============================] - 0s - loss: 1.8120e-04
Epoch 267/500
50/50 [==============================] - 0s - loss: 1.9500e-04
Epoch 268/500
50/50 [==============================] - 0s - loss: 2.1498e-04
Epoch 269/500
50/50 [==============================] - 0s - loss: 2.2383e-04
Epoch 270/500
50/50 [==============================] - 0s - loss: 3.5013e-04
Epoch 271/500
50/50 [==============================] - 0s - loss: 2.8964e-04
Epoch 272/500
50/50 [==============================] - 0s - loss: 2.4384e-04
Epoch 273/500
50/50 [==============================] - 0s - loss: 2.0750e-04
Epoch 274/500
50/50 [==============================] - 0s - loss: 1.9713e-04
Epoch 275/500
50/50 [==============================] - 0s - loss: 1.9325e-04
Epoch 276/500
50/50 [==============================] - 0s - loss: 1.7192e-04
Epoch 277/500
50/50 [==============================] - 0s - loss: 2.0703e-04
Epoch 278/500
50/50 [==============================] - 0s - loss: 1.7470e-04
Epoch 279/500
50/50 [==============================] - 0s - loss: 1.9346e-04
Epoch 280/500
50/50 [==============================] - 0s - loss: 1.7791e-04
Epoch 281/500
50/50 [==============================] - 0s - loss: 1.6172e-04
Epoch 282/500
50/50 [==============================] - 0s - loss: 1.5737e-04
Epoch 283/500
50/50 [==============================] - 0s - loss: 1.6304e-04
Epoch 284/500
50/50 [==============================] - 0s - loss: 1.3964e-04
Epoch 285/500
50/50 [==============================] - 0s - loss: 1.4456e-04
Epoch 286/500
50/50 [==============================] - 0s - loss: 1.4176e-04
Epoch 287/500
50/50 [==============================] - 0s - loss: 1.4758e-04
Epoch 288/500
50/50 [==============================] - 0s - loss: 1.5645e-04
Epoch 289/500
50/50 [==============================] - 0s - loss: 1.5490e-04
Epoch 290/500
50/50 [==============================] - 0s - loss: 1.6918e-04
Epoch 291/500
50/50 [==============================] - 0s - loss: 1.5733e-04
Epoch 292/500
50/50 [==============================] - 0s - loss: 1.7729e-04
Epoch 293/500
50/50 [==============================] - 0s - loss: 1.5604e-04
Epoch 294/500
50/50 [==============================] - 0s - loss: 1.5673e-04
Epoch 295/500
50/50 [==============================] - 0s - loss: 1.6785e-04
Epoch 296/500
50/50 [==============================] - 0s - loss: 2.3351e-04
Epoch 297/500
50/50 [==============================] - 0s - loss: 3.4187e-04
Epoch 298/500
50/50 [==============================] - 0s - loss: 2.8274e-04
Epoch 299/500
50/50 [==============================] - 0s - loss: 7.4605e-04
Epoch 300/500
50/50 [==============================] - 0s - loss: 7.1247e-04
Epoch 301/500
50/50 [==============================] - 0s - loss: 0.0018
Epoch 302/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 303/500
50/50 [==============================] - 0s - loss: 0.0013
Epoch 304/500
50/50 [==============================] - 0s - loss: 8.2988e-04
Epoch 305/500
50/50 [==============================] - 0s - loss: 0.0014
Epoch 306/500
50/50 [==============================] - 0s - loss: 0.0010
Epoch 307/500
50/50 [==============================] - 0s - loss: 0.0010
Epoch 308/500
50/50 [==============================] - 0s - loss: 6.2367e-04
Epoch 309/500
50/50 [==============================] - 0s - loss: 4.3657e-04
Epoch 310/500
50/50 [==============================] - 0s - loss: 5.3147e-04
Epoch 311/500
50/50 [==============================] - 0s - loss: 6.3534e-04
Epoch 312/500
50/50 [==============================] - 0s - loss: 4.8613e-04
Epoch 313/500
50/50 [==============================] - 0s - loss: 4.6632e-04
Epoch 314/500
50/50 [==============================] - 0s - loss: 5.1928e-04
Epoch 315/500
50/50 [==============================] - 0s - loss: 4.0766e-04
Epoch 316/500
50/50 [==============================] - 0s - loss: 3.1295e-04
Epoch 317/500
50/50 [==============================] - 0s - loss: 1.5869e-04
Epoch 318/500
50/50 [==============================] - 0s - loss: 1.3559e-04
Epoch 319/500
50/50 [==============================] - 0s - loss: 1.9816e-04
Epoch 320/500
50/50 [==============================] - 0s - loss: 2.3883e-04
Epoch 321/500
50/50 [==============================] - 0s - loss: 2.7415e-04
Epoch 322/500
50/50 [==============================] - 0s - loss: 1.7932e-04
Epoch 323/500
50/50 [==============================] - 0s - loss: 1.8675e-04
Epoch 324/500
50/50 [==============================] - 0s - loss: 2.0247e-04
Epoch 325/500
50/50 [==============================] - 0s - loss: 2.7127e-04
Epoch 326/500
50/50 [==============================] - 0s - loss: 4.1569e-04
Epoch 327/500
50/50 [==============================] - 0s - loss: 1.6736e-04
Epoch 328/500
50/50 [==============================] - 0s - loss: 1.5547e-04
Epoch 329/500
50/50 [==============================] - 0s - loss: 1.3511e-04
Epoch 330/500
50/50 [==============================] - 0s - loss: 1.2903e-04
Epoch 331/500
50/50 [==============================] - 0s - loss: 1.4018e-04
Epoch 332/500
50/50 [==============================] - 0s - loss: 1.2294e-04
Epoch 333/500
50/50 [==============================] - 0s - loss: 1.1013e-04
Epoch 334/500
50/50 [==============================] - 0s - loss: 1.1959e-04
Epoch 335/500
50/50 [==============================] - 0s - loss: 1.2213e-04
Epoch 336/500
50/50 [==============================] - 0s - loss: 1.3356e-04
Epoch 337/500
50/50 [==============================] - 0s - loss: 1.3340e-04
Epoch 338/500
50/50 [==============================] - 0s - loss: 1.3023e-04
Epoch 339/500
50/50 [==============================] - 0s - loss: 1.4317e-04
Epoch 340/500
50/50 [==============================] - 0s - loss: 2.4639e-04
Epoch 341/500
50/50 [==============================] - 0s - loss: 3.4356e-04
Epoch 342/500
50/50 [==============================] - 0s - loss: 7.7125e-04
Epoch 343/500
50/50 [==============================] - 0s - loss: 0.0012
Epoch 344/500
50/50 [==============================] - 0s - loss: 9.5286e-04
Epoch 345/500
50/50 [==============================] - 0s - loss: 5.0073e-04
Epoch 346/500
50/50 [==============================] - 0s - loss: 1.8193e-04
Epoch 347/500
50/50 [==============================] - 0s - loss: 1.6465e-04
Epoch 348/500
50/50 [==============================] - 0s - loss: 1.9031e-04
Epoch 349/500
50/50 [==============================] - 0s - loss: 3.1856e-04
Epoch 350/500
50/50 [==============================] - 0s - loss: 1.7926e-04
Epoch 351/500
50/50 [==============================] - 0s - loss: 2.2730e-04
Epoch 352/500
50/50 [==============================] - 0s - loss: 2.0651e-04
Epoch 353/500
50/50 [==============================] - 0s - loss: 2.1259e-04
Epoch 354/500
50/50 [==============================] - 0s - loss: 1.9287e-04
Epoch 355/500
50/50 [==============================] - 0s - loss: 2.5754e-04
Epoch 356/500
50/50 [==============================] - 0s - loss: 1.8971e-04
Epoch 357/500
50/50 [==============================] - 0s - loss: 1.9872e-04
Epoch 358/500
50/50 [==============================] - 0s - loss: 1.6058e-04
Epoch 359/500
50/50 [==============================] - 0s - loss: 1.3750e-04
Epoch 360/500
50/50 [==============================] - 0s - loss: 1.1955e-04
Epoch 361/500
50/50 [==============================] - 0s - loss: 1.1172e-04
Epoch 362/500
50/50 [==============================] - 0s - loss: 1.1305e-04
Epoch 363/500
50/50 [==============================] - 0s - loss: 1.1997e-04
Epoch 364/500
50/50 [==============================] - 0s - loss: 1.0658e-04
Epoch 365/500
50/50 [==============================] - 0s - loss: 1.0188e-04
Epoch 366/500
50/50 [==============================] - 0s - loss: 1.0373e-04
Epoch 367/500
50/50 [==============================] - 0s - loss: 1.0062e-04
Epoch 368/500
50/50 [==============================] - 0s - loss: 9.3453e-05
Epoch 369/500
50/50 [==============================] - 0s - loss: 1.0263e-04
Epoch 370/500
50/50 [==============================] - 0s - loss: 9.8204e-05
Epoch 371/500
50/50 [==============================] - 0s - loss: 9.9297e-05
Epoch 372/500
50/50 [==============================] - 0s - loss: 1.2152e-04
Epoch 373/500
50/50 [==============================] - 0s - loss: 1.0667e-04
Epoch 374/500
50/50 [==============================] - 0s - loss: 9.6208e-05
Epoch 375/500
50/50 [==============================] - 0s - loss: 1.1083e-04
Epoch 376/500
50/50 [==============================] - 0s - loss: 1.5626e-04
Epoch 377/500
50/50 [==============================] - 0s - loss: 1.6902e-04
Epoch 378/500
50/50 [==============================] - 0s - loss: 1.2281e-04
Epoch 379/500
50/50 [==============================] - 0s - loss: 1.0164e-04
Epoch 380/500
50/50 [==============================] - 0s - loss: 9.3808e-05
Epoch 381/500
50/50 [==============================] - 0s - loss: 1.1797e-04
Epoch 382/500
50/50 [==============================] - 0s - loss: 1.7151e-04
Epoch 383/500
50/50 [==============================] - 0s - loss: 1.5230e-04
Epoch 384/500
50/50 [==============================] - 0s - loss: 1.4393e-04
Epoch 385/500
50/50 [==============================] - 0s - loss: 2.8754e-04
Epoch 386/500
50/50 [==============================] - 0s - loss: 5.0727e-04
Epoch 387/500
50/50 [==============================] - 0s - loss: 6.0481e-04
Epoch 388/500
50/50 [==============================] - 0s - loss: 4.3744e-04
Epoch 389/500
50/50 [==============================] - 0s - loss: 6.6372e-04
Epoch 390/500
50/50 [==============================] - 0s - loss: 2.6848e-04
Epoch 391/500
50/50 [==============================] - 0s - loss: 1.8372e-04
Epoch 392/500
50/50 [==============================] - 0s - loss: 2.6044e-04
Epoch 393/500
50/50 [==============================] - 0s - loss: 2.3628e-04
Epoch 394/500
50/50 [==============================] - 0s - loss: 1.6265e-04
Epoch 395/500
50/50 [==============================] - 0s - loss: 2.0938e-04
Epoch 396/500
50/50 [==============================] - 0s - loss: 9.9512e-05
Epoch 397/500
50/50 [==============================] - 0s - loss: 1.0325e-04
Epoch 398/500
50/50 [==============================] - 0s - loss: 1.7551e-04
Epoch 399/500
50/50 [==============================] - 0s - loss: 2.5023e-04
Epoch 400/500
50/50 [==============================] - 0s - loss: 1.9458e-04
Epoch 401/500
50/50 [==============================] - 0s - loss: 1.6818e-04
Epoch 402/500
50/50 [==============================] - 0s - loss: 1.1085e-04
Epoch 403/500
50/50 [==============================] - 0s - loss: 9.4352e-05
Epoch 404/500
50/50 [==============================] - 0s - loss: 1.1952e-04
Epoch 405/500
50/50 [==============================] - 0s - loss: 9.2653e-05
Epoch 406/500
50/50 [==============================] - 0s - loss: 9.1602e-05
Epoch 407/500
50/50 [==============================] - 0s - loss: 1.0439e-04
Epoch 408/500
50/50 [==============================] - 0s - loss: 1.5231e-04
Epoch 409/500
50/50 [==============================] - 0s - loss: 2.2874e-04
Epoch 410/500
50/50 [==============================] - 0s - loss: 2.8399e-04
Epoch 411/500
50/50 [==============================] - 0s - loss: 8.7380e-04
Epoch 412/500
50/50 [==============================] - 0s - loss: 4.8638e-04
Epoch 413/500
50/50 [==============================] - 0s - loss: 8.3462e-04
Epoch 414/500
50/50 [==============================] - 0s - loss: 4.5237e-04
Epoch 415/500
50/50 [==============================] - 0s - loss: 3.1885e-04
Epoch 416/500
50/50 [==============================] - 0s - loss: 2.1449e-04
Epoch 417/500
50/50 [==============================] - 0s - loss: 2.3494e-04
Epoch 418/500
50/50 [==============================] - 0s - loss: 3.7915e-04
Epoch 419/500
50/50 [==============================] - 0s - loss: 3.9378e-04
Epoch 420/500
50/50 [==============================] - 0s - loss: 1.3125e-04
Epoch 421/500
50/50 [==============================] - 0s - loss: 9.9610e-05
Epoch 422/500
50/50 [==============================] - 0s - loss: 8.3851e-05
Epoch 423/500
50/50 [==============================] - 0s - loss: 8.9807e-05
Epoch 424/500
50/50 [==============================] - 0s - loss: 9.3711e-05
Epoch 425/500
50/50 [==============================] - 0s - loss: 7.9862e-05
Epoch 426/500
50/50 [==============================] - 0s - loss: 1.4845e-04
Epoch 427/500
50/50 [==============================] - 0s - loss: 1.3240e-04
Epoch 428/500
50/50 [==============================] - 0s - loss: 9.1374e-05
Epoch 429/500
50/50 [==============================] - 0s - loss: 1.1843e-04
Epoch 430/500
50/50 [==============================] - 0s - loss: 3.5493e-04
Epoch 431/500
50/50 [==============================] - 0s - loss: 3.1804e-04
Epoch 432/500
50/50 [==============================] - 0s - loss: 5.3038e-04
Epoch 433/500
50/50 [==============================] - 0s - loss: 2.2880e-04
Epoch 434/500
50/50 [==============================] - 0s - loss: 2.5017e-04
Epoch 435/500
50/50 [==============================] - 0s - loss: 1.8401e-04
Epoch 436/500
50/50 [==============================] - 0s - loss: 4.8451e-04
Epoch 437/500
50/50 [==============================] - 0s - loss: 6.2923e-04
Epoch 438/500
50/50 [==============================] - 0s - loss: 0.0024
Epoch 439/500
50/50 [==============================] - ETA: 0s - loss: 0.003 - 0s - loss: 0.0032
Epoch 440/500
50/50 [==============================] - 0s - loss: 0.0056
Epoch 441/500
50/50 [==============================] - 0s - loss: 0.0061
Epoch 442/500
50/50 [==============================] - 0s - loss: 0.0059
Epoch 443/500
50/50 [==============================] - 0s - loss: 0.0057
Epoch 444/500
50/50 [==============================] - 0s - loss: 0.0054
Epoch 445/500
50/50 [==============================] - 0s - loss: 0.0022
Epoch 446/500
50/50 [==============================] - 0s - loss: 0.0015
Epoch 447/500
50/50 [==============================] - 0s - loss: 0.0018
Epoch 448/500
50/50 [==============================] - 0s - loss: 9.3641e-04
Epoch 449/500
50/50 [==============================] - 0s - loss: 4.6422e-04
Epoch 450/500
50/50 [==============================] - 0s - loss: 1.7507e-04
Epoch 451/500
50/50 [==============================] - 0s - loss: 1.2961e-04
Epoch 452/500
50/50 [==============================] - 0s - loss: 1.2196e-04
Epoch 453/500
50/50 [==============================] - 0s - loss: 1.3834e-04
Epoch 454/500
50/50 [==============================] - 0s - loss: 1.4996e-04
Epoch 455/500
50/50 [==============================] - 0s - loss: 1.4211e-04
Epoch 456/500
50/50 [==============================] - 0s - loss: 1.2840e-04
Epoch 457/500
50/50 [==============================] - 0s - loss: 1.1148e-04
Epoch 458/500
50/50 [==============================] - 0s - loss: 1.0200e-04
Epoch 459/500
50/50 [==============================] - 0s - loss: 9.4559e-05
Epoch 460/500
50/50 [==============================] - 0s - loss: 9.0671e-05
Epoch 461/500
50/50 [==============================] - 0s - loss: 8.7393e-05
Epoch 462/500
50/50 [==============================] - 0s - loss: 8.2632e-05
Epoch 463/500
50/50 [==============================] - 0s - loss: 8.2027e-05
Epoch 464/500
50/50 [==============================] - 0s - loss: 8.3542e-05
Epoch 465/500
50/50 [==============================] - 0s - loss: 9.3496e-05
Epoch 466/500
50/50 [==============================] - 0s - loss: 9.1898e-05
Epoch 467/500
50/50 [==============================] - 0s - loss: 8.7911e-05
Epoch 468/500
50/50 [==============================] - 0s - loss: 8.1280e-05
Epoch 469/500
50/50 [==============================] - 0s - loss: 8.0064e-05
Epoch 470/500
50/50 [==============================] - 0s - loss: 7.4668e-05
Epoch 471/500
50/50 [==============================] - 0s - loss: 9.8129e-05
Epoch 472/500
50/50 [==============================] - 0s - loss: 9.8426e-05
Epoch 473/500
50/50 [==============================] - 0s - loss: 1.0846e-04
Epoch 474/500
50/50 [==============================] - 0s - loss: 1.2331e-04
Epoch 475/500
50/50 [==============================] - 0s - loss: 1.0845e-04
Epoch 476/500
50/50 [==============================] - 0s - loss: 1.2702e-04
Epoch 477/500
50/50 [==============================] - 0s - loss: 1.2744e-04
Epoch 478/500
50/50 [==============================] - 0s - loss: 3.6578e-04
Epoch 479/500
50/50 [==============================] - 0s - loss: 4.6970e-04
Epoch 480/500
50/50 [==============================] - 0s - loss: 4.2829e-04
Epoch 481/500
50/50 [==============================] - 0s - loss: 4.3254e-04
Epoch 482/500
50/50 [==============================] - 0s - loss: 3.0393e-04
Epoch 483/500
50/50 [==============================] - 0s - loss: 2.0324e-04
Epoch 484/500
50/50 [==============================] - 0s - loss: 2.0914e-04
Epoch 485/500
50/50 [==============================] - 0s - loss: 2.0757e-04
Epoch 486/500
50/50 [==============================] - 0s - loss: 3.1470e-04
Epoch 487/500
50/50 [==============================] - 0s - loss: 4.4788e-04
Epoch 488/500
50/50 [==============================] - 0s - loss: 4.7563e-04
Epoch 489/500
50/50 [==============================] - 0s - loss: 3.3888e-04
Epoch 490/500
50/50 [==============================] - 0s - loss: 1.5677e-04
Epoch 491/500
50/50 [==============================] - 0s - loss: 1.3321e-04
Epoch 492/500
50/50 [==============================] - 0s - loss: 1.4758e-04
Epoch 493/500
50/50 [==============================] - 0s - loss: 9.5357e-05
Epoch 494/500
50/50 [==============================] - 0s - loss: 8.4090e-05
Epoch 495/500
50/50 [==============================] - 0s - loss: 9.1502e-05
Epoch 496/500
50/50 [==============================] - 0s - loss: 7.8059e-05
Epoch 497/500
50/50 [==============================] - 0s - loss: 7.9166e-05
Epoch 498/500
50/50 [==============================] - 0s - loss: 1.3885e-04
Epoch 499/500
50/50 [==============================] - 0s - loss: 1.2836e-04
Epoch 500/500
50/50 [==============================] - 0s - loss: 1.1666e-04

Out[297]:
<keras.callbacks.History at 0x15752c1d0>
In [298]:
nn_moist_preds = (nn_moist_mod.predict(norm_test_input) * l_sd + l_mean) * ureg.K

In [302]:
fig = plt.figure(figsize=(8, 10))
sk = SkewT(fig=fig, rotation=30)
sk.ax.set_xlim(-60, 120)
sk.ax.set_ylim(1000, 100)
for p in range(0, nn_moist_preds.shape[0], 3):
if p == 0:
label = "True"
else:
label = None
sk.plot(pressures, (test_data[p]* ureg.K).to("degC"), color="red", label=label, marker='v', ms=5)
for p in range(0, nn_moist_preds.shape[0], 3):
if p == 0:
label = "Conv Net"
else:
label = None
sk.plot(pressures, nn_moist_preds[p].to("degC"), color="purple", label=label, marker='o', ms=5)
plt.legend()
plt.xlabel("Temperature (C)")
plt.ylabel("Pressure (hPa)")

In [108]:
def dt(t, p):
rs = saturation_mixing_ratio(p, t)
frac = ((Rd * t + Lv * rs) /
(Cp_d + (Lv * Lv * rs * epsilon / (Rd * t * t)))).to('kelvin')
return frac / p

In [124]:
temps_dt = np.arange(230, 350, 2)
pres_dt = np.arange(100, 1020, 20)
temp_grid, pres_grid = np.meshgrid(temps_dt, pres_dt)
dt_grid = np.zeros(temp_grid.shape)
print(dt_grid.shape)
for (i, j), t in np.ndenumerate(temp_grid):
dt_grid[i, j] = dt(units.Quantity(temp_grid[i, j], "kelvin"),
units.Quantity(pres_grid[i, j], "hPa")).m

(46, 60)

In [257]:
nn_lapse_input = Input(shape=(2,))
nn_lapse = Dense(20, activation="tanh")(nn_lapse_input)
nn_lapse = Dense(20, activation="tanh")(nn_lapse)
nn_lapse = Dense(1)(nn_lapse)
nn_lapse_mod = Model(nn_lapse_input, nn_lapse)
opt = SGD(lr=0.001, momentum=0.99, decay=1e-6, nesterov=True)
nn_lapse_mod.compile(opt, "mse")

In [214]:
lapse_train_data = pd.DataFrame({"temp": temp_grid.ravel(), "pres": pres_grid.ravel(), "lapse": dt_grid.ravel()})
norms = pd.DataFrame(index=lapse_train_data.columns, columns=["mean", "sd"], dtype=float)
for col in lapse_train_data.columns:
norms.loc[col, "mean"] = lapse_train_data[col].mean()
norms.loc[col, "sd"] = lapse_train_data[col].std()
lapse_train_data[col + "_norm"] = (lapse_train_data[col] - norms.loc[col, "mean"]) / norms.loc[col, "sd"]

In [267]:
nn_lapse_mod.fit(lapse_train_data[["temp_norm", "pres_norm"]].values, lapse_train_data["lapse"].values, epochs=100, batch_size=8)

Epoch 1/100
2760/2760 [==============================] - 0s - loss: 2.5946e-04
Epoch 2/100
2760/2760 [==============================] - 0s - loss: 2.5334e-04
Epoch 3/100
2760/2760 [==============================] - 0s - loss: 2.4986e-04
Epoch 4/100
2760/2760 [==============================] - 0s - loss: 2.4147e-04
Epoch 5/100
2760/2760 [==============================] - 0s - loss: 2.3440e-04
Epoch 6/100
2760/2760 [==============================] - 0s - loss: 2.2913e-04
Epoch 7/100
2760/2760 [==============================] - 0s - loss: 2.3300e-04
Epoch 8/100
2760/2760 [==============================] - 0s - loss: 2.3282e-04
Epoch 9/100
2760/2760 [==============================] - 0s - loss: 2.2562e-04
Epoch 10/100
2760/2760 [==============================] - 0s - loss: 2.1956e-04
Epoch 11/100
2760/2760 [==============================] - 0s - loss: 2.1264e-04
Epoch 12/100
2760/2760 [==============================] - 0s - loss: 2.2009e-04
Epoch 13/100
2760/2760 [==============================] - 0s - loss: 2.1862e-04
Epoch 14/100
2760/2760 [==============================] - 0s - loss: 2.0811e-04
Epoch 15/100
2760/2760 [==============================] - 0s - loss: 2.0263e-04
Epoch 16/100
2760/2760 [==============================] - 0s - loss: 2.0873e-04
Epoch 17/100
2760/2760 [==============================] - 0s - loss: 2.0528e-04
Epoch 18/100
2760/2760 [==============================] - 0s - loss: 1.9970e-04
Epoch 19/100
2760/2760 [==============================] - 0s - loss: 1.9522e-04
Epoch 20/100
2760/2760 [==============================] - 0s - loss: 1.9923e-04
Epoch 21/100
2760/2760 [==============================] - 0s - loss: 1.9656e-04
Epoch 22/100
2760/2760 [==============================] - 0s - loss: 2.0064e-04
Epoch 23/100
2760/2760 [==============================] - 0s - loss: 1.9055e-04     - ETA: 0s - loss: 1
Epoch 24/100
2760/2760 [==============================] - 0s - loss: 1.8448e-04
Epoch 25/100
2760/2760 [==============================] - 0s - loss: 1.8248e-04
Epoch 26/100
2760/2760 [==============================] - 0s - loss: 1.8472e-04
Epoch 27/100
2760/2760 [==============================] - 0s - loss: 1.8384e-04
Epoch 28/100
2760/2760 [==============================] - 0s - loss: 1.8833e-04
Epoch 29/100
2760/2760 [==============================] - 0s - loss: 1.7964e-04
Epoch 30/100
2760/2760 [==============================] - 0s - loss: 1.7543e-04     - ETA: 0s - loss: 2.
Epoch 31/100
2760/2760 [==============================] - 0s - loss: 1.8010e-04
Epoch 32/100
2760/2760 [==============================] - 0s - loss: 1.7674e-04
Epoch 33/100
2760/2760 [==============================] - 0s - loss: 1.7656e-04
Epoch 34/100
2760/2760 [==============================] - 0s - loss: 1.7868e-04
Epoch 35/100
2760/2760 [==============================] - 0s - loss: 1.7324e-04
Epoch 36/100
2760/2760 [==============================] - 0s - loss: 1.6833e-04
Epoch 37/100
2760/2760 [==============================] - 0s - loss: 1.6294e-04
Epoch 38/100
2760/2760 [==============================] - 0s - loss: 1.6769e-04
Epoch 39/100
2760/2760 [==============================] - 0s - loss: 1.6437e-04
Epoch 40/100
2760/2760 [==============================] - 0s - loss: 1.6589e-04
Epoch 41/100
2760/2760 [==============================] - 0s - loss: 1.5900e-04
Epoch 42/100
2760/2760 [==============================] - 0s - loss: 1.5613e-04
Epoch 43/100
2760/2760 [==============================] - 0s - loss: 1.5460e-04
Epoch 44/100
2760/2760 [==============================] - 0s - loss: 1.5792e-04
Epoch 45/100
2760/2760 [==============================] - 0s - loss: 1.5385e-04
Epoch 46/100
2760/2760 [==============================] - 0s - loss: 1.5374e-04
Epoch 47/100
2760/2760 [==============================] - 0s - loss: 1.4795e-04
Epoch 48/100
2760/2760 [==============================] - 0s - loss: 1.4735e-04
Epoch 49/100
2760/2760 [==============================] - 0s - loss: 1.5258e-04
Epoch 50/100
2760/2760 [==============================] - 0s - loss: 1.5217e-04
Epoch 51/100
2760/2760 [==============================] - 0s - loss: 1.4109e-04
Epoch 52/100
2760/2760 [==============================] - 0s - loss: 1.4449e-04
Epoch 53/100
2760/2760 [==============================] - 0s - loss: 1.4906e-04
Epoch 54/100
2760/2760 [==============================] - 0s - loss: 1.4242e-04
Epoch 55/100
2760/2760 [==============================] - 0s - loss: 1.4010e-04
Epoch 56/100
2760/2760 [==============================] - 0s - loss: 1.4031e-04
Epoch 57/100
2760/2760 [==============================] - 0s - loss: 1.4158e-04
Epoch 58/100
2760/2760 [==============================] - 0s - loss: 1.3524e-04
Epoch 59/100
2760/2760 [==============================] - 0s - loss: 1.3444e-04
Epoch 60/100
2760/2760 [==============================] - 0s - loss: 1.3649e-04
Epoch 61/100
2760/2760 [==============================] - 0s - loss: 1.3252e-04
Epoch 62/100
2760/2760 [==============================] - 0s - loss: 1.3303e-04
Epoch 63/100
2760/2760 [==============================] - 0s - loss: 1.3708e-04
Epoch 64/100
2760/2760 [==============================] - 0s - loss: 1.2831e-04
Epoch 65/100
2760/2760 [==============================] - 0s - loss: 1.2490e-04
Epoch 66/100
2760/2760 [==============================] - 0s - loss: 1.2514e-04
Epoch 67/100
2760/2760 [==============================] - 0s - loss: 1.2663e-04
Epoch 68/100
2760/2760 [==============================] - 0s - loss: 1.2144e-04
Epoch 69/100
2760/2760 [==============================] - 0s - loss: 1.2257e-04
Epoch 70/100
2760/2760 [==============================] - 0s - loss: 1.1791e-04
Epoch 71/100
2760/2760 [==============================] - 0s - loss: 1.1975e-04
Epoch 72/100
2760/2760 [==============================] - 0s - loss: 1.2321e-04
Epoch 73/100
2760/2760 [==============================] - 0s - loss: 1.2001e-04
Epoch 74/100
2760/2760 [==============================] - 0s - loss: 1.1850e-04
Epoch 75/100
2760/2760 [==============================] - 0s - loss: 1.1311e-04
Epoch 76/100
2760/2760 [==============================] - 0s - loss: 1.1760e-04
Epoch 77/100
2760/2760 [==============================] - 0s - loss: 1.1305e-04
Epoch 78/100
2760/2760 [==============================] - 0s - loss: 1.1372e-04
Epoch 79/100
2760/2760 [==============================] - 0s - loss: 1.0996e-04
Epoch 80/100
2760/2760 [==============================] - 0s - loss: 1.1101e-04
Epoch 81/100
2760/2760 [==============================] - 0s - loss: 1.1101e-04
Epoch 82/100
2760/2760 [==============================] - 0s - loss: 1.0932e-04
Epoch 83/100
2760/2760 [==============================] - 0s - loss: 1.0507e-04
Epoch 84/100
2760/2760 [==============================] - 0s - loss: 1.0510e-04
Epoch 85/100
2760/2760 [==============================] - 0s - loss: 1.0312e-04
Epoch 86/100
2760/2760 [==============================] - 0s - loss: 1.0723e-04
Epoch 87/100
2760/2760 [==============================] - 0s - loss: 1.0253e-04
Epoch 88/100
2760/2760 [==============================] - 0s - loss: 9.9962e-05
Epoch 89/100
2760/2760 [==============================] - 0s - loss: 1.0260e-04
Epoch 90/100
2760/2760 [==============================] - 0s - loss: 9.9754e-05
Epoch 91/100
2760/2760 [==============================] - 0s - loss: 9.7193e-05
Epoch 92/100
2760/2760 [==============================] - 0s - loss: 1.0143e-04
Epoch 93/100
2760/2760 [==============================] - 0s - loss: 9.8767e-05
Epoch 94/100
2760/2760 [==============================] - 0s - loss: 9.7355e-05
Epoch 95/100
2760/2760 [==============================] - 0s - loss: 9.3634e-05
Epoch 96/100
2760/2760 [==============================] - 0s - loss: 9.3300e-05
Epoch 97/100
2760/2760 [==============================] - 0s - loss: 9.5346e-05
Epoch 98/100
2760/2760 [==============================] - 0s - loss: 8.9899e-05
Epoch 99/100
2760/2760 [==============================] - 0s - loss: 9.0696e-05
Epoch 100/100
2760/2760 [==============================] - 0s - loss: 9.0016e-05

Out[267]:
<keras.callbacks.History at 0x1533b9c18>
In [268]:
lapse_preds = nn_lapse_mod.predict(lapse_train_data[["temp_norm", "pres_norm"]].values)

In [269]:
plt.hist(lapse_train_data["lapse"].values, bins=np.arange(0, 0.6, 0.05))
plt.hist(lapse_preds, bins=np.arange(0, 0.6, 0.05), histtype="step", lw=3)

Out[269]:
(array([  8.89000000e+02,   1.10200000e+03,   3.97000000e+02,
1.82000000e+02,   7.80000000e+01,   4.90000000e+01,
3.20000000e+01,   2.00000000e+01,   1.00000000e+01,
1.00000000e+00,   0.00000000e+00]),
array([ 0.  ,  0.05,  0.1 ,  0.15,  0.2 ,  0.25,  0.3 ,  0.35,  0.4 ,
0.45,  0.5 ,  0.55]),
<a list of 1 Patch objects>)
In [181]:
pressures

Out[181]:
$\begin{pmatrix}1000 & 980 & 960 & 940 & 920 & 900 & 880 & 860 & 840 & 820 & 800 & 780 & 760 & 740 & 720 & 700 & 680 & 660 & 640 & 620 & 600 & 580 & 560 & 540 & 520 & 500 & 480 & 460 & 440 & 420 & 400 & 380 & 360 & 340 & 320 & 300 & 280 & 260 & 240 & 220 & 200 & 180 & 160 & 140 & 120 & 100\end{pmatrix} hectopascal$
In [270]:
nn_temps = np.zeros(test_data.shape)
print(nn_temps.shape)
for t, temp in enumerate(test_temps):
nn_temps[t, 0] = temp.m
norm_temp = (temp.m - norms.loc["temp", "mean"]) / norms.loc["temp", "sd"]
curr_temp = temp.m
pres = pressures.m[0]
p = 1
while pres > pressures.m.min():
norm_pres = (pres - norms.loc["pres", "mean"]) / norms.loc["pres", "sd"]
lapse = nn_lapse_mod.predict(np.array([[norm_temp, norm_pres]]))
curr_temp -= lapse * 4
if pres in pressures.m:
nn_temps[t, p] = curr_temp
p += 1
pres -= 4
norm_temp = (curr_temp - norms.loc["temp", "mean"]) / norms.loc["temp", "sd"]

(50, 46)

In [271]:
fig = plt.figure(figsize=(8, 10))
sk = SkewT(fig=fig, rotation=30)
sk.ax.set_xlim(-60, 120)
sk.ax.set_ylim(1000, 100)
for p in range(0, nn_moist_preds.shape[0], 3):
if p == 0:
label = "True"
else:
label = None
sk.plot(pressures, (test_data[p]* ureg.K).to("degC"), color="red", label=label)
for p in range(0, nn_moist_preds.shape[0], 3):
if p == 0:
label = "Neural Net"
else:
label = None
sk.plot(pressures, (nn_temps[p] * ureg.K).to("degC"), color="purple", label=label)
plt.legend()

Out[271]:
<matplotlib.legend.Legend at 0x1537aa630>
In [272]:
plt.scatter(lapse_train_data["lapse"], lapse_preds)
plt.plot(np.arange(0, 0.6, 0.1), np.arange(0, 0.6, 0.1), 'k--')

Out[272]:
[<matplotlib.lines.Line2D at 0x153579400>]
In [273]:
plt.pcolormesh(temps_dt, pres_dt, lapse_preds.reshape(temp_grid.shape), vmin=0, vmax=0.5)
plt.colorbar()

Out[273]:
<matplotlib.colorbar.Colorbar at 0x153b1d048>
In [274]:
plt.pcolormesh(temps_dt, pres_dt, dt_grid, vmin=0, vmax=0.5)
plt.colorbar()

Out[274]:
<matplotlib.colorbar.Colorbar at 0x153c39828>
In [275]:
plt.pcolormesh(temps_dt, pres_dt, lapse_preds.reshape(temp_grid.shape) - dt_grid, cmap="RdBu_r", vmin=-0.1, vmax=0.1)
plt.colorbar()

Out[275]:
<matplotlib.colorbar.Colorbar at 0x153d5a470>