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
40 changes: 40 additions & 0 deletions .github/workflows/test-ipynb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Testing Jupyter Notebooks

on:
workflow_dispatch:
pull_request:
branches:
- "**"

jobs:
test:
timeout-minutes: 30

strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ['3.10', '3.11', '3.12']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should concentrate on a single python version (3.12?) but include more OS-es. This is especially important for assuring file paths are properly set on Windows/Linux

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's have a full matrix with 3 python versions and 3 os versions to make sure everything is ok for all major combinations. Added to workflow config.


runs-on: ${{ matrix.os }}

steps:
- name: Check-out repository
uses: actions/checkout@v4

- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade package installer for Python
shell: bash
run: python -m pip install --upgrade pip

- name: Install Python dependences
shell: bash
run: pip install '.[dev]'

- name: Run tests on Jupyter Notebooks
shell: bash
run: pytest --nbmake examples/*ipynb --nbmake-timeout=300 -n=auto
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

## Getting Started

Currently, easydiffraction is in beta and has not been released on PyPI. Please use the alternative method given below to install easydiffraction from our GitHub repository.

### Install EasyDiffraction python library

* Create and go to, e.g., **easydiffraction** directory (*optional*)
Expand All @@ -31,7 +33,7 @@
```
* Install **easydiffraction**
```
pip install easydiffraction
pip install easydiffraction --extra-index-url https://easyscience.github.io/pypi
```

## Examples
Expand All @@ -42,7 +44,7 @@

* Install **easydiffraction**, including `charts` extras for visualization
```
pip install 'easydiffraction[charts]'
pip install 'easydiffraction[charts]' --extra-index-url https://easyscience.github.io/pypi
```
* Install Jupyter Notebook
```
Expand Down
5 changes: 0 additions & 5 deletions binder/postBuild

This file was deleted.

36 changes: 22 additions & 14 deletions easydiffraction/Job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
# © 2021-2024 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffraction

import builtins
import importlib.util
import time
from copy import deepcopy
Expand Down Expand Up @@ -59,6 +60,10 @@
except ImportError:
print("pandas not installed")

try:
from IPython.display import display
except ImportError:
pass

T_ = TypeVar('T_')

Expand Down Expand Up @@ -744,7 +749,7 @@ def show_analysis_chart(self):

y_calc = self.calculate_profile()

peak_idx, _ = find_peaks(y_calc) #, prominence=1)
peak_idx, _ = find_peaks(y_calc)
x_bragg = self.experiment.x.data[peak_idx]
y_bragg = np.zeros_like(x_bragg)

Expand All @@ -759,8 +764,8 @@ def show_analysis_chart(self):
)

trace_bragg = go.Scatter(
x=x_bragg, # np.random.uniform(low=self.experiment.x.data.min(), high=self.experiment.x.data.max(), size=(50,)),
y=y_bragg, #np.zeros(50),
x=x_bragg,
y=y_bragg,
xaxis='x2',
yaxis='y2',
line=dict(color='rgb(230, 171, 2)'), #color=px.colors.qualitative.Plotly[9]),
Expand All @@ -778,7 +783,7 @@ def show_analysis_chart(self):
y=self.background,
xaxis='x3',
yaxis='y3',
line=dict(color='gray'), # default: width=2?
line=dict(color='gray'),
mode='lines',
name='Background (Ibkg)'
)
Expand Down Expand Up @@ -841,27 +846,25 @@ def show_analysis_chart(self):
title_text=x_axis_title,
anchor='y',
range=[x_min, x_max],
# linecolor='blue',
showline=True, mirror=True, zeroline=False
),
xaxis2=dict(
matches='x',
anchor='y2',
range=[x_min, x_max],
# linecolor='green',
showline=True, mirror=True, zeroline=False, showticklabels=False
),
xaxis3=dict(
matches='x',
anchor='y3',
range=[x_min, x_max],
# linecolor='red',
showline=True, mirror=True, zeroline=False, showticklabels=False
),
yaxis=dict(
title_text='Imeas - Icalc',
domain=[0, resid_height / full_height - 0.01],
range=[resid_y_min, resid_y_max],
tickvals=[int(resid_y_min), 0, int(resid_y_max)],
# nticks = 3,
showline=True, mirror=True, showgrid=False
),
yaxis2=dict(
Expand All @@ -877,12 +880,14 @@ def show_analysis_chart(self):
)

fig = go.Figure(data=data, layout=layout)

# fig.update_xaxes(showline=True, mirror=True)
# fig.update_yaxes(showline=True, mirror=True)

fig.show()

def is_notebook(self):
'''
Check if the code is running in a Jupyter notebook.
'''
return hasattr(builtins, "__IPYTHON__")

def print_free_parameters(self):
'''
Print the free parameters.
Expand All @@ -893,11 +898,14 @@ def print_free_parameters(self):
parameters['names'].append(parameter.display_name)
parameters['values'].append(parameter.raw_value)
parameters['errors'].append(parameter.error)
parameters['units'].append(f'{parameter.unit:~H}')
parameters['units'].append(f'{parameter.unit:~P}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at some point, we need to refactor out the plotting and printing methods from Job.py. This should be easily possible. (Not now, let's wait until you are done with the main functionality)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely agree with that.

df = pd.DataFrame(parameters)
df.index += 1
df.style.format(precision=5)
return df
if self.is_notebook():
display(df)
else:
print(df)
else:
for parameter in self.get_fit_parameters():
print(parameter)
Expand Down
2 changes: 1 addition & 1 deletion examples/Change_minimizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
" print(\"Running in Google Colab\")\n",
" # Install the easydiffraction library if it is not installed (including charts extras)\n",
" if importlib.util.find_spec(\"easydiffraction\") is None:\n",
" !pip install 'easydiffraction[charts]'\n",
" !pip install 'easydiffraction[charts]' --extra-index-url https://easyscience.github.io/pypi\n",
" # Download the data files to be read in notebook\n",
" for fname in ['lbco.cif', 'hrpt.xye']:\n",
" pooch.retrieve(\n",
Expand Down
121,030 changes: 79,869 additions & 41,161 deletions examples/Fitting_PD-NEUT-CW_LBCO-HRPT.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/Fitting_PD-NEUT-TOF_NCAF-WISH.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
" print(\"Running in Google Colab\")\n",
" # Install the easydiffraction library if it is not installed (including charts extras)\n",
" if importlib.util.find_spec(\"easydiffraction\") is None:\n",
" !pip install 'easydiffraction[charts]'\n",
" !pip install 'easydiffraction[charts]' --extra-index-url https://easyscience.github.io/pypi\n",
" # Download the data files to be read in notebook\n",
" for fname in ['ncaf.cif', 'wish.xye']:\n",
" pooch.retrieve(\n",
Expand Down
6 changes: 3 additions & 3 deletions examples/Fitting_PD-NEUT-TOF_Si-SEPD.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"colab"
],
"ExecuteTime": {
"end_time": "2024-10-21T21:25:54.088976Z",
"start_time": "2024-10-21T21:25:54.072841Z"
"end_time": "2024-10-22T10:09:35.372871Z",
"start_time": "2024-10-22T10:09:35.339954Z"
}
},
"source": [
Expand All @@ -52,7 +52,7 @@
" print(\"Running in Google Colab\")\n",
" # Install the easydiffraction library if it is not installed (including charts extras)\n",
" if importlib.util.find_spec(\"easydiffraction\") is None:\n",
" !pip install 'easydiffraction[charts]'\n",
" !pip install 'easydiffraction[charts]' --extra-index-url https://easyscience.github.io/pypi\n",
" # Download the data files to be read in notebook\n",
" for fname in ['sepd.xye']:\n",
" pooch.retrieve(\n",
Expand Down
8 changes: 4 additions & 4 deletions examples/data/lbco.cif
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _atom_site.fract_z
_atom_site.occupancy
_atom_site.ADP_type
_atom_site.B_iso_or_equiv
La La 0 0 0 0.5 Biso 0.49
Ba Ba 0 0 0 0.5 Biso 0.49
Co Co 0.5 0.5 0.5 1 Biso 0.26
O O 0 0.5 0.5 1 Biso 1.40
La La 0 0 0 0.5 Biso 0.1
Ba Ba 0 0 0 0.5 Biso 0.1
Co Co 0.5 0.5 0.5 1 Biso 0.1
O O 0 0.5 0.5 1 Biso 0.1
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = 'hatchling.build'

[project]
name = 'easydiffraction'
version = '0.1.0'
version = '0.1.1'
description = 'Making diffraction data analysis and modelling easy'
authors = [{name = 'EasyDiffractionLib contributors'}]
readme = 'README.md'
Expand All @@ -23,9 +23,9 @@ classifiers = [
]
requires-python = '>=3.9,<3.13'
dependencies = [
'cryspy @ git+https://github.com/ikibalin/cryspy.git@beta',
'cryspy @ git+https://github.com/EasyScience/cryspy.git@beta',
'EasyScience @ git+https://github.com/EasyScience/EasyScience.git@free-params',
'easycrystallography @ git+https://github.com/EasyScience/EasyCrystallography.git@develop',
'easycrystallography @ git+https://github.com/EasyScience/EasyCrystallography.git@adp_cif_naming',
'pycifrw>=4.4.1',
'pooch',
'funcy'
Expand All @@ -41,12 +41,14 @@ dev = [
'flake8>=6.0.0',
'pytest>=5.2',
'pytest-cov>=3.0.0',
'pytest-xdist', # used with nbmake to run parallel tests
'nbmake', # testing jupyter notebooks
'playwright', # needed for nbmake
'jinja2', # nedeed for nbmake
'ruff',
'toml>=0.10',
'yapf>=0.31.0',
'requests',
'py3Dmol',
'bokeh',
'gemmi',
'periodictable',
]
Expand Down