We often need to draw multiple similar maps using the same colorbar. A good way is to use the AxesGrid from the Cartopy package. Below is one of my examples of sharing colorbars for 4 submaps. This example can also answer other questions: How to add ocean, river, lakes,coastline and province border to a map? ..
Category : AI
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’) ..
The ISIMIP data is widely used in climate change impact analysis. The data is in netcdf format, and the amount of data is very large. There are many files to download. Using wget and the ISIMIP interface, it’s easy to download the file you want. First, use the ISIMIP interface to select the file and ..
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 ..