Tag : howto

My example of Python code for mapping variables overlay with geographic information. Elements in the map include ocean, coastline,borders,lakes,rivers,province borders, contour, contourf, pcolormesh, scatter, labels, province (or state) names. Also includes information about how to set cmap, what range of the data (minimum, maximum) to show, how many levels to display the data. How to ..

Read more

Method to write and read a single N-Dimension numpy array to a .npy file. Sample code import numpy as np #write a 3-dimension varaible trend38 np.save(‘indexes_trend38_sens_slope.npy’,trend38) #read the 3-dimention variable to trend38 (use different name is ok) trend38=np.load(‘indexes_trend38_sens_slope.npy’) My original full version code:Indexes_ERA5_GreatLakesRegion_sens_s..

Read more

Add multiple variables with the same dimension to an existing nc file. Read the target nc file and include the new variables into the file and save to the new file. Sample code import xarray as xr #read nc file fn1 = ‘Annual_average_temperature.nc’ TxTn90p10p=xr.open_dataset(fn1) #add new variables TxTn90p10p[‘TX90p’]=xr.DataArray(TX90p.astype(np.float32), coords=TxTn90p10p.coords, dims=TxTn90p10p.t2m.dims, attrs=TxTn90p10p.attrs) TxTn90p10p[‘TX10p’]=xr.DataArray(TX10p.astype(np.float32), coords=TxTn90p10p.coords, dims=TxTn90p10p.t2m.dims, attrs=TxTn90p10p.attrs) ..

Read more

pr_data[‘PrTot’]=xr.DataArray(PrTot.astype(np.float32), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘R1mm’]=xr.DataArray(R1mm.astype(np.int16), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘R10mm’]=xr.DataArray(R10mm.astype(np.int16), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘R20mm’]=xr.DataArray(R20mm.astype(np.int16), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘SDII’]=xr.DataArray(SDII.astype(np.float32), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘Rx1day’]=xr.DataArray(Rx1day.astype(np.float32), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘Rx5day’]=xr.DataArray(Rx5day.astype(np.float32), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) See example code: /media/Data1/OnClimate/Precipitation_indexes_EAR5_GreatLakesRegion.ipynb Pay attention to line: dims=pr_dat..

Read more

Introduction This article includes some Python functions for calculating the core climate extreme index. I post them here for my future reference, and share them with people who are interested in python or climate change. No guarantee of accuracy. The definitions of the core climate extreme indices 1.Description of Climate Extreme Indexes by OCDP 2.Definitions ..

Read more