API reference

Here we will add the documentation for selected modules.

Grid

Grid

A structured grid on a map projection.

Grid attributes

Grid.proj

pyproj.Proj instance defining the grid’s map projection.

Grid.nx

number of grid points in the x direction.

Grid.ny

number of grid points in the y direction.

Grid.dx

x grid spacing (always positive).

Grid.dy

y grid spacing (positive if ll_corner, negative if ul_corner).

Grid.x0

X reference point in projection coordinates.

Grid.y0

Y reference point in projection coordinates.

Grid.origin

'upper-left' or 'lower-left'.

Grid.pixel_ref

if coordinates are at the 'center' or 'corner' of the grid.

Grid.x_coord

x coordinates of the grid points (1D, no mesh)

Grid.y_coord

y coordinates of the grid points (1D, no mesh)

Grid.xy_coordinates

Tuple of x, y coordinates of the grid points.

Grid.ll_coordinates

Tuple of longitudes, latitudes of the grid points.

Grid.xstagg_xy_coordinates

Tuple of x, y coordinates of the X staggered grid.

Grid.ystagg_xy_coordinates

Tuple of x, y coordinates of the Y staggered grid.

Grid.xstagg_ll_coordinates

Tuple of longitudes, latitudes of the X staggered grid.

Grid.ystagg_ll_coordinates

Tuple of longitudes, latitudes of the Y staggered grid.

Grid.center_grid

salem.Grid instance representing the grid in center coordinates.

Grid.corner_grid

salem.Grid instance representing the grid in corner coordinates.

Grid.extent

[left, right, bottom, top] boundaries of the grid in the grid’s projection.

Grid methods

Grid.extent_in_crs

Get the extent of the grid in a desired crs.

Grid.ij_to_crs

Converts local i, j to cartesian coordinates in a specified crs

Grid.almost_equal

A less strict comparison between grids.

Grid.region_of_interest

Computes a region of interest (ROI).

Grid.regrid

Make a copy of the grid with an updated spatial resolution.

Grid.transform

Converts any coordinates into the local grid.

Grid.map_gridded_data

Reprojects any structured data onto the local grid.

Grid.grid_lookup

Performs forward transformation of any other grid into self.

Grid.lookup_transform

Performs the forward transformation of gridded data into self.

Grid.to_dict

Serialize this grid to a dictionary.

Grid.from_dict

Create a Grid from a dictionary

Grid.to_json

Serialize this grid to a json file.

Grid.from_json

Create a Grid from a json file

Grid.to_dataset

Creates an empty dataset based on the Grid’s geolocalisation.

Grid.to_geometry

Makes a geometrical representation of the grid (e.g.

Georeferencing utils

check_crs

Checks if the crs represents a valid grid, projection or ESPG string.

proj_is_same

Checks is two pyproj projections are equal.

proj_to_cartopy

Converts a pyproj.Proj to a cartopy.crs.Projection

transform_proj

Wrapper around the pyproj.transform function.

transform_geometry

Reprojects a shapely geometry.

transform_geopandas

Reprojects a geopandas dataframe.

mercator_grid

Local (transverse) mercator map centered on a specified point.

grid_from_dataset

Find out if the dataset contains enough info for Salem to understand.

reduce

Reduces an array’s size by a given factor.

Graphics

DataLevels

Assigns the right color to your data.

Map

Plotting georeferenced data.

get_cmap

Get a colormap from mpl, and also those defined by Salem.

Map & DataLevels methods

DataLevels.append_colorbar

Appends a colorbar to existing axes

DataLevels.colorbarbase

Returns a ColorbarBase to add to the cax axis.

DataLevels.set_cmap

Set a colormap.

DataLevels.set_data

Any kind of data array (also masked).

DataLevels.set_plot_params

Shortcut to all parameters related to the plot.

DataLevels.set_extend

Colorbar extensions: ‘neither’ | ‘both’ | ‘min’ | ‘max’

DataLevels.set_levels

Levels you define.

DataLevels.set_nlevels

Automatic N levels.

DataLevels.set_vmax

Maximum level value.

DataLevels.set_vmin

Mininum level value.

DataLevels.visualize

Quick plot, useful for debugging.

DataLevels.plot

Add a kind of plot of the data to an axis.

Map methods

Map.set_data

Adds data to the plot.

Map.set_contour

Adds data to contour on the map.

Map.set_contourf

Adds data to contourfill on the map.

Map.set_geometry

Adds any Shapely geometry to the map.

Map.set_lonlat_contours

Add longitude and latitude contours to the map.

Map.set_points

Shortcut for set_geometry() accepting coordinates as input.

Map.set_rgb

Manually force to a rgb img

Map.set_shapefile

Add a shapefile to the plot.

Map.set_text

Add a text to the map.

Map.set_topography

Add topographical shading to the map.

Map.set_scale_bar

Add a legend bar showing the scale to the plot.

Map.transform

Get a matplotlib transform object for a given reference system

Map.visualize

Quick plot, useful for debugging.

Map.plot

Add the map plot to an axis.

Input/output

get_demo_file

Returns the path to the desired demo file.

read_shapefile

Reads a shapefile using geopandas.

read_shapefile_to_grid

Same as read_shapefile but directly transformed to a grid.

xarray

open_xr_dataset

Thin wrapper around xarray’s open_dataset.

open_metum_dataset

Wrapper to Met Office Unified Model files (experimental)

open_wrf_dataset

Wrapper around xarray’s open_dataset to make WRF files a bit better.

open_mf_wrf_dataset

Open multiple WRF files as a single WRF dataset.

xarray accessors

Salem adds accessors to xarray objects. They can be accessed via the .salem attribute and add the following methods:

DataArray

DataArrayAccessor.subset

Get a subset of the dataset.

DataArrayAccessor.roi

Make a region of interest (ROI) for the dataset.

DataArrayAccessor.transform

Reprojects an other Dataset or DataArray onto self.

DataArrayAccessor.lookup_transform

Reprojects an other Dataset or DataArray onto self using the forward tranform lookup.

DataArrayAccessor.cartopy

Get a cartopy.crs.Projection for this dataset.

DataArrayAccessor.get_map

Make a salem.Map out of the dataset.

DataArrayAccessor.quick_map

Make a plot of the DataArray.

DataArrayAccessor.interpz

Interpolates the array along the vertical dimension

DataArrayAccessor.deacc

De-accumulates the variable (i.e.

Dataset

DatasetAccessor.subset

Get a subset of the dataset.

DatasetAccessor.roi

Make a region of interest (ROI) for the dataset.

DatasetAccessor.transform

Reprojects an other Dataset or DataArray onto self.

DatasetAccessor.lookup_transform

Reprojects an other Dataset or DataArray onto self using the forward tranform lookup.

DatasetAccessor.transform_and_add

Reprojects an other Dataset and adds it’s content to the current one.

DatasetAccessor.cartopy

Get a cartopy.crs.Projection for this dataset.

DatasetAccessor.get_map

Make a salem.Map out of the dataset.

DatasetAccessor.quick_map

Make a plot of a variable of the DataSet.

DatasetAccessor.wrf_zlevel

Interpolates to a specified height above sea level.

DatasetAccessor.wrf_plevel

Interpolates to a specified pressure level (hPa).

Old-style datasets

Old-style Datasets (prior to xarray), kept for backwards compatibility reasons and because they are quite lightweight. They might be replaced by xarray’s datasets one day.

GeoDataset

Interface for georeferenced datasets.

GeoTiff

Geolocalised tiff images (needs rasterio).

GeoNetcdf

NetCDF files with geolocalisation info.

WRF

WRF proof-of-concept template.

GoogleCenterMap

Google static map centered on a point.

GoogleVisibleMap

Google static map automatically sized and zoomed to a selected region.

Other

geogrid_simulator

Emulates geogrid.exe, which is useful when defining new WRF domains.