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

Creating a class with .get() function for quick and convenient loading of datasets #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In test_get(), how can I use assert statement to test whether the correct dataset is loaded?

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


samples = test_get()
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