From 050729c188a40dbcafcda2295d08d9a3ec9d65e3 Mon Sep 17 00:00:00 2001 From: David Kirkby Date: Mon, 17 Apr 2017 17:04:57 -0700 Subject: [PATCH 1/6] Add unit test that should fail with astropy 1.3.2 and pass with 1.2.1 --- specsim/tests/test_simulator.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/specsim/tests/test_simulator.py b/specsim/tests/test_simulator.py index 158ee31..c373481 100644 --- a/specsim/tests/test_simulator.py +++ b/specsim/tests/test_simulator.py @@ -110,6 +110,21 @@ def test_fiber_positioning(): assert np.allclose(sim.focal_y.to(u.mm).value, 0.) +def test_output_table_units(): + """Test that units are preserved after calling simulate(). + + This test was added in response to issue #62 + """ + sim = specsim.simulator.Simulator('test', num_fibers=1) + for table in (sim.simulated, sim.camera_output[0]): + units_before = {} + for name in table.colnames: + units_before[name] = table[name].unit + sim.simulate() + for name in table.colnames: + assert units_before[name] == table[name].unit + + def test_plot(): s = Simulator('test') s.simulate() From a5087b53a35474c20e8174a523ac144787ee75a3 Mon Sep 17 00:00:00 2001 From: David Kirkby Date: Mon, 17 Apr 2017 17:15:00 -0700 Subject: [PATCH 2/6] Update new unit test --- specsim/tests/test_simulator.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/specsim/tests/test_simulator.py b/specsim/tests/test_simulator.py index c373481..3cac71b 100644 --- a/specsim/tests/test_simulator.py +++ b/specsim/tests/test_simulator.py @@ -116,11 +116,12 @@ def test_output_table_units(): This test was added in response to issue #62 """ sim = specsim.simulator.Simulator('test', num_fibers=1) + units_before = {} for table in (sim.simulated, sim.camera_output[0]): - units_before = {} for name in table.colnames: units_before[name] = table[name].unit - sim.simulate() + sim.simulate() + for table in (sim.simulated, sim.camera_output[0]): for name in table.colnames: assert units_before[name] == table[name].unit From 3149d8ff746f9d2ffd381fef4b11864ff10772d3 Mon Sep 17 00:00:00 2001 From: David Kirkby Date: Mon, 17 Apr 2017 17:15:51 -0700 Subject: [PATCH 3/6] Ingore .eggs folder (?) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 46489e0..dd299cd 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ docs/_build dist build eggs +.eggs parts bin var From c18f3855df886ee025859fbe3503fd7bdab2a5dd Mon Sep 17 00:00:00 2001 From: David Kirkby Date: Mon, 17 Apr 2017 17:16:22 -0700 Subject: [PATCH 4/6] Fix warning about [pytest] --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 7bb1d65..3422010 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,7 +12,7 @@ all_files = 1 upload-dir = docs/_build/html show-response = 1 -[pytest] +[tool:pytest] minversion = 2.2 norecursedirs = build docs/_build doctest_plus = enabled From 6073fb38bce4a6da9f0628c0ed40a640842c8f24 Mon Sep 17 00:00:00 2001 From: David Kirkby Date: Mon, 17 Apr 2017 17:18:03 -0700 Subject: [PATCH 5/6] Implement fix for units changing after call to simulate() --- specsim/simulator.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/specsim/simulator.py b/specsim/simulator.py index c6173ff..89d5a6a 100644 --- a/specsim/simulator.py +++ b/specsim/simulator.py @@ -477,15 +477,15 @@ def simulate(self, sky_positions=None, focal_positions=None, camera.read_noise_per_bin[:, np.newaxis].to(u.electron).value) # Calculate the corresponding downsampled output quantities. - output['num_source_electrons'] = ( + output['num_source_electrons'][:] = ( camera.downsample(num_source_electrons.T)).T - output['num_sky_electrons'] = ( + output['num_sky_electrons'][:] = ( camera.downsample(num_sky_electrons.T)).T - output['num_dark_electrons'] = ( + output['num_dark_electrons'][:] = ( camera.downsample(num_dark_electrons.T)).T - output['read_noise_electrons'] = np.sqrt( + output['read_noise_electrons'][:] = np.sqrt( camera.downsample(read_noise_electrons.T ** 2)).T - output['variance_electrons'] = ( + output['variance_electrons'][:] = ( output['num_source_electrons'] + output['num_sky_electrons'] + output['num_dark_electrons'] + @@ -493,16 +493,16 @@ def simulate(self, sky_positions=None, focal_positions=None, # Calculate the effective calibration from detected electrons to # source flux above the atmosphere, downsampled to output pixels. - output['flux_calibration'] = 1.0 / camera.downsample( + output['flux_calibration'][:] = 1.0 / camera.downsample( camera.apply_resolution( source_flux_to_photons.T * camera.throughput)).T # Calculate the calibrated flux in this camera. - output['observed_flux'] = ( + output['observed_flux'][:] = ( output['flux_calibration'] * output['num_source_electrons']) # Calculate the corresponding flux inverse variance. - output['flux_inverse_variance'] = ( + output['flux_inverse_variance'][:] = ( output['flux_calibration'] ** -2 * output['variance_electrons'] ** -1) From f0183bd5ea215a949e6e9467b60a433e437854ae Mon Sep 17 00:00:00 2001 From: David Kirkby Date: Mon, 17 Apr 2017 19:15:40 -0700 Subject: [PATCH 6/6] Update change log --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index f05a6e1..91b7902 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,7 @@ 0.9 (unreleased) ---------------- +- Fix Simulator output table units with astropy 1.3.2 (#62). - Add support for simulating calibration exposures (#54). - Add wavelength min/max options to Simulator.plot(). - Better support for alternate simulation wavelength grids (PR #60).