polartoolkit.profiles#

Attributes#

Functions#

create_profile(method[, start, stop, num, shapefile, ...])

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

sample_grids(df, grid, sampled_name, **kwargs)

Sample data at every point along a line

fill_nans(df)

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

shorten(df[, max_dist, min_dist])

Shorten a dataframe at either end based on distance column.

make_data_dict(names, grids, colors[, axes])

Create nested dictionary of data and attributes

default_layers(version[, hemisphere, reference, ...])

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

default_data([region, hemisphere, verbose])

Fetch default gravity and magnetic datasets.

plot_profile(method[, layers_dict, data_dict, ...])

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

plot_data(method[, data_dict, add_map, fig_height, ...])

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

relative_dist(df[, reverse])

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

cumulative_dist(df, **kwargs)

calculate cumulative distance of points along a line.

draw_lines(**kwargs)

Plot an interactive map, and use the "Draw a Polyline" button to create vertices of

Module Contents#

display = None[source]#
ipyleaflet = None[source]#
create_profile(method, start=None, stop=None, num=None, shapefile=None, polyline=None, **kwargs)[source]#

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

Parameters:
  • method (str) – Choose sampling method, either “points”, “shapefile”, or “polyline”

  • start (tuple[float, float], optional) – Coordinates for starting point of profile, by default None

  • stop (tuple[float, float], optional) – Coordinates for ending point of profile, by default None

  • num (int, optional) – Number of points to sample at, for “points” by default is 100, for other methods num by default is determined by shapefile or dataframe

  • shapefile (str, optional) – shapefile file name to create points along, by default None

  • polyline (pandas.DataFrame, optional) – pandas dataframe with columns x and y as vertices of a polyline, by default None

  • kwargs (Any)

Returns:

Dataframe with ‘easting’, ‘northing’, and ‘dist’ columns for points along line or shapefile path.

Return type:

pandas.DataFrame

sample_grids(df, grid, sampled_name, **kwargs)[source]#

Sample data at every point along a line

Parameters:
  • df (pandas.DataFrame) – Dataframe containing columns ‘easting’, ‘northing’, or columns with names defined by kwarg “coord_names”.

  • grid (str or xarray.DataArray) – Grid to sample, either file name or xarray.DataArray

  • sampled_name (str,) – Name for sampled column

  • kwargs (Any)

Returns:

Dataframe with new column (sampled_name) of sample values from (grid)

Return type:

pandas.DataFrame

fill_nans(df)[source]#

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

Parameters:

df (pandas.DataFrame) – First 3 columns as they are assumed to by x, y, dist.

Returns:

Dataframe with NaN’s of lower layers filled

Return type:

pandas.DataFrame

shorten(df, max_dist=None, min_dist=None)[source]#

Shorten a dataframe at either end based on distance column.

Parameters:
  • df (pandas.DataFrame) – Dataframe to shorten and recalculate distance, must contain ‘easting’, ‘northing’, ‘dist’

  • max_dist (float, optional) – remove rows with dist>max_dist, by default None

  • min_dist (float, optional) – remove rows with dist<min_dist, by default None

Returns:

Shortened dataframe

Return type:

pandas.DataFrame

make_data_dict(names, grids, colors, axes=None)[source]#

Create nested dictionary of data and attributes

Parameters:
  • names (list[str]) – data names

  • grids (list[str or xarray.DataArray]) – files or xarray.DataArray’s

  • colors (list[str]) – colors to plot data

  • axes (list[int]) – 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.

Returns:

Nested dictionaries of grids and attributes

Return type:

dict[dict]

default_layers(version, hemisphere=None, reference=None, region=None, spacing=None)[source]#

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

Parameters:
  • version (str) – choose between ‘bedmap2’, ‘bedmap3’, and ‘bedmachine’ layers for Antarctica, and just ‘bedmachine’ Greenland

  • hemisphere (str, optional) – choose between plotting in the “north” or “south” hemispheres, by default None

  • reference (str, optional) – choose between ‘ellipsoid’, ‘eigen-6c4’ or ‘eigen-gl04c’ (only for bedmap), for an elevation reference frame, by default None

  • region (tuple[float], optional) – region to subset grids by, in format [xmin, xmax, ymin, ymax], by default None

  • spacing (float, optional) – grid spacing to resample the grids to, by default None

Returns:

Nested dictionary of earth layers and attributes

Return type:

dict[str, dict[str, str | xarray.DataArray]]

default_data(region=None, hemisphere=None, verbose='q')[source]#

Fetch default gravity and magnetic datasets.

Parameters:
  • region (tuple[float, float, float, float], optional) – region to subset grids by, in format [xmin, xmax, ymin, ymax], by default None

  • hemisphere (str, optional) – choose between plotting in the “north” or “south” hemispheres, by default None

  • verbose (str)

Returns:

Nested dictionary of data and attributes

Return type:

dict[Any, Any]

plot_profile(method, layers_dict=None, data_dict=None, add_map=False, layers_version=None, fig_height=9, fig_width=14, hemisphere=None, **kwargs)[source]#

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

Parameters:
  • method (str) – Choose sampling method, either “points”, “shapefile”, or “polyline”

  • layers_dict (dict, optional) – nested dictionary of layers to include in cross-section, construct with profiles.make_data_dict, by default is Bedmap2 layers.

  • data_dict (dict, optional) – nested dictionary of data to include in option graph, construct with profiles.make_data_dict, by default is gravity and magnetic anomalies.

  • add_map (bool) – Choose whether to add a location map, by default is False.

  • layers_version (str, optional) – choose between using ‘bedmap2’ or ‘bedmachine’ layers, by default is Bedmap2, unless plotting for Greenland, then it is Bedmachine.

  • fig_height (float, optional) – Set the height of the figure (excluding the map) in cm, by default is 9.

  • fig_width (float, optional) – Set the width of the figure (excluding the map) in cm, by default is 14.

  • hemisphere (str, optional) – choose between plotting in the “north” or “south” hemispheres, by default None

  • kwargs (Any)

Keyword Arguments:
  • fillnans (bool) – Choose whether to fill nans in layers, defaults to True.

  • num (int) – Number of points to sample at along a line.

  • max_dist (int) – Clip all distances greater than.

  • min_dist (int) – Clip all distances less than.

  • map_background (str or xarray.DataArray) – Change the map background by passing a filename string or grid, by default is imagery.

  • map_cmap (str) – Change the map colorscale by passing a valid GMT cmap string, by default is ‘viridis’.

  • map_buffer (float) – Change map zoom as relative percentage of profile length (0-1), by default is 0.3.

  • layer_buffer (float) – Change vertical white space within cross-section (0-1), by default is 0.1.

  • data_buffer (float) – Change vertical white space within data graph (0-1), by default is 0.1.

  • layers_legend_loc (str) – Change the legend location with a GMT position string, by default is “JBR+jBL+o0c”.

  • data_legend_loc (str) – Change the legend location with a GMT position string, by default is “JBR+jBL+o0c”.

  • layers_legend_columns (int) – Change the number of columns in the legend, by default is 1.

  • inset (bool) – choose to plot inset map showing figure location, by default is True

  • inset_position (str) – position for inset map with PyGMT syntax, by default is “jTL+jTL+o0/0”

  • save (bool) – Choose to save the image, by default is False.

  • path (str) – Filename for saving image, by default is None.

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.

Return type:

tuple[pygmt.Figure, pandas.DataFrame, pandas.DataFrame]

plot_data(method, data_dict=None, add_map=False, fig_height=9, fig_width=14, hemisphere=None, **kwargs)[source]#

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

Parameters:
  • method (str) – Choose sampling method, either “points”, “shapefile”, or “polyline”

  • data_dict (dict, optional) – nested dictionary of data to include in option graph, construct with profiles.make_data_dict, by default is gravity and magnetic anomalies.

  • add_map (bool) – Choose whether to add a location map, by default is False.

  • fig_height (float, optional) – Set the height of the figure (excluding the map) in cm, by default is 9.

  • fig_width (float, optional) – Set the width of the figure (excluding the map) in cm, by default is 14.

  • hemisphere (str, optional) – choose between plotting in the “north” or “south” hemispheres, by default None

  • kwargs (Any)

Keyword Arguments:
  • num (int) – Number of points to sample at along a line.

  • max_dist (int) – Clip all distances greater than.

  • min_dist (int) – Clip all distances less than.

  • map_background (str or xarray.DataArray) – Change the map background by passing a filename string or grid, by default is imagery.

  • map_cmap (str) – Change the map colorscale by passing a valid GMT cmap string, by default is ‘viridis’.

  • map_buffer (float) – Change map zoom as relative percentage of profile length (0-1), by default is 0.3.

  • data_buffer (float) – Change vertical white space within data graph (0-1), by default is 0.1.

  • data_legend_loc (str) – Change the legend location with a GMT position string, by default is “JBR+jBL+o0c”.

  • inset (bool) – choose to plot inset map showing figure location, by default is True

  • inset_position (str) – position for inset map with PyGMT syntax, by default is “jTL+jTL+o0/0”

  • save (bool) – Choose to save the image, by default is False.

  • path (str) – Filename for saving image, by default is None.

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.

Return type:

tuple[pygmt.Figure, pandas.DataFrame]

relative_dist(df, reverse=False)[source]#

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

Parameters:
  • df (pandas.DataFrame) – Dataframe containing columns x and y in meters.

  • reverse (bool, optional,) – choose whether to reverse the profile, by default is False

Returns:

Returns original dataframe with additional column rel_dist

Return type:

pandas.DataFrame

cumulative_dist(df, **kwargs)[source]#

calculate cumulative distance of points along a line.

Parameters:
  • df (pandas.DataFrame) – Dataframe containing columns x, y, and rel_dist

  • kwargs (Any)

Returns:

Returns original dataframe with additional column dist

Return type:

pandas.DataFrame

draw_lines(**kwargs)[source]#

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.

Return type:

list[Any]

Parameters:

kwargs (Any)