Category : Numpy

If you have grid or point data and polygon shapefiles for longitude and longitude. Using geopandas and shapely it’s easy to find grids or points in specific polygons. import geopandas as gpd import pandas as pd import numpy as np import matplotlib.pyplot as plt from shapely.geometry import Point # US state polygon shape file US_states=gpd.GeoDataFrame.from_file(‘states_province_shapefile\cb_2018_us_state_20m\cb_2018_us_state_20m.shp’) ..

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

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

This example is used for fitting world covid-19 cases number import numpy as np import pandas as pd from datetime import datetime from lmfit import Minimizer, Parameters, report_fit import chart_studio.plotly as py import cufflinks as cf def Cauchy_cumulative_hazard_fit(x,loc,scale,decaybase): decayterm=np.power(decaybase,(x-loc)) decayterm[np.whe..

Read more