|
105 | 105 | " output_core_dims=[\n", |
106 | 106 | " [], [], [], [], []\n", |
107 | 107 | " ],\n", |
108 | | - " vectorize=True\n", |
| 108 | + " vectorize=True,\n", |
| 109 | + " keep_attrs=\"drop_conflicts\",\n", |
109 | 110 | " )\n", |
110 | 111 | "\n", |
111 | 112 | " vmax, pmin, ifl, t0, otl = result\n", |
112 | 113 | " \n", |
113 | | - " out_ds=xr.Dataset({\n", |
114 | | - " 'vmax': vmax, \n", |
115 | | - " 'pmin': pmin,\n", |
116 | | - " 'ifl': ifl,\n", |
117 | | - " 't0': t0,\n", |
118 | | - " 'otl': otl\n", |
119 | | - " })\n", |
| 114 | + " out_ds=xr.Dataset(\n", |
| 115 | + " {\n", |
| 116 | + " 'vmax': vmax, \n", |
| 117 | + " 'pmin': pmin,\n", |
| 118 | + " 'ifl': ifl,\n", |
| 119 | + " 't0': t0,\n", |
| 120 | + " 'otl': otl,\n", |
| 121 | + " },\n", |
| 122 | + " coords=ds.coords,\n", |
| 123 | + " attrs=ds.attrs,\n", |
| 124 | + " )\n", |
120 | 125 | " \n", |
121 | 126 | " # add names and units\n", |
122 | 127 | " out_ds.vmax.attrs['standard_name'],out_ds.vmax.attrs['units']='Maximum Potential Intensity','m/s'\n", |
|
286 | 291 | " output_core_dims=[\n", |
287 | 292 | " [],\n", |
288 | 293 | " ],\n", |
289 | | - " vectorize=True\n", |
| 294 | + " vectorize=True,\n", |
| 295 | + " keep_attrs=\"drop_conflicts\",\n", |
290 | 296 | " )\n", |
291 | 297 | " \n", |
292 | 298 | " diseq = xr.apply_ufunc(\n", |
|
299 | 305 | " output_core_dims=[\n", |
300 | 306 | " [],\n", |
301 | 307 | " ],\n", |
302 | | - " vectorize=True\n", |
| 308 | + " vectorize=True,\n", |
| 309 | + " keep_attrs=\"drop_conflicts\",\n", |
303 | 310 | " )\n", |
304 | 311 | " \n", |
305 | 312 | " result1 = xr.apply_ufunc(\n", |
|
312 | 319 | " output_core_dims=[\n", |
313 | 320 | " [], [], [], [],\n", |
314 | 321 | " ],\n", |
315 | | - " vectorize=True\n", |
| 322 | + " vectorize=True,\n", |
| 323 | + " keep_attrs=\"drop_conflicts\",\n", |
316 | 324 | " )\n", |
317 | 325 | "\n", |
318 | 326 | " lnpi, lneff, lndiseq, lnCKCD = result1\n", |
319 | 327 | " \n", |
320 | | - " out_ds = xr.Dataset({\n", |
321 | | - " 'eff': efficiency, \n", |
322 | | - " 'diseq': diseq,\n", |
323 | | - " 'lnpi': lnpi,\n", |
324 | | - " 'lneff': lneff,\n", |
325 | | - " 'lndiseq': lndiseq,\n", |
326 | | - " 'lnCKCD': lnCKCD[0,0,0]\n", |
327 | | - " })\n", |
| 328 | + " out_ds = xr.Dataset(\n", |
| 329 | + " {\n", |
| 330 | + " 'eff': efficiency, \n", |
| 331 | + " 'diseq': diseq,\n", |
| 332 | + " 'lnpi': lnpi,\n", |
| 333 | + " 'lneff': lneff,\n", |
| 334 | + " 'lndiseq': lndiseq,\n", |
| 335 | + " 'lnCKCD': lnCKCD[0,0,0],\n", |
| 336 | + " },\n", |
| 337 | + " coords=pi_ds.coords,\n", |
| 338 | + " attrs=pi_ds.attrs,\n", |
| 339 | + " )\n", |
328 | 340 | " \n", |
329 | 341 | " # add names and units (where applicable)\n", |
330 | 342 | " out_ds.eff.attrs['standard_name'],out_ds.eff.attrs['units']='Tropical Cyclone Efficiency','unitless fraction'\n", |
|
379 | 391 | " 'lneff': diag_ds.lneff,\n", |
380 | 392 | " 'lndiseq': diag_ds.lndiseq,\n", |
381 | 393 | " 'lnCKCD': diag_ds.lnCKCD\n", |
382 | | - " })\n", |
| 394 | + " },\n", |
| 395 | + " coords=diag_ds.coords,\n", |
| 396 | + " attrs=diag_ds.attrs,\n", |
| 397 | + ")\n", |
383 | 398 | "del pi_ds, ds, diag_ds" |
384 | 399 | ] |
385 | 400 | }, |
|
703 | 718 | " weights = np.cos(np.deg2rad(dat_array.lat))\n", |
704 | 719 | " \n", |
705 | 720 | " # find the basin locations in the data structure\n", |
706 | | - " var_slice=dat_array.sel(lon=slice(basin_dict.bounds.values[1,0], basin_dict.bounds.values[1,1]), \\\n", |
707 | | - " lat=slice(basin_dict.bounds.values[0,1], basin_dict.bounds.values[0,0]))\n", |
| 721 | + " var_slice=dat_array.sel(\n", |
| 722 | + " lon=slice(basin_dict[\"lon_min\"], basin_dict[\"lon_max\"]),\n", |
| 723 | + " # Warning: latitude is decreasing from 90 to -90, so the slice is reversed\n", |
| 724 | + " lat=slice(basin_dict[\"lat_max\"], basin_dict[\"lat_min\"]),\n", |
| 725 | + " )\n", |
708 | 726 | " \n", |
709 | 727 | " # take latitude weighted basin average\n", |
710 | 728 | " basin_mean=var_slice.weighted(weights).mean((\"lon\", \"lat\"))\n", |
|
766 | 784 | "outputs": [], |
767 | 785 | "source": [ |
768 | 786 | "# define the function to plot the seasonal cycle of a variable\n", |
769 | | - "def plot_pi_seascycle(var_want,meanb,basin_dict):\n", |
| 787 | + "def plot_pi_seascycle(var_want,meanb,basins):\n", |
770 | 788 | " plt.figure()\n", |
771 | 789 | " mongrid=np.linspace(1,12,12)\n", |
772 | 790 | " for k in basins.keys():\n", |
773 | | - " plt.plot(mongrid,meanb[var_want][k],lw=4,color=str(basins[k].color.values),label=str(basins[k].shortname.values))\n", |
| 791 | + " plt.plot(mongrid,meanb[var_want][k],lw=4,color=str(basins[k][\"color\"]),label=str(basins[k][\"shortname\"]))\n", |
774 | 792 | " plt.xlim([0.75,12.25])\n", |
775 | 793 | " plt.xticks(mongrid,labels=monlabels)\n", |
776 | 794 | " plt.xlabel('Month')\n", |
|
0 commit comments