slicersim 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. slicersim-1.0.0/LICENSE +201 -0
  2. slicersim-1.0.0/PKG-INFO +217 -0
  3. slicersim-1.0.0/README.md +177 -0
  4. slicersim-1.0.0/pyproject.toml +114 -0
  5. slicersim-1.0.0/setup.cfg +4 -0
  6. slicersim-1.0.0/src/slicersim/__init__.py +20 -0
  7. slicersim-1.0.0/src/slicersim/config/blackbody.toml +15 -0
  8. slicersim-1.0.0/src/slicersim/config/dispersion_default.ecsv +58 -0
  9. slicersim-1.0.0/src/slicersim/config/flatsource.toml +3 -0
  10. slicersim-1.0.0/src/slicersim/config/lazuli_cbe.toml +91 -0
  11. slicersim-1.0.0/src/slicersim/config/lazuli_eol.toml +21 -0
  12. slicersim-1.0.0/src/slicersim/config/lazuli_test.toml +91 -0
  13. slicersim-1.0.0/src/slicersim/config/mapping_spotdata.csv +5221 -0
  14. slicersim-1.0.0/src/slicersim/config/qe_H4RG17_default.ecsv +66 -0
  15. slicersim-1.0.0/src/slicersim/config/stdstar.toml +13 -0
  16. slicersim-1.0.0/src/slicersim/config/supernova.toml +15 -0
  17. slicersim-1.0.0/src/slicersim/config/throughput_bol.csv +1698 -0
  18. slicersim-1.0.0/src/slicersim/config/throughput_eol.csv +1698 -0
  19. slicersim-1.0.0/src/slicersim/config/throughput_eol_given.csv +1703 -0
  20. slicersim-1.0.0/src/slicersim/config/throughput_ssci_28052026.csv +1703 -0
  21. slicersim-1.0.0/src/slicersim/config/zodi.toml +5 -0
  22. slicersim-1.0.0/src/slicersim/detector.py +839 -0
  23. slicersim-1.0.0/src/slicersim/extra/__init__.py +4 -0
  24. slicersim-1.0.0/src/slicersim/extra/calspec.py +157 -0
  25. slicersim-1.0.0/src/slicersim/iotools.py +363 -0
  26. slicersim-1.0.0/src/slicersim/lazuli.py +748 -0
  27. slicersim-1.0.0/src/slicersim/mapper.py +888 -0
  28. slicersim-1.0.0/src/slicersim/nea.py +218 -0
  29. slicersim-1.0.0/src/slicersim/profiles.py +409 -0
  30. slicersim-1.0.0/src/slicersim/sample.py +403 -0
  31. slicersim-1.0.0/src/slicersim/scene/__init__.py +46 -0
  32. slicersim-1.0.0/src/slicersim/scene/background.py +129 -0
  33. slicersim-1.0.0/src/slicersim/scene/base.py +152 -0
  34. slicersim-1.0.0/src/slicersim/scene/host.py +1 -0
  35. slicersim-1.0.0/src/slicersim/scene/pointsource.py +520 -0
  36. slicersim-1.0.0/src/slicersim/scene/scene.py +403 -0
  37. slicersim-1.0.0/src/slicersim/simulation.py +2326 -0
  38. slicersim-1.0.0/src/slicersim/spectrograph.py +2629 -0
  39. slicersim-1.0.0/src/slicersim/target.py +489 -0
  40. slicersim-1.0.0/src/slicersim/telescope.py +448 -0
  41. slicersim-1.0.0/src/slicersim/thermal.py +545 -0
  42. slicersim-1.0.0/src/slicersim/utils.py +368 -0
  43. slicersim-1.0.0/src/slicersim.egg-info/PKG-INFO +217 -0
  44. slicersim-1.0.0/src/slicersim.egg-info/SOURCES.txt +58 -0
  45. slicersim-1.0.0/src/slicersim.egg-info/dependency_links.txt +1 -0
  46. slicersim-1.0.0/src/slicersim.egg-info/not-zip-safe +1 -0
  47. slicersim-1.0.0/src/slicersim.egg-info/requires.txt +24 -0
  48. slicersim-1.0.0/src/slicersim.egg-info/top_level.txt +1 -0
  49. slicersim-1.0.0/tests/test_detector.py +57 -0
  50. slicersim-1.0.0/tests/test_mapper.py +102 -0
  51. slicersim-1.0.0/tests/test_profiles.py +18 -0
  52. slicersim-1.0.0/tests/test_sample.py +73 -0
  53. slicersim-1.0.0/tests/test_scene.py +49 -0
  54. slicersim-1.0.0/tests/test_simulation.py +246 -0
  55. slicersim-1.0.0/tests/test_spectrograph.py +171 -0
  56. slicersim-1.0.0/tests/test_target.py +180 -0
  57. slicersim-1.0.0/tests/test_telescope.py +39 -0
  58. slicersim-1.0.0/tests/test_thermal.py +12 -0
  59. slicersim-1.0.0/tests/test_throughut.py +44 -0
  60. slicersim-1.0.0/tests/test_utils.py +60 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,217 @@
1
+ Metadata-Version: 2.4
2
+ Name: slicersim
3
+ Version: 1.0.0
4
+ Summary: Simulating Transient in the sky and how to observe them
5
+ Author-email: Mickael Rigault <m.rigault@ipnl.in2p3.fr>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/MickaelRigault/slicersim
8
+ Keywords: astronomy,astrophysics
9
+ Classifier: Development Status :: 2 - Pre-Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
13
+ Classifier: Topic :: Scientific/Engineering :: Physics
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: astropy
18
+ Requires-Dist: extinction
19
+ Requires-Dist: numpy
20
+ Requires-Dist: pandas
21
+ Requires-Dist: requests
22
+ Requires-Dist: scipy
23
+ Requires-Dist: sep
24
+ Requires-Dist: shapely
25
+ Requires-Dist: sncosmo
26
+ Provides-Extra: docs
27
+ Requires-Dist: matplotlib; extra == "docs"
28
+ Requires-Dist: myst-nb; extra == "docs"
29
+ Requires-Dist: nbsphinx; extra == "docs"
30
+ Requires-Dist: numpydoc; extra == "docs"
31
+ Requires-Dist: pandas-sphinx; extra == "docs"
32
+ Requires-Dist: sphinx-book-theme; extra == "docs"
33
+ Requires-Dist: sphinx_copybutton; extra == "docs"
34
+ Requires-Dist: sphinx-design; extra == "docs"
35
+ Provides-Extra: tests
36
+ Requires-Dist: pytest; extra == "tests"
37
+ Requires-Dist: pytest-doctestplus; extra == "tests"
38
+ Requires-Dist: pytest-cov; extra == "tests"
39
+ Dynamic: license-file
40
+
41
+ [![codecov](https://codecov.io/github/MickaelRigault/slicersim/graph/badge.svg?token=A78ZDQQ9N3)](https://codecov.io/github/MickaelRigault/slicersim)
42
+ [![Run unit tests](https://github.com/MickaelRigault/slicersim/actions/workflows/ci.yml/badge.svg)](https://github.com/MickaelRigault/slicersim/actions/workflows/ci.yml)
43
+
44
+ # slicersim
45
+ Simulation of Slicer observations
46
+
47
+
48
+
49
+ ***
50
+ # Installation
51
+ ```bash
52
+ git clone https://github.com/MickaelRigault/slicersim.git
53
+ cd slicersim
54
+ pip install .
55
+ ```
56
+ or
57
+ ```bash
58
+ pip install git+https://github.com/MickaelRigault/slicersim.git
59
+ ```
60
+ ***
61
+ # Top level ETC
62
+
63
+ ```python
64
+ >>> import slicersim
65
+ >>> import numpy as np
66
+
67
+ ```
68
+
69
+ ## Any spectra
70
+
71
+ Compute the exposure time needed any input spectrum:
72
+
73
+ ```python
74
+ >>> lbda_ref = np.linspace(3000, 20_000, 500) # larger than lazuli bandpass
75
+ >>> flux_ref = np.ones(lbda_ref.shape) # flat spectrum
76
+ >>> exptime, lazulitarget = slicersim.lazuli_etc(lbda_ref, flux_ref, snr=20, mag=21, band="bessellb")
77
+ >>> print(exptime)
78
+ 237.72
79
+
80
+ ```
81
+
82
+ ## Supernova
83
+
84
+ Compute the exposure time needed to observe a Supernovae:
85
+
86
+ ```python
87
+ >>> exptime, snia_target = slicersim.lazuli_sn_etc(snr=20, model="salt", redshift=1.2, x1=1.5, c=0.2, phase=-2.2)
88
+ >>> print(exptime)
89
+ 5795.84
90
+
91
+ ```
92
+
93
+ ***
94
+ # Quick look
95
+
96
+ ```python
97
+ import slicersim
98
+ # load a SN Ia (see also: `slicersim.LazuliTarget(lbda, flux)`)
99
+ snia = slicersim.LazuliSN(redshift=0.8, c=0.2, x1=-1.2, phase=1.5)
100
+
101
+ # update configuration to reach a signal-to-noise of 20
102
+ _ = snia.setup_to_snr(20)
103
+
104
+ # grab the expected observed spectrum
105
+ lbda, flux_1, variance_1 = snia.get_spectrum(unit="adu")
106
+
107
+ # change the target property
108
+ # warning: without updating the setting, this new target won't have a snr=20
109
+ snia.set_properties(redshift=1.2)
110
+ lbda, flux_2, variance_2 = snia.get_spectrum(unit="adu")
111
+ ```
112
+
113
+ and show your simulated spectra
114
+ ```python
115
+ import matplotlib.pyplot as plt
116
+ import numpy as np
117
+ fig, ax = plt.subplots(figsize=[7,3])
118
+
119
+ ax.plot(lbda, flux_1)
120
+ ax.fill_between(lbda,
121
+ flux_1-np.sqrt(variance_1),
122
+ flux_1+np.sqrt(variance_1), alpha=0.3,
123
+ label="z=0.8")
124
+
125
+ ax.plot(lbda, flux_2)
126
+ ax.fill_between(lbda,
127
+ flux_2-np.sqrt(variance_2),
128
+ flux_2+np.sqrt(variance_2), alpha=0.3,
129
+ label="z=1.2")
130
+ ax.legend(frameon=False, fontsize="small")
131
+ ax.set(xlabel=r"wavelength [$\AA$]", ylabel="flux [ADU]")
132
+ ```
133
+ ![readme example](docs/gallery/spectra_examples.png)
134
+
135
+ ***
136
+ # Tutorials
137
+
138
+ ## Beginner
139
+ - [ETC and simuated spectra: top level function](docs/notebooks/beginner_ETC_lazulitarget.ipynb)
140
+ - Exposure time calculator for any target or a supernovae
141
+ - get the simulated spectrum and variance
142
+ - [LazuliTarget (Any target, Type Ia Supernovae, CalSpec)](docs/notebooks/beginner_LazuliTargets.ipynb):
143
+ - Specify the desired signal to noise
144
+ - get exposure time, and read-mode
145
+ - get simulated spectra
146
+ - [Check the origin of the variance sources](docs/notebooks/beginner_variancesource.ipynb)
147
+ - origin of variance (read-out noise, target poisson noise, dark-current etc)
148
+ - switch off any contribution and see resulting variance
149
+ - scan all variance contributions, get the resulting dataframe and plot the result.
150
+ - [Change properties of the target](beginner_change_properties.ipynb):
151
+ - change any supernovae properties
152
+ - change the magnitude of a loaded target
153
+
154
+ ## Advanced
155
+ - [Change the detector read-out mode or spectrograph spatial sampling](advanced_change_detector_and_spectrograph.ipynb)
156
+ - change the detector mode: max-group, n-frames per group
157
+ - force the read-our mode (and see which SNR you eventually get)
158
+ - change the spectrograph sampling (fine and medium grid)
159
+ - [Access the detector QE, throughtput, effective spectral resolution...](advanced_access_qe_spectral_resolution_etc.ipynb)
160
+ - Access any property of any simulation element, and change them !
161
+
162
+
163
+ ## Experts
164
+ - Noise Equivalent area
165
+ - Build you own “scene”
166
+ - Build your own configuration
167
+ ***
168
+ # Lower-level: Simulator & config.
169
+
170
+ Example: Study origin of variance
171
+
172
+ You can load a slicersim object at a lower level than an lazuli object: a Simulator. This object is at the core of slicersim and combines information of all sources needed to simulate our observations: a scene (what is observed), a mirror, a spectrograph and a detector.
173
+
174
+ The Simulator combine these to be able to generate a datacube with realistic noise, and extract a realistic spectrum from it.
175
+
176
+ Once your simulator is loaded, you have several method to check the variance origin.
177
+ - `estimate_variance_contribution`: that probe the variance origin for a given wavelength rate
178
+ - `estimate_variance_contribution_spectra`: similar but for whole spectrum
179
+ - `show_variance_sources`: plotting function associated to `estimate_variance_contribution_spectra`
180
+
181
+ ```python
182
+ import slicersim
183
+ # load the correct simulator
184
+ config = slicersim.iotools.get_config(instrument='lazuli.toml')
185
+ sim = slicersim.Simulation.from_config(config)
186
+
187
+ # Set the target you want
188
+ sim.update(target__redshift=1., target__x1=0, target__c=0)
189
+
190
+ # look for the config needed to get an average SNR of 20 in [4000, 6800] rest-frame
191
+ new_config, snr, integration_time = sim.fetch_snr(20, lbda_range=[4000, 6800], frame='rest')
192
+ sim.update(**new_config) # let's set it
193
+
194
+ # get the expected spectrum (in ADU)
195
+ lbda, flux, variance = sim.get_spectrum()
196
+
197
+ # Show details
198
+ fig = sim.show_variance_sources(flux_calibrated=False)
199
+ ```
200
+ ![readme example](docs/gallery/spectra_variance.png)
201
+
202
+ ***
203
+ # PSF & Noise equivalent area
204
+
205
+ by default, the code assumes gaussian PSF both for spatial (at the slicer/mla) and cross-dispersion (at pixels) level.
206
+
207
+ `slicersim.profiles` contains additional PSF model (from [astropy.modeling](https://docs.astropy.org/en/latest/modeling/predef_models2D.html)
208
+ that can be used to build 2D model or estimate the PSF noise equivalent area (nea).
209
+
210
+ *(more to come..., see: `slicersim.profiles.get_2dpsf_nea()`)*
211
+
212
+
213
+
214
+
215
+ ***
216
+ # Credits
217
+ Developped by M. Rigault ; _adapted from the original MLAPerf v:0.18.0 developed by Y. Copin and M. Rigault_
@@ -0,0 +1,177 @@
1
+ [![codecov](https://codecov.io/github/MickaelRigault/slicersim/graph/badge.svg?token=A78ZDQQ9N3)](https://codecov.io/github/MickaelRigault/slicersim)
2
+ [![Run unit tests](https://github.com/MickaelRigault/slicersim/actions/workflows/ci.yml/badge.svg)](https://github.com/MickaelRigault/slicersim/actions/workflows/ci.yml)
3
+
4
+ # slicersim
5
+ Simulation of Slicer observations
6
+
7
+
8
+
9
+ ***
10
+ # Installation
11
+ ```bash
12
+ git clone https://github.com/MickaelRigault/slicersim.git
13
+ cd slicersim
14
+ pip install .
15
+ ```
16
+ or
17
+ ```bash
18
+ pip install git+https://github.com/MickaelRigault/slicersim.git
19
+ ```
20
+ ***
21
+ # Top level ETC
22
+
23
+ ```python
24
+ >>> import slicersim
25
+ >>> import numpy as np
26
+
27
+ ```
28
+
29
+ ## Any spectra
30
+
31
+ Compute the exposure time needed any input spectrum:
32
+
33
+ ```python
34
+ >>> lbda_ref = np.linspace(3000, 20_000, 500) # larger than lazuli bandpass
35
+ >>> flux_ref = np.ones(lbda_ref.shape) # flat spectrum
36
+ >>> exptime, lazulitarget = slicersim.lazuli_etc(lbda_ref, flux_ref, snr=20, mag=21, band="bessellb")
37
+ >>> print(exptime)
38
+ 237.72
39
+
40
+ ```
41
+
42
+ ## Supernova
43
+
44
+ Compute the exposure time needed to observe a Supernovae:
45
+
46
+ ```python
47
+ >>> exptime, snia_target = slicersim.lazuli_sn_etc(snr=20, model="salt", redshift=1.2, x1=1.5, c=0.2, phase=-2.2)
48
+ >>> print(exptime)
49
+ 5795.84
50
+
51
+ ```
52
+
53
+ ***
54
+ # Quick look
55
+
56
+ ```python
57
+ import slicersim
58
+ # load a SN Ia (see also: `slicersim.LazuliTarget(lbda, flux)`)
59
+ snia = slicersim.LazuliSN(redshift=0.8, c=0.2, x1=-1.2, phase=1.5)
60
+
61
+ # update configuration to reach a signal-to-noise of 20
62
+ _ = snia.setup_to_snr(20)
63
+
64
+ # grab the expected observed spectrum
65
+ lbda, flux_1, variance_1 = snia.get_spectrum(unit="adu")
66
+
67
+ # change the target property
68
+ # warning: without updating the setting, this new target won't have a snr=20
69
+ snia.set_properties(redshift=1.2)
70
+ lbda, flux_2, variance_2 = snia.get_spectrum(unit="adu")
71
+ ```
72
+
73
+ and show your simulated spectra
74
+ ```python
75
+ import matplotlib.pyplot as plt
76
+ import numpy as np
77
+ fig, ax = plt.subplots(figsize=[7,3])
78
+
79
+ ax.plot(lbda, flux_1)
80
+ ax.fill_between(lbda,
81
+ flux_1-np.sqrt(variance_1),
82
+ flux_1+np.sqrt(variance_1), alpha=0.3,
83
+ label="z=0.8")
84
+
85
+ ax.plot(lbda, flux_2)
86
+ ax.fill_between(lbda,
87
+ flux_2-np.sqrt(variance_2),
88
+ flux_2+np.sqrt(variance_2), alpha=0.3,
89
+ label="z=1.2")
90
+ ax.legend(frameon=False, fontsize="small")
91
+ ax.set(xlabel=r"wavelength [$\AA$]", ylabel="flux [ADU]")
92
+ ```
93
+ ![readme example](docs/gallery/spectra_examples.png)
94
+
95
+ ***
96
+ # Tutorials
97
+
98
+ ## Beginner
99
+ - [ETC and simuated spectra: top level function](docs/notebooks/beginner_ETC_lazulitarget.ipynb)
100
+ - Exposure time calculator for any target or a supernovae
101
+ - get the simulated spectrum and variance
102
+ - [LazuliTarget (Any target, Type Ia Supernovae, CalSpec)](docs/notebooks/beginner_LazuliTargets.ipynb):
103
+ - Specify the desired signal to noise
104
+ - get exposure time, and read-mode
105
+ - get simulated spectra
106
+ - [Check the origin of the variance sources](docs/notebooks/beginner_variancesource.ipynb)
107
+ - origin of variance (read-out noise, target poisson noise, dark-current etc)
108
+ - switch off any contribution and see resulting variance
109
+ - scan all variance contributions, get the resulting dataframe and plot the result.
110
+ - [Change properties of the target](beginner_change_properties.ipynb):
111
+ - change any supernovae properties
112
+ - change the magnitude of a loaded target
113
+
114
+ ## Advanced
115
+ - [Change the detector read-out mode or spectrograph spatial sampling](advanced_change_detector_and_spectrograph.ipynb)
116
+ - change the detector mode: max-group, n-frames per group
117
+ - force the read-our mode (and see which SNR you eventually get)
118
+ - change the spectrograph sampling (fine and medium grid)
119
+ - [Access the detector QE, throughtput, effective spectral resolution...](advanced_access_qe_spectral_resolution_etc.ipynb)
120
+ - Access any property of any simulation element, and change them !
121
+
122
+
123
+ ## Experts
124
+ - Noise Equivalent area
125
+ - Build you own “scene”
126
+ - Build your own configuration
127
+ ***
128
+ # Lower-level: Simulator & config.
129
+
130
+ Example: Study origin of variance
131
+
132
+ You can load a slicersim object at a lower level than an lazuli object: a Simulator. This object is at the core of slicersim and combines information of all sources needed to simulate our observations: a scene (what is observed), a mirror, a spectrograph and a detector.
133
+
134
+ The Simulator combine these to be able to generate a datacube with realistic noise, and extract a realistic spectrum from it.
135
+
136
+ Once your simulator is loaded, you have several method to check the variance origin.
137
+ - `estimate_variance_contribution`: that probe the variance origin for a given wavelength rate
138
+ - `estimate_variance_contribution_spectra`: similar but for whole spectrum
139
+ - `show_variance_sources`: plotting function associated to `estimate_variance_contribution_spectra`
140
+
141
+ ```python
142
+ import slicersim
143
+ # load the correct simulator
144
+ config = slicersim.iotools.get_config(instrument='lazuli.toml')
145
+ sim = slicersim.Simulation.from_config(config)
146
+
147
+ # Set the target you want
148
+ sim.update(target__redshift=1., target__x1=0, target__c=0)
149
+
150
+ # look for the config needed to get an average SNR of 20 in [4000, 6800] rest-frame
151
+ new_config, snr, integration_time = sim.fetch_snr(20, lbda_range=[4000, 6800], frame='rest')
152
+ sim.update(**new_config) # let's set it
153
+
154
+ # get the expected spectrum (in ADU)
155
+ lbda, flux, variance = sim.get_spectrum()
156
+
157
+ # Show details
158
+ fig = sim.show_variance_sources(flux_calibrated=False)
159
+ ```
160
+ ![readme example](docs/gallery/spectra_variance.png)
161
+
162
+ ***
163
+ # PSF & Noise equivalent area
164
+
165
+ by default, the code assumes gaussian PSF both for spatial (at the slicer/mla) and cross-dispersion (at pixels) level.
166
+
167
+ `slicersim.profiles` contains additional PSF model (from [astropy.modeling](https://docs.astropy.org/en/latest/modeling/predef_models2D.html)
168
+ that can be used to build 2D model or estimate the PSF noise equivalent area (nea).
169
+
170
+ *(more to come..., see: `slicersim.profiles.get_2dpsf_nea()`)*
171
+
172
+
173
+
174
+
175
+ ***
176
+ # Credits
177
+ Developped by M. Rigault ; _adapted from the original MLAPerf v:0.18.0 developed by Y. Copin and M. Rigault_