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

Switched test_orf to nside=16 to decrease memory footprint #404

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
37 changes: 31 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import os
import unittest
import pytest

import numpy as np

Expand All @@ -20,9 +19,32 @@
from enterprise.signals import utils
from tests.enterprise_test_data import datadir

from functools import wraps

IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"


def set_env_variable(key, value):
"""A decorator to temporarily set an environment variable for a test."""

def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
original_value = os.environ.get(key)
try:
os.environ[key] = value
return func(*args, **kwargs)
finally:
if original_value is not None:
os.environ[key] = original_value
else:
del os.environ[key]

return wrapper

return decorator


class TestUtils(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -170,7 +192,7 @@ def test_psd(self):
assert np.allclose(utils.powerlaw(f, log10_A, gamma), pl), msg
assert np.allclose(utils.turnover(f, log10_A, gamma, lf0, kappa, beta), pt), msg

@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions due to limited memory.")
@set_env_variable("OMP_NUM_THREADS", "1")
def test_orf(self):
"""Test ORF functions."""
p1 = np.array([0.3, 0.648, 0.7])
Expand All @@ -188,9 +210,10 @@ def test_orf(self):
mp_exp = 1.0 + 1e-5
#
psr_positions = np.array([[1.318116071652818, 2.2142974355881808], [1.1372584174390601, 0.79539883018414359]])
anis_basis = anis.anis_basis(psr_positions, lmax=1)
anis_basis = anis.anis_basis(psr_positions, lmax=1, nside=4)
anis_orf = round(utils.anis_orf(p1, p1, [0.0, 1.0, 0.0], anis_basis=anis_basis, psrs_pos=[p1, p2], lmax=1), 3)
anis_orf_exp = 1.147
# anis_orf_exp = 1.147 <-- for nside=16, for nside=8,4 1.46
anis_orf_exp = 1.146
#

msg = "ORF auto term incorrect for {}"
Expand All @@ -212,9 +235,11 @@ def test_orf(self):
mp_exp = 1.0
#
psr_positions = np.array([[1.318116071652818, 2.2142974355881808], [1.1372584174390601, 0.79539883018414359]])
anis_basis = anis.anis_basis(psr_positions, lmax=1)
anis_basis = anis.anis_basis(psr_positions, lmax=1, nside=4)
anis_orf = round(utils.anis_orf(p1, p2, [0.0, 1.0, 0.0], anis_basis=anis_basis, psrs_pos=[p1, p2], lmax=1), 3)
anis_orf_exp = -0.150
# anis_orf_exp = -0.150 <-- for nside=16, for nside=8 -0.152
# anis_orf_exp = -0.150 <-- for nside=16, for nside=4 -0.151
anis_orf_exp = -0.151
#

msg = "ORF cross term incorrect for {}"
Expand Down
Loading