Skip to content

Commit

Permalink
Minimal pip packaging (#4)
Browse files Browse the repository at this point in the history
* added error message on no data file

* added install script

* removed orphics dependency

* allowed changing of data dir

* added pyproject from flit

* added gitignore

* update gitignore to boilerplate

* corrected data dir global use

* added pandas req

* remove pandas dep (oops)

* ver bump

* requirements again

* deps still weird

* version and url

* direct people to orphics
  • Loading branch information
itrharrison authored Aug 18, 2023
1 parent 5df396c commit 4aa5e94
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 7 deletions.
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
**/.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/
1 change: 1 addition & 0 deletions act_dr6_lenslike/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Likelihood for the Atacama Cosmology Telescope DR6 CMB lensing data."""
__author__ = "Mathew Madhavacheril"
__version__ = "1.0.0"

Expand Down
15 changes: 9 additions & 6 deletions act_dr6_lenslike/act_dr6_lenslike.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def parse_variant(variant):
include_planck = True if 'actplanck' in variant else False
return v,baseline,include_planck


# ==================
# Generic likelihood
# ==================
Expand All @@ -153,7 +152,8 @@ def parse_variant(variant):
chi_square = -2 lnlike
"""

def load_data(variant,lens_only=False,
def load_data(variant, ddir=data_dir,
lens_only=False,
apply_hartlap=True,like_corrections=True,mock=False,
nsims_act=796,nsims_planck=400,trim_lmax=2998,scale_cov=None):
"""
Expand Down Expand Up @@ -191,13 +191,13 @@ def load_data(variant,lens_only=False,

# Fiducial spectra
if like_corrections:
f_ls, f_tt, f_ee, f_bb, f_te = np.loadtxt(f"{data_dir}/like_corrs/cosmo2017_10K_acc3_lensedCls.dat",unpack=True)
f_ls, f_tt, f_ee, f_bb, f_te = np.loadtxt(f"{ddir}/like_corrs/cosmo2017_10K_acc3_lensedCls.dat",unpack=True)
f_tt = f_tt / (f_ls * (f_ls+1.)) * 2. * np.pi
f_ee = f_ee / (f_ls * (f_ls+1.)) * 2. * np.pi
f_bb = f_bb / (f_ls * (f_ls+1.)) * 2. * np.pi
f_te = f_te / (f_ls * (f_ls+1.)) * 2. * np.pi

fd_ls, f_dd = np.loadtxt(f"{data_dir}/like_corrs/cosmo2017_10K_acc3_lenspotentialCls.dat",unpack=True,usecols=[0,5])
fd_ls, f_dd = np.loadtxt(f"{ddir}/like_corrs/cosmo2017_10K_acc3_lenspotentialCls.dat",unpack=True,usecols=[0,5])
f_kk = f_dd * 2. * np.pi / 4.
d['fiducial_cl_tt'] = standardize(f_ls,f_tt,trim_lmax)
d['fiducial_cl_te'] = standardize(f_ls,f_te,trim_lmax)
Expand All @@ -207,7 +207,6 @@ def load_data(variant,lens_only=False,


# Return data bandpowers, covariance matrix and binning matrix
ddir = data_dir
if baseline:
start = 2
end = -6
Expand Down Expand Up @@ -369,7 +368,11 @@ class GenericLimberCosmicShear(InstallableLikelihood):
cmb_noise = None

def initialize(self):
from orphics import stats
try:
from orphics import stats
except ImportError:
print("Error importing orphics library. Please install.\n\
available at https://github.com/msyriac/orphics")
import pyfisher
bin_edges = np.geomspace(self.glmin,self.lmax,self.nell)
bin_edges = bin_edges[bin_edges>self.lmin]
Expand Down
11 changes: 10 additions & 1 deletion act_dr6_lenslike/tests/test_act.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
data_dir = alike.data_dir



class ACTLikeTest(unittest.TestCase):

def generic_call(self,variant,lens_only,exp_chisq=None):
ell, cl_tt, cl_ee, cl_bb, cl_te, cl_pp, cl_tp, cl_ep= np.loadtxt(data_dir+'like_corrs/cosmo2017_10K_acc3_lenspotentialCls.dat', unpack=True)
data_file = data_dir+'like_corrs/cosmo2017_10K_acc3_lenspotentialCls.dat'
try:
ell, cl_tt, cl_ee, cl_bb, cl_te, cl_pp, cl_tp, cl_ep= np.loadtxt(data_file, unpack=True)
except OSError:
raise
finally:
print('Required data file not found at {}'.format(data_file))
print('Please obtain it and place it correctly.')
print('The script get-act-data.sh will download and place it.')
prefac = 2*np.pi/ell/(ell+1.)
cl_kk=cl_pp/4*2*np.pi
cl_bb = cl_bb*prefac
Expand Down
18 changes: 18 additions & 0 deletions get-act-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# script from Joe Zuntz

if [ -d act_dr6_lenslike/data/v1.1 ]
then
echo ACT DR6 Lensing data already downloaded
elif ! command -v wget &> /dev/null
then
echo wget not installed. Please obtain it \(e.g. conda install wget\) to download the data.
else
mkdir -p act_dr6_lenslike/data
pushd act_dr6_lenslike/data
wget https://lambda.gsfc.nasa.gov/data/suborbital/ACT/ACT_dr6/likelihood/data/ACT_dr6_likelihood_v1.1.tgz
tar -zxvf ACT_dr6_likelihood_v1.1.tgz
rm ACT_dr6_likelihood_v1.1.tgz
popd
fi
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "act_dr6_lenslike"
authors = [{name = "Mathew Madhavacheril", email = "[email protected]"}]
readme = "README.md"
classifiers = [
"License :: OSI Approved :: BSD License",
]
dynamic = ["version", "description"]
dependencies = ["numpy >=1", "scipy >=1"]

[project.urls]
Source = "https://github.com/ACTCollaboration/act_dr6_lenslike"

0 comments on commit 4aa5e94

Please sign in to comment.