Skip to content

Commit

Permalink
Merge pull request #239 from teutoburg/fh/tldr
Browse files Browse the repository at this point in the history
Improve example notebooks
  • Loading branch information
teutoburg authored Jul 3, 2023
2 parents 6ad75c5 + e70b192 commit 3490ce1
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 1,209 deletions.
202 changes: 26 additions & 176 deletions docs/source/5_liners/bang_strings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,20 @@
"\n",
"## !-strings are for setting simulation parameters\n",
"\n",
"### TL;DR\n",
"\n",
" import scopesim as sim\n",
" opt = sim.load_example_optical_train()\n",
" opt.cmds[\"!ATMO\"]\n",
" opt.cmds[\"!ATMO.background\"]\n",
" opt.cmds[\"!ATMO.background.filter_name\"]\n",
"\n",
".. note: !-strings only work on `UserCommands` objects\n",
"\n",
"!-strings are a convenient way of accessing multiple layers of a nested dictionary structure with a single string using the format:\n",
"\n",
" \"!<ALIAS>.<sub-dict>...<sub-dict>.<param>\"\n",
" \n",
"Any level of the nested dictionary can be reached by truncating the keyword."
"Any level of the nested dictionary can be reached by truncating the keyword.\n",
"\n",
"**Note: !-strings only work on `UserCommands` objects**\n",
"\n",
"Below is an example of how to use !-strings, using the example optical train."
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "loved-franchise",
"metadata": {},
"outputs": [],
Expand All @@ -39,64 +33,30 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "uniform-cursor",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'background': {'filter_name': 'J', 'value': 16.6, 'unit': 'mag'},\n",
" 'element_name': 'basic_atmosphere'}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"opt.cmds[\"!ATMO\"]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "domestic-chemical",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'filter_name': 'J', 'value': 16.6, 'unit': 'mag'}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"opt.cmds[\"!ATMO.background\"]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "earned-indicator",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'J'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"opt.cmds[\"!ATMO.background.filter_name\"]"
]
Expand All @@ -108,82 +68,19 @@
"source": [
"## #-strings are for accessing Effect object parameters\n",
"\n",
"### TL;DR\n",
"\n",
" opt.effects\n",
" opt[\"#exposure_action.\"]\n",
" opt[\"#exposure_action.ndit\"]\n",
" opt[\"#exposure_action.ndit!\"]\n",
"\n",
"\n",
".. note: !-strings only work on `OpticalTrain` objects\n",
"\n",
"Similar to !-strings, #-strings allow us to get at the preset values inside the Effect-objects of the optical system. #-strings allow us to pring the contents of an effect's meta dictionary.\n",
"\n",
"First let's list the effects"
"**Note: !-strings only work on `OpticalTrain` objects**\n",
"\n",
"Here, we're again using the example optical train defined above. First let's list the effects:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "hydraulic-astrology",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<i>Table length=17</i>\n",
"<table id=\"table2455016965344\" class=\"table-striped table-bordered table-condensed\">\n",
"<thead><tr><th>element</th><th>name</th><th>class</th><th>included</th></tr></thead>\n",
"<thead><tr><th>str16</th><th>str22</th><th>str29</th><th>bool</th></tr></thead>\n",
"<tr><td>basic_atmosphere</td><td>atmospheric_radiometry</td><td>AtmosphericTERCurve</td><td>False</td></tr>\n",
"<tr><td>basic_telescope</td><td>psf</td><td>SeeingPSF</td><td>True</td></tr>\n",
"<tr><td>basic_telescope</td><td>telescope_reflection</td><td>TERCurve</td><td>True</td></tr>\n",
"<tr><td>basic_instrument</td><td>static_surfaces</td><td>SurfaceList</td><td>True</td></tr>\n",
"<tr><td>basic_instrument</td><td>filter_wheel : [J]</td><td>FilterWheel</td><td>True</td></tr>\n",
"<tr><td>basic_instrument</td><td>slit_wheel : [narrow]</td><td>SlitWheel</td><td>False</td></tr>\n",
"<tr><td>basic_detector</td><td>detector_window</td><td>DetectorWindow</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>qe_curve</td><td>QuantumEfficiencyCurve</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>exposure_action</td><td>SummedExposure</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>dark_current</td><td>DarkCurrent</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>shot_noise</td><td>ShotNoise</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>detector_linearity</td><td>LinearityCurve</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>readout_noise</td><td>PoorMansHxRGReadoutNoise</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>source_fits_keywords</td><td>SourceDescriptionFitsKeywords</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>effects_fits_keywords</td><td>EffectsMetaKeywords</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>config_fits_keywords</td><td>SimulationConfigFitsKeywords</td><td>True</td></tr>\n",
"<tr><td>basic_detector</td><td>extra_fits_keywords</td><td>ExtraFitsKeywords</td><td>True</td></tr>\n",
"</table>"
],
"text/plain": [
"<Table length=17>\n",
" element name class included\n",
" str16 str22 str29 bool \n",
"---------------- ---------------------- ----------------------------- --------\n",
"basic_atmosphere atmospheric_radiometry AtmosphericTERCurve False\n",
" basic_telescope psf SeeingPSF True\n",
" basic_telescope telescope_reflection TERCurve True\n",
"basic_instrument static_surfaces SurfaceList True\n",
"basic_instrument filter_wheel : [J] FilterWheel True\n",
"basic_instrument slit_wheel : [narrow] SlitWheel False\n",
" basic_detector detector_window DetectorWindow True\n",
" basic_detector qe_curve QuantumEfficiencyCurve True\n",
" basic_detector exposure_action SummedExposure True\n",
" basic_detector dark_current DarkCurrent True\n",
" basic_detector shot_noise ShotNoise True\n",
" basic_detector detector_linearity LinearityCurve True\n",
" basic_detector readout_noise PoorMansHxRGReadoutNoise True\n",
" basic_detector source_fits_keywords SourceDescriptionFitsKeywords True\n",
" basic_detector effects_fits_keywords EffectsMetaKeywords True\n",
" basic_detector config_fits_keywords SimulationConfigFitsKeywords True\n",
" basic_detector extra_fits_keywords ExtraFitsKeywords True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"opt.effects"
]
Expand All @@ -197,40 +94,15 @@
"\n",
" \"#<effect-name>.\"\n",
" \n",
".. note: The `.` at the end is important, otherwise the optical train will look for a non-existant effect named `#<effect-name>`"
"**Note: The `.` at the end is important, otherwise the optical train will look for a non-existant effect named `#<effect-name>`**"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "exterior-romania",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'filename': None,\n",
" 'description': 'Summing up sky signal for all DITs and NDITs',\n",
" 'history': [],\n",
" 'name': 'exposure_action',\n",
" 'image_plane_id': 0,\n",
" 'temperature': -230,\n",
" 'dit': '!OBS.dit',\n",
" 'ndit': '!OBS.ndit',\n",
" 'width': 1024,\n",
" 'height': 1024,\n",
" 'x': 0,\n",
" 'y': 0,\n",
" 'element_name': 'basic_detector',\n",
" 'z_order': [860],\n",
" 'include': True}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"opt[\"#exposure_action.\"]"
]
Expand All @@ -245,21 +117,10 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "independent-benjamin",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'!OBS.ndit'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"opt[\"#exposure_action.ndit\"]"
]
Expand All @@ -274,29 +135,18 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "internal-capital",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"opt[\"#exposure_action.ndit!\"]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -310,7 +160,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 3490ce1

Please sign in to comment.