Skip to content
spam is a Python 3 package, used to search for imprints of Hu-Sawicki f(R) gravity in the rotation curves of the SPARC sample.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


spam is a python-3 package to search for imprints of Hu-Sawicki f(R) gravity on the rotation curves of the SPARC sample, using the MCMC sampler emcee.

This code was used to generate the results in Naik et al., (2019). Please direct any comments/questions to the author, Aneesh Naik, at an485@[Cambridge University].


This code was written and implemented with python (version 3.6.8), and requires the following external packages (the version numbers in parentheses indicate the versions employed at time of writing, not particular dependencies):

  • emcee (2.2.1)
  • numpy (1.16.1)
  • scipy (1.2.0)


Running the MCMC sampling for any of the preset models listed in Table 1 of the paper is straightforward. The following examples demonstrates how to do this for one galaxy under 'Model B'.

import spam

# name of chosen galaxy
name = 'NGC2403'

# load SPARC data for galaxy
galaxy ='NGC2403')

# set up model B MCMC; 30 walkers and 4 temperatures
f =, nwalkers=30, ntemps=4, model='B')

# run 1000 iterations

Note that the models including f(R) gravity can be rather time-expensive due to the computational cost of the scalar field solver (see discussion in paper). It is recommended to run these models on multiple CPU threads. See GalaxyFit documentation for instructions on how to do this.

One can inspect the MCMC chains via the GalaxyFit.chain attribute. The GalaxyFit.theta_dict attribute is a useful dictionary which translates names of parameters to indices.

Here is some code to generate a histogram showing the marginal posterior distribution for fR0 from the MCMC sampling we performed above.

import matplotlib.pyplot as plt

# get the fR0 chain
# first index is 0 to get the zeroth temperature chain
# the third index slices from 500 to 'burn in' the first 500 iterations.
chain = f.chain[0, :, 500:, f.theta_dict['fR0']]

# flatten the chain
flatchain = chain.flatten()

# plot a histogram of the chain with 200 bins
plt.hist(flatchain, bins=200)

All of the spam output data analysed in the paper can be found here. Note that the chains, and therefore file sizes, are rather large. However, summary data for each model can be found in the 'summaries' folder. These are stored as pickled spam.analysis.FitSummary objects.

The scripts used to generate all of the figures in the paper can be found in the submodule spam.plot. These scripts search for an environment variable SPAMFITDIR, which is the directory containing all of the fit data linked above. All figures except 5) and A1) can be generated with the summary files only.


This code was written by Aneesh Naik (website). The research was performed in collaboration with the co-authors of Naik et al. (2019):


Copyright (2019) Aneesh Naik and co-authors.

SPAM is free software made available under the MIT license. For details see LICENSE.

If you make use of SPAM in your work, please cite our paper (arXiv, ADS).


Please see the acknowledgments in the paper for a list of the many people and institutions to whom we are indebted!

You can’t perform that action at this time.