def test_trim(capsys): # eureka.lib.util.trim test #Let's trim by giving metadata some xwindow and ywindow information which is normally given by the user in the S3_ecf trim_x0 = 10 trim_x1 = 90 trim_y0 = 2 trim_y1 = 14 meta = MetaClass() data = DataClass() n = 7 ny = 20 nx = 100 #Let's assume we have a dataset with 7 integrations and every spectrum has the dimensions of 100x20 data.data = np.ones((n, ny, nx)) data.err = np.ones((n, ny, nx)) data.dq = np.ones((n, ny, nx)) data.wave = np.ones((n, ny, nx)) data.v0 = np.ones((n, ny, nx)) meta.ywindow = [trim_y0, trim_y1] meta.xwindow = [trim_x0, trim_x1] res_dat, res_md = util.trim(data, meta) #Let's check if the dimensions agree assert res_dat.subdata.shape == (n, (trim_y1 - trim_y0), (trim_x1 - trim_x0))
def test_eclipsemodel(self): """Tests for the BatmanEclipseModel class""" # Set the intial parameters params = Parameters() params.rp = 0.22, 'fixed' # rprs params.fp = 0.08, 'free', 0.0, 0.1, 'U' # fprs params.per = 10.721490, 'fixed' params.t0 = 0.48, 'free', 0, 1, 'U' params.inc = 89.7, 'free', 80., 90., 'U' params.a = 18.2, 'free', 15., 20., 'U' # aprs params.ecc = 0., 'fixed' params.w = 90., 'fixed' # omega params.Rs = 1., 'independent' # Make the eclipse model meta = MetaClass() meta.sharedp = False longparamlist, paramtitles = s5_fit.make_longparamlist(meta, params, 1) log = logedit.Logedit('./data/test.log') self.e_model = models.BatmanEclipseModel(parameters=params, name='transit', fmt='r--', log=log, longparamlist=longparamlist, nchan=1, paramtitles=paramtitles) # Remove the temporary log file os.system("rm ./data/test.log") # Evaluate and test output self.e_model.time = self.time vals = self.e_model.eval() self.assertEqual(vals.size, self.time.size)
def test_transitmodel(self): """Tests for the BatmanTransitModel class""" # Set the intial parameters params = Parameters() params.rp = 0.22, 'free', 0.0, 0.4, 'U' # rprs params.per = 10.721490, 'fixed' params.t0 = 0.48, 'free', 0, 1, 'U' params.inc = 89.7, 'free', 80., 90., 'U' params.a = 18.2, 'free', 15., 20., 'U' # aprs params.ecc = 0., 'fixed' params.w = 90., 'fixed' # omega params.limb_dark = '4-parameter', 'independent' params.u1 = 0.1, 'free', 0., 1., 'U' params.u2 = 0.1, 'free', 0., 1., 'U' params.u3 = 0.1, 'free', 0., 1., 'U' params.u4 = 0.1, 'free', 0., 1., 'U' # Make the transit model meta = MetaClass() meta.sharedp = False longparamlist, paramtitles = s5_fit.make_longparamlist(meta, params, 1) self.t_model = models.BatmanTransitModel(parameters=params, name='transit', fmt='r--', longparamlist=longparamlist, nchan=1, paramtitles=paramtitles) # Evaluate and test output self.t_model.time = self.time vals = self.t_model.eval() self.assertEqual(vals.size, self.time.size)
def test_WFC3(capsys): with capsys.disabled(): # is able to display any message without failing a test # useful to leave messages for future users who run the tests print( "\n\nIMPORTANT: Make sure that any changes to the ecf files are " + "included in demo ecf files and documentation (docs/source/ecf.rst)" ) print("\nWFC3 S3 test: ", end='', flush=True) # explicitly define meta variables to be able to run pathdirectory fn locally meta = MetaClass() meta.eventlabel = 'WFC3' meta.topdir = '../tests' ecf_path = './WFC3_ecfs/' reload(s3) s3_meta = s3.reduceJWST(meta.eventlabel, ecf_path=ecf_path) # run assertions for S3 meta.outputdir_raw = 'data/WFC3/Stage3/' name = pathdirectory(meta, 'S3', 1, ap=8, bg=40) assert os.path.exists(name) assert os.path.exists(name + '/figs') # remove temporary files os.system("rm -r data/WFC3/Stage3")
def test_sinsoidalmodel(self): """Tests for the PolynomialModel class""" # create dictionary params = Parameters() params.rp = 0.22, 'free', 0.0, 0.4, 'U' # rprs params.fp = 0.08, 'free', 0.0, 0.1, 'U' # fprs params.per = 10.721490, 'fixed' params.t0 = 0.48, 'free', 0, 1, 'U' params.inc = 89.7, 'free', 80., 90., 'U' params.a = 18.2, 'free', 15., 20., 'U' # aprs params.ecc = 0., 'fixed' params.w = 90., 'fixed' # omega params.limb_dark = '4-parameter', 'independent' params.u1 = 0.1, 'free', 0., 1., 'U' params.u2 = 0.1, 'free', 0., 1., 'U' params.u3 = 0.1, 'free', 0., 1., 'U' params.u4 = 0.1, 'free', 0., 1., 'U' params.AmpSin1 = 0.1, 'free', -0.5, 0.5, 'U' params.AmpCos1 = 0.3, 'free', 0.0, 0.5, 'U' params.AmpSin2 = 0.01, 'free', -1, 1, 'U' params.AmpCos2 = 0.01, 'free', -1, 1, 'U' params.Rs = 1., 'independent' # Create the model meta = MetaClass() meta.sharedp = False longparamlist, paramtitles = s5_fit.make_longparamlist(meta, params, 1) log = logedit.Logedit('./data/test.log') self.t_model = models.BatmanTransitModel(parameters=params, name='transit', fmt='r--', longparamlist=longparamlist, nchan=1, paramtitles=paramtitles) self.e_model = models.BatmanEclipseModel(parameters=params, name='transit', fmt='r--', log=log, longparamlist=longparamlist, nchan=1, paramtitles=paramtitles) self.phasecurve = models.SinusoidPhaseCurveModel( parameters=params, name='phasecurve', fmt='r--', longparamlist=longparamlist, nchan=1, paramtitles=paramtitles, transit_model=self.t_model, eclipse_model=self.e_model) # Remove the temporary log file os.system("rm ./data/test.log") # Evaluate and test output self.phasecurve.time = self.time vals = self.phasecurve.eval() self.assertEqual(vals.size, self.time.size)
def test_NIRCam(capsys): with capsys.disabled(): # is able to display any message without failing a test # useful to leave messages for future users who run the tests print( "\n\nIMPORTANT: Make sure that any changes to the ecf files are " + "included in demo ecf files and documentation (docs/source/ecf.rst)" ) print("\nNIRCam S3-6 test: ", end='', flush=True) # explicitly define meta variables to be able to run pathdirectory fn locally meta = MetaClass() meta.eventlabel = 'NIRCam' meta.topdir = '../tests' ecf_path = './NIRCam_ecfs/' reload(s3) reload(s4) reload(s5) reload(s6) s3_meta = s3.reduceJWST(meta.eventlabel, ecf_path=ecf_path) s4_meta = s4.lcJWST(meta.eventlabel, ecf_path=ecf_path, s3_meta=s3_meta) s5_meta = s5.fitJWST(meta.eventlabel, ecf_path=ecf_path, s4_meta=s4_meta) s6_meta = s6.plot_spectra(meta.eventlabel, ecf_path=ecf_path, s5_meta=s5_meta) # run assertions for S3 meta.outputdir_raw = 'data/JWST-Sim/NIRCam/Stage3/' name = pathdirectory(meta, 'S3', 1, ap=20, bg=20) assert os.path.exists(name) assert os.path.exists(name + '/figs') # run assertions for S4 meta.outputdir_raw = 'data/JWST-Sim/NIRCam/Stage4/' name = pathdirectory(meta, 'S4', 1, ap=20, bg=20) assert os.path.exists(name) assert os.path.exists(name + '/figs') # run assertions for S5 meta.outputdir_raw = 'data/JWST-Sim/NIRCam/Stage5/' name = pathdirectory(meta, 'S5', 1, ap=20, bg=20) assert os.path.exists(name) assert os.path.exists(name + '/figs') # run assertions for S6 meta.outputdir_raw = 'data/JWST-Sim/NIRCam/Stage6/' name = pathdirectory(meta, 'S6', 1, ap=20, bg=20) assert os.path.exists(name) assert os.path.exists(name + '/figs') # remove temporary files os.system("rm -r data/JWST-Sim/NIRCam/Stage3") os.system("rm -r data/JWST-Sim/NIRCam/Stage4") os.system("rm -r data/JWST-Sim/NIRCam/Stage5") os.system("rm -r data/JWST-Sim/NIRCam/Stage6")
def test_NIRSpec(capsys): s2_installed = 'eureka.S2_calibrations.s2_calibrate' in sys.modules if not s2_installed: with capsys.disabled(): print( "\n\nIMPORTANT: Make sure that any changes to the ecf files are " + "included in demo ecf files and documentation (docs/source/ecf.rst)" ) print( '\nSkipping NIRSpec Stage 2 tests as could not import eureka.S2_calibrations.s2_calibrate' ) print("\nNIRSpec S3-5 test: ", end='', flush=True) else: with capsys.disabled(): # is able to display any message without failing a test # useful to leave messages for future users who run the tests print( "\n\nIMPORTANT: Make sure that any changes to the ecf files are " + "included in demo ecf files and documentation (docs/source/ecf.rst)" ) print("\nNIRSpec S2-5 test: ", end='', flush=True) # explicitly define meta variables to be able to run pathdirectory fn locally meta = MetaClass() meta.eventlabel = 'NIRSpec' meta.topdir = '../tests' ecf_path = './NIRSpec_ecfs/' if s2_installed: # Only run S2 stuff if jwst package has been installed reload(s2) reload(s3) reload(s4) reload(s5) if s2_installed: # Only run S2 stuff if jwst package has been installed s2_meta = s2.calibrateJWST(meta.eventlabel, ecf_path=ecf_path) s3_meta = s3.reduceJWST(meta.eventlabel, ecf_path=ecf_path) s4_meta = s4.lcJWST(meta.eventlabel, ecf_path=ecf_path, s3_meta=s3_meta) s5_meta = s5.fitJWST(meta.eventlabel, ecf_path=ecf_path, s4_meta=s4_meta) # run assertions for S2 if s2_installed: # Only run S2 stuff if jwst package has been installed meta.outputdir_raw = '/data/JWST-Sim/NIRSpec/Stage2/' name = pathdirectory(meta, 'S2', 1) assert os.path.exists(name) assert os.path.exists(name + '/figs') # run assertions for S3 meta.outputdir_raw = '/data/JWST-Sim/NIRSpec/Stage3/' name = pathdirectory(meta, 'S3', 1, ap=8, bg=10) assert os.path.exists(name) assert os.path.exists(name + '/figs') # run assertions for S4 meta.outputdir_raw = 'data/JWST-Sim/NIRSpec/Stage4/' name = pathdirectory(meta, 'S4', 1, ap=8, bg=10) assert os.path.exists(name) assert os.path.exists(name + '/figs') # run assertions for S5 meta.outputdir_raw = 'data/JWST-Sim/NIRSpec/Stage5/' name = pathdirectory(meta, 'S5', 1, ap=8, bg=10) assert os.path.exists(name) assert os.path.exists(name + '/figs') # remove temp files if s2_installed: # Only run S2 stuff if jwst package has been installed os.system("rm -r data/JWST-Sim/NIRSpec/Stage2/S2_*") pass os.system("rm -r data/JWST-Sim/NIRSpec/Stage3") os.system("rm -r data/JWST-Sim/NIRSpec/Stage4") os.system("rm -r data/JWST-Sim/NIRSpec/Stage5")
""" import unittest import numpy as np import os import sys sys.path.insert(0, '../') from eureka.S5_lightcurve_fitting import lightcurve, models, simulations from eureka.lib.readEPF import Parameters, Parameter from eureka.lib.readECF import MetaClass from eureka.lib import logedit from eureka.S5_lightcurve_fitting import s5_fit meta = MetaClass() meta.eventlabel = 'NIRCam' ''' NOTE: Currently does not run. Since only a single function of Stage 5 is being run here and not the whole process, the metadata from S5_NIRCam.ecf and S5_fit_par.ecf is not read into the function. The metadata will have to be parsed explicitly here for the test to run correctly. (or the test will need to be restructured) class TestLightcurve(unittest.TestCase): """Tests for the lightcurve.py module""" def setUp(self): """Setup for the lightcurve""" self.time = np.linspace(0, 1, 100) self.unc = np.random.uniform(low=1E-4, high=0.01, size=100) self.flux = np.random.normal(np.ones_like(self.time), scale=self.unc)