icenet.plotting package#

Submodules#

icenet.plotting.utils module#

icenet.plotting.utils.broadcast_forecast(start_date: object, end_date: object, datafiles: object = None, dataset: object = None, target: object = None) object[source]#
Parameters:
  • start_date

  • end_date

  • datafiles

  • dataset

  • target

Returns:

icenet.plotting.utils.calculate_extents(x1: int, x2: int, y1: int, y2: int)[source]#
Parameters:
  • x1

  • x2

  • y1

  • y2

Returns:

icenet.plotting.utils.filter_ds_by_obs(ds: object, obs_da: object, forecast_date: str) object[source]#
Parameters:
  • ds

  • obs_da

  • forecast_date – initialisation date of the forecast

Returns:

icenet.plotting.utils.geographic_box(lon_bounds: array, lat_bounds: array, segments: int = 1)[source]#

Rectangular boundary coordinates in lon/lat coordinates.

Parameters:
  • lon_bounds – (min, max) lon values

  • lat_bounds – (min, max) lat values

  • segments – Number of segments per edge

Returns:

(lats, lons) for rectangular boundary region

icenet.plotting.utils.get_bounds(proj=None, pole=1)[source]#

Get min/max bounds for a given CRS projection

icenet.plotting.utils.get_crs(crs_str: str)[source]#

Get Coordinate Reference System (CRS) from string input argument

Parameters:

crs_str – A CRS given as EPSG code (e.g. EPSG:3347 for North Canada) or, a pre-defined Cartopy CRS call (e.g. “PlateCarree”)

icenet.plotting.utils.get_custom_cmap(cmap)[source]#

Creates a new colormap, but with nan set to <0.

Hack since cartopy needs transparency for nan regions to wraparound

correctly with pcolormesh.

icenet.plotting.utils.get_forecast_ds(forecast_file: object, forecast_date: str, stddev: bool = False) object[source]#
Parameters:
  • forecast_file – a path to a .nc file

  • forecast_date – initialisation date of the forecast

  • stddev

Returns tuple(fc_ds, obs_ds, land_mask):

icenet.plotting.utils.get_geoextent_polygon(extent, crs=<Projected CRS: +proj=eqc +ellps=WGS84 +a=6378137.0 +lon_0=0.0 +to ...> Name: unknown Axis Info [cartesian]: - E[east]: Easting (unknown) - N[north]: Northing (unknown) - h[up]: Ellipsoidal height (metre) Area of Use: - undefined Coordinate Operation: - name: unknown - method: Equidistant Cylindrical Datum: Unknown based on WGS 84 ellipsoid - Ellipsoid: WGS 84 - Prime Meridian: Greenwich, n_points=100)[source]#

Create a high-resolution polygon for the boundary.

Increase the number of points to approximate the curved edges Define the number of interpolation points for the curves

icenet.plotting.utils.get_obs_da(hemisphere: str, start_date: str, end_date: str, obs_source: object = './data/osisaf') object[source]#
Parameters:
  • hemisphere – string, typically either ‘north’ or ‘south’

  • start_date

  • end_date

  • obs_source

Returns:

icenet.plotting.utils.get_plot_axes(x1: int = 0, x2: int = 432, y1: int = 0, y2: int = 432, north: bool = True, south: bool = False, geoaxes: bool = True, target_crs: object = None, figsize: int = (10, 8), dpi: int = 150)[source]#
Parameters:
  • x1

  • x2

  • y1

  • y2

  • geoaxes

Returns:

icenet.plotting.utils.get_seas_forecast_da(hemisphere: str, date: str, bias_correct: bool = True, source_path: object = './data/mars.seas') tuple[source]#

Atmospheric model Ensemble 15-day forecast (Set III - ENS)

Coordinates:
  • time (time) datetime64[ns] 2022-04-01 … 2022-0…

  • yc (yc) float64 5.388e+06 … -5.388e+06

  • xc (xc) float64 -5.388e+06 … 5.388e+06

    param hemisphere:

    string, typically either ‘north’ or ‘south’

    param date:

    param bias_correct:

    param source_path:

icenet.plotting.utils.get_seas_forecast_init_dates(hemisphere: str, source_path: object = './data/mars.seas') object[source]#

Obtains list of dates for which we have SEAS forecasts we have.

Parameters:
  • hemisphere – string, typically either ‘north’ or ‘south’

  • source_path – path where north and south SEAS forecasts are stored

Returns:

list of dates

icenet.plotting.utils.pixel_to_projection(pixel_x_min, pixel_x_max, pixel_y_min, pixel_y_max, x_min_proj: float = -5387500, x_max_proj: float = 5387500, y_min_proj: float = -5387500, y_max_proj: float = 5387500, image_width: int = 432, image_height: int = 432)[source]#

Converts pixel coordinates to CRS projection coordinates

icenet.plotting.utils.process_block(block, target_crs)[source]#
icenet.plotting.utils.process_probes(probes, data) tuple[source]#
Parameters:
  • probes – A sequence of locations (pairs)

  • data – A sequence of xr.DataArray

icenet.plotting.utils.process_region(region: tuple = None, data: tuple = None, pole: int = 1, src_da: object = None, region_definition: str = 'pixel') tuple[source]#

Extract subset of pan-Arctic/Antarctic region based on region bounds.

Parameters:
  • region – Either image pixel bounds, or geographic bounds.

  • data – Contains list of xarray DataArrays.

  • region_definition – Whether providing pixel coordinates or geographic (i.e. lon/lat).

Returns:

icenet.plotting.utils.projection_to_geographic_coords(data, target_crs)[source]#
icenet.plotting.utils.reproject_array(array, target_crs)[source]#
icenet.plotting.utils.reproject_projected_coords(data: object, target_crs: object, pole: int = 1) object[source]#

Reprojects an xarray Dataset from LambertAzimuthalEqualArea to target_crs.

The Dataset is expected to have dims of (xc, yc).

Parameters:
  • data – xarray dataset with dims (xc, yc), and also coords of lon and lat.

  • target_crs – Cartopy CRS to project to (e.g. ccrs.Mercator())

  • pole – Whether north (1) or south pole (-1).

Returns:

Reprojected data as an xarray dataset.

Examples:

>>> reprojected_data = reproject_projected_coords(arr,
>>>             target_crs=target_crs,
>>>             pole=pole,
>>>             )
icenet.plotting.utils.set_ffmpeg_path()[source]#

Set Matplotlib’s ffmpeg exe path to the one from imageio_ffmpeg

icenet.plotting.utils.set_plot_geoaxes(ax, region_definition: str = None, extent: list = None, coastlines: str = None, gridlines: bool = False, north: bool = True, south: bool = False)[source]#
icenet.plotting.utils.set_plot_geoextent(ax, extent, crs=<Projected CRS: +proj=eqc +ellps=WGS84 +a=6378137.0 +lon_0=0.0 +to ...> Name: unknown Axis Info [cartesian]: - E[east]: Easting (unknown) - N[north]: Northing (unknown) - h[up]: Ellipsoidal height (metre) Area of Use: - undefined Coordinate Operation: - name: unknown - method: Equidistant Cylindrical Datum: Unknown based on WGS 84 ellipsoid - Ellipsoid: WGS 84 - Prime Meridian: Greenwich, n_points=100)[source]#

Create a high-resolution polygon for the boundary

icenet.plotting.utils.show_img(ax, arr, x1: int = 0, x2: int = 432, y1: int = 0, y2: int = 432, cmap: object = None, geoaxes: bool = True, vmin: float = 0.0, vmax: float = 1.0, north: bool = True, south: bool = False, crs: object = None, extents: list = None)[source]#
Parameters:
  • ax

  • arr

  • x1

  • x2

  • y1

  • y2

  • cmap

  • geoaxes

  • vmin

  • vmax

  • north

  • south

Returns:

icenet.plotting.video module#

icenet.plotting.video.cli_args()[source]#
Returns:

icenet.plotting.video.data_cli()[source]#
icenet.plotting.video.get_dataarray_from_files(files: object, numpy: bool = False) object[source]#
Parameters:
  • files

  • numpy

Returns:

icenet.plotting.video.recurse_data_folders(base_path: object, lookups: object, children: object, filetype: str = 'nc') object[source]#
Parameters:
  • base_path

  • lookups

  • children

  • filetype

Returns:

icenet.plotting.video.video_process(files: object, numpy: object, output_dir: object, fps: int) object[source]#
Parameters:
  • files

  • numpy

  • output_dir

  • fps

Returns:

icenet.plotting.video.xarray_to_video(da: object, fps: int, video_path: object = None, reproject: bool = False, north: bool = True, south: bool = False, extent: tuple = None, region_definition: str = 'pixel', coastlines: str = 'default', gridlines: bool = False, target_crs: object = None, transform_crs: object = None, mask: object = None, mask_type: str = 'contour', clim: object = None, crop: object = None, data_type: str = 'abs', video_dates: object = None, cmap: object = <matplotlib.colors.ListedColormap object>, figsize: tuple = (10, 8), dpi: int = 150, imshow_kwargs: dict = None, ax_init: object = None, ax_extra: callable = None, colorbar_label: str = '') object[source]#

Generate video of an xarray.DataArray. Optionally input a list of video_dates to show, otherwise the full set of time coordiantes of the dataset is used.

Parameters:
  • da – Dataset to create video of.

  • video_path – Path to save the video to.

  • fps – Frames per second of the video.

  • mask – Boolean mask with True over masked elements to overlay

as a contour or filled contour. Defaults to None (no mask plotting). :param mask_type: ‘contour’ or ‘contourf’ dictating whether the mask is overlaid as a contour line or a filled contour. :param data_type: ‘abs’ or ‘anom’ describing whether the data is in absolute or anomaly format. If anomaly, the colorbar is centred on 0. :param video_dates: List of Pandas Timestamps or datetime.datetime objects to plot video from the dataset. :param crop: [(a, b), (c, d)] to crop the video from a:b and c:d :param clim: Colormap limits. Default is None, in which case the min and max values of the array are used. :param cmap: Matplotlib colormap object. :param figsize: Figure size in inches. :param dpi: Figure DPI. :param imshow_kwargs: Extra arguments for displaying array :param ax_init: pre-initialised axes object for display :param ax_extra: Extra method called with axes for additional plotting

Module contents#