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

No more UserCommands as rc.currsys #157

Merged
merged 9 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions ELT/tests/test_TER_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import matplotlib.pyplot as plt
import scopesim as sim
from scopesim import rc
from scopesim import UserCommands

TOP_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))
rc.__search_path__ += [TOP_PATH]
Expand All @@ -34,14 +35,18 @@ def test_eso_vs_scopesim_throughput():


## .todo: the values are not correct
@pytest.mark.xfail(reason="Does fail with ScopeSim 0.7.1. TODO: Remove mark when 0.8.0 is released.")
def test_eso_vs_scopesim_emission():
rc.__currsys__["!ATMO.temperature"] = 0.
rc.__currsys__["!TEL.temperature"] = "!ATMO.temperature"
rc.__currsys__["!TEL.etendue"] = (1 * u.m * u.arcsec)**2
cmds = UserCommands(properties={
"!ATMO.temperature": 0.,
"!TEL.temperature": "!ATMO.temperature",
"!TEL.etendue": (1 * u.m * u.arcsec)**2,
})

slist = sim.effects.SurfaceList(filename="LIST_mirrors_ELT.tbl")
slist = sim.effects.SurfaceList(filename="LIST_mirrors_ELT.tbl", cmds=cmds)
ter = sim.effects.TERCurve(filename="TER_ELT_5_mirror.dat",
temperature="!ATMO.temperature")
temperature="!ATMO.temperature",
cmds=cmds)

wave = np.linspace(0.3, 12.5, 100) * u.um
sl_flux = slist.emission(wave)
Expand Down
12 changes: 6 additions & 6 deletions HAWKI/test_hawki/test_full_package_hawki.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def test_works_seamlessly_for_hawki_package(self, capsys):
opt["detector_array_list"].include = True
opt.update()

# test that the major values have been updated in rc.__currsys__
assert rc.__currsys__["!TEL.area"].value == approx(52.02, rel=1e-3)
assert rc.__currsys__["!TEL.etendue"].value == approx(0.58455, rel=1e-3)
assert rc.__currsys__["!INST.pixel_scale"] == approx(0.106, rel=1e-3)
# test that the major values have been updated
assert opt.cmds["!TEL.area"].value == approx(52.02, rel=1e-3)
assert opt.cmds["!TEL.etendue"].value == approx(0.58455, rel=1e-3)
assert opt.cmds["!INST.pixel_scale"] == approx(0.106, rel=1e-3)

# test that OpticalTrain builds properly
assert isinstance(opt, scopesim.OpticalTrain)
Expand Down Expand Up @@ -137,8 +137,8 @@ def test_works_seamlessly_for_hawki_package(self, capsys):
plt.imshow(hdu[i].data)
plt.show()

dit = rc.__currsys__["!OBS.dit"]
ndit = rc.__currsys__["!OBS.ndit"]
dit = opt.cmds["!OBS.dit"]
ndit = opt.cmds["!OBS.ndit"]
assert np.average(hdu[1].data) == approx(ndit * dit * 0.1, abs=0.5)

def test_system_transmission_is_similar_to_eso_etc(self):
Expand Down
5 changes: 3 additions & 2 deletions METIS/METIS_DET_IFU.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ changes:
- 2021-12-16 (OC) some rearrangements

properties:
image_plane_id: 0
temperature: -233
dit: "!OBS.dit"
ndit: "!OBS.ndit"
Expand All @@ -18,7 +19,7 @@ properties:
readout_noise: 70 # electrons, AI on RvB: check
layout:
file_name: "FPA_metis_lms_layout.dat"
quantum_efficiency:
qe_curve:
file_name: "QE_detector_H2RG_METIS.dat"
linearity:
file_name: "FPA_linearity_HxRG.dat"
Expand All @@ -31,7 +32,7 @@ effects:
kwargs:
filename: "!DET.layout.file_name"

- name: qe_curve
- name: quantum_efficiency
description: Quantum efficiency curves for each detector
class: QuantumEfficiencyCurve
kwargs:
Expand Down
1 change: 1 addition & 0 deletions METIS/METIS_DET_IMG_N_Aquarius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ changes:

properties:
detector: Raytheon Aquarius
image_plane_id: 0
temperature: -265
dit: "!OBS.dit"
ndit: "!OBS.ndit"
Expand Down
3 changes: 3 additions & 0 deletions METIS/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ properties:
obsname: "MyScienceTest"
ra: 0.0
dec: 0.0
# These defaults are overruled by the individual modes:
filter_name: open
nd_filter_name: open

mode_yamls:
- object: observation
Expand Down
468 changes: 468 additions & 0 deletions METIS/docs/example_notebooks/IFU-example.ipynb

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions METIS/docs/example_notebooks/demos/demo_auto_exposure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@
"outputs": [],
"source": [
"outimg = metis.readout()[0][1].data \n",
"outimg /= sim.utils.from_currsys(metis['summed_exposure'].meta['ndit'])\n",
"outimg /= metis.cmds[metis['summed_exposure'].meta['ndit']]\n",
"\n",
"full_well = sim.utils.from_currsys(\"!DET.full_well\")\n",
"full_well = metis.cmds[\"!DET.full_well\"]\n",
"print(\"\\nResult\\n======\")\n",
"print(\"Maximum value in readout (per DIT): {:8.1f}\".format(outimg.max()))\n",
"print(\"Detector full well: {:8.1f}\".format(full_well))\n",
Expand All @@ -109,9 +109,9 @@
"outputs": [],
"source": [
"outimg = metis.readout(exptime = 1000)[0][1].data \n",
"outimg /= sim.utils.from_currsys(metis['summed_exposure'].meta['ndit'])\n",
"outimg /= metis.cmds[metis['summed_exposure'].meta['ndit']]\n",
"\n",
"full_well = sim.utils.from_currsys(\"!DET.full_well\")\n",
"full_well = metis.cmds[\"!DET.full_well\"]\n",
"print(\"\\nResult\\n======\")\n",
"print(\"Maximum value in readout (per DIT): {:8.1f}\".format(outimg.max()))\n",
"print(\"Detector full well: {:8.1f}\".format(full_well))\n",
Expand Down Expand Up @@ -159,9 +159,9 @@
"outputs": [],
"source": [
"outimg = metis.readout()[0][1].data \n",
"outimg /= sim.utils.from_currsys(metis['summed_exposure'].meta['ndit'])\n",
"outimg /= metis.cmds[metis['summed_exposure'].meta['ndit']]\n",
"\n",
"full_well = sim.utils.from_currsys(\"!DET.full_well\")\n",
"full_well = metis.cmds[\"!DET.full_well\"]\n",
"print(\"\\nResult\\n======\")\n",
"print(\"Maximum value in readout (per DIT): {:9.1f}\".format(outimg.max()))\n",
"print(\"Detector full well: {:9.1f}\".format(full_well))\n",
Expand Down Expand Up @@ -209,8 +209,9 @@
"outputs": [],
"source": [
"outimg = metis.readout(exptime=3600.)[0][1].data \n",
"outimg /= sim.utils.from_currsys(metis['summed_exposure'].meta['ndit'])\n",
"full_well = sim.utils.from_currsys(\"!DET.full_well\")\n",
"outimg /= metis.cmds[metis['summed_exposure'].meta['ndit']]\n",
"\n",
"full_well = metis.cmds[\"!DET.full_well\"]\n",
"\n",
"print(\"\\nResult\\n======\")\n",
"print(\"Maximum value in readout (per DIT): {:8.1f}\".format(outimg.max()))\n",
Expand Down Expand Up @@ -269,8 +270,9 @@
"outputs": [],
"source": [
"outimg = metis.readout()[0][1].data\n",
"outimg /= sim.utils.from_currsys(metis['summed_exposure'].meta['ndit'])\n",
"full_well = sim.utils.from_currsys(\"!DET.full_well\")\n",
"outimg /= metis.cmds[metis['summed_exposure'].meta['ndit']]\n",
"\n",
"full_well = metis.cmds[\"!DET.full_well\"]\n",
"\n",
"print(\"\\nResult\\n======\")\n",
"print(\"Maximum value in readout (per DIT): {:9.1f}\".format(outimg.max()))\n",
Expand Down Expand Up @@ -313,6 +315,13 @@
"npix = (outimg >= full_well).sum()\n",
"print(\"Number of saturated pixels:\", npix)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"Chop offsets:\", sim.utils.from_currsys(metis['chop_nod'].meta['chop_offsets']))\n",
"print(\"Nod offsets: \", sim.utils.from_currsys(metis['chop_nod'].meta['nod_offsets']))"
"print(\"Chop offsets:\", metis.cmds[metis['chop_nod'].meta['chop_offsets']])\n",
"print(\"Nod offsets: \", metis.cmds[metis['chop_nod'].meta['nod_offsets']])"
]
},
{
Expand Down Expand Up @@ -194,7 +194,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
29 changes: 14 additions & 15 deletions METIS/docs/example_notebooks/demos/demo_detector_modes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"outputs": [],
"source": [
"import scopesim as sim\n",
"from scopesim.utils import from_currsys\n",
"sim.bug_report()\n",
"\n",
"# Edit this path if you have a custom install directory, otherwise comment it out.\n",
Expand Down Expand Up @@ -107,7 +106,7 @@
"metadata": {},
"outputs": [],
"source": [
"from_currsys(metis['readout_noise'].meta['noise_std'])"
"metis.cmds[metis['readout_noise'].meta['noise_std']]"
]
},
{
Expand Down Expand Up @@ -158,7 +157,7 @@
"metadata": {},
"outputs": [],
"source": [
"from_currsys(metis['readout_noise'].meta['noise_std'])"
"metis.cmds[metis['readout_noise'].meta['noise_std']]"
]
},
{
Expand Down Expand Up @@ -219,14 +218,14 @@
"metadata": {},
"outputs": [],
"source": [
"ndit_slow = from_currsys(\"!OBS.ndit\")\n",
"dit_slow = from_currsys(\"!OBS.dit\")\n",
"ndit_slow = metis.cmds[\"!OBS.ndit\"]\n",
"dit_slow = metis.cmds[\"!OBS.dit\"]\n",
"\n",
"bg_slow = hdul_slow[1].data[250:1750, 10:200].mean()\n",
"bg_slow_expected = dit_slow * ndit_slow * from_currsys(\"!DET.dark_current\")\n",
"bg_slow_expected = dit_slow * ndit_slow * metis.cmds[\"!DET.dark_current\"]\n",
"\n",
"noise_slow = hdul_slow[1].data[250:1750, 10:200].std()\n",
"noise_slow_expected = np.sqrt(ndit_slow) * from_currsys(\"!DET.readout_noise\")"
"noise_slow_expected = np.sqrt(ndit_slow) * metis.cmds[\"!DET.readout_noise\"]"
]
},
{
Expand All @@ -251,14 +250,14 @@
"metadata": {},
"outputs": [],
"source": [
"ndit_fast = from_currsys(\"!OBS.ndit\")\n",
"dit_fast = from_currsys(\"!OBS.dit\")\n",
"ndit_fast = metis.cmds[\"!OBS.ndit\"]\n",
"dit_fast = metis.cmds[\"!OBS.dit\"]\n",
"\n",
"bg_fast = hdul_fast[1].data[250:1750, 10:200].mean()\n",
"bg_fast_expected = dit_fast * ndit_fast * from_currsys(\"!DET.dark_current\")\n",
"bg_fast_expected = dit_fast * ndit_fast * metis.cmds[\"!DET.dark_current\"]\n",
"\n",
"noise_fast = hdul_fast[1].data[250:1750, 10:200].std()\n",
"noise_fast_expected = np.sqrt(ndit_fast) * from_currsys(\"!DET.readout_noise\")"
"noise_fast_expected = np.sqrt(ndit_fast) * metis.cmds[\"!DET.readout_noise\"]"
]
},
{
Expand Down Expand Up @@ -330,12 +329,12 @@
"metis_n.observe(star, update=True)\n",
"print(\"--- high-capacity mode ---\")\n",
"hdul_high = metis_n.readout(detector_readout_mode=\"high_capacity\")[0]\n",
"fullwell_high = from_currsys(\"!DET.full_well\")\n",
"ndit_high = from_currsys(\"!OBS.ndit\")\n",
"fullwell_high = metis.cmds[\"!DET.full_well\"]\n",
"ndit_high = metis.cmds[\"!OBS.ndit\"]\n",
"print(\"--- low-capacity mode ---\")\n",
"hdul_low = metis_n.readout(detector_readout_mode=\"low_capacity\")[0]\n",
"ndit_low = from_currsys(\"!OBS.ndit\")\n",
"fullwell_low = from_currsys(\"!DET.full_well\")"
"ndit_low = metis.cmds[\"!OBS.ndit\"]\n",
"fullwell_low = metis.cmds[\"!DET.full_well\"]"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions WFC3/test_wfc3/test_full_package_wfc3_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def test_works_seamlessly_for_wfc3_package(self, capsys):
cmd = scopesim.UserCommands(use_instrument="WFC3")
opt = scopesim.OpticalTrain(cmd)

# test that the major values have been updated in rc.__currsys__
assert rc.__currsys__["!TEL.area"].value == approx(4.453, rel=1e-3)
assert rc.__currsys__["!TEL.etendue"].value == approx(0.0753, rel=1e-3)
assert rc.__currsys__["!INST.pixel_scale"] == approx(0.13, rel=1e-3)
# test that the major values have been updated
assert opt.cmds["!TEL.area"].value == approx(4.453, rel=1e-3)
assert opt.cmds["!TEL.etendue"].value == approx(0.0753, rel=1e-3)
assert opt.cmds["!INST.pixel_scale"] == approx(0.13, rel=1e-3)

# test that OpticalTrain builds properly
assert isinstance(opt, scopesim.OpticalTrain)
Expand Down Expand Up @@ -138,8 +138,8 @@ def test_works_seamlessly_for_wfc3_package(self, capsys):
plt.imshow(hdu[0].data)
plt.show()

dit = rc.__currsys__["!OBS.dit"]
ndit = rc.__currsys__["!OBS.ndit"]
dit = opt.cmds["!OBS.dit"]
ndit = opt.cmds["!OBS.ndit"]
assert np.average(hdu[1].data) == approx(ndit * dit * 0.048, abs=1)


Expand Down
1 change: 0 additions & 1 deletion docs/code/generate_rst_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def make_micado_rst_files():
"SPEC_3000x50"]

cmd = sim.UserCommands(use_instrument="MICADO", set_modes=all_modes)
rc.__currsys__ = cmd

opt_els = []
for yaml in cmd.yaml_dicts:
Expand Down
Loading