{ "cells": [ { "cell_type": "markdown", "id": "adb3e352-ec0d-44b4-8d5e-b7ab84d9dbce", "metadata": {}, "source": [ "# `CircularExclusion` Overview" ] }, { "cell_type": "code", "execution_count": null, "id": "4ae898fc-477a-419c-8325-2768e658e973", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "id": "46416d10-4fd6-4454-a1c1-f3b9f1826ad6", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import sys\n", "import xarray as xr" ] }, { "cell_type": "code", "execution_count": null, "id": "ad5a56bf-7182-49f0-9e80-d0c8fa3ca33a", "metadata": {}, "outputs": [], "source": [ "try:\n", " from bapsf_motion.motion_builder.exclusions import CircularExclusion\n", "except ModuleNotFoundError:\n", " from pathlib import Path\n", "\n", " HERE = Path().cwd()\n", " BAPSF_MOTION = (HERE / \"..\" / \"..\" / \"..\" ).resolve()\n", " sys.path.append(str(BAPSF_MOTION))\n", " \n", " from bapsf_motion.motion_builder.exclusions import CircularExclusion\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "3a465d6d-ecb1-4bae-94a1-5b562e9bff17", "metadata": {}, "outputs": [], "source": [ "plt.rcParams.update(\n", " {\n", " # \"figure.figsize\": [12, 0.56 * 12],\n", " \"figure.figsize\": [10, 0.8 * 10],\n", " \"font.size\": 16,\n", " }\n", ")" ] }, { "cell_type": "markdown", "id": "54f5a53e-ecf0-4778-a753-cc697a7effa6", "metadata": {}, "source": [ "## LaPD Exclusion in XY\n", "\n", "Create the seeding boolean mask. In the boolean mask a `True` value indicates a point allowed for a motion list and a `False` value indicaes an exclusion zone." ] }, { "cell_type": "code", "execution_count": null, "id": "f6055f59-3083-4dd6-b817-5469873df2e2", "metadata": {}, "outputs": [], "source": [ "size = 100\n", "side = np.linspace(-35, 35, num=size)\n", "ds = xr.Dataset(\n", " {\"mask\": ((\"x\", \"y\"), np.ones((size, size), dtype=bool))},\n", " coords={\n", " \"x\": side,\n", " \"y\": side,\n", " },\n", ")\n", "\n", "ds.mask.plot(x=\"x\", y=\"y\")" ] }, { "cell_type": "markdown", "id": "f7dc2dee-6d06-4be8-b65d-4d60c7ef0f16", "metadata": {}, "source": [ "Add a circular XY exclusion that simulates the LaPD inner diameter" ] }, { "cell_type": "code", "execution_count": null, "id": "65a510f8-7617-4604-9ea6-f92565f78032", "metadata": {}, "outputs": [], "source": [ "ex1 = CircularExclusion(ds, radius=30)\n", "ds[\"mask\"].plot(x=\"x\", y=\"y\");" ] }, { "cell_type": "markdown", "id": "f2468421-47df-45c8-a74c-04ade3cc3a0c", "metadata": {}, "source": [ "The exclusion configuration is avaibled as a dictionary via the `config` attribute." ] }, { "cell_type": "code", "execution_count": null, "id": "7a05b8d8-5f07-4a94-9c9c-3b5eef371ef6", "metadata": {}, "outputs": [], "source": [ "ex1.config" ] }, { "cell_type": "markdown", "id": "3cacbe19-9aab-4018-ba13-09e8f8541809", "metadata": {}, "source": [ "Note that `CircularExclusion` updates the overall mask and stores it's exclusion later into the `xarray.Dataset` as `mask_ex1`." ] }, { "cell_type": "code", "execution_count": null, "id": "63a77890-6806-4d17-8c0a-b37a0a549b92", "metadata": {}, "outputs": [], "source": [ "ds" ] }, { "cell_type": "markdown", "id": "441b0c15-a5a1-42b3-b15a-4ee9a51ae020", "metadata": {}, "source": [ "We can check if a specific point is considered excluded or not." ] }, { "cell_type": "code", "execution_count": null, "id": "efe3a512-1c92-4987-b75d-abfb1be5f3aa", "metadata": {}, "outputs": [], "source": [ "(\n", " ex1.is_excluded((0, 0)),\n", " ex1.is_excluded((-30, 30)),\n", ")" ] }, { "cell_type": "markdown", "id": "5cabc0f5-9293-4822-8aee-f0656bf7c4bf", "metadata": {}, "source": [ "## Let's add a 2nd Circular Exclusion" ] }, { "cell_type": "code", "execution_count": null, "id": "cf48b209-3027-49da-b716-a19dd6b84702", "metadata": {}, "outputs": [], "source": [ "ex2 = CircularExclusion(ds, radius=20, center=(10.0, 10.0), exclude=\"inside\")\n", "ds[\"mask\"].plot(x=\"x\", y=\"y\");" ] }, { "cell_type": "markdown", "id": "9bc16cb2-9aeb-4952-9cac-7d1072846272", "metadata": {}, "source": [ "Now both exclusion layers are stored in the `Dataset`." ] }, { "cell_type": "code", "execution_count": null, "id": "1edbd49d-3636-4c92-aadc-9838936ce2dc", "metadata": {}, "outputs": [], "source": [ "ds" ] }, { "cell_type": "markdown", "id": "7bf3ca57-9e40-4660-94d8-5718214c3d92", "metadata": {}, "source": "Note that the `is_exclusion()` function only checks for exclusion from the class instance the point is being checked to. The exclusion evaluation is done by the overall `MotionBuilder` class. Please refer to the `MotionBuilder` notebook for further details." }, { "cell_type": "code", "execution_count": null, "id": "a421f304-0c41-43b2-a4e9-19c1751d3220", "metadata": {}, "outputs": [], "source": [ "(\n", " ex1.is_excluded((0, 0)),\n", " ex2.is_excluded((0, 0)),\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.13" } }, "nbformat": 4, "nbformat_minor": 5 }