# Reference {.doc .doc-index}

## Utilities

Functions for processing data.

| | |
| --- | --- |
| [anc_to_deme_dict](anc_to_deme_dict.qmd#spaceprime.anc_to_deme_dict) | Converts the ancestral population assignments of demes into a dictionary mapping ancestral population IDs to deme indices. |
| [calc_migration_matrix](calc_migration_matrix.qmd#spaceprime.calc_migration_matrix) | Calculates a migration matrix based on deme sizes and a global migration rate. The migration rate can be scaled based on population size or set as a constant. |
| [coords_to_deme_dict](coords_to_deme_dict.qmd#spaceprime.coords_to_deme_dict) | Finds the cells a given set of coordinates belong to in a raster and returns a dictionary mapping the cell indices to the centroid coordinates of those cells. |
| [coords_to_sample_dict](coords_to_sample_dict.qmd#spaceprime.coords_to_sample_dict) | Convert sample coordinates to sample dictionaries for simulation and analysis. Can optionally include empirical data, which is accepted as a path to a VCF file. |
| [create_raster](create_raster.qmd#spaceprime.create_raster) | Creates a raster dataset from a numpy array and reference raster and writes it to a new GeoTiff file. |
| [mtp_thresh_from_coords](mtp_thresh_from_coords.qmd#spaceprime.mtp_thresh_from_coords) | This function takes the coordinates of empirical sampling localities, finds which raster cells they belong to, extracts the values of the first layer for those localities, and finds the minimum value. |
| [raster_to_demes](raster_to_demes.qmd#spaceprime.raster_to_demes) | Converts a raster to a 2D np.ndarray of deme sizes using either linear, threshold, or sigmoid transformation functions. For more detail about transformation functions, see [this brief overview](transformation-functions.qmd). |
| [split_landscape_by_pop](split_landscape_by_pop.qmd#spaceprime.split_landscape_by_pop) | Uses nearest-neighbor interpolation to classify a landscape raster based on the ancestral population assigned to sampled individuals. |

## Demography

Methods to create and manipulate demographic models.

| | |
| --- | --- |
| [spDemography](spDemography.qmd#spaceprime.spDemography) |  |
| [spDemography.add_ancestral_populations](spDemography.add_ancestral_populations.qmd#spaceprime.spDemography.add_ancestral_populations) | Adds ancestral populations to the given demographic model, mapping demes in the spatial simulation to ancestral populations. |
| [spDemography.stepping_stone_2d](spDemography.stepping_stone_2d.qmd#spaceprime.spDemography.stepping_stone_2d) | Create a 2D stepping stone model, either for a single time step or for multiple time steps of deme size change. |

## Plotting

Functions for visualizing data.

| | |
| --- | --- |
| [plot_landscape](plot_landscape.qmd#spaceprime.plot_landscape) | Plots a static map of a transformed landscape at the timestep of your choice. |
| [plot_model](plot_model.qmd#spaceprime.plot_model) | Plots the demes and migration rates for a given timestep as an interactive map. |
| [plot_timeseries](plot_timeseries.qmd#spaceprime.plot_timeseries) | Plots the total number of individuals across the landscape across time. |

## Simulation

Thin wrappers around msprime simulation functions.

| | |
| --- | --- |
| [sim_ancestry](sim_ancestry.qmd#spaceprime.sim_ancestry) | A thin wrapper around msprime.sim_ancestry. |
| [sim_mutations](sim_mutations.qmd#spaceprime.sim_mutations) | A thin wrapper around msprime.sim_mutations. |

## Analysis

Functions for analyzing data.

| | |
| --- | --- |
| [calc_sumstats](calc_sumstats.qmd#spaceprime.calc_sumstats) | Calculates a suite of genetic summary statistics on allele counts matrices generated by `filter_gt` or otherwise generated through scikit-allel. |
| [filter_gt](filter_gt.qmd#spaceprime.filter_gt) | Filter genotype matrices output by ts.genotype_matrix() to filter out monomorphic sites, loci in linkage disequilibrium, and recreate missing data patterns common to empirical genotype data. |