polartoolkit.profile#

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 (pd.DataFrame, optional) – pandas dataframe with columns x and y as vertices of a polyline, by default None

  • kwargs (Any)

Returns:

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

Return type:

pd.Dataframe

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

calculate cumulative distance of points along a line.

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

  • kwargs (Any)

Returns:

Returns original dataframe with additional column dist

Return type:

pd.DataFrame

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

Fetch default gravity and magnetic datasets.

Parameters:
Returns:

Nested dictionary of data and attributes

Return type:

dict[Any, Any]

default_layers(version, reference=None, region=None, spacing=None, verbose='q')[source]#

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

Parameters:
  • version (str) – choose between ‘bedmap2’ and ‘bedmachine’ layers

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

  • region (tuple[float], optional) – bounding region to subset grids by, by default None

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

  • verbose (str)

Returns:

Nested dictionary of earth layers and attributes

Return type:

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

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:

Any

Parameters:

kwargs (Any)

fill_nans(df)[source]#

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

Parameters:

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

Returns:

Dataframe with NaN’s of lower layers filled

Return type:

pd.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]

plot_data(method, data_dict=None, add_map=False, fig_height=9, fig_width=14, **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 profile.make_data_dict, by default is gravity and magnetic anomalies.

  • add_map (bool = False) – 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.

  • kwargs (Any)

Keyword Arguments:
  • clip (bool) – Choose whether to clip the profile based on distance.

  • 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 ‘earth’.

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

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

  • legend_loc (str) – Change the legend location with a GMT position string, by default is “JBR+jBL+o0c” which puts the Bottom Left corner of the legend in the Bottom Right corner of the plot, with 0 offset.

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

  • inset_pos (str) – position for inset map; either ‘TL’, ‘TR’, BL’, ‘BR’, by default is ‘TL’

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

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

Return type:

tuple[Figure, DataFrame]

plot_profile(method, layers_dict=None, data_dict=None, add_map=False, layers_version='bedmap2', fig_height=9, fig_width=14, **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 profile.make_data_dict, by default is Bedmap2 layers.

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

  • add_map (bool = False) – 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’

  • 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.

  • kwargs (Any)

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

  • clip (bool) – Choose whether to clip the profile based on distance.

  • 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 ‘earth’.

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

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

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

  • legend_loc (str) – Change the legend location with a GMT position string, by default is “JBR+jBL+o0c” which puts the Bottom Left corner of the legend in the Bottom Right corner of the plot, with 0 offset.

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

  • inset_pos (str) – position for inset map; either ‘TL’, ‘TR’, BL’, ‘BR’, by default is ‘TL’

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

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

Return type:

tuple[Figure, DataFrame, DataFrame]

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

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

Parameters:
  • df (pd.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:

pd.DataFrame

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

Sample data at every point along a line

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

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

  • sampled_name (str,) – Name for sampled column

  • kwargs (Any)

Returns:

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

Return type:

pd.DataFrame

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

Shorten a dataframe at either end based on distance column.

Parameters:
  • df (pd.DataFrame) – Dataframe to shorten and recalculate distance, must contain ‘x’, ‘y’, ‘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:

pd.DataFrame