|
121 | 121 | "import xarray as xr\n",
|
122 | 122 | "import os\n",
|
123 | 123 | "import warnings\n",
|
| 124 | + "\n", |
124 | 125 | "warnings.filterwarnings(action=\"ignore\", category=UserWarning)"
|
125 | 126 | ]
|
126 | 127 | },
|
|
133 | 134 | "source": [
|
134 | 135 | "grid1_path = pydda.tests.EXAMPLE_RADAR0\n",
|
135 | 136 | "grid2_path = pydda.tests.EXAMPLE_RADAR1\n",
|
136 |
| - "Grid1 = pyart.io.read_grid(grid1_path)\n", |
137 |
| - "Grid2 = pyart.io.read_grid(grid2_path)" |
| 137 | + "Grid1 = pydda.io.read_grid(grid1_path)\n", |
| 138 | + "Grid2 = pydda.io.read_grid(grid2_path)" |
138 | 139 | ]
|
139 | 140 | },
|
140 | 141 | {
|
|
172 | 173 | }
|
173 | 174 | ],
|
174 | 175 | "source": [
|
175 |
| - "if any(field_name in Grid1.fields for field_name in ['u', 'v', 'w']):\n", |
| 176 | + "if any(field_name in Grid1.fields for field_name in [\"u\", \"v\", \"w\"]):\n", |
176 | 177 | " # If any of 'u', 'v', or 'w' exists in Grid1.fields, remove them\n",
|
177 |
| - " fields_to_remove = ['u', 'v', 'w']\n", |
| 178 | + " fields_to_remove = [\"u\", \"v\", \"w\"]\n", |
178 | 179 | " for field_name in fields_to_remove:\n",
|
179 | 180 | " if field_name in Grid1.fields:\n",
|
180 | 181 | " del Grid1.fields[field_name]\n",
|
|
257 | 258 | ],
|
258 | 259 | "source": [
|
259 | 260 | "Grid1 = pydda.initialization.make_initialization_from_era5(\n",
|
260 |
| - " Grid1, vel_field='corrected_velocity',\n", |
261 |
| - " dest_era_file=f'./data/ERA_{str(xg1.time.dt.strftime(\"%Y%m%d_%H%M%S\").values[0])}.nc')" |
| 261 | + " Grid1,\n", |
| 262 | + " vel_field=\"corrected_velocity\",\n", |
| 263 | + " dest_era_file=f'./data/ERA_{str(xg1.time.dt.strftime(\"%Y%m%d_%H%M%S\").values[0])}.nc',\n", |
| 264 | + ")" |
262 | 265 | ]
|
263 | 266 | },
|
264 | 267 | {
|
|
289 | 292 | "metadata": {},
|
290 | 293 | "outputs": [],
|
291 | 294 | "source": [
|
292 |
| - "u = Grid1.fields['u']['data']\n", |
293 |
| - "v = Grid1.fields['v']['data']\n", |
294 |
| - "w = Grid1.fields['w']['data']" |
| 295 | + "u = Grid1.fields[\"u\"][\"data\"]\n", |
| 296 | + "v = Grid1.fields[\"v\"][\"data\"]\n", |
| 297 | + "w = Grid1.fields[\"w\"][\"data\"]" |
295 | 298 | ]
|
296 | 299 | },
|
297 | 300 | {
|
|
440 | 443 | " u_init=u,\n",
|
441 | 444 | " v_init=v,\n",
|
442 | 445 | " w_init=w,\n",
|
443 |
| - " Cx=2, Cy=2, Cz=2,\n", |
444 |
| - "# filter_window=5,\n", |
445 |
| - "# filter_order=3,\n", |
446 |
| - " Co=1e-1, Cm=10, frz=3900.0, Cb=0,\n", |
| 446 | + " Cx=2,\n", |
| 447 | + " Cy=2,\n", |
| 448 | + " Cz=2,\n", |
| 449 | + " # filter_window=5,\n", |
| 450 | + " # filter_order=3,\n", |
| 451 | + " Co=1e-1,\n", |
| 452 | + " Cm=10,\n", |
| 453 | + " frz=3900.0,\n", |
| 454 | + " Cb=0,\n", |
447 | 455 | " mask_outside_opt=False,\n",
|
448 | 456 | " wind_tol=0.1,\n",
|
449 | 457 | " max_iterations=200,\n",
|
450 | 458 | " engine=\"scipy\",\n",
|
451 |
| - " refl_field='reflectivity',\n", |
452 |
| - " vel_name='corrected_velocity')" |
| 459 | + " refl_field=\"reflectivity\",\n", |
| 460 | + " vel_name=\"corrected_velocity\",\n", |
| 461 | + ")" |
453 | 462 | ]
|
454 | 463 | },
|
455 | 464 | {
|
|
493 | 502 | ],
|
494 | 503 | "source": [
|
495 | 504 | "import matplotlib.pyplot as plt\n",
|
| 505 | + "\n", |
496 | 506 | "# Plot a horizontal cross section\n",
|
497 | 507 | "plt.figure(figsize=(6, 5))\n",
|
498 | 508 | "pydda.vis.plot_horiz_xsection_barbs(\n",
|
|
502 | 512 | " w_vel_contours=[5, 10, 15],\n",
|
503 | 513 | " barb_spacing_x_km=5.0,\n",
|
504 | 514 | " barb_spacing_y_km=15.0,\n",
|
505 |
| - " colorbar_flag=True, cmap='pyart_ChaseSpectral')\n", |
| 515 | + " colorbar_flag=True,\n", |
| 516 | + " cmap=\"pyart_ChaseSpectral\",\n", |
| 517 | + ")\n", |
506 | 518 | "plt.show()\n",
|
507 | 519 | "# Plot a vertical X-Z cross section\n",
|
508 | 520 | "plt.figure(figsize=(6, 5))\n",
|
|
513 | 525 | " w_vel_contours=[5, 10, 15],\n",
|
514 | 526 | " barb_spacing_x_km=10.0,\n",
|
515 | 527 | " barb_spacing_z_km=2.0,\n",
|
516 |
| - " colorbar_flag=True, cmap='pyart_ChaseSpectral',\n", |
517 |
| - " wind_vel_contours=[5, 10])\n", |
| 528 | + " colorbar_flag=True,\n", |
| 529 | + " cmap=\"pyart_ChaseSpectral\",\n", |
| 530 | + " wind_vel_contours=[5, 10],\n", |
| 531 | + ")\n", |
518 | 532 | "plt.show()\n",
|
519 | 533 | "\n",
|
520 | 534 | "# Plot a vertical Y-Z cross section\n",
|
|
525 | 539 | " level=70,\n",
|
526 | 540 | " barb_spacing_y_km=10.0,\n",
|
527 | 541 | " barb_spacing_z_km=2.0,\n",
|
528 |
| - " colorbar_flag=True, cmap='pyart_ChaseSpectral', wind_vel_contours=[5, 10])\n", |
| 542 | + " colorbar_flag=True,\n", |
| 543 | + " cmap=\"pyart_ChaseSpectral\",\n", |
| 544 | + " wind_vel_contours=[5, 10],\n", |
| 545 | + ")\n", |
529 | 546 | "plt.show()"
|
530 | 547 | ]
|
531 | 548 | },
|
|
546 | 563 | },
|
547 | 564 | "outputs": [],
|
548 | 565 | "source": [
|
549 |
| - "Grid1 = pydda.constraints.make_constraint_from_era5(Grid1,\n", |
550 |
| - " vel_field='corrected_velocity',\n", |
551 |
| - " file_name=\"./data/ERA_20060120_004008.nc\")\n", |
552 |
| - "Grid1 = pydda.initialization.make_constant_wind_field(Grid1, (0.0, 0.0, 0.0), vel_field='corrected_velocity')" |
| 566 | + "Grid1 = pydda.constraints.make_constraint_from_era5(\n", |
| 567 | + " Grid1, vel_field=\"corrected_velocity\", file_name=\"./data/ERA_20060120_004008.nc\"\n", |
| 568 | + ")\n", |
| 569 | + "Grid1 = pydda.initialization.make_constant_wind_field(\n", |
| 570 | + " Grid1, (0.0, 0.0, 0.0), vel_field=\"corrected_velocity\"\n", |
| 571 | + ")" |
553 | 572 | ]
|
554 | 573 | },
|
555 | 574 | {
|
|
668 | 687 | "new_grids, _ = pydda.retrieval.get_dd_wind_field(\n",
|
669 | 688 | " [Grid1, Grid2],\n",
|
670 | 689 | " Cmod=0,\n",
|
671 |
| - " Cx=2, Cy=2, Cz=2,\n", |
672 |
| - " Co=1e-1, Cm=10, frz=3900.0, Cb=0,\n", |
| 690 | + " Cx=2,\n", |
| 691 | + " Cy=2,\n", |
| 692 | + " Cz=2,\n", |
| 693 | + " Co=1e-1,\n", |
| 694 | + " Cm=10,\n", |
| 695 | + " frz=3900.0,\n", |
| 696 | + " Cb=0,\n", |
673 | 697 | " wind_tol=0.1,\n",
|
674 | 698 | " max_iterations=100,\n",
|
675 | 699 | " mask_outside_opt=True,\n",
|
676 | 700 | " engine=\"scipy\",\n",
|
677 |
| - " refl_field='reflectivity',\n", |
678 |
| - " vel_name='corrected_velocity',\n", |
679 |
| - " model_fields=[\"era5\"],)" |
| 701 | + " refl_field=\"reflectivity\",\n", |
| 702 | + " vel_name=\"corrected_velocity\",\n", |
| 703 | + " model_fields=[\"era5\"],\n", |
| 704 | + ")" |
680 | 705 | ]
|
681 | 706 | },
|
682 | 707 | {
|
|
730 | 755 | ],
|
731 | 756 | "source": [
|
732 | 757 | "import matplotlib.pyplot as plt\n",
|
| 758 | + "\n", |
733 | 759 | "# Plot a horizontal cross section\n",
|
734 | 760 | "plt.figure(figsize=(6, 5))\n",
|
735 | 761 | "pydda.vis.plot_horiz_xsection_barbs(\n",
|
|
739 | 765 | " w_vel_contours=[5, 10, 15],\n",
|
740 | 766 | " barb_spacing_x_km=5.0,\n",
|
741 | 767 | " barb_spacing_y_km=15.0,\n",
|
742 |
| - " cmap='pyart_ChaseSpectral')\n", |
| 768 | + " cmap=\"pyart_ChaseSpectral\",\n", |
| 769 | + ")\n", |
743 | 770 | "\n",
|
744 | 771 | "plt.show()\n",
|
745 | 772 | "# Plot a vertical X-Z cross section\n",
|
|
751 | 778 | " w_vel_contours=[5, 10, 15],\n",
|
752 | 779 | " barb_spacing_x_km=10.0,\n",
|
753 | 780 | " barb_spacing_z_km=2.0,\n",
|
754 |
| - " cmap='pyart_ChaseSpectral')\n", |
| 781 | + " cmap=\"pyart_ChaseSpectral\",\n", |
| 782 | + ")\n", |
755 | 783 | "plt.show()\n",
|
756 | 784 | "\n",
|
757 | 785 | "# Plot a vertical Y-Z cross section\n",
|
|
762 | 790 | " level=70,\n",
|
763 | 791 | " barb_spacing_y_km=10.0,\n",
|
764 | 792 | " barb_spacing_z_km=2.0,\n",
|
765 |
| - " cmap='pyart_ChaseSpectral')" |
| 793 | + " cmap=\"pyart_ChaseSpectral\",\n", |
| 794 | + ")" |
766 | 795 | ]
|
767 | 796 | },
|
768 | 797 | {
|
|
805 | 834 | "source": [
|
806 | 835 | "xg = new_grids[0].to_xarray().isel(time=0, z=1).sel(x=slice(0, 20e3), y=slice(-20e3, 0))\n",
|
807 | 836 | "fig, ax = plt.subplots(figsize=[6, 5], dpi=100)\n",
|
808 |
| - "xg['reflectivity'].plot(cmap='pyart_ChaseSpectral', ax=ax)\n", |
| 837 | + "xg[\"reflectivity\"].plot(cmap=\"pyart_ChaseSpectral\", ax=ax)\n", |
809 | 838 | "stride = 2 # Adjust the stride value to control the density of arrows\n",
|
810 | 839 | "xg_downsampled = xg.isel(x=slice(None, None, stride), y=slice(None, None, stride))\n",
|
811 |
| - "xg_downsampled.plot.quiver(x='x', y='y', u='u', v='v', ax=ax, pivot='mid')" |
| 840 | + "xg_downsampled.plot.quiver(x=\"x\", y=\"y\", u=\"u\", v=\"v\", ax=ax, pivot=\"mid\")" |
812 | 841 | ]
|
813 | 842 | },
|
814 | 843 | {
|
|
841 | 870 | "source": [
|
842 | 871 | "xg = new_grids[0].to_xarray().isel(time=0).sel(x=slice(-20e3, 20e3), y=-10e3)\n",
|
843 | 872 | "fig, ax = plt.subplots(figsize=[6, 5], dpi=100)\n",
|
844 |
| - "xg['reflectivity'].plot(cmap='pyart_ChaseSpectral', ax=ax)\n", |
| 873 | + "xg[\"reflectivity\"].plot(cmap=\"pyart_ChaseSpectral\", ax=ax)\n", |
845 | 874 | "stride = 5 # Adjust the stride value to control the density of arrows\n",
|
846 | 875 | "xg_downsampled = xg.isel(x=slice(None, None, stride), z=slice(None, None, stride))\n",
|
847 |
| - "xg_downsampled.plot.quiver(x='x', y='z', u='u', v='v', ax=ax, pivot='mid')" |
| 876 | + "xg_downsampled.plot.quiver(x=\"x\", y=\"z\", u=\"u\", v=\"v\", ax=ax, pivot=\"mid\")" |
848 | 877 | ]
|
849 | 878 | },
|
850 | 879 | {
|
|
0 commit comments