Skip to content

Earth Science Tools

These are a few simple tools that can be helpful with dealing spatial-temporal aware datasets in particular from the xarray package. These xr.Datasets are in the format (lat x lon x time x variable) and many times we just need X and y. There are a few useful functions in here that will help getting coverting that data into useful arrays for processing.


Key Helpful Functions

Density Cubes

We can extract 'density cubes' which transform point estimates to estimates with spatial and temporal features. It is like a sliding window except in lat-lon-time space. Very useful when attempted to get do density estimation. A demo notebook can be found here.

Regrid Function

Utilizing the xESMF package, we can regrid datasets based on a reference dataset. Very useful when we don't have datasets with the same spatial dimensions.

ShapeFile Masks

This has various functions to allows one to use shapefiles to mask datasets. I have only a few sample functions that parse shape files of interest like countries or US states. But it is flexible enough to use other interesting attributes like population. We only need the raster functions. A demo notebook can be found here.

Useful Resources

Manipulating ShapeFiles

  • RegionMask > Some additional functionality for having specialized regions.
  • Shapely > The original library which allows one parse shapefiles in an efficient way.
  • Affine > The package used to do the tranformation of the polygons to the lat,lon coordinates.
  • Rasterio > Very powerful python package that is really good at transforming the coordinates of your datasets. See Gonzalo's tutorial for a more specific usecase.

Visualization

  • xarray > The xarray docs have a few examples for how one can plot.
  • geopandas > This package handles polygons and I have found that it's really good for plotting polygons out-of-the-box.
  • cartopy > A package that handles all of the projections needed for better visualizations of the globe. Works well with geopandas and xarray.
  • folium > This is the first of the packages on this list that starts to utilize javascript under the hood. This one is particularly nice for things to do with maps and polygons.
  • hvplot > A nice package that offers a higher level API to the Bokeh library. It allows you do do quite a lot of interactive plots. They have some tutorials for geographic data whether it be polygons or gridded data.
  • holoviews > This has been recommended for large scale datasets with millions of points! They have some tutorials for polygons and xarray grids.
  • Maps in Scientific Python > A great tutorial by Rabernat