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’) ..
Category : Python
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 ..
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 = ..
The following python program show you the method to draw a rectangular area in a map and mark state or province name on the map. Answer to other questions: How to add ocean, lake, river, coastline, province border to map? How to set map extent? How to set xtick or ytick intervals? # Ignore warnings ..
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 ..
conda create –name pygdal conda activate pygdal conda install -c conda-forge gdal #from osgeo import gdal #to make jupyter server work pip install –upgrade jupyterhub pip install –upgrade nbconvert conda install -c conda-forge notebook conda install -c conda-forge jupyter_contrib_nbextensions # install cartopy conda install -c conda-forge cartopy #install rasterio for reading tiff file conda install ..
Ignore warnings # Ignore warnings import sys import warnings if not sys.warnoptions: warnings.simplefilter(‘ignore’) Ignore some errors # function FN does not work when there are nan in X try: mktest=FN(X) trend=mktest except: trend=np.nan From my original code:Indexes_ERA5_GreatLakesRegion_sens_s..