Skip to content
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
39 changes: 15 additions & 24 deletions docs/user-guide/overall_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -518,49 +518,39 @@
"print(rot)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "49",
"metadata": {},
"outputs": [],
"source": [
"with mcstastox.Read(file_path) as loaded_data:\n",
" raw_event_data = loaded_data.get_event_data(variables=[\"id\", \"t\", \"L\"], component_name=\"Square_1\")"
]
},
{
"cell_type": "markdown",
"id": "50",
"id": "49",
"metadata": {},
"source": [
"## Add additional data to a scipp object\n",
"We can add data read directly to the scipp object, here the actual wavelength recorded by McStas."
"In addition to weight, time and pixel id, event data recorded by McStas can be added to the scipp object using `mcstastox.Transfer`.\n",
"Here the actual wavelength recorded by the detector is added as a coordinate named *sim_wavelength*."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "51",
"id": "50",
"metadata": {},
"outputs": [],
"source": [
"import scipp as sc\n",
"\n",
"with mcstastox.Read(file_path) as loaded_data:\n",
" sq1 = loaded_data.export_scipp_simple(source_name=\"source\", sample_name=\"sample_position\", component_name=\"Square_1\")\n",
"\n",
"sq1.coords[\"sim_wavelength\"] = sc.array(dims=[\"events\"], values=raw_event_data[\"L\"], unit=\"Å\")\n",
" sq1 = loaded_data.export_scipp_simple(source_name=\"source\", sample_name=\"sample_position\", component_name=\"Square_1\",\n",
" extra_variables=[mcstastox.Transfer(scipp_coord=\"sim_wavelength\",\n",
" mcstas_variable=\"L\",\n",
" unit=\"angstrom\")])\n",
"\n",
"sq1.coords[\"tof\"] = sq1.coords[\"t\"]\n",
"sq1 = sq1.transform_coords(\"wavelength\", graph=graph)\n",
"sq1.coords[\"wavelength_ratio\"] = (sq1.coords[\"sim_wavelength\"] - sq1.coords[\"wavelength\"])/sq1.coords[\"sim_wavelength\"]"
"# Relative deviation between the simulated and calculated wavelengths.\n",
"sq1.coords[\"wavelength_deviation\"] = (sq1.coords[\"sim_wavelength\"] - sq1.coords[\"wavelength\"])/sq1.coords[\"sim_wavelength\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "52",
"id": "51",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -569,7 +559,7 @@
},
{
"cell_type": "markdown",
"id": "53",
"id": "52",
"metadata": {},
"source": [
"## Plotting comparison between actual and calculated wavelength"
Expand All @@ -578,10 +568,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "54",
"id": "53",
"metadata": {},
"outputs": [],
"source": [
"import scipp as sc\n",
"w_start = 0.5\n",
"w_end=3.2\n",
"w_steps=401\n",
Expand All @@ -591,7 +582,7 @@
"pp.plot({\n",
" \"calculated wavelength\": sq1.hist(wavelength=wavs),\n",
" \"true wavelength\": sq1.hist(sim_wavelength=sim_wavs).rename(sim_wavelength=\"wavelength\")\n",
"}) / sq1.hist(wavelength_ratio=200).plot()"
"}) / sq1.hist(wavelength_deviation=200).plot()"
]
}
],
Expand Down
71 changes: 65 additions & 6 deletions docs/user-guide/scipp_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,36 @@
"cell_type": "markdown",
"id": "30",
"metadata": {},
"source": [
"### Add additional variables\n",
"\n",
"McStas can record additional event data, here the wavelength (`L`) of `Square_1` (see `get_component_variables`).\n",
"Using `mcstastox.Transfer` it is added as a scipp coordinate with a custom name and unit.\n",
"Note that `Square_1` is requested explicitly, since it is the only component that records the wavelength."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "31",
"metadata": {},
"outputs": [],
"source": [
"with mcstastox.Read(file_path) as loaded_data:\n",
" scipp_object_wl = loaded_data.export_scipp(source_name=\"source\",\n",
" sample_name=\"sample_position\",\n",
" component_name=\"Square_1\",\n",
" extra_variables=[mcstastox.Transfer(scipp_coord=\"sim_wavelength\",\n",
" mcstas_variable=\"L\",\n",
" unit=\"angstrom\")])\n",
"\n",
"scipp_object_wl[\"events\"].bins.coords[\"sim_wavelength\"]"
]
},
{
"cell_type": "markdown",
"id": "32",
"metadata": {},
"source": [
"### Plot pixels with intensities\n",
"With this setup we can plot the total intensity in each pixel rather than all events individually."
Expand All @@ -318,7 +348,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "31",
"id": "33",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -329,7 +359,36 @@
},
{
"cell_type": "markdown",
"id": "32",
"id": "34",
"metadata": {},
"source": [
"## Export to a simple Scipp object\n",
"\n",
"The *export_scipp_simple* method provides a single scipp DataArray that is easier to work with but takes more space.\n",
"Additional variables are added exactly as for *export_scipp*, here as a single `Transfer` instead of a list."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "35",
"metadata": {},
"outputs": [],
"source": [
"with mcstastox.Read(file_path) as loaded_data:\n",
" simple_scipp_object = loaded_data.export_scipp_simple(source_name=\"source\",\n",
" sample_name=\"sample_position\",\n",
" component_name=\"Square_1\",\n",
" extra_variables=mcstastox.Transfer(scipp_coord=\"sim_wavelength\",\n",
" mcstas_variable=\"L\",\n",
" unit=\"angstrom\"))\n",
"\n",
"simple_scipp_object.coords[\"sim_wavelength\"]"
]
},
{
"cell_type": "markdown",
"id": "36",
"metadata": {},
"source": [
"## Perform coordinate transforms\n",
Expand All @@ -339,7 +398,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "33",
"id": "37",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -357,7 +416,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "34",
"id": "38",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -366,7 +425,7 @@
},
{
"cell_type": "markdown",
"id": "35",
"id": "39",
"metadata": {},
"source": [
"Note extra .sum(\"pixel_id\") in plot."
Expand All @@ -375,7 +434,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "36",
"id": "40",
"metadata": {},
"outputs": [],
"source": [
Expand Down
Loading
Loading