Reference to all functions in marxanconpy

marxanconpy

The base module, marxanconpy, contains only the most basic utility functions.

marxanconpy.progress_bar_update(count, dlg, keepGoing, n, progressbar=True)[source]

Progress Bar Update

Function that manages the updates for progress bar dialogs

Parameters
  • count – The total number of steps for the progress bar

  • dlg – The progressbar dialog (wx.ProgressDialog).

  • keepGoing

  • n – The number of steps to move forward

  • progressbar – Logical. True if you want to see a progressbar

Returns

marxanconpy.read_csv_tsv(filepath)[source]

Marxan file reader

Reads comma or tab separated Marxan input or output files. Reads as csv first, if there is only 1 column (i.e. wrong delimiters), then the file is read as a tsv.

Parameters

filepath – Filepath for file in question

Returns

marxanconpy.warn_dialog(message, caption='Warning!')[source]

Warning Dialog

Creates a warning pop-up (a wx.MessageBox)

Parameters
  • message – A string containing the contents of the warning

  • caption – The heading caption

Returns

marxanconpy.manipulation

This module contains all the functions which manipulate data.

marxanconpy.manipulation.calc_metrics(project, progressbar, calc_metrics_pu=True, calc_metrics_cu=False)[source]

Calculate connectivity metrics

Calculates connectivity metrics to be used as conservation features and prepares the connectivity to be used as spatial dependencies

Parameters
  • project – Project dictionary created by’marxanconpy.marcon.new_project()’ or ‘marxanconpy.marcon.load_file()’. The later reads the .MarCon JSON project file

  • progressbar – Logical. True if you want to see a progressbar

  • calc_metrics_pu – Logical. True if you want to calculate metrics for planning units.

  • calc_metrics_cu – Logical. True if you want to calculate metrics for connectivity units if such data is supplied. For exploration purposes only as these will not be used in any Marxan analyses.

Returns

marxanconpy.manipulation.check_matrix_list_format(format, filepath)[source]

Check format

Quality control function to assure that the file format is ‘as advertised’

Parameters
  • format – The expected format of the connectivity file (i.e. “Matrix”, “Edge List”, “Edge List with Type”, “Edge List with Time”). See http://marxanconnect.ca/glossary.html#data_formats for a detailed description of formats

  • filepath – The filepath to the connectivity data

Returns

marxanconpy.manipulation.connectivity2graph(connectivity, format, IDs)[source]

Convert Connectivity data to graph format

Parameters
  • connectivity – The connectivity data as a pandas data frame (in any format)

  • format – The format of the connectivity file (i.e. “Matrix”, “Edge List”, “Edge List with Type”, “Edge List with Time”). See http://marxanconnect.ca/glossary.html#data_formats for a detailed description of formats

  • IDs – Planning unit IDs

Returns

marxanconpy.manipulation.convert_graph_type(current, desired, graph, localProd)[source]

Convert Graph Types

Converts connectivity data in graph (igraph) format to/from various types (e.g. “Probability”, “Migration”, “Flow”). See http://marxanconnect.ca/glossary.html#data_types for detailed description

Parameters
  • current – Current connectivity data type (e.g. “Probability”, “Migration”, “Flow”)

  • desired – Current connectivity data type (e.g. “Probability”, “Migration”, “Flow”)

  • graph – Connectivity Graph

  • localProd – Local Production at each site in the connectivity matrix

Returns

marxanconpy.manipulation.convert_matrix_type(current, desired, matrix, localProd)[source]

Convert Matrix Types

Converts connectivity data in matrix format to/from various types (e.g. “Probability”, “Migration”, “Flow”). See http://marxanconnect.ca/glossary.html#data_types for detailed description

Parameters
  • current – Current connectivity data type (e.g. “Probability”, “Migration”, “Flow”)

  • desired – Current connectivity data type (e.g. “Probability”, “Migration”, “Flow”)

  • matrix – Connectivity Matrix

  • localProd – Local Production at each site in the connectivity matrix

Returns

marxanconpy.manipulation.get_marxan_output(input_file, type='Best Solution')[source]

Get Marxan Output

Extract Marxan output from a file

Parameters
  • input_file – filename of Marxan file to read

  • type – Marxan file type (i.e. ‘Best Solution’, ‘Selection Frequency’,

Returns

marxanconpy.marcon

This module contains all the functions that deal with the project dictionary and .MarCon files.

marxanconpy.marcon.edit_working_directory(project, wd, type='relative')[source]

Edit the working directory Edits the filepath in the project dictionary. If type = ‘relative’, the absolute paths that contain the working directory are changed to relative paths and vice versa for type = ‘absolute’ :param project: the project dictionary :param wd: the working directory :param type: either ‘relative’ or ‘absolute’ :return: dict

marxanconpy.marcon.load_project(filename)[source]

Load Project Loads the project dictionary from a .MarCon file. :param filename: :return: dict

marxanconpy.marcon.new_project(rootpath='.')[source]

New Project Create a new project dictionary :return: dict

marxanconpy.marcon.save_project(project, projfile=False)[source]

Save Project

Saves the project dictionary to a .MarCon file. :param project: the project dictionary :param projfile: the (optional) filename for the project file to override the projfile entry given in the project dictionary. :return:

marxanconpy.marcon.validate_project(project)[source]

Validate Project

A function to validate project dictionaries to ensure that they contains all necessary fields (i.e. keys). Different versions of marxanconpy may require slightly different fields. :param project: the project dictionary :return: dict

marxanconpy.metrics

This module provides all the functions required to calculate the connectivity metrics.

marxanconpy.metrics.get_intersect_id(area_filepath, pu_filepath, pu_id='ID')[source]
Parameters
  • area_filepath

  • pu_filepath

  • pu_id

Returns

marxanconpy.metrics.graph2betweencent(graph)[source]

Connectivity graph to betweeness centrality

Parameters

graph – igraph formatted graph

Returns

marxanconpy.metrics.graph2connboundary(graph)[source]

Connectivity graph to spatial dependency

Parameters

graph – igraph formatted graph

Returns

marxanconpy.metrics.graph2diagonal(graph)[source]

Connectivity graph to diagonal

Parameters

graph – igraph formatted graph

Returns

marxanconpy.metrics.graph2donors(graph, area_filepath, pu_filepath, pu_id='ID', inverse=False)[source]

Connectivity graph to donors

Parameters
  • graph – igraph formatted graph

  • area_filepath

  • pu_filepath

  • pu_id

  • inverse

Returns

marxanconpy.metrics.graph2eigvectcent(graph)[source]

Connectivity graph to eigenvector centrality

Parameters

graph – igraph formatted graph

Returns

marxanconpy.metrics.graph2google(graph)[source]

Connectivity graph to Google Page Rank

Parameters

graph – igraph formatted graph

Returns

marxanconpy.metrics.graph2inflow(graph)[source]

Connectivity graph to inflow

Parameters

graph – igraph formatted graph

Returns

marxanconpy.metrics.graph2outflow(graph)[source]

Connectivity graph to outflow

Parameters

graph – igraph formatted graph

Returns

marxanconpy.metrics.graph2recipients(graph, area_filepath, pu_filepath, pu_id='ID', inverse=False)[source]

Connectivity graph to recipients

Parameters
  • graph – igraph formatted graph

  • area_filepath

  • pu_filepath

  • pu_id

  • inverse

Returns

marxanconpy.metrics.graph2vertexdegree(graph, mode='ALL')[source]

Connectivity graph

Parameters
  • graph – igraph formatted graph

  • mode – String describing mode (i.e. ‘ALL’, ‘IN’, ‘OUT”)

Returns

marxanconpy.metrics.graphtime2temp_conn_cov(graph_time, fa_filepath, pu_filepath)[source]

Connectivity graph with time to temporal connectivity covariance

Parameters
  • graph_time

  • fa_filepath

  • pu_filepath

Returns

marxanconpy.posthoc

This module contains the functions that relate to the post-hoc analysis of Marxan results.

marxanconpy.posthoc.calc_postHoc(pu, filename, format, IDs, selectionIDs)[source]

Calculate PostHoc Metrics

Calculate PostHoc Metrics for a given Marxan solution

Parameters
  • filename – filename of the connectivity data

  • format – The format of the connectivity file (i.e. “Matrix”, “Edge List”, “Edge List with Type”, “Edge List with Time”). See http://marxanconnect.ca/glossary.html#data_formats for a detailed description of formats

  • IDs – Planning unit IDs

  • selectionIDs – Planning unit IDs for those included in the Marxan solution

Returns

marxanconpy.spatial

This module contains spatially intensive functions.

marxanconpy.spatial.buffer_shp_corners(gdf_list, bufferwidth=0)[source]

Finds the lower left and upper right corners of a list of geopandas.GeoDataFrame objects. Optionally define a buffer (in degrees) around the list GeoDataFrames :param gdf_list: :param bufferwidth: :return:

marxanconpy.spatial.get_appropriate_projection(shapefile, equal='area')[source]
Parameters
  • shapefile

  • equal

Returns

marxanconpy.spatial.habitatresistance2conmats(buff, hab_filepath, hab_id, res_mat_filepath, pu_filepath, pu_id, res_type, progressbar=False)[source]
Parameters
  • buff

  • hab_filepath

  • hab_id

  • res_mat_filepath

  • pu_filepath

  • pu_id

  • res_type

  • progressbar

Returns

marxanconpy.spatial.rescale_matrix(pu_filepath, pu_id, cu_filepath, cu_id, cm_filepath, matrixformat, edge, progressbar=False)[source]

rescale the connectivity matrix to match the scale of the planning units :param pu_filepath: :param pu_id: :param cu_filepath: :param cu_id: :param cm_filepath: :param matrixformat: :param edge: :param progressbar: :return: