Skip to content

Commit

Permalink
to have a clearer view of unit tests, decided to split scripts accord…
Browse files Browse the repository at this point in the history
…ing to modules
  • Loading branch information
Philippe Gris committed Mar 25, 2020
1 parent 3ea84bc commit 639cd4e
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/testSNtools_rate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from builtins import zip
import numpy as np
import unittest
import lsst.utils.tests
from sn_tools.sn_rate import SN_Rate
from sn_tools.sn_utils import GenerateSample
from sn_tools.sn_cadence_tools import ReferenceData, GenerateFakeObservations, TemplateData
from sn_tools.sn_telescope import Telescope
import os
from lsst.sims.photUtils import PhotometricParameters
from lsst.sims.photUtils import Bandpass, Sed
from numpy.testing import assert_almost_equal, assert_equal

m5_ref = dict(zip('ugrizy', [23.60, 24.83, 24.38, 23.92, 23.35, 22.44]))


class TestSNRate(unittest.TestCase):

def testSNRate(self):
"""Test sn_rate tool """

rate_type = 'Perrett'
rate = SN_Rate(rate=rate_type)
zmin = 0.05
zmax = 0.2
dz = 0.01
duration = 180.
zz, rate, err_rate, nsn, err_nsn = rate(
zmin=zmin, zmax=zmax, duration=duration)

zz_ref = [0.055, 0.065, 0.075, 0.085, 0.095, 0.105, 0.115, 0.125, 0.135, 0.145, 0.155, 0.165,
0.175, 0.185, 0.195, 0.205]

rate_ref = [1.90331912e-05, 1.94158583e-05, 1.98025346e-05, 2.01932243e-05,
2.05879314e-05, 2.09866601e-05, 2.13894142e-05, 2.17961980e-05,
2.22070152e-05, 2.26218698e-05, 2.30407657e-05, 2.34637068e-05,
2.38906970e-05, 2.43217399e-05, 2.47568395e-05, 2.51959995e-05]

err_rate_ref = [3.37089644e-06, 3.44338970e-06, 3.51749665e-06, 3.59323907e-06,
3.67063815e-06, 3.74971453e-06, 3.83048831e-06, 3.91297906e-06,
3.99720582e-06, 4.08318713e-06, 4.17094104e-06, 4.26048514e-06,
4.35183652e-06, 4.44501188e-06, 4.54002746e-06, 4.63689909e-06]

nsn_ref = [0.05936766, 0.08306682, 0.1108024, 0.14258917, 0.17843839, 0.21835781,
0.26235176, 0.31042126, 0.36256408, 0.41877485, 0.47904512, 0.54336348,
0.61171562, 0.68408448, 0.76045026, 0.84079061]

err_nsn_ref = [0.01051438, 0.01473185, 0.01968168, 0.02537272, 0.03181392, 0.03901428,
0.04698284, 0.05572861, 0.06526061, 0.07558774, 0.08671886, 0.09866267,
0.11142774, 0.12502245, 0.139455, 0.15473334]

assert(np.isclose(np.array(zz), np.array(zz_ref)).all())
assert(np.isclose(np.array(rate), np.array(rate_ref)).all())
assert(np.isclose(np.array(err_rate), np.array(err_rate_ref)).all())
assert(np.isclose(np.array(nsn), np.array(nsn_ref)).all())
assert(np.isclose(np.array(err_nsn), np.array(err_nsn_ref)).all())


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main(verbosity=5)

0 comments on commit 639cd4e

Please sign in to comment.