Skip to content

Commit

Permalink
Merge pull request #65 from easyScience/plopp-plotting-more-strict-scipp
Browse files Browse the repository at this point in the history
Bumped scipp to 23.08
  • Loading branch information
andped10 authored Jan 10, 2024
2 parents b8c383c + aaba24d commit eab0d31
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 44 deletions.
65 changes: 34 additions & 31 deletions EasyReflectometry/plot.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
__author__ = 'github.com/arm61'

import scipp as sc
import ipympl
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

color_cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']


def plot(data: sc.Dataset) -> ipympl.backend_nbagg.Canvas:
def plot(data: sc.Dataset):
"""
A general plotting function for EasyReflectometry.
Expand All @@ -17,53 +16,57 @@ def plot(data: sc.Dataset) -> ipympl.backend_nbagg.Canvas:
:returns: The plot canvas.
"""
if len([i for i in list(data.keys()) if 'SLD' in i]) == 0:
plot_sld = False
fig = plt.figure(figsize=(5, 3))
gs = GridSpec(1, 1, figure=fig)
else:
plot_sld = True
fig = plt.figure(figsize=(5, 6))
gs = GridSpec(2, 1, figure=fig)
ax2 = fig.add_subplot(gs[1, 0])
ax1 = fig.add_subplot(gs[0, 0])
refl_nums = [k[3:] for k, v in data.coords.items() if 'Qz' == k[:2]]
for i, name in enumerate(refl_nums):
copy = data[f'R_{name}'].copy()
for i, refl_num in enumerate(refl_nums):
copy = data[f'R_{refl_num}'].copy()
copy.data *= sc.scalar(10.**i, unit=copy.unit)
sc.plot(copy,
ax=ax1,
norm='log',
linestyle='',
marker='.',
color=color_cycle[i])
copy.coords[f'Qz_{refl_num}'].variances = None
sc.plot(
copy,
ax=ax1,
norm='log',
linestyle='',
marker='.',
color=color_cycle[i]
)
try:
copy = data[f'R_{name}_model'].copy()
copy = data[f'R_{refl_num}_model'].copy()
copy.data *= sc.scalar(10.**float(i))
sc.plot(copy,
ax=ax1,
norm='log',
linestyle='--',
color=color_cycle[i],
marker='')
copy.coords[f'Qz_{refl_num}'].variances = None
sc.plot(
copy,
ax=ax1,
norm='log',
linestyle='--',
color=color_cycle[i],
marker=''
)
except KeyError:
pass
ax1.autoscale(True)
ax1.relim()
ax1.autoscale_view()

for i, name in enumerate(refl_nums):
try:
copy = data[f'SLD_{name}'].copy()
if plot_sld:
for i, refl_num in enumerate(refl_nums):
copy = data[f'SLD_{refl_num}'].copy()
copy.data += sc.scalar(10. * i, unit=copy.unit)
sc.plot(data[f'SLD_{name}'],
ax=ax2,
linestyle='-',
color=color_cycle[i],
marker='')
except KeyError:
pass
try:
sc.plot(
data[f'SLD_{refl_num}'],
ax=ax2,
linestyle='-',
color=color_cycle[i],
marker=''
)
ax2.autoscale(True)
ax2.relim()
ax2.autoscale_view()
except UnboundLocalError:
pass
return fig.canvas
12 changes: 11 additions & 1 deletion docs/monolayer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@
"First, we will import the relevant packages and functions."
]
},
{
"cell_type": "markdown",
"id": "e46c0e41",
"metadata": {},
"source": [
"First configure matplotlib to place figures in notebook and import needed modules"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "619bb767-475a-408b-b576-552f0bc4f2a7",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import EasyReflectometry\n",
"import refnx\n",
"from EasyReflectometry.data import load\n",
Expand Down Expand Up @@ -441,7 +451,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
15 changes: 12 additions & 3 deletions docs/multi_contrast.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
"\n",
"In the use of neutron reflectometry, it is common to use multiple isotopic contrasts of experimental data to analyse a system in a constrained fashion. \n",
"That is to say, that we have data from multiple different species (where isotopic substitution has been used to produce data with different scattering length density) that shar ethe same structure. \n",
"In this tutorial we will look at how `EasyReflectometry` can be used to fit multiple contrasts of data from a [surfactant monolayer](./monolayer.html) system, if you haven't looked at the tutorial for a single contrast of surfactant monolayer data it is suggested that you as this tutorial will build on it.\n",
"First, as always, we import the relevant packages and print the version numbers."
"In this tutorial we will look at how `EasyReflectometry` can be used to fit multiple contrasts of data from a [surfactant monolayer](./monolayer.html) system, if you haven't looked at the tutorial for a single contrast of surfactant monolayer data it is suggested that you as this tutorial will build on it."
]
},
{
"cell_type": "markdown",
"id": "9e2929d2",
"metadata": {},
"source": [
"First configure matplotlib to place figures in notebook and import needed modules"
]
},
{
Expand All @@ -20,6 +27,8 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import EasyReflectometry\n",
"import refnx\n",
"from EasyReflectometry.data import load\n",
Expand Down Expand Up @@ -439,7 +448,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
10 changes: 10 additions & 0 deletions docs/repeating.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@
"Before performing analysis, we should import the packages that we need."
]
},
{
"cell_type": "markdown",
"id": "f5d0bd58",
"metadata": {},
"source": [
"First configure matplotlib to place figures in notebook and import needed modules"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "29d5d62d-af4a-416d-bbe2-1338d32b30f5",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import numpy as np\n",
"import scipp as sc\n",
"import EasyReflectometry\n",
Expand Down
10 changes: 10 additions & 0 deletions docs/simple_fitting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@
"Before we start on any analysis, we will import the necessary packages and functions."
]
},
{
"cell_type": "markdown",
"id": "d0fea80b",
"metadata": {},
"source": [
"First configure matplotlib to place figures in notebook and import needed modules"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f026d35c-6a4a-4e9d-889c-d23ea6ee7adc",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import EasyReflectometry\n",
"import refnx\n",
"from EasyReflectometry.data import load\n",
Expand Down
12 changes: 11 additions & 1 deletion docs/solvation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@
"Here, we will show how to use the `MaterialMixture` [type](./material_library.html#materialmixture) to perform this analysis. "
]
},
{
"cell_type": "markdown",
"id": "f404875e",
"metadata": {},
"source": [
"First configure matplotlib to place figures in notebook and import needed modules"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "88c86e82-88dd-4c2d-ad99-826f409ec7b7",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import numpy as np\n",
"import scipp as sc\n",
"import EasyReflectometry\n",
Expand Down Expand Up @@ -333,7 +343,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
17 changes: 9 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ dependencies = [

[project.optional-dependencies]
dev = [
"pytest>=5.2",
"pytest-cov>=3.0.0",
"codecov>=2.1.11",
"yapf>=0.31.0",
"toml>=0.10",
"jupyter>=1.0.0",
"flake8>=6.0.0",
"jupyterlab",
"coverage",
"coveralls",
"flake8>=6.0.0",
"ipykernel",
"jupyter>=1.0.0",
"jupyterlab",
"nbsphinx",
"plopp",
"pytest>=5.2",
"pytest-cov>=3.0.0",
"sphinx_book_theme",
"sphinx_autodoc_typehints"
"sphinx_autodoc_typehints",
"toml>=0.10",
"yapf>=0.31.0",
]

[project.urls]
Expand Down

0 comments on commit eab0d31

Please sign in to comment.