Skip to content

Instantly share code, notes, and snippets.

@gully
Created April 5, 2018 20:54
Show Gist options
  • Save gully/52fb2873a3240fcc5eae1bc42a283055 to your computer and use it in GitHub Desktop.
Save gully/52fb2873a3240fcc5eae1bc42a283055 to your computer and use it in GitHub Desktop.
A function to use the Zenodo API to automatically upload your large, raw, emcee MCMC chain .npy files for reproducibility of posteriors. Requires a Zenodo API token.
#!/usr/bin/env python
import os
import requests
#See http://developers.zenodo.org/ to get a token
# You may want to change your token path
## Also, do not share your token, it is like a password!
token_file = "../token.txt"
token_fn = os.path.expandvars(token_file)
with open(token_fn) as fp:
tok = fp.readline()
r = requests.get('https://zenodo.org/api/deposit/depositions',
params={'access_token': tok})
# If you have multiple zenodo projects, you may want to hardcode your "deposition_id"
proj_num = 0 # change this
deposition_id = r.json()[proj_num]['id']
# Change the new_fn to suit your project--
## use an arg parser for commandline input
new_fn = 'emcee_chain_ProjName_exper05_run01.npy'
old_fn = 'emcee_chain.npy'
os.system("cp {} {}".format(old_fn, new_fn))
data = {'filename': new_fn}
files = {'file': open(new_fn, 'rb')}
query_string = 'https://zenodo.org/api/deposit/depositions/{}/files'.format(deposition_id)
r = requests.post(query_string,params={'access_token': tok}, data=data,files=files)
print(r.status_code)
print(r.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment