|
46 | 46 | }, |
47 | 47 | "outputs": [], |
48 | 48 | "source": [ |
49 | | - "# These libraries are needed for the pygrib library in Colab. \n", |
| 49 | + "# These libraries are needed for the pygrib library in Colab.\n", |
50 | 50 | "# Note that is needed if you install pygrib using pip.\n", |
51 | 51 | "# If you use conda, the libraries will be installed automatically.\n", |
52 | 52 | "! apt-get install libeccodes-dev libproj-dev\n", |
|
68 | 68 | "source": [ |
69 | 69 | "# Uninstall existing shapely\n", |
70 | 70 | "# We will re-install shapely in the next step by ignoring the binary\n", |
71 | | - "# wheels to make it compatible with other modules that depend on \n", |
| 71 | + "# wheels to make it compatible with other modules that depend on\n", |
72 | 72 | "# GEOS, such as Cartopy (used here).\n", |
73 | 73 | "!pip uninstall --yes shapely" |
74 | 74 | ] |
|
83 | 83 | }, |
84 | 84 | "outputs": [], |
85 | 85 | "source": [ |
86 | | - "# To install cartopy in Colab using pip, we need to install the library \n", |
| 86 | + "# To install cartopy in Colab using pip, we need to install the library\n", |
87 | 87 | "# dependencies first.\n", |
88 | 88 | "\n", |
89 | 89 | "!apt-get install -qq libgdal-dev libgeos-dev\n", |
|
170 | 170 | }, |
171 | 171 | "outputs": [], |
172 | 172 | "source": [ |
173 | | - "# If the configuration file is placed in one of the default locations \n", |
174 | | - "# (https://pysteps.readthedocs.io/en/latest/user_guide/set_pystepsrc.html#configuration-file-lookup) \n", |
175 | | - "# it will be loaded automatically when pysteps is imported. \n", |
| 173 | + "# If the configuration file is placed in one of the default locations\n", |
| 174 | + "# (https://pysteps.readthedocs.io/en/latest/user_guide/set_pystepsrc.html#configuration-file-lookup)\n", |
| 175 | + "# it will be loaded automatically when pysteps is imported.\n", |
176 | 176 | "config_file_path = create_default_pystepsrc(\"pysteps_data\")" |
177 | 177 | ] |
178 | 178 | }, |
|
198 | 198 | "source": [ |
199 | 199 | "# Import pysteps and load the new configuration file\n", |
200 | 200 | "import pysteps\n", |
| 201 | + "\n", |
201 | 202 | "_ = pysteps.load_config_file(config_file_path, verbose=True)" |
202 | 203 | ] |
203 | 204 | }, |
|
224 | 225 | "source": [ |
225 | 226 | "# The default parameters are stored in pysteps.rcparams.\n", |
226 | 227 | "from pprint import pprint\n", |
227 | | - "pprint(pysteps.rcparams.data_sources['mrms'])" |
| 228 | + "\n", |
| 229 | + "pprint(pysteps.rcparams.data_sources[\"mrms\"])" |
228 | 230 | ] |
229 | 231 | }, |
230 | 232 | { |
|
272 | 274 | "start_time = time.time()\n", |
273 | 275 | "\n", |
274 | 276 | "# Import the data\n", |
275 | | - "precipitation, metadata, timestep = load_dataset('mrms',frames=35) # precipitation in mm/h\n", |
| 277 | + "precipitation, metadata, timestep = load_dataset(\n", |
| 278 | + " \"mrms\", frames=35\n", |
| 279 | + ") # precipitation in mm/h\n", |
276 | 280 | "\n", |
277 | 281 | "end_time = time.time()\n", |
278 | 282 | "\n", |
|
330 | 334 | }, |
331 | 335 | "outputs": [], |
332 | 336 | "source": [ |
333 | | - "timestep # In minutes" |
| 337 | + "timestep # In minutes" |
334 | 338 | ] |
335 | 339 | }, |
336 | 340 | { |
|
450 | 454 | "\n", |
451 | 455 | "# Let's define some plotting default parameters for the next plots\n", |
452 | 456 | "# Note: This is not strictly needed.\n", |
453 | | - "plt.rc('figure', figsize=(4,4))\n", |
454 | | - "plt.rc('figure', dpi=100)\n", |
455 | | - "plt.rc('font', size=14) # controls default text sizes\n", |
456 | | - "plt.rc('axes', titlesize=14) # fontsize of the axes title\n", |
457 | | - "plt.rc('axes', labelsize=14) # fontsize of the x and y labels\n", |
458 | | - "plt.rc('xtick', labelsize=14) # fontsize of the tick labels\n", |
459 | | - "plt.rc('ytick', labelsize=14) # fontsize of the tick labels\n", |
| 457 | + "plt.rc(\"figure\", figsize=(4, 4))\n", |
| 458 | + "plt.rc(\"figure\", dpi=100)\n", |
| 459 | + "plt.rc(\"font\", size=14) # controls default text sizes\n", |
| 460 | + "plt.rc(\"axes\", titlesize=14) # fontsize of the axes title\n", |
| 461 | + "plt.rc(\"axes\", labelsize=14) # fontsize of the x and y labels\n", |
| 462 | + "plt.rc(\"xtick\", labelsize=14) # fontsize of the tick labels\n", |
| 463 | + "plt.rc(\"ytick\", labelsize=14) # fontsize of the tick labels\n", |
460 | 464 | "\n", |
461 | 465 | "# Let's use the last available composite for nowcasting from the \"training\" data (train_precip[-1])\n", |
462 | 466 | "# Also, we will discard any invalid value.\n", |
463 | 467 | "valid_precip_values = train_precip[-1][~np.isnan(train_precip[-1])]\n", |
464 | 468 | "\n", |
465 | 469 | "# Plot the histogram\n", |
466 | | - "bins= np.concatenate( ([-0.01,0.01], np.linspace(1,40,39)))\n", |
467 | | - "plt.hist(valid_precip_values,bins=bins,log=True, edgecolor='black')\n", |
468 | | - "plt.autoscale(tight=True, axis='x')\n", |
| 470 | + "bins = np.concatenate(([-0.01, 0.01], np.linspace(1, 40, 39)))\n", |
| 471 | + "plt.hist(valid_precip_values, bins=bins, log=True, edgecolor=\"black\")\n", |
| 472 | + "plt.autoscale(tight=True, axis=\"x\")\n", |
469 | 473 | "plt.xlabel(\"Rainfall intensity [mm/h]\")\n", |
470 | 474 | "plt.ylabel(\"Counts\")\n", |
471 | | - "plt.title('Precipitation rain rate histogram in mm/h units')\n", |
| 475 | + "plt.title(\"Precipitation rain rate histogram in mm/h units\")\n", |
472 | 476 | "plt.show()" |
473 | 477 | ] |
474 | 478 | }, |
|
507 | 511 | "source": [ |
508 | 512 | "from pysteps.utils import transformation\n", |
509 | 513 | "\n", |
510 | | - "# Log-transform the data to dBR. \n", |
| 514 | + "# Log-transform the data to dBR.\n", |
511 | 515 | "# The threshold of 0.1 mm/h sets the fill value to -15 dBR.\n", |
512 | | - "train_precip_dbr, metadata_dbr = transformation.dB_transform(train_precip, metadata, \n", |
513 | | - " threshold=0.1, \n", |
514 | | - " zerovalue=-15.0)" |
| 516 | + "train_precip_dbr, metadata_dbr = transformation.dB_transform(\n", |
| 517 | + " train_precip, metadata, threshold=0.1, zerovalue=-15.0\n", |
| 518 | + ")" |
515 | 519 | ] |
516 | 520 | }, |
517 | 521 | { |
|
554 | 558 | "\n", |
555 | 559 | "# We will only use one composite to fit the function to speed up things.\n", |
556 | 560 | "# First, remove the no precip areas.\"\n", |
557 | | - "precip_to_fit = valid_precip_dbr[valid_precip_dbr > -15] \n", |
| 561 | + "precip_to_fit = valid_precip_dbr[valid_precip_dbr > -15]\n", |
558 | 562 | "\n", |
559 | 563 | "fit_params = scipy.stats.lognorm.fit(precip_to_fit)\n", |
560 | 564 | "\n", |
|
617 | 621 | "plt.title(\"Estimated motion field with the Lukas-Kanade algorithm\")\n", |
618 | 622 | "\n", |
619 | 623 | "# Plot the last rainfall field in the \"training\" data.\n", |
620 | | - "# Remember to use the mm/h precipitation data since plot_precip_field assumes \n", |
| 624 | + "# Remember to use the mm/h precipitation data since plot_precip_field assumes\n", |
621 | 625 | "# mm/h by default. You can change this behavior using the \"units\" keyword.\n", |
622 | 626 | "plot_precip_field(train_precip[-1], geodata=metadata, axis=\"off\")\n", |
623 | 627 | "\n", |
|
662 | 666 | "\n", |
663 | 667 | "last_observation[~np.isfinite(last_observation)] = metadata[\"zerovalue\"]\n", |
664 | 668 | "\n", |
665 | | - "# We set the number of leadtimes (the length of the forecast horizon) to the \n", |
| 669 | + "# We set the number of leadtimes (the length of the forecast horizon) to the\n", |
666 | 670 | "# length of the observed/verification preipitation data. In this way, we'll get\n", |
667 | 671 | "# a forecast that covers these time intervals.\n", |
668 | 672 | "n_leadtimes = observed_precip.shape[0]\n", |
|
746 | 750 | " 64,\n", |
747 | 751 | "] # In grid points.\n", |
748 | 752 | "\n", |
749 | | - "scales_in_km = np.array(scales)*4\n", |
| 753 | + "scales_in_km = np.array(scales) * 4\n", |
750 | 754 | "\n", |
751 | 755 | "# Set the threshold\n", |
752 | 756 | "thr = 1.0 # in mm/h\n", |
|
764 | 768 | "\n", |
765 | 769 | "# Now plot it\n", |
766 | 770 | "plt.figure()\n", |
767 | | - "x = np.arange(1, n_leadtimes+1) * timestep\n", |
| 771 | + "x = np.arange(1, n_leadtimes + 1) * timestep\n", |
768 | 772 | "plt.plot(x, score, lw=2.0)\n", |
769 | 773 | "plt.xlabel(\"Lead time [min]\")\n", |
770 | 774 | "plt.ylabel(\"FSS ( > 1.0 mm/h ) \")\n", |
771 | 775 | "plt.title(\"Fractions Skill Score\")\n", |
772 | 776 | "plt.legend(\n", |
773 | | - " scales_in_km, \n", |
| 777 | + " scales_in_km,\n", |
774 | 778 | " title=\"Scale [km]\",\n", |
775 | 779 | " loc=\"center left\",\n", |
776 | 780 | " bbox_to_anchor=(1.01, 0.5),\n", |
|
0 commit comments