Skip to content
Open
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
216 changes: 216 additions & 0 deletions examples/cryostat.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "brown-despite",
"metadata": {},
"outputs": [],
"source": [
"from mcstasscript.interface import instr, functions, plotter\n",
"import matplotlib\n",
"%matplotlib widget"
]
},
{
"cell_type": "markdown",
"id": "approved-parade",
"metadata": {},
"source": [
"## Demo of cryostat builder\n",
"This notebook contains a quick demo of the Cryostat class that makes the task of adding a cryostat model much less daunting. First an instrument object is created with just a source."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "composed-custody",
"metadata": {},
"outputs": [],
"source": [
"instrument = instr.McStas_instr(\"cryostat_test\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "secret-convert",
"metadata": {},
"outputs": [],
"source": [
"source = instrument.add_component(\"source\", \"Source_simple\")\n",
"source.xwidth = 0.01\n",
"source.yheight = 0.01\n",
"source.focus_xw = 0.01\n",
"source.focus_yh = 0.01\n",
"source.dist = 2\n",
"source.E0 = 5\n",
"source.dE = 0.1"
]
},
{
"cell_type": "markdown",
"id": "eastern-journal",
"metadata": {},
"source": [
"## Creating a cryostat\n",
"One use the Cryostat class to make a cryostat object. This object can be placed in the instrument file much like a component with *set_AT* and *set_ROTATED*. Here we place it 2 m after the source.\n",
"\n",
"Then the different layers of the cryostat is added, starting with the smallest closest to the sample. A negative value for top or bottom thickness removes the cap in that end. After adding a layer, it can be accessed with the attribute *last_layer*, which allows adding a window. Here 4 layers are set up, 3 of which have windows."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "welcome-cathedral",
"metadata": {},
"outputs": [],
"source": [
"orange_cryostat = functions.Cryostat(\"orange\", instrument)\n",
"orange_cryostat.set_AT([0,0,2], source)\n",
"\n",
"orange_cryostat.add_layer(inner_radius=70E-3/2, outer_radius=75E-3/2,\n",
" sample_to_bottom=83E-3, bottom_thickness=5E-3,\n",
" sample_to_top=200E-3, top_thickness=-1E-3,\n",
" material=\"Al\", p_interact=0.2)\n",
"orange_cryostat.last_layer.add_window(outer_radius=73E-3/2, sample_to_top=44.42E-3, sample_to_bottom=88.2E-3)\n",
"\n",
"orange_cryostat.add_layer(inner_radius=80E-3/2, outer_radius=81E-3/2,\n",
" sample_to_bottom=90E-3, bottom_thickness=2E-3,\n",
" sample_to_top=240E-3, top_thickness=-1E-3, p_interact=0.2)\n",
"\n",
"orange_cryostat.add_layer(inner_radius=95E-3/2, outer_radius=99.5E-3/2,\n",
" sample_to_bottom=93E-3, bottom_thickness=6E-3,\n",
" sample_to_top=225E-3, top_thickness=9E-3, p_interact=0.2)\n",
"orange_cryostat.last_layer.add_window(outer_radius=97E-3/2, sample_to_top=52E-3, sample_to_bottom=100E-3)\n",
"\n",
"orange_cryostat.add_layer(inner_radius=120E-3/2, outer_radius=127E-3/2,\n",
" sample_to_bottom=109E-3, bottom_thickness=11E-3,\n",
" sample_to_top=205E-3, top_thickness=22E-3, p_interact=0.2)\n",
"orange_cryostat.last_layer.add_window(outer_radius=125E-3/2, inner_radius=122E-3/2,\n",
" sample_to_top=55.7E-3, sample_to_bottom=93.54E-3)"
]
},
{
"cell_type": "markdown",
"id": "coral-retention",
"metadata": {},
"source": [
"After the cryostat description is done one can optionally add Union loggers that show scattering intensity in space using the *add_spatial_loggers* method. Shows the cryostat from the 3 directions along axis, and a zoom in on a cut in zy that clearly shows all windows added. In addition its possible to record the scattering as a function of time, this is done with the *add_time_histogram* and *add_animation* methods, the first of which adds a simple histogram and the latter of which records spatial scattering in a number of time frames.\n",
"\n",
"At the end it is necessary to run the *build* method, this assigns the appropriate priorites to each Union component used, and adds a Union_master component to the end. A sample could be added before the *build* method is called using Union components."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dutch-prevention",
"metadata": {},
"outputs": [],
"source": [
"orange_cryostat.add_spatial_loggers()\n",
"orange_cryostat.add_time_histogram(t_min=0.00195, t_max=0.0024)\n",
"orange_cryostat.add_animation(t_min=0.00195, t_max=0.0024, n_frames=5)\n",
"orange_cryostat.build()"
]
},
{
"cell_type": "markdown",
"id": "pregnant-rwanda",
"metadata": {},
"source": [
"For further information on these methods, the built in help can be used shown below"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "noticed-third",
"metadata": {},
"outputs": [],
"source": [
"help(orange_cryostat.add_animation)"
]
},
{
"cell_type": "markdown",
"id": "armed-graph",
"metadata": {},
"source": [
"### Running the simulation\n",
"This is sufficient to run the simulation and see the resulting plots."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "paperback-palmer",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"data = instrument.run_full_instrument(foldername=\"test_cryostat\", increment_folder_name=True, ncount=1E7)"
]
},
{
"cell_type": "markdown",
"id": "solar-checkout",
"metadata": {},
"source": [
"### Plotting with interface\n",
"Recommend using log plot and orders of magnitude = 5 to see details. It may be necessary to refresh this cell after the simulation has been performed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "mobile-strike",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib widget\n",
"plotter.interface(data)"
]
},
{
"cell_type": "markdown",
"id": "generic-ability",
"metadata": {},
"source": [
"## Future expansions\n",
"Some additional features are expected to be added to this system at a later point.\n",
"\n",
"### Entry windows\n",
"Create a layer method to make entry windows, square and circular.\n",
"\n",
"### Mounting plate\n",
"A cryostat usually has a mounting plate with a larger radius than the widest layer, could easily add such a feature.\n",
"\n",
"### External sample\n",
"Create a cryostat method that takes an external sample component that is not in Union but incorperates this into the cryostat using the best practice method."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions mcstasscript/interface/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os

from mcstasscript.data.data import McStasData
from mcstasscript.tools.cryostat import Cryostat
import mcstasscript.helper.managed_mcrun as managed_mcrun


Expand Down
Empty file added mcstasscript/tools/__init__.py
Empty file.
Loading