Looking at results from model run trying to imitate a wind event from 15Jan17.
import numpy as np
import netCDF4 as nc
import matplotlib.pyplot as plt
from salishsea_tools import (nc_tools, viz_tools, gsw_calls)
import numpy.ma as ma
from matplotlib import animation, rc
%matplotlib inline
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:90% !important; }</style>"))
rc('animation', html='html5')
mesh_mask = nc.Dataset('/home/vdo/MEOPAR/NEMO-forcing/grid/mesh_mask201702.nc')
new_domain = mesh_mask.variables['tmask'][0,:,334:898,114:398]
def calc_rho(Sal, TempC, P):
sqrSal = np.sqrt(Sal)
R1 = ((((6.536332e-9 * TempC - 1.120083e-6) * TempC + 1.001685e-4)
* TempC - 9.095290e-3) * TempC + 6.793952e-2) * TempC - 28.263737
R2 = (((5.3875e-9 * TempC - 8.2467e-7) * TempC + 7.6438e-5)
* TempC - 4.0899e-3) * TempC + 8.24493e-1
R3 = (-1.6546e-6 * TempC + 1.0227e-4) * TempC - 5.72466e-3
SIG = (4.8314e-4 * Sal + R3 * sqrSal + R2) * Sal + R1
V350P = 1.0 / 1028.1063
SVA = -SIG * V350P / (1028.1063 + SIG)
rho = 28.106331 - SVA / (V350P * (V350P + SVA)) + 1000
return rho
def animate_one_density(file1,file2, rho):
depth = file1.variables['deptht'][:]
saline1 = file1.variables['vosaline'][:]
temp1 = file1.variables['votemper'][:]
saline2 = file1.variables['vosaline'][:]
temp2 = file1.variables['votemper'][:]
density1 = calc_rho(saline1, temp1, depth[np.newaxis,:,np.newaxis,np.newaxis])
index1 = (np.abs(density1 - rho)).argmin(axis=1)
density2 = calc_rho(saline2, temp2, depth[np.newaxis,:,np.newaxis,np.newaxis])
index2 = (np.abs(density2 - rho)).argmin(axis=1)
list_of_depths1 = np.zeros((160,564,284))
for t in range(160):
for y in range(564):
for x in range(284):
list_of_depths1[t,y,x] = depth[index1[t,y,x]]
list_of_depths2 = np.zeros((160,564,284))
for t in range(160):
for y in range(564):
for x in range(284):
list_of_depths2[t,y,x] = depth[index2[t,y,x]]
mask_land = 1 - new_domain[0,:,:]
fig,ax = plt.subplots(1,2,figsize=(8,8))
def animate30(i):
ax[0].clear()
masked_depths1 = ma.masked_array(list_of_depths1[i,:,:], mask = mask_land)
ax[0].contourf(masked_depths1,
levels = np.linspace(0, 30, 8))
ax[0].set_title('hour = %03d'%(i))
ax[1].clear()
masked_depths2 = ma.masked_array(list_of_depths2[i,:,:], mask = mask_land)
ax[1].contourf(masked_depths2,
levels = np.linspace(0, 30, 8))
ax[1].set_title('hour = %03d'%(i))
return ax
interval = 0.25#in seconds
ani40 = animation.FuncAnimation(fig,animate30,frames=160,interval=interval*1e+3,
repeat=False)
return ani40
fig, ax = plt.subplots(figsize= (8,8))
den = ax.contourf(np.ones((20,20)), levels = np.linspace(0,30,8))
fig.colorbar(den, ax=ax)
<matplotlib.colorbar.Colorbar at 0x7fe93238da20>
no_utau = nc.Dataset('/ocean/vdo/MEOPAR/completed-runs/SalishSeaLake/no_utau/SalishSea_1h_20170101_20170107_grid_T.nc')
with_utau = nc.Dataset('/ocean/vdo/MEOPAR/completed-runs/SalishSeaLake/with_utau/SalishSea_1h_20170101_20170107_grid_T.nc')
animate_one_density(no_utau, with_utau, 1022.8)
animate_one_density(no_utau, with_utau, 1022.5)
lakebathy = bathy.variables['Bathymetry'][335:, 115:]
plt.pcolormesh(lakebathy)
for point in thalweg_points:
plt.plot(point[1], point[0], 'r.')
thalweg_points = np.loadtxt('cropped-thalweg.txt')
thalweg_points[0]
array([ 335., 247.])
f = open(''.txt').readlines()
for x in f:
print( str (int(x[:3]) - 334), str( int(x[4:7]) - 114))
72 -112 72 -111 72 -110 72 -109 71 -109 71 -108 71 -107 70 -107 69 -107 69 -106 69 -105 69 -104 68 -104 68 -103 67 -103 67 -102 66 -102 66 -101 65 -101 65 -100 64 -100 64 -99 64 -98 63 -98 63 -97 62 -97 62 -96 61 -96 61 -95 60 -95 60 -94 59 -94 59 -93 59 -92 58 -92 58 -91 57 -91 57 -90 56 -90 56 -89 55 -89 55 -88 54 -88 54 -87 53 -87 53 -86 52 -86 52 -85 52 -84 51 -84 51 -83 50 -83 50 -82 49 -82 49 -81 48 -81 48 -80 47 -80 47 -79 46 -79 46 -78 45 -78 45 -77 44 -77 44 -76 44 -75 44 -74 43 -74 42 -74 41 -74 41 -73 40 -73 39 -73 39 -72 38 -72 37 -72 37 -73 36 -73 35 -73 34 -73 34 -72 33 -72 33 -71 32 -71 31 -71 31 -70 30 -70 30 -69 29 -69 29 -68 28 -68 27 -68 27 -67 26 -67 26 -66 26 -65 25 -65 25 -64 24 -64 24 -63 24 -62 23 -62 23 -61 22 -61 22 -60 21 -60 21 -59 21 -58 20 -58 19 -58 19 -57 18 -57 18 -56 17 -56 17 -55 16 -55 15 -55 14 -55 13 -55 12 -55 11 -55 10 -55 9 -55 8 -55 8 -54 7 -54 6 -54 5 -54 4 -54 4 -53 3 -53 3 -52 2 -52 2 -51 1 -51 0 -51 0 -50 -1 -50 -1 -49 -2 -49 -2 -48 -2 -47 -2 -46 -3 -46 -3 -45 -3 -44 -4 -44 -4 -43 -4 -42 -4 -41 -5 -41 -5 -40 -6 -40 -6 -39 -7 -39 -7 -38 -8 -38 -8 -37 -9 -37 -9 -36 -9 -35 -9 -34 -10 -34 -10 -33 -10 -32 -11 -32 -11 -31 -12 -31 -12 -30 -12 -29 -12 -28 -13 -28 -13 -27 -14 -27 -15 -27 -15 -26 -16 -26 -16 -25 -17 -25 -17 -24 -18 -24 -18 -23 -19 -23 -19 -22 -19 -21 -19 -20 -20 -20 -20 -19 -20 -18 -20 -17 -20 -16 -19 -16 -19 -15 -19 -14 -19 -13 -19 -12 -19 -11 -18 -11 -18 -10 -18 -9 -18 -8 -18 -7 -18 -6 -18 -5 -18 -4 -19 -4 -19 -3 -19 -2 -20 -2 -21 -2 -21 -1 -22 -1 -23 -1 -24 -1 -25 -1 -25 0 -25 1 -26 1 -26 2 -27 2 -27 3 -28 3 -29 3 -30 3 -30 4 -31 4 -31 5 -32 5 -32 6 -32 7 -33 7 -34 7 -34 8 -35 8 -35 9 -35 10 -35 11 -36 11 -36 12 -36 13 -36 14 -37 14 -37 15 -38 15 -38 16 -39 16 -40 16 -41 16 -41 17 -42 17 -42 18 -42 19 -43 19 -43 20 -44 20 -44 21 -45 21 -45 22 -45 23 -46 23 -46 24 -46 25 -47 25 -47 26 -48 26 -48 27 -48 28 -49 28 -49 29 -49 30 -49 31 -50 31 -50 32 -50 33 -50 34 -51 34 -51 35 -51 36 -51 37 -52 37 -52 38 -52 39 -52 40 -53 40 -54 40 -54 39 -55 39 -55 38 -56 38 -57 38 -58 38 -58 39 -59 39 -60 39 -61 39 -61 40 -61 41 -62 41 -62 42 -62 43 -62 44 -63 44 -63 45 -64 45 -65 45 -66 45 -67 45 -67 46 -68 46 -69 46 -69 47 -70 47 -71 47 -72 47 -73 47 -73 48 -74 48 -74 49 -74 50 -75 50 -75 51 -75 52 -75 53 -75 54 -75 55 -75 56 -75 57 -75 58 -75 59 -75 60 -75 61 -75 62 -76 62 -76 63 -76 64 -76 65 -76 66 -76 67 -76 68 -75 68 -75 69 -75 70 -75 71 -75 72 -75 73 -76 73 -76 74 -76 75 -76 76 -76 77 -76 78 -76 79 -77 79 -77 80 -78 80 -79 80 -80 80 -81 80 -82 80 -82 81 -82 82 -82 83 -82 84 -82 85 -83 85 -83 86 -83 87 -84 87 -84 88 -84 89 -84 90 -84 91 -84 92 -85 92 -86 92 -86 93 -86 94 -86 95 -86 96 -86 97 -86 98 -86 99 -86 100 -86 101 -86 102 -86 103 -85 103 -85 104 -85 105 -85 106 -85 107 -86 107 -86 108 -86 109 -86 110 -86 111 -85 111 -85 112 -85 113 -84 113 -84 114 -83 114 -83 115 -82 115 -82 116 -82 117 -81 117 -81 118 -81 119 -80 119 -80 120 -80 121 -79 121 -79 122 -78 122 -78 123 -78 124 -77 124 -77 125 -77 126 -77 127 -77 128 -76 128 -76 129 -75 129 -74 129 -74 130 -73 130 -72 130 -72 131 -71 131 -70 131 -70 132 -69 132 -68 132 -67 132 -66 132 -65 132 -64 132 -64 133 -63 133 -62 133 -62 132 -61 132 -61 131 -60 131 -59 131 -58 131 -57 131 -56 131 -56 130 -55 130 -54 130 -53 130 -52 130 -51 130 -50 130 -49 130 -49 129 -48 129 -47 129 -46 129 -46 130 -45 130 -44 130 -43 130 -42 130 -42 129 -41 129 -40 129 -40 128 -39 128 -39 127 -38 127 -38 126 -37 126 -36 126 -36 125 -35 125 -34 125 -33 125 -32 125 -31 125 -30 125 -30 124 -30 123 -29 123 -28 123 -28 124 -27 124 -26 124 -25 124 -24 124 -23 124 -22 124 -21 124 -20 124 -19 124 -18 124 -17 124 -16 124 -15 124 -15 125 -14 125 -14 126 -13 126 -13 127 -12 127 -12 128 -11 128 -11 129 -10 129 -9 129 -9 130 -8 130 -7 130 -7 131 -6 131 -6 132 -5 132 -4 132 -3 132 -2 132 -1 132 -1 133 0 133 1 133 2 133 2 132 3 132 4 132 5 132 6 132 7 132 8 132 8 133 9 133 10 133 10 134 11 134 11 135 11 136 11 137 12 137 12 138 13 138 13 139 13 140 13 141 13 142 13 143 12 143 12 144 12 145 11 145 11 146 11 147 11 148 11 149 11 150 11 151 11 152 11 153 10 153 10 154 10 155 10 156 10 157 10 158 10 159 10 160 10 161 10 162 10 163 11 163 11 164 11 165 11 166 11 167 11 168 11 169 11 170 11 171 10 171 10 172 9 172 9 173 9 174 9 175 10 175 10 176 10 177 11 177 11 178 11 179 11 180 11 181 11 182 11 183 11 184 11 185 10 185 10 186 10 187 11 187 12 187 12 188 13 188 14 188 15 188 16 188 17 188 17 189 17 190 17 191 18 191 18 192 19 192 20 192 21 192 21 193 21 194 22 194 23 194 24 194 24 193 25 193 26 193 26 192 26 191 27 191 27 190 27 189 27 188 28 188 28 187 29 187 29 186 29 185 29 184 28 184 28 183 27 183 27 182 27 181 28 181 28 180 28 179 28 178 28 177 28 176 28 175 28 174 28 173 29 173 30 173 30 172 30 171 31 171 31 170 31 169 32 169 32 168 32 167 33 167 33 166 34 166 35 166 35 165 36 165 36 164 37 164 37 163 38 163 39 163 39 162 40 162 41 162 41 161 42 161 43 161 44 161 45 161 45 160 46 160 47 160 48 160 48 159 49 159 50 159 50 158 51 158 52 158 52 157 53 157 54 157 54 156 55 156 56 156 56 155 57 155 58 155 58 154 59 154 60 154 61 154 62 154 63 154 64 154 64 153 65 153 66 153 67 153 68 153 68 152 69 152 70 152 71 152 71 151 72 151 73 151 74 151 75 151 76 151 77 151 78 151 79 151 80 151 80 150 81 150 82 150 82 149 83 149 84 149 85 149 86 149 87 149 88 149 89 149 89 148 90 148 90 147 91 147 92 147 93 147 94 147 95 147 96 147 97 147 97 148 97 149 98 149 98 150 99 150 100 150 101 150 102 150 103 150 104 150 105 150 106 150 107 150 107 149 108 149 108 148 109 148 110 148 110 147 111 147 112 147 113 147 114 147 114 148 115 148 116 148 117 148 118 148 119 148 120 148 121 148 122 148 123 148 124 148 124 149 125 149 126 149 126 148 126 147 127 147 128 147 128 146 129 146 130 146 130 145 131 145 132 145 132 144 133 144 134 144 135 144 135 143 136 143 137 143 138 143 138 142 139 142 139 141 140 141 141 141 142 141 143 141 143 140 144 140 144 139 145 139 145 138 146 138 146 137 147 137 147 136 148 136 148 135 149 135 149 134 150 134 150 133 151 133 151 132 152 132 152 131 152 130 153 130 153 129 154 129 154 128 155 128 156 128 157 128 157 127 158 127 158 126 159 126 160 126 160 125 161 125 161 124 162 124 163 124 163 123 163 122 164 122 165 122 165 121 165 120 166 120 167 120 167 119 167 118 168 118 169 118 169 117 170 117 171 117 172 117 173 117 174 117 174 116 174 115 175 115 175 114 176 114 176 113 176 112 177 112 177 111 178 111 178 110 178 109 179 109 179 108 179 107 180 107 180 106 180 105 181 105 181 104 182 104 182 103 183 103 183 102 184 102 184 101 185 101 186 101 187 101 187 100 188 100 189 100 189 99 189 98 190 98 190 97 191 97 191 96 192 96 192 95 192 94 193 94 194 94 194 93 195 93 195 92 196 92 196 91 197 91 197 90 198 90 199 90 200 90 201 90 201 89 202 89 202 88 203 88 204 88 205 88 206 88 206 87 207 87 207 86 208 86 208 85 209 85 209 84 210 84 210 83 210 82 210 81 211 81 211 80 211 79 212 79 212 78 212 77 213 77 213 76 213 75 214 75 214 74 215 74 215 73 216 73 217 73 218 73 219 73 219 72 220 72 220 71 220 70 221 70 221 69 222 69 222 68 223 68 224 68 224 67 225 67 225 66 225 65 226 65 226 64 227 64 228 64 228 63 229 63 230 63 230 62 230 61 231 61 231 60 232 60 232 59 232 58 233 58 233 57 233 56 234 56 235 56 236 56 237 56 238 56 238 55 238 54 239 54 240 54 241 54 241 53 242 53 242 52 242 51 243 51 243 50 244 50 244 49 245 49 245 48 246 48 247 48 247 47 248 47 249 47 250 47 250 48 251 48 251 49 252 49 253 49 254 49 254 48 255 48 256 48 256 49 257 49 257 50 257 51 257 52 258 52 259 52 259 53 260 53 260 54 260 55 259 55 259 56 259 57 259 58 259 59 259 60 259 61 260 61 260 62 261 62 261 63 262 63 262 64 263 64 264 64 264 65 265 65 265 66 265 67 266 67 267 67 267 68 268 68 268 69 269 69 269 70 270 70 270 71 270 72 271 72 272 72 273 72 274 72 274 71 275 71 276 71 276 70 277 70 278 70 279 70 279 69 280 69 281 69 282 69 282 68 283 68 284 68 284 67 285 67 285 66 286 66 286 65 287 65 288 65 288 64 289 64 289 63 290 63 290 62 291 62 292 62 292 61 293 61 293 60 293 59 294 59 295 59 296 59 297 59 297 58 298 58 299 58 300 58 300 57 301 57 302 57 303 57 304 57 305 57 306 57 307 57 307 56 308 56 309 56 309 55 309 54 310 54 311 54 312 54 312 53 313 53 313 52 314 52 314 51 315 51 316 51 317 51 317 50 318 50 318 49 319 49 319 48 320 48 320 47 321 47 322 47 323 47 324 47 324 48 325 48 326 48 327 48 328 48 328 47 329 47 329 46 330 46 330 45 331 45 332 45 333 45 333 44 334 44 334 43 335 43 336 43 336 42 337 42 338 42 339 42 340 42 340 41 341 41 342 41 343 41 344 41 345 41 346 41 346 40 346 39 347 39 347 38 348 38 349 38 349 37 350 37 350 36 351 36 351 35 352 35 352 34 353 34 354 34 354 33 354 32 355 32 356 32 357 32 357 31 358 31 358 30 359 30 360 30 361 30 361 29 362 29 362 28 363 28 364 28 364 27 365 27 366 27 367 27 368 27 369 27 369 26 370 26 371 26 372 26 373 26 374 26 375 26 376 26 377 26 378 26 379 26 380 26 380 25 381 25 381 24 382 24 382 23 383 23 383 22 384 22 384 21 385 21 385 20 386 20 386 19 386 18 387 18 388 18 388 17 389 17 389 16 390 16 391 16 391 15 391 14 392 14 393 14 393 13 394 13 395 13 395 12 396 12 396 11 397 11 397 10 398 10 399 10 400 10 401 10 402 10 403 10 404 10 405 10 405 11 406 11 407 11 407 12 408 12 409 12 410 12 410 11 411 11 412 11 412 12 413 12 414 12 414 11 415 11 416 11 416 12 417 12 418 12 419 12 420 12 421 12 422 12 423 12 424 12 424 11 425 11 426 11 427 11 428 11 428 10 429 10 430 10 430 9 431 9 432 9 433 9 434 9 434 8 435 8 435 7 436 7 436 6 436 5 437 5 438 5 439 5 439 6 440 6 441 6 441 7 442 7 443 7 443 8 444 8 444 9 445 9 446 9 447 9 448 9 449 9 449 10 450 10 451 10 452 10 452 11 453 11 453 12 454 12 455 12 456 12 456 13 457 13 458 13 459 13 460 13 460 14 461 14 462 14 463 14 463 15 464 15 464 16 465 16 466 16 467 16 468 16 469 16 469 17 470 17 471 17 472 17 473 17 474 17 475 17 476 17 477 17 478 17 479 17 480 17 480 18 481 18 481 19 481 20 482 20 483 20 484 20 485 20 486 20 486 19 487 19 487 18 487 17 488 17 488 16 488 15 488 14 489 14 489 13 489 12 490 12 490 11 491 11 492 11 492 10 493 10 493 9 494 9 494 8 494 7 495 7 496 7 496 6 497 6 498 6 498 5 499 5 500 5 500 4 501 4 502 4 503 4 503 3 503 2 503 1 504 1 504 0 504 -1 504 -2 504 -3 505 -3 505 -4 505 -5 506 -5 506 -6 506 -7 507 -7 507 -8 507 -9 508 -9 508 -10 508 -11 508 -12 509 -12 509 -13 509 -14 509 -15 510 -15 510 -16 510 -17 510 -18 510 -19 511 -19 511 -20 512 -20 512 -21 513 -21 513 -22 513 -23 514 -23 514 -24 514 -25 515 -25 515 -26 515 -27 516 -27 517 -27 518 -27 519 -27 520 -27 521 -27 522 -27 522 -28 523 -28 523 -29 524 -29 524 -30 524 -31 524 -32 524 -33 524 -34 524 -35 524 -36 524 -37 525 -37 525 -38 525 -39 526 -39 526 -40 527 -40 527 -41 528 -41 529 -41 529 -42 530 -42 530 -43 530 -44 531 -44 531 -45 532 -45 532 -46 533 -46 533 -47 534 -47 535 -47 535 -48 535 -49 536 -49 537 -49 538 -49 538 -50 539 -50 539 -51 540 -51 540 -52 541 -52 542 -52 543 -52 544 -52 544 -53 545 -53 545 -54 546 -54 547 -54 548 -54 548 -53 549 -53 550 -53 551 -53 551 -54 551 -55 551 -56 552 -56 552 -57 553 -57 553 -58 553 -59 553 -60 554 -60 554 -61 555 -61 555 -62 556 -62 556 -63 557 -63 557 -64 558 -64 558 -65 558 -66 559 -66 559 -67 560 -67 560 -68 560 -69 561 -69 561 -70 562 -70 562 -71 562 -72 563 -72
sal0 = no_utau.variables['vosaline'][0,:,:,:]
sal0.shape
(40, 564, 284)
from salishsea_tools import visualisations
lakebathy = nc.Dataset('/home/vdo/MEOPAR/NEMO-forcing/grid/lake_bathy201702.nc')
lake_meshmask = nc.Dataset('/home/vdo/MEOPAR/NEMO-forcing/grid/lake_meshmask201702.nc')
fig,ax = plt.subplots()
visualisations.contour_thalweg(ax, sal0, lakebathy, lake_meshmask, 'salinity',
thalweg_file='salishsealakethalweg.txt')
<matplotlib.colorbar.Colorbar at 0x7fe88b92c710>
density = calc_rho(no_utau.variables['vosaline'][:], no_utau.variables['votemper'][:],
no_utau.variables['deptht'][:][np.newaxis, :, np.newaxis, np.newaxis])
density2 = calc_rho(with_utau.variables['vosaline'][:], with_utau.variables['votemper'][:],
with_utau.variables['deptht'][:][np.newaxis, :, np.newaxis, np.newaxis])
fig, ax = plt.subplots(figsize=(8,8))
den = ax.contourf(np.ones((20,20)), levels = np.linspace(1021.8, 1024.5, 8), cmap = 'bwr')
fig.colorbar(den, ax=ax)
<matplotlib.colorbar.Colorbar at 0x7f0ab5645748>
fig,ax = plt.subplots(2,1,figsize=(16,8))
def animate30(i):
ax[0].clear()
visualisations.contour_thalweg(ax[0], density[i,...], lakebathy, lake_meshmask,
np.linspace(1021.8, 1024.5, 8),
thalweg_file='salishsealakethalweg.txt')
ax[0].set_ylim(100,0)
ax[0].set_title('hour = %03d'%(i))
ax[1].clear()
visualisations.contour_thalweg(ax[1], density2[i,...], lakebathy, lake_meshmask,
np.linspace(1021.8, 1024.5, 8),
thalweg_file='salishsealakethalweg.txt')
ax[1].set_ylim(100,0)
ax[1].set_title('hour = %03d'%(i))
return ax
interval = 0.25#in seconds
ani40 = animation.FuncAnimation(fig,animate30,frames=160,interval=interval*1e+3,
repeat=False)
ani40
Made new thalweg points file, did animation for model run trying to imitate winds from 15Jan17.