Skip to content

Commit

Permalink
Use widgets for plots and scopesimple interface for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg committed Nov 20, 2024
1 parent f83d203 commit 003e1fc
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 40 deletions.
29 changes: 14 additions & 15 deletions docs/source/examples/1_scopesim_intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"%matplotlib widget\n",
"\n",
"import scopesim as sim\n",
"from scopesim import Simulation\n",
"from scopesim_templates.stellar.clusters import cluster"
]
},
Expand All @@ -38,7 +38,7 @@
"id": "heard-motel",
"metadata": {},
"source": [
"Now, create a star cluster as the source using the ``scopesim_templates`` package. You can ignore the output that is sometimes printed. The `seed` argument is used to control the random number generation that creates the stars in the cluster. If this number is kept the same, the output will be consistent with each run, otherwise the position and brightness of the stars is randomised every time."
"Now, create a star cluster as the source using the `scopesim_templates` package. You can ignore the output that is sometimes printed. The `seed` argument is used to control the random number generation that creates the stars in the cluster. If this number is kept the same, the output will be consistent with each run, otherwise the position and brightness of the stars is randomised every time."
]
},
{
Expand All @@ -61,9 +61,9 @@
"id": "finite-linux",
"metadata": {},
"source": [
"Next, make the MICADO optical system model with ``OpticalTrain``. Observe the cluster ``Source`` object with the ``.observe()`` method and read out the MICADO detectors with ``.readout()``. This may take a few moments on slower machines.\n",
"Next, create the MICADO optical system model with the new simplified `Simulation` interface. Observe the cluster `Source` object simply by calling the simulation instance, which returns the resulting FITS HDUL. This may take a few moments on slower machines.\n",
"\n",
"The resulting FITS file can either be returned as an ``astropy.fits.HDUList`` object, or saved to disk using the optional ``filename`` parameter."
"The resulting FITS file can either be returned as an `astropy.fits.HDUList` object, which can be saved to disk using the `writeto` method."
]
},
{
Expand All @@ -73,36 +73,35 @@
"metadata": {},
"outputs": [],
"source": [
"micado = sim.OpticalTrain(\"MICADO\")\n",
"micado.observe(source)\n",
"hdul = micado.readout()\n",
"# micado.readout(filename=\"TEST.fits\")"
"simulation = Simulation(\"MICADO\", [\"SCAO\", \"IMG_4mas\"])\n",
"hdul = simulation(source)\n",
"# hdul.writeto(\"TEST.fits\")"
]
},
{
"cell_type": "markdown",
"id": "latest-ranking",
"metadata": {},
"source": [
"Display the contents the first HDU"
"Plot the results of the simulation. The `fig_kwargs` are passed to matplotlib's figure creation."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "undefined-flush",
"id": "a4a2e783-8459-4be9-87dd-77b8625446e1",
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(10,8))\n",
"plt.imshow(hdul[0][1].data, norm=\"log\", vmin=3e3, vmax=3e4, cmap=\"hot\")\n",
"plt.colorbar();"
"simulation.plot(norm=\"log\", vmin=3e3, vmax=3e4, cmap=\"hot\",\n",
" fig_kwargs={\"figsize\": (8, 8), \"layout\": \"tight\"})\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4a2e783-8459-4be9-87dd-77b8625446e1",
"id": "02cd19cd-f99f-4800-9212-5655c1fbdaca",
"metadata": {},
"outputs": [],
"source": []
Expand Down
33 changes: 13 additions & 20 deletions docs/source/examples/2_multiple_telescopes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"%matplotlib widget\n",
"\n",
"import scopesim as sim\n",
"from scopesim import Simulation\n",
"from scopesim_templates.stellar.clusters import cluster"
]
},
Expand Down Expand Up @@ -70,11 +70,8 @@
"metadata": {},
"outputs": [],
"source": [
"lfoa = sim.OpticalTrain(\"LFOA\")\n",
"lfoa.observe(source,\n",
" properties={\"!OBS.ndit\": 10, \"!OBS.ndit\": 360},\n",
" update=True)\n",
"data_lfoa = lfoa.readout()[0][1].data"
"lfoa = Simulation(\"LFOA\")\n",
"data_lfoa = lfoa(source, dit=10, ndit=360)[1].data"
]
},
{
Expand All @@ -94,17 +91,13 @@
"metadata": {},
"outputs": [],
"source": [
"micado = sim.OpticalTrain(\"MICADO\")\n",
"micado = Simulation(\"MICADO\")\n",
"# Use the central detector of the full MICADO array\n",
"micado[\"detector_window\"].include = False\n",
"micado[\"full_detector_array\"].include = True\n",
"micado[\"full_detector_array\"].meta[\"active_detectors\"] = [5]\n",
"micado.cmds[\"!OBS.dit\"] = 10\n",
"micado.cmds[\"!OBS.ndit\"] = 360\n",
"micado.update()\n",
"\n",
"micado.observe(source)\n",
"data_micado = micado.readout()[0][1].data"
"micado.optical_train[\"detector_window\"].include = False\n",
"micado.optical_train[\"full_detector_array\"].include = True\n",
"micado.optical_train[\"full_detector_array\"].meta[\"active_detectors\"] = [5]\n",
"\n",
"data_micado = micado(source, dit=10, ndit=360)[1].data"
]
},
{
Expand Down Expand Up @@ -152,8 +145,8 @@
"metadata": {},
"outputs": [],
"source": [
"pixel_scale_lfoa = lfoa.cmds[\"!INST.pixel_scale\"]\n",
"pixel_scale_micado = micado.cmds[\"!INST.pixel_scale\"]\n",
"pixel_scale_lfoa = lfoa.settings[\"!INST.pixel_scale\"]\n",
"pixel_scale_micado = micado.settings[\"!INST.pixel_scale\"]\n",
"scale_factor = pixel_scale_lfoa / pixel_scale_micado\n",
"\n",
"size_lfoa_x = data_micado.shape[0] / scale_factor /2\n",
Expand Down Expand Up @@ -191,7 +184,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2cfbf286-fed2-4c26-a09c-f637ac35fb7d",
"id": "e4c30619-8205-49f9-94d6-97a3e1e3f40c",
"metadata": {},
"outputs": [],
"source": []
Expand Down
25 changes: 21 additions & 4 deletions docs/source/examples/3_custom_effects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,31 @@
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib widget\n",
"\n",
"import scopesim as sim\n",
"from scopesim_templates.stellar import stars, star_grid"
]
},
{
"cell_type": "markdown",
"id": "5b93a241-6994-4308-a940-03c9470e0300",
"metadata": {},
"source": [
"In this examples, we will use the \"advanced\" interface of ScopeSim, which involves multiple steps to create and run the simulation, but allows for more (and easier) cutomisation of the optical train model."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cdeee262-51f5-4522-8226-0f84bea9b8f1",
"metadata": {},
"outputs": [],
"source": [
"cmd = sim.UserCommands(use_instrument=\"MICADO\", set_modes=[\"SCAO\", \"IMG_1.5mas\"])\n",
"micado = sim.OpticalTrain(cmd)"
]
},
{
"cell_type": "markdown",
"id": "loving-skill",
Expand All @@ -42,13 +62,10 @@
{
"cell_type": "code",
"execution_count": null,
"id": "celtic-fluid",
"id": "98032a6d-b720-4db2-90a6-e4a530c71cb0",
"metadata": {},
"outputs": [],
"source": [
"cmd = sim.UserCommands(use_instrument=\"MICADO\", set_modes=[\"SCAO\", \"IMG_1.5mas\"])\n",
"micado = sim.OpticalTrain(cmd)\n",
"\n",
"micado.effects"
]
},
Expand Down
36 changes: 35 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ optional = true
jupyter = "^1.0"
jupytext = "^1.10.0"
ipykernel = "^6.24.0"
ipympl = "^0.9.4"

[tool.poetry.group.test.dependencies]
pytest = "^7.4.3"
Expand All @@ -67,6 +68,7 @@ nbsphinx = "^0.9.3"
numpydoc = "^1.6.0"
scopesim_templates = ">=0.6.0"
ipykernel = "^6.24.0"
ipympl = "^0.9.4"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/AstarVienna/ScopeSim/issues"
Expand Down

0 comments on commit 003e1fc

Please sign in to comment.