The following example is to find latitude and longitude of a city from the data worldcities (https://datahub.io/core/world-cities) and then based on the latitude and longitude to slice data from era5 data of this city. It also can be used to find data from other source spatial data. Answer other questions: How to read netcdf file ..
Tag : howto
The global historical climate network daily data (ghcnd) is the widely used global climate data for all purposes. However, the data size is huge. If you only want to use data from a certain area, your best bet is to find the site information first, and then download the data for those weather stations directly. ..
We often use running averages to remove noise from time series. Below is a simple python code to do this easily. import numpy as np from numpy import random import matplotlib.pyplot as plt # your data data = random.random(size=(1,100)) # set window kernel_size = 10 # window width is 10 # set weight, you can ..
Xarray data is often used in huge spatial datasets. We often need to fetch data in subregions. The following example shows you how to extract subset data from a large xarray. import numpy as np import xarray as xr #set the sub domain box min_lon = 100 min_lat = 20 max_lon = 150 max_lat = ..
The example provided here is to read a geotiff file; get data in the box and convert it to an array; get the corresponding latitude and longitude of the box. import numpy as np import rasterio import rasterio.plot #!pip install geotiff #https://pypi.org/project/geotiff/ from geotiff import GeoTiff # use rasterio to read geotiff file data_name = ..
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 ..
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..
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) ..
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..
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 ..