{ "cells": [ { "cell_type": "markdown", "id": "utility-python", "metadata": {}, "source": [ "# Functions\n", "McStasScritpt includes some freestanding functions located in the functions module." ] }, { "cell_type": "code", "execution_count": null, "id": "naughty-layout", "metadata": {}, "outputs": [], "source": [ "import mcstasscript as ms" ] }, { "cell_type": "code", "execution_count": null, "id": "unauthorized-billion", "metadata": {}, "outputs": [], "source": [ "import laue_example" ] }, { "cell_type": "code", "execution_count": null, "id": "royal-camel", "metadata": { "scrolled": true, "tags": [ "hide-output" ] }, "outputs": [], "source": [ "data = laue_example.create_data(\"data_for_loading\")" ] }, { "cell_type": "code", "execution_count": null, "id": "negative-captain", "metadata": {}, "outputs": [], "source": [ "data_path = data[0].get_data_location()" ] }, { "cell_type": "markdown", "id": "satellite-dealing", "metadata": {}, "source": [ "## load_data function\n", "The [*load_data*](../_autosummary/mcstasscript.interface.functions.load_data.rst) function reads a McStas dataset from disk and returns it in the form of [McStasData](../_autosummary/mcstasscript.data.data.McStasData.rst) and [McStasDataEvent](../_autosummary/mcstasscript.data.data.McStasDataEvent.rst) objects in a list. The input is the path to the folder containing the McStas data. The path can be absolute or relative. Here the path from the generated example data is used." ] }, { "cell_type": "code", "execution_count": null, "id": "plain-growth", "metadata": {}, "outputs": [], "source": [ "loaded_data = ms.load_data(data_path)\n", "print(loaded_data)" ] }, { "cell_type": "markdown", "id": "explicit-holocaust", "metadata": {}, "source": [ "The *load_data* function provides a way to work with data not created in the current session or created without McStasScript." ] }, { "cell_type": "markdown", "id": "presidential-tuesday", "metadata": {}, "source": [ "## name_search\n", "The [*name_search*](../_autosummary/mcstasscript.interface.functions.name_search.rst) function searches a list of data for instances that match a monitor name or a filename. If a monitor creates more than one dataset, [*name_search*](../_autosummary/mcstasscript.interface.functions.name_search.rst) may return multiple data objects.\n", "\n", "Here a search for the component name is performed." ] }, { "cell_type": "code", "execution_count": null, "id": "sticky-circus", "metadata": {}, "outputs": [], "source": [ "div_lambda_h = ms.name_search(\"div_lambda_h\", data)\n", "print(div_lambda_h)" ] }, { "cell_type": "code", "execution_count": null, "id": "facial-guidance", "metadata": {}, "outputs": [], "source": [ "ms.make_plot(div_lambda_h, fontsize=14, figsize=(10, 6))" ] }, { "cell_type": "markdown", "id": "opposite-advice", "metadata": {}, "source": [ "It is also possible to search for the name of the datafile." ] }, { "cell_type": "code", "execution_count": null, "id": "egyptian-spencer", "metadata": {}, "outputs": [], "source": [ "transmission = ms.name_search(\"lambda_transmission.dat\", data)\n", "ms.make_plot(transmission, fontsize=14, figsize=(10, 6))" ] }, { "cell_type": "markdown", "id": "synthetic-transformation", "metadata": {}, "source": [ "## name_plot_options\n", "The [*name_plot_options*](../_autosummary/mcstasscript.interface.functions.name_plot_options.rst) function combines a search with *name_search* and a call to its *set_plot_options*. Setting plot options changes how the data will be plotted, and this provides a nice way to control one plot per line in a neat manner." ] }, { "cell_type": "code", "execution_count": null, "id": "reduced-airline", "metadata": {}, "outputs": [], "source": [ "ms.name_plot_options(\"PSD\", data, log=True, orders_of_mag=7)\n", "ms.name_plot_options(\"div_lambda_h\", data, log=True, orders_of_mag=5)\n", "ms.name_plot_options(\"div_lambda_v\", data, log=False, colormap=\"hot\")\n", "ms.name_plot_options(\"lambda\", data, log=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "satellite-majority", "metadata": { "scrolled": false }, "outputs": [], "source": [ "ms.make_plot(data, figsize=(8, 6))" ] }, { "cell_type": "code", "execution_count": null, "id": "brown-membership", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "technical-kennedy", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Tags", "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.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }