calculate_extent

mcalf.utils.plot.calculate_extent(shape, resolution, offset=(0, 0), ax=None, dimension=None, **kwargs)[source]

Calculate the extent from a particular data shape and resolution.

This function assumes a lower origin is being used with matplotlib.

Parameters
  • shape (tuple[int]) – Shape (y, x) of the numpy.ndarray of the data being plotted. First integer corresponds to the y-axis and the second integer is for the x-axis.

  • resolution (tuple[float] or astropy.units.quantity.Quantity) – A 2-tuple (x, y) containing the length of each pixel in the x and y direction respectively. If a value has type astropy.units.quantity.Quantity, its axis label will include its attached unit, otherwise the unit will default to Mm. The ax parameter must be specified to set its labels. If resolution is None, this function will immediately return None.

  • offset (tuple[float] or int, length=2, optional, default=(0, 0)) – Two offset values (x, y) for the x and y axis respectively. Number of pixels from the 0 pixel to the first pixel. Defaults to the first pixel being at 0 length units. For example, in a 1000 pixel wide dataset, setting offset to -500 would place the 0 Mm location at the centre.

  • ax (matplotlib.axes.Axes, optional, default=None) – Axes into which axis labels will be plotted. Defaults to not printing axis labels.

  • dimension (str or tuple[str] or list[str], length=2, optional, default=None) – If an ax (and resolution) is provided, use this string as the dimension name that appears before the (unit) in the axis label. A 2-tuple (x, y) or list [x, y] can instead be given to provide a different name for the x-axis and y-axis respectively. Defaults is equivalent to dimension=('x-axis', 'y-axis').

  • **kwargs (dict, optional) – Extra keyword arguments to pass to calculate_axis_extent().

Returns

extent – The extent value that will be passed to matplotlib functions with a lower origin. Will return None if resolution is None.

Return type

tuple[float], length=4