Traceback (most recent call last): File "/nird/home/yanchun/.local/lib/python3.13/site-packages/jupyter_core/utils/__init__.py", line 154, in wrapped asyncio.get_running_loop() ~~~~~~~~~~~~~~~~~~~~~~~~^^ RuntimeError: no running event loop During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/diagnostics/cmip7validate-env/lib/python3.13/site-packages/jupyter_cache/executors/utils.py", line 58, in single_nb_execution executenb( ~~~~~~~~~^ nb, ^^^ ...<4 lines>... **kwargs, ^^^^^^^^^ ) ^ File "/nird/home/yanchun/.local/lib/python3.13/site-packages/nbclient/client.py", line 1319, in execute return NotebookClient(nb=nb, resources=resources, km=km, **kwargs).execute() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "/nird/home/yanchun/.local/lib/python3.13/site-packages/jupyter_core/utils/__init__.py", line 158, in wrapped return loop.run_until_complete(inner) ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ File "/diagnostics/cmip7validate-env/lib/python3.13/asyncio/base_events.py", line 719, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/nird/home/yanchun/.local/lib/python3.13/site-packages/nbclient/client.py", line 709, in async_execute await self.async_execute_cell( cell, index, execution_count=self.code_cells_executed + 1 ) File "/nird/home/yanchun/.local/lib/python3.13/site-packages/nbclient/client.py", line 1062, in async_execute_cell await self._check_raise_for_error(cell, cell_index, exec_reply) File "/nird/home/yanchun/.local/lib/python3.13/site-packages/nbclient/client.py", line 918, in _check_raise_for_error raise CellExecutionError.from_cell_and_msg(cell, exec_reply_content) nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell: ------------------ # loop through compound names and plot for cname in cnames: mth_vert = 'mean' mth_ts = 'mean' mth_cmap = 'mpl.colormaps["viridis"]' if cname not in methods.keys(): print(f"{cname} not found in methods.txt, using default methods for plotting.") else: if methods[cname] is not None: if 'vertical' in methods[cname].keys(): mth_vert = methods[cname]['vertical'] if 'timeseries' in methods[cname].keys(): mth_ts = methods[cname]['timeseries'] if 'cmap' in methods[cname].keys(): mth_cmap = methods[cname]['cmap'] realm = cname.split('.')[0] var = cname.split('.')[1] coord = cname.split('.')[2] freq = cname.split('.')[3] if realm != 'ocean' or coord not in coords: continue data_file = var+'_'+coord+'_*_'+grid_label+'_'+source_id+'_'+experiment_id+'_'+variant_label+'_*.nc' if not glob.glob(os.path.join(data_path, data_file)): continue #with xr.open_mfdataset(os.path.join(data_path, data_file)) as ds: data_file = glob.glob(os.path.join(data_path, data_file))[0] with xr.open_dataset(os.path.join(data_path, data_file)) as ds: if var in ds: data = ds[var] else: continue if 'lev' not in data.dims: print(f"{cname} does not have vertical dimension 'lev' , skipping vertical aggregation.") continue if mth_vert == 'mean': data2d = data.mean(dim='lev',keep_attrs=True).where(pmask == 1) elif mth_vert == 'sum': data2d = data.sum(dim='lev',keep_attrs=True).where(pmask == 1) else: raise ValueError(f'Unsupported vertical aggregation method: {mth_vert}') display(HTML(f'
')) print(f'\033[1m{cname}\033[0m') print(f'long name: {data2d.long_name} ({data2d.units})') print(f'vertical aggregation method for 3D->2D plot: {mth_vert}') print(f'timeseries aggregation method for 3D->1D plot: {mth_ts}') print(f'original_name: {data2d.attrs["original_name"]} -> {var}') if 'history' in data2d.attrs: print(f'history: {data2d.attrs["history"]}') if 'comment' in data2d.attrs: print(f'comment: {data2d.attrs["comment"]}') #ax1 = fig.add_subplot(1, 2, 1, projection=proj) #fig, (ax1, ax2) = plt.subplots( nrows=1, ncols=2, figsize=(12, 5), gridspec_kw={'width_ratios': [2, 1]}, subplot_kw={'projection': proj}) fig = plt.figure(figsize=(16, 3), dpi=96) gs = fig.add_gridspec(nrows=1, ncols=2, width_ratios=[2, 1]) proj = ccrs.PlateCarree(central_longitude=90.0) # plot 2D map ax1 = fig.add_subplot(gs[0], projection=proj) # rescale vmin, vmax = data2d.quantile([0.001, 0.999], dim=None).values if mth_cmap == 'cmocean.cm.balance': vmax = max(abs(vmin),abs(vmax)) vmin = -vmax # Define the discrete levels (boundaries) and the corresponding colors levels = np.linspace(vmin, vmax, 21) n_levels = 20 colors = eval(mth_cmap)(np.linspace(0,1,n_levels)) cmap = ListedColormap(colors) # Create a BoundaryNorm to map data to discrete color indices norm = BoundaryNorm(levels, ncolors=len(cmap.colors), clip=False) if vmin == vmax: pm = ax1.pcolormesh(lon, lat, data2d.mean(dim='time'), cmap=cmap, transform=ccrs.PlateCarree(), shading='auto', rasterized=True) else: pm = ax1.pcolormesh(lon, lat, data2d.mean(dim='time'), cmap=cmap, norm=norm, transform=ccrs.PlateCarree(), shading='auto', rasterized=True) # Add map features #ax.stock_img() ax1.add_feature(cfeature.LAND, facecolor='lightgray') gl = ax1.gridlines(ylocs=range(-90, 90, 30), draw_labels=True) gl.ylocator = mpl.ticker.FixedLocator(range(-90,90,30)) # Add colorbar cb = plt.colorbar(pm, ax=ax1, fraction=0.4, shrink=0.8, label='[yr]') cb.set_label(label=data.units, size=14) cb.ax.tick_params(labelsize=12) plt.tight_layout() #fig, ax = plot_map2d(lon, lat, data2d.mean(dim='time'), proj='PlateCarree', norm=None, cmap=eval(mth_cmap)) ax1.coastlines(resolution='110m') ax1.add_feature(cfeature.LAND, facecolor='lightgray') plt.suptitle(data2d.long_name, y=1.1) # plot 1D timeseries if mth_ts == 'mean': data1d = (data2d*parea).mean(dim=['j', 'i'], keep_attrs=True) / \ parea.mean(dim=['j', 'i']) elif mth_ts == 'sum': data1d = (data2d*parea).sum(dim=['j', 'i'], keep_attrs=True)a /\ parea.sum(dim=['j', 'i']) else: raise ValueError(f'Unsupported timeseries method: {mth_ts}') data1d.attrs = data2d.attrs.copy() ax2 = fig.add_subplot(gs[1]) if data1d.sizes["time"] < 2: ax2.text(0.1, 0.8, (f"global {mth_ts} value: {data1d.values[0]} {data1d.units}")) ax2.text(0.1, 0.6, ("less than 2 time steps.")) ax2.text(0.1, 0.4, ("skipping timeseries plot.")) else: data1d.plot(ax=ax2) plt.show() del data, data2d, data1d del ax1, ax2, pm, cb, gl, fig ------------------ Cell In[6], line 113  data1d = (data2d*parea).sum(dim=['j', 'i'], keep_attrs=True)a /\ ^ SyntaxError: invalid syntax