|
250 | 250 | "ds_wT_Jun_month]" |
251 | 251 | ] |
252 | 252 | }, |
253 | | - { |
254 | | - "cell_type": "markdown", |
255 | | - "metadata": {}, |
256 | | - "source": [ |
257 | | - "# Deleted particles" |
258 | | - ] |
259 | | - }, |
260 | | - { |
261 | | - "cell_type": "code", |
262 | | - "execution_count": 12, |
263 | | - "metadata": {}, |
264 | | - "outputs": [], |
265 | | - "source": [ |
266 | | - "\n", |
267 | | - "# these are matplotlib.patch.Patch properties\n", |
268 | | - "props = dict(boxstyle='round', facecolor='wheat', alpha=.5)\n" |
269 | | - ] |
270 | | - }, |
271 | 253 | { |
272 | 254 | "cell_type": "markdown", |
273 | 255 | "metadata": {}, |
|
289 | 271 | " lonmax=-21., \n", |
290 | 272 | " latmin=32.5, \n", |
291 | 273 | " latmax=36.5\n", |
292 | | - ")#lomin -35 #lomax -18 # lamin 30 # lamax 40" |
| 274 | + ")" |
293 | 275 | ] |
294 | 276 | }, |
295 | 277 | { |
|
314 | 296 | "metadata": {}, |
315 | 297 | "outputs": [], |
316 | 298 | "source": [ |
317 | | - "nbins = (60, 40)\n", |
318 | | - "\n", |
319 | | - "xmin = subregion.lonmin\n", |
320 | | - "xmax = subregion.lonmax\n", |
321 | | - "ymin = subregion.latmin\n", |
322 | | - "ymax = subregion.latmax\n", |
| 299 | + "def calc_hist2d(dsp, nbins, nsubregion):\n", |
| 300 | + " \"\"\"\n", |
| 301 | + " xxxx\n", |
| 302 | + " dsp: xarray dataset \n", |
| 303 | + " \"\"\" \n", |
| 304 | + " xmin = nsubregion.lonmin\n", |
| 305 | + " xmax = nsubregion.lonmax\n", |
| 306 | + " ymin = nsubregion.latmin\n", |
| 307 | + " ymax = nsubregion.latmax\n", |
| 308 | + " \n", |
| 309 | + " lon_end_nonans, lat_end_nonans = rem_nans(dsp)\n", |
| 310 | + " counts, xedges, yedges = np.histogram2d(lon_end_nonans, lat_end_nonans, bins=nbins, range=((xmin, xmax), (ymin, ymax)))\n", |
323 | 311 | "\n", |
324 | | - "vmin=0.\n", |
325 | | - "vmax=30." |
326 | | - ] |
327 | | - }, |
328 | | - { |
329 | | - "cell_type": "markdown", |
330 | | - "metadata": {}, |
331 | | - "source": [ |
332 | | - "# Histogram 1D" |
| 312 | + " return counts.ravel()\n", |
| 313 | + " " |
333 | 314 | ] |
334 | 315 | }, |
335 | 316 | { |
336 | 317 | "cell_type": "code", |
337 | | - "execution_count": 16, |
| 318 | + "execution_count": null, |
338 | 319 | "metadata": {}, |
339 | 320 | "outputs": [], |
340 | 321 | "source": [ |
341 | | - "ymax_1d = .2\n", |
342 | | - "xmax_1d = 90\n", |
343 | | - "\n", |
344 | | - "nbins_1d = 20" |
| 322 | + "bins_2d = (60, 40) # --> 0.1 degree" |
345 | 323 | ] |
346 | 324 | }, |
347 | 325 | { |
348 | 326 | "cell_type": "code", |
349 | | - "execution_count": 17, |
| 327 | + "execution_count": null, |
350 | 328 | "metadata": {}, |
351 | 329 | "outputs": [], |
352 | 330 | "source": [ |
353 | | - "def plot_hist1d_particles_b(dsp, axn, nbins_1d, ntitle, labelf, ncolor='b'):\n", |
354 | | - " \"\"\"\n", |
355 | | - " \"\"\" \n", |
356 | | - " ######\n", |
357 | | - " # Title\n", |
358 | | - " if ntitle in ntitles[0:6]:\n", |
359 | | - " nyear = '2009'\n", |
360 | | - " elif ntitle in ntitles[6::]:\n", |
361 | | - " nyear = '2010'\n", |
362 | | - " else:\n", |
363 | | - " print('Error nyear')\n", |
364 | | - " dgdsgsg\n", |
365 | | - " \n", |
366 | | - " strtitle = ntitle + ' ' + nyear\n", |
367 | | - " axn.set_title(strtitle, size=16)\n", |
368 | | - " ######\n", |
369 | | - " \n", |
370 | | - " lon_end_nonans, lat_end_nonans = rem_nans(dsp)\n", |
371 | | - " counts, xedges, yedges = np.histogram2d(lon_end_nonans, lat_end_nonans, bins=nbins, range=((xmin, xmax), (ymin, ymax)))\n", |
| 331 | + "counts_nT = np.ones((12, 60*40)) * np.nan\n", |
| 332 | + "counts_wT = np.ones((12, 60*40)) * np.nan\n", |
372 | 333 | "\n", |
373 | | - " axn.hist(counts.ravel(), bins=nbins_1d, density=True, color=ncolor, alpha=.5, label=labelf)\n", |
374 | | - " axn.set_ylim([0, ymax_1d])\n", |
375 | | - " axn.set_xlim([0, xmax_1d])\n", |
376 | | - " axn.grid()\n", |
377 | | - " axn.axvline(x=counts.ravel().max(), color=ncolor)\n", |
378 | | - " #print(counts.ravel().max())\n", |
379 | | - " skw_2D = scipy.stats.skew(counts.ravel())\n", |
380 | | - " # axn.annotate('Skewness = ' + str(np.round(scipy.stats.skew(counts.ravel()), 2)),\n", |
381 | | - " # xy=(22, .17), xycoords='data', size=16)\n", |
382 | | - " return skw_2D, counts.ravel()\n", |
383 | | - " " |
| 334 | + "for ii in range(0, len(ntitles)):\n", |
| 335 | + " counts_nT[ii,:] = calc_hist2d(dsps_nT[ii], bins_2d, subregion)\n", |
| 336 | + " counts_wT[ii,:] = calc_hist2d(dsps_wT[ii], bins_2d, subregion)\n" |
384 | 337 | ] |
385 | 338 | }, |
386 | 339 | { |
387 | | - "cell_type": "code", |
388 | | - "execution_count": 18, |
| 340 | + "cell_type": "markdown", |
389 | 341 | "metadata": {}, |
390 | | - "outputs": [], |
391 | 342 | "source": [ |
392 | | - "#https://matplotlib.org/3.3.4/gallery/recipes/placing_text_boxes.html\n", |
393 | | - "\n", |
394 | | - "# these are matplotlib.patch.Patch properties\n", |
395 | | - "props = dict(boxstyle='round', facecolor='wheat', alpha=1) # alpha=\n" |
| 343 | + "# Histogram 1D" |
396 | 344 | ] |
397 | 345 | }, |
398 | 346 | { |
399 | 347 | "cell_type": "markdown", |
400 | 348 | "metadata": {}, |
401 | 349 | "source": [ |
402 | | - "# Defining same binsize for all months instead of bin number" |
| 350 | + "## Doing it with number of bins:" |
403 | 351 | ] |
404 | 352 | }, |
405 | 353 | { |
406 | | - "cell_type": "code", |
407 | | - "execution_count": 19, |
| 354 | + "cell_type": "markdown", |
408 | 355 | "metadata": {}, |
409 | | - "outputs": [], |
410 | 356 | "source": [ |
411 | | - "ymax_1d = .15\n", |
412 | | - "\n", |
413 | | - "bins_list = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]\n", |
414 | | - "# specify bin start and end points" |
| 357 | + "* 10 max 70:" |
415 | 358 | ] |
416 | 359 | }, |
417 | 360 | { |
418 | 361 | "cell_type": "code", |
419 | | - "execution_count": 20, |
| 362 | + "execution_count": 16, |
420 | 363 | "metadata": {}, |
421 | 364 | "outputs": [], |
422 | 365 | "source": [ |
423 | | - "ymax_1d = .15\n", |
| 366 | + "bins_list = 10\n", |
424 | 367 | "\n", |
425 | | - "bins_list = [0, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90]\n", |
426 | | - "# specify bin start and end points" |
| 368 | + "ymax_1d = 0.185\n", |
| 369 | + "xmax_1d = 77" |
427 | 370 | ] |
428 | 371 | }, |
429 | 372 | { |
|
445 | 388 | } |
446 | 389 | ], |
447 | 390 | "source": [ |
448 | | - "xmax_1d = 80\n", |
449 | | - "\n", |
450 | 391 | "fig = plt.figure(figsize=(16,13)) #(17,5)\n", |
451 | 392 | "\n", |
452 | 393 | "#cbar_ticks = [0.005, 0.0055, 0.006, 0.0065, 0.007, 0.0075, 0.008, 0.0085, 0.009] \n", |
|
472 | 413 | " strtitle = ntitle + '. ' + nyear\n", |
473 | 414 | " ax1.set_title(strtitle, size=16)\n", |
474 | 415 | " ######\n", |
| 416 | + " \n", |
| 417 | + " counts_nT_1, binEdges_nT = np.histogram(counts_nT[ii,:], bins=bins_list, density=True)\n", |
| 418 | + " counts_wT_1, binEdges_wT = np.histogram(counts_wT[ii,:], bins=bins_list, density=True)\n", |
| 419 | + " \n", |
| 420 | + " bincenters_nT = 0.5 * (binEdges_nT[1:] + binEdges_nT[:-1])\n", |
| 421 | + " bincenters_wT = 0.5 * (binEdges_wT[1:] + binEdges_wT[:-1])\n", |
475 | 422 | " \n", |
476 | | - " ax1.hist(counts_nT[ii,:], bins=bins_list, density=True, alpha=.5, label='No tidal forcing', color='b')\n", |
| 423 | + " ax1.plot(bincenters_nT, counts_nT_1, '.-', color='C0', label='No tidal forcing', linewidth=2, markersize=10)# , linewidth=4\n", |
477 | 424 | " ax1.set_ylim([0, ymax_1d])\n", |
478 | 425 | " ax1.set_xlim([0, xmax_1d])\n", |
479 | | - " ax1.axvline(x=counts_nT[ii,:].max(), color='b')\n", |
| 426 | + " ax1.axvline(x=counts_nT[ii,:].max(), linestyle='--', color='C0')\n", |
480 | 427 | " \n", |
481 | | - " ax1.hist(counts_wT[ii,:], bins=bins_list, density=True, alpha=.5, label='Tidal forcing', color='r')\n", |
| 428 | + " ax1.plot(bincenters_wT, counts_wT_1, '.-', color='C3', label='Tidal forcing', linewidth=2, markersize=10)# , linewidth=4\n", |
482 | 429 | " ax1.set_ylim([0, ymax_1d])\n", |
483 | 430 | " ax1.set_xlim([0, xmax_1d])\n", |
484 | | - " ax1.axvline(x=counts_wT[ii,:].max(), color='r')\n", |
| 431 | + " ax1.axvline(x=counts_wT[ii,:].max(), linestyle='--', color='C3')\n", |
485 | 432 | " \n", |
486 | 433 | " #skw_2D_wT, _ = plot_hist1d_particles_b(dsps_wT[ii], ax1, bins_list, ntitles[ii], labelf='Tidal', ncolor='r')\n", |
487 | 434 | " ax1.grid()\n", |
488 | 435 | " ax1.tick_params(axis='both', which='major', labelsize=14)\n", |
489 | 436 | "\n", |
490 | 437 | " if ii == 0:\n", |
491 | | - " ax1.legend(loc=0, fontsize=14)\n", |
| 438 | + " legend = ax1.legend(loc=0, fontsize=12)\n", |
| 439 | + " legend.get_frame().set_alpha(None)\n", |
| 440 | + " legend.get_frame().set_facecolor('white')\n", |
492 | 441 | " if ((ii==4)):\n", |
493 | 442 | " ax1.set_ylabel('Normalized frequency', size=20) # Normalized bin counts\n", |
494 | 443 | " if ((ii==9)):\n", |
|
497 | 446 | " ax1.axes.xaxis.set_ticklabels([])\n", |
498 | 447 | " if (ii != 0) & (ii != 4) & (ii != 8) :\n", |
499 | 448 | " ax1.axes.yaxis.set_ticklabels([])\n", |
500 | | - "# textstr = '\\n'.join((\n", |
501 | | - "# r'$nT=%.2f$' % (skw_2D_nT, ),\n", |
502 | | - "# r'$wT=%.2f$' % (skw_2D_wT, )))\n", |
503 | | - "# # place a text box in upper left in axes coords\n", |
504 | | - "# ax1.text(0.55, 0.95, textstr, transform=ax1.transAxes, fontsize=14,\n", |
505 | | - "# verticalalignment='top', bbox=props)\n", |
506 | | - "\n", |
507 | | - "plt.savefig('figs/' + 'hist1d_nT_wT_monthly_nobox.jpg', dpi=300)\n", |
| 449 | + " \n", |
| 450 | + "plt.savefig('../../Figures/' + 'hist1d_nT_wT_monthly_nobox.jpg', dpi=300)\n", |
508 | 451 | " \n", |
509 | 452 | "plt.show()\n" |
510 | 453 | ] |
|
535 | 478 | "name": "python", |
536 | 479 | "nbconvert_exporter": "python", |
537 | 480 | "pygments_lexer": "ipython3", |
538 | | - "version": "3.8.11" |
| 481 | + "version": "3.11.6" |
539 | 482 | } |
540 | 483 | }, |
541 | 484 | "nbformat": 4, |
|
0 commit comments