set_data

MapsGrid.set_data(data=None, x=None, y=None, crs=None, encoding=None, cpos='c', cpos_radius=None, parameter=None)

This will execute the corresponding action on ALL Maps objects of the MapsGrid!

Set the properties of the dataset you want to plot.

Use this function to update multiple data-specs in one go Alternatively you can set the data-specifications via

>>> m.data_specs.< property > = ...`
Parameters:
  • data (array-like) –

    The data of the Maps-object. Accepted inputs are:

    • a pandas.DataFrame with the coordinates and the data-values

    • a pandas.Series with only the data-values

    • a 1D or 2D numpy-array with the data-values

    • a 1D list of data values

  • x (array-like or str, optional) –

    Specify the coordinates associated with the provided data. Accepted inputs are:

    • a string (corresponding to the column-names of the pandas.DataFrame)

      • ONLY if “data” is provided as a pandas.DataFrame!

    • a pandas.Series

    • a 1D or 2D numpy-array

    • a 1D list

    The default is “lon” and “lat”.

  • y (array-like or str, optional) –

    Specify the coordinates associated with the provided data. Accepted inputs are:

    • a string (corresponding to the column-names of the pandas.DataFrame)

      • ONLY if “data” is provided as a pandas.DataFrame!

    • a pandas.Series

    • a 1D or 2D numpy-array

    • a 1D list

    The default is “lon” and “lat”.

  • crs (int, dict or str) –

    The coordinate-system of the provided coordinates. Can be one of:

    • PROJ string

    • Dictionary of PROJ parameters

    • PROJ keyword arguments for parameters

    • JSON string with PROJ parameters

    • CRS WKT string

    • An authority string [i.e. ‘epsg:4326’]

    • An EPSG integer code [i.e. 4326]

    • A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)]

    • An object with a to_wkt method.

    • A pyproj.crs.CRS class

    (see pyproj.CRS.from_user_input for more details)

    The default is 4326 (e.g. geographic lon/lat crs)

  • parameter (str, optional) –

    MANDATORY IF a pandas.DataFrame that specifies both the coordinates and the data-values is provided as data!

    The name of the column that should be used as parameter.

    If None, the first column (despite of the columns assigned as “x” and “y”) will be used. The default is None.

  • encoding (dict or False, optional) –

    A dict containing the encoding information in case the data is provided as encoded values (useful to avoid decoding large integer-encoded datasets).

    If provided, the data will be decoded “on-demand” with respect to the provided “scale_factor” and “add_offset” according to the formula:

    >>> actual_value = encoding["add_offset"] + encoding["scale_factor"] * value
    

    Note: Colorbars and pick-callbakcs will use the encoding-information to display the actual data-values!

    If False, no value-transformation is performed. The default is False

  • cpos (str, optional) – Indicator if the provided x-y coordinates correspond to the center (“c”), upper-left corner (“ul”), lower-left corner (“ll”) etc. of the pixel. If any value other than “c” is provided, a “cpos_radius” must be set! The default is “c”.

  • cpos_radius (int or tuple, optional) – The pixel-radius (in the input-crs) that will be used to set the center-position of the provided data. If a number is provided, the pixels are treated as squares. If a tuple (rx, ry) is provided, the pixels are treated as rectangles. The default is None.

Examples

  • using a single pandas.DataFrame

    >>> data = pd.DataFrame(dict(lon=[...], lat=[...], a=[...], b=[...]))
    >>> m.set_data(data, x="lon", y="lat", parameter="a", crs=4326)
    
  • using individual pandas.Series

    >>> lon, lat, vals = pd.Series([...]), pd.Series([...]), pd.Series([...])
    >>> m.set_data(vals, x=lon, y=lat, crs=4326)
    
  • using 1D lists

    >>> lon, lat, vals = [...], [...], [...]
    >>> m.set_data(vals, x=lon, y=lat, crs=4326)
    
  • using 1D or 2D numpy.arrays

    >>> lon, lat, vals = np.array([[...]]), np.array([[...]]), np.array([[...]])
    >>> m.set_data(vals, x=lon, y=lat, crs=4326)
    
  • integer-encoded datasets

    >>> lon, lat, vals = [...], [...], [1, 2, 3, ...]
    >>> encoding = dict(scale_factor=0.01, add_offset=1)
    >>> # colorbars and pick-callbacks will now show values as (1 + 0.01 * value)
    >>> # e.g. the "actual" data values are [0.01, 0.02, 0.03, ...]
    >>> m.set_data(vals, x=lon, y=lat, crs=4326, encoding=encoding)