Codes and Data for “Clustering and correlations: inferring resilience from spatial patterns in ecosystems”, submitted to Methods in Ecology and Evolution.
1. A C++ code (pqmodel.cpp) for the spatially-explicit model which simulates critical transitions in a system with variable positive-feedback interactions. Written by Sabiha Majumder.
To run this code, use any latest linux or Mac OS. We have run this on Ubuntu 12.04. It is expected to work on other OS as well, if you have the compilers, but we haven’t tested. To run this code, type the following command on the command prompt. g++ -o pqsim pqmodel.cpp This will compile the C++ code and provide an executable named pqsim. Now execute this on the command prompt: nohup ./pqsim >> pqsim.out& This will run the code in the backgound and generate a .out file at the end of the simulation, which contains the value of p and corresponding steady state density for each complete run of the simulation (or each replicate of ’t’ time steps from initial conditions). In the default settings, it will also output two .dat files for each value of q in the simulation as it runs (i.e at the end of a simulation with 1000q values, there will be 2000 files). For each q value simulated, one .dat file contains the average steady state densities of the simulated landscape for each replicate of the range of p values in the simulation. This can be used to construct the phase diagram. The second .dat file contains spatial information of the steady-state matrix for each replicate of the range of simulated values for p. The data in this file runs as a single column of output values, each value corresponding to the state of a cell in the final matrix. So for a simulation with matix size 1024x1024 and 10 replicates ,run over 1000 values of p, each spatial information containing .dat output file will have 1024x1024x10x1000 values.
It must be noted that the pqmodel.cpp code file uploaded here runs the simulation with a matrix of size 128x128, for 10 values of p and 2 values of q (0.92 and 0) and 5 replicates of each combination. The user is adviced to modify the code according to the range of p and q values, matrix size, and number of replicates that they desire. Please note that when changing the matrix size, the number of time-steps ('T' in the code) must also be modified accordingly, to ensure that the simulations reach a steady-state before the output is saved.
2. PatchSize&matrixes.m : a matlab code that reads the .dat spatial data files generated by the simulation and output spatial snapshots for each replicate in matrix form (in n rows and n columns). This code calls the functions check.m and patchsizes.m (also included here), so save it in the same folder This code also generates the data of patch-sizes. It will output `n’ .csv files of patches for ’n’ replicates, and 1 .csv file containing all the sizes of patches realised across all the replicates. (Written by Sumithra)
3. Power-spectrum code that will call two functions (which must be saved in the same folder), rspec_ews.R and myfftshift.R (both written by Dr. Vishwesha Guttal). It will read all the .csv matrices generated by the patch-size code and construct the power-spectrum for each and save them as .csv files in sub-folders of the different combinations of p and q values. (Written by Sumithra)
4. Patch size distribution code to read in the patch sizes file and fit it according to the fitting methods described in Appendix B. We have provided two files of patch size distributions (that were plotted in Fig 5 of the main text) for reproduction. These functions for fitting were all provided as part of the power-law package and in the companion repository (https://github.com/jeffalstott/powerlaw/tree/master/testing/pli-R-v0.0.3-2007-07-25). They were compiled and structured for use with the current project data by Sumithra and Ashwin.
5. Power Spectrum fitting code with reads in the all the power-spectra files in a folder and fits the spectra. We have provided 4 power-spectra datasets (that were plotted in Fig 7 of the main text) for reproduction. (Written by Sumithra)
1. Sample data sets of patch sizes (corresponding to Fig 4. of main manuscript) : q0.92p0.2852PSD.csv , q0.92p0.2865PSD.csv , q0p0.7225PSD.csv and q0p0.62275PSD.csv
2. Sample data sets of power-spectra for 50 replicate snapshots for p and q values corresponding to Fig. 7 of main text : folders q0.92p0.2865PowSpecReps q0.92p0.2852PowSpecReps q0p0.7225PowSpecReps and q0p0.62275PowSpecReps