Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unimpeded_database #17

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/test_unimpeded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from unimpeded.unimpeded import unimpeded

# These locations will be changed to Zenodo links in the future.
loc = 'local'
if loc == 'local':
location = '/Users/ongdily/Documents/Cambridge/project2/codes/'
elif loc == 'hpc':
location = '/home/dlo26/rds/rds-dirac-dp192-63QXlf5HuFo/dlo26/'


def test_get():
database = unimpeded(location=location)
samples = database.get(model='klcdm', dataset='bao.sdss_dr16', method='ns')
return samples


samples = test_get()
33 changes: 33 additions & 0 deletions unimpeded/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import requests
from anesthetic import read_chains
import os

class database:
def __init__(self, sandbox=True, ACCESS_TOKEN=None, bucket_url=None):
self.sandbox = sandbox
self.ACCESS_TOKEN = ACCESS_TOKEN
self.bucket_url = bucket_url

def upload(self, method, model, dataset, loc):
filename = f"{method}_{model}_{dataset}.csv"
if loc == 'hpc':
samples = read_chains(f"/home/dlo26/rds/rds-dirac-dp192-63QXlf5HuFo/dlo26/{method}/{model}/{dataset}/{dataset}_polychord_raw/{dataset}") # for hpc
elif loc == 'local':
samples = read_chains(f"../{method}/{model}/{dataset}/{dataset}_polychord_raw/{dataset}")
samples.to_csv(filename) # saving samples as csv, but is it necessary?
path = f"./{filename}"
print(path)
params = {'access_token': self.ACCESS_TOKEN}
with open(path, "rb") as fp:
print(path)
r = requests.put(
f"{self.bucket_url}/{filename}",
data=fp,
params=params
)
def download(self, ID, method, model, dataset):
filename = f"{method}_{model}_{dataset}.csv"
url = f'https://sandbox.zenodo.org/record/{ID}/files/{filename}?download=1'
response = requests.get(url)
with open(filename, 'wb') as file:
file.write(response.content)
32 changes: 32 additions & 0 deletions unimpeded/unimpeded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Loading datasets."""
from anesthetic import read_chains


class unimpeded:
"""Loading datasets.

**kwargs
----------
location : str
The location where the datasets are stored.

"""
def __init__(self, **kwargs):
self.location = kwargs.pop('location', None)

def get(self, model, dataset, method):
"""Get the samples from the dataset.

Parameters
----------
method : str
The chosen method, ns or mcmc.
model : str
The chosen model, e.g. klcdm.
dataset : str
The chosen dataset, e.g. bao.sdss_dr16.
"""
samples = read_chains(
self.location + f"{method}/{model}/{dataset}/"
f"{dataset}_polychord_raw/{dataset}")
return samples
Loading