polartoolkit.profiles
=====================

.. py:module:: polartoolkit.profiles


Attributes
----------

.. autoapisummary::

   polartoolkit.profiles.display
   polartoolkit.profiles.ipyleaflet


Functions
---------

.. autoapisummary::

   polartoolkit.profiles.create_profile
   polartoolkit.profiles.sample_grids
   polartoolkit.profiles.fill_nans
   polartoolkit.profiles.shorten
   polartoolkit.profiles.make_data_dict
   polartoolkit.profiles.default_layers
   polartoolkit.profiles.default_data
   polartoolkit.profiles.plot_profile
   polartoolkit.profiles.plot_data
   polartoolkit.profiles.relative_dist
   polartoolkit.profiles.cumulative_dist
   polartoolkit.profiles.draw_lines


Module Contents
---------------

.. py:data:: display
   :value: None


.. py:data:: ipyleaflet
   :value: None


.. py:function:: create_profile(method, start = None, stop = None, num = None, shapefile = None, polyline = None, **kwargs)

   Create a pandas DataFrame of points along a line with multiple methods.

   :param method: Choose sampling method, either "points", "shapefile", or "polyline"
   :type method: str
   :param start: Coordinates for starting point of profile, by default None
   :type start: tuple[float, float], optional
   :param stop: Coordinates for ending point of profile, by default None
   :type stop: tuple[float, float], optional
   :param num: Number of points to sample at, for "points" by default is 100, for other methods
               num by default is determined by shapefile or dataframe
   :type num: int, optional
   :param shapefile: shapefile file name to create points along, by default None
   :type shapefile: str, optional
   :param polyline: pandas dataframe with columns x and y as vertices of a polyline, by default None
   :type polyline: pandas.DataFrame, optional

   :returns: Dataframe with 'easting', 'northing', and 'dist' columns for points along line
             or shapefile path.
   :rtype: pandas.DataFrame


.. py:function:: sample_grids(df, grid, sampled_name, **kwargs)

   Sample data at every point along a line

   :param df: Dataframe containing columns 'easting', 'northing', or columns with names
              defined by kwarg "coord_names".
   :type df: pandas.DataFrame
   :param grid: Grid to sample, either file name or xarray.DataArray
   :type grid: str or xarray.DataArray
   :param sampled_name: Name for sampled column
   :type sampled_name: str,

   :returns: Dataframe with new column (sampled_name) of sample values from (grid)
   :rtype: pandas.DataFrame


.. py:function:: fill_nans(df)

   Fill NaN's in sampled layer with values from above layer.

   :param df: First 3 columns as they are assumed to by x, y, dist.
   :type df: pandas.DataFrame

   :returns: Dataframe with NaN's of lower layers filled
   :rtype: pandas.DataFrame


.. py:function:: shorten(df, max_dist = None, min_dist = None)

   Shorten a dataframe at either end based on distance column.

   :param df: Dataframe to shorten and recalculate distance, must contain 'easting',
              'northing', 'dist'
   :type df: pandas.DataFrame
   :param max_dist: remove rows with dist>max_dist, by default None
   :type max_dist: float, optional
   :param min_dist: remove rows with dist<min_dist, by default None
   :type min_dist: float, optional

   :returns: Shortened dataframe
   :rtype: pandas.DataFrame


.. py:function:: make_data_dict(names, grids, colors, axes = None)

   Create nested dictionary of data and attributes

   :param names: data names
   :type names: list[str]
   :param grids: files or xarray.DataArray's
   :type grids: list[str or xarray.DataArray]
   :param colors: colors to plot data
   :type colors: list[str]
   :param axes: y axes to use for each data. By default all data are on axis 0. Only 0 and 1 are
                used, if you supply values > 1, they will use the same axis as 1.
   :type axes: list[int]

   :returns: Nested dictionaries of grids and attributes
   :rtype: dict[dict]


.. py:function:: default_layers(version, hemisphere = None, reference = None, region = None, spacing = None)

   Fetch default ice surface, ice base, and bed layers.

   :param version: choose between 'bedmap2', 'bedmap3', and 'bedmachine' layers for Antarctica, and
                   just 'bedmachine' Greenland
   :type version: str
   :param hemisphere: choose between plotting in the "north" or "south" hemispheres, by default None
   :type hemisphere: str, optional
   :param reference: choose between 'ellipsoid', 'eigen-6c4' or 'eigen-gl04c' (only for bedmap),
                     for an elevation reference frame, by default None
   :type reference: str, optional
   :param region: region to subset grids by, in format [xmin, xmax, ymin, ymax], by default None
   :type region: tuple[float], optional
   :param spacing: grid spacing to resample the grids to, by default None
   :type spacing: float, optional

   :returns: Nested dictionary of earth layers and attributes
   :rtype: dict[str, dict[str, str | xarray.DataArray]]


.. py:function:: default_data(region = None, hemisphere = None, verbose = 'q')

   Fetch default gravity and magnetic datasets.

   :param region: region to subset grids by, in format [xmin, xmax, ymin, ymax], by default None
   :type region: tuple[float, float, float, float], optional
   :param hemisphere: choose between plotting in the "north" or "south" hemispheres, by default None
   :type hemisphere: str, optional

   :returns: Nested dictionary of data and attributes
   :rtype: dict[typing.Any, typing.Any]


.. py:function:: plot_profile(method, layers_dict = None, data_dict = None, add_map = False, layers_version = None, fig_height = 9, fig_width = 14, hemisphere = None, **kwargs)

   Show sampled layers and/or data on a cross section, with an optional location map.

   :param method: Choose sampling method, either "points", "shapefile", or "polyline"
   :type method: str
   :param layers_dict: nested dictionary of layers to include in cross-section, construct with
                       `profiles.make_data_dict`, by default is Bedmap2 layers.
   :type layers_dict: dict, optional
   :param data_dict: nested dictionary of data to include in option graph, construct with
                     `profiles.make_data_dict`, by default is gravity and magnetic anomalies.
   :type data_dict: dict, optional
   :param add_map: Choose whether to add a location map, by default is False.
   :type add_map: bool
   :param layers_version: choose between using 'bedmap2' or 'bedmachine' layers, by default is Bedmap2,
                          unless plotting for Greenland, then it is Bedmachine.
   :type layers_version: str, optional
   :param fig_height: Set the height of the figure (excluding the map) in cm, by default is 9.
   :type fig_height: float, optional
   :param fig_width: Set the width of the figure (excluding the map) in cm, by default is 14.
   :type fig_width: float, optional
   :param hemisphere: choose between plotting in the "north" or "south" hemispheres, by default None
   :type hemisphere: str, optional

   :keyword fillnans: Choose whether to fill nans in layers, defaults to True.
   :kwtype fillnans: bool
   :keyword num: Number of points to sample at along a line.
   :kwtype num: int
   :keyword max_dist: Clip all distances greater than.
   :kwtype max_dist: int
   :keyword min_dist: Clip all distances less than.
   :kwtype min_dist: int
   :keyword map_background: Change the map background by passing a filename string or grid, by default is
                            imagery.
   :kwtype map_background: str or xarray.DataArray
   :keyword map_cmap: Change the map colorscale by passing a valid GMT cmap string, by default is
                      'viridis'.
   :kwtype map_cmap: str
   :keyword map_buffer: Change map zoom as relative percentage of profile length (0-1), by default is
                        0.3.
   :kwtype map_buffer: float
   :keyword layer_buffer: Change vertical white space within cross-section (0-1), by default is 0.1.
   :kwtype layer_buffer: float
   :keyword data_buffer: Change vertical white space within data graph (0-1), by default is 0.1.
   :kwtype data_buffer: float
   :keyword layers_legend_loc: Change the legend location with a GMT position string, by default is
                               "JBR+jBL+o0c".
   :kwtype layers_legend_loc: str
   :keyword data_legend_loc: Change the legend location with a GMT position string, by default is
                             "JBR+jBL+o0c".
   :kwtype data_legend_loc: str
   :keyword layers_legend_columns: Change the number of columns in the legend, by default is 1.
   :kwtype layers_legend_columns: int
   :keyword inset: choose to plot inset map showing figure location, by default is True
   :kwtype inset: bool
   :keyword inset_position: position for inset map with PyGMT syntax, by default is "jTL+jTL+o0/0"
   :kwtype inset_position: str
   :keyword save: Choose to save the image, by default is False.
   :kwtype save: bool
   :keyword path: Filename for saving image, by default is None.
   :kwtype path: str

   :returns: * **fig** (*pygmt.Figure*) -- a PyGMT figure object with the cross-section and data plotted.
             * **df_layers** (*pd.DataFrame*) -- DataFrame with sampled layers along the cross-section.
             * **df_data** (*pd.DataFrame*) -- DataFrame with sampled data along the cross-section, if data_dict is None,
               this will be an empty DataFrame.


.. py:function:: plot_data(method, data_dict = None, add_map = False, fig_height = 9, fig_width = 14, hemisphere = None, **kwargs)

   Show sampled data on a cross section, with an optional location map.

   :param method: Choose sampling method, either "points", "shapefile", or "polyline"
   :type method: str
   :param data_dict: nested dictionary of data to include in option graph, construct with
                     `profiles.make_data_dict`, by default is gravity and magnetic anomalies.
   :type data_dict: dict, optional
   :param add_map: Choose whether to add a location map, by default is False.
   :type add_map: bool
   :param fig_height: Set the height of the figure (excluding the map) in cm, by default is 9.
   :type fig_height: float, optional
   :param fig_width: Set the width of the figure (excluding the map) in cm, by default is 14.
   :type fig_width: float, optional
   :param hemisphere: choose between plotting in the "north" or "south" hemispheres, by default None
   :type hemisphere: str, optional

   :keyword num: Number of points to sample at along a line.
   :kwtype num: int
   :keyword max_dist: Clip all distances greater than.
   :kwtype max_dist: int
   :keyword min_dist: Clip all distances less than.
   :kwtype min_dist: int
   :keyword map_background: Change the map background by passing a filename string or grid, by default is
                            imagery.
   :kwtype map_background: str or xarray.DataArray
   :keyword map_cmap: Change the map colorscale by passing a valid GMT cmap string, by default is
                      'viridis'.
   :kwtype map_cmap: str
   :keyword map_buffer: Change map zoom as relative percentage of profile length (0-1), by default is
                        0.3.
   :kwtype map_buffer: float
   :keyword data_buffer: Change vertical white space within data graph (0-1), by default is 0.1.
   :kwtype data_buffer: float
   :keyword data_legend_loc: Change the legend location with a GMT position string, by default is
                             "JBR+jBL+o0c".
   :kwtype data_legend_loc: str
   :keyword inset: choose to plot inset map showing figure location, by default is True
   :kwtype inset: bool
   :keyword inset_position: position for inset map with PyGMT syntax, by default is "jTL+jTL+o0/0"
   :kwtype inset_position: str
   :keyword save: Choose to save the image, by default is False.
   :kwtype save: bool
   :keyword path: Filename for saving image, by default is None.
   :kwtype path: str

   :returns: * **fig** (*pygmt.Figure*) -- a PyGMT figure object with the profile data plotted.
             * **df_data** (*pd.DataFrame*) -- DataFrame with sampled data along the cross-section, if data_dict is None,
               this will be an empty DataFrame.


.. py:function:: relative_dist(df, reverse = False)

   calculate distance between x,y points in a dataframe, relative to the previous row.

   :param df: Dataframe containing columns x and y in meters.
   :type df: pandas.DataFrame
   :param reverse: choose whether to reverse the profile, by default is False
   :type reverse: bool, optional,

   :returns: Returns original dataframe with additional column rel_dist
   :rtype: pandas.DataFrame


.. py:function:: cumulative_dist(df, **kwargs)

   calculate cumulative distance of points along a line.

   :param df: Dataframe containing columns x, y, and rel_dist
   :type df: pandas.DataFrame

   :returns: Returns original dataframe with additional column dist
   :rtype: pandas.DataFrame


.. py:function:: draw_lines(**kwargs)

   Plot an interactive map, and use the "Draw a Polyline" button to create vertices of
   a line. Vertices will be returned as the output of the function.

   :returns: Returns a list of list of vertices for each polyline in lat long.
   :rtype: list[typing.Any]


