Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataclass material refactor #159

Closed
wants to merge 231 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
231 commits
Select commit Hold shift + click to select a range
d245065
adding basic socketio webserver for gui
bmaranville Sep 27, 2022
4242336
initial commit of web gui for refl1d
bmaranville Sep 27, 2022
f17d0bf
update title and favicon
bmaranville Sep 27, 2022
419c34c
adding mathjax
bmaranville Sep 30, 2022
99fb4d1
adding plotting libraries
bmaranville Sep 30, 2022
6d16a2b
move component-specific listener registration on socket to components…
bmaranville Sep 30, 2022
c9d6582
interact directly with the socket, registering listeners and performi…
bmaranville Sep 30, 2022
0fef02c
add minimal style.css
bmaranville Sep 30, 2022
beb31da
add minimal style.css
bmaranville Sep 30, 2022
2acf6cd
adding view components
bmaranville Sep 30, 2022
2a3bc2f
fix missing oversampling argument
bmaranville Sep 30, 2022
8b81917
add methods to webserver to support parameter view, profile view and …
bmaranville Sep 30, 2022
5fbca59
fix bug in assigning visible status
bmaranville Sep 30, 2022
c5ce0da
prevent re-render on active slider, and send parameter updates to server
bmaranville Sep 30, 2022
c129d1e
update existing plot if already created (preserves zoom)
bmaranville Sep 30, 2022
ed12693
clear profile plot before redraw
bmaranville Sep 30, 2022
4ee68cf
create new figure for each profile plot draw, and update model after …
bmaranville Sep 30, 2022
3a51ebe
add second panel to right of first
bmaranville Sep 30, 2022
2d263df
set min-height so panels can shrink in height
bmaranville Sep 30, 2022
7a8d644
separate local_str and local value so sliders can work independently …
bmaranville Oct 3, 2022
09ccaca
clean up styling
bmaranville Oct 3, 2022
d281661
make get_plot_data awaitable
bmaranville Oct 3, 2022
425a9ed
add animation loop, only call for new profile plot after finished ret…
bmaranville Oct 3, 2022
94e3f97
messages will be sent with timestamps
bmaranville Oct 3, 2022
da74102
add types for plotly
bmaranville Oct 3, 2022
1e9b86d
send timestamp with messages from topics
bmaranville Oct 3, 2022
1a5c873
give profile plot div unique id so it can be used wherever it is (eve…
bmaranville Oct 3, 2022
a8daa06
add typings for DataView (Plotly)
bmaranville Oct 3, 2022
be83fef
improve layout of Summary table
bmaranville Oct 3, 2022
5cc8b44
node id starting with number causes issue with CSS selectors... prepe…
bmaranville Oct 4, 2022
c5625a0
make data plot full height
bmaranville Oct 4, 2022
a051896
allow dbl-click to choose file
bmaranville Oct 4, 2022
f349f14
send full fit_settings on update
bmaranville Oct 4, 2022
330aaa8
adding icon in a supported size for favicon (48x48)
bmaranville Oct 5, 2022
8dc7596
adding icon in a supported size for favicon (48x48)
bmaranville Oct 5, 2022
55a8886
import Component as type
bmaranville Oct 5, 2022
c70f591
pass all settings back to server, not just active one
bmaranville Oct 5, 2022
f7b5020
add new method to get seriallized model
bmaranville Oct 5, 2022
f8e657d
adding new component to visualize serialized model tree
bmaranville Oct 5, 2022
59c0615
adding support for json viewer for ModelInspect panel
bmaranville Oct 5, 2022
de938af
add definition of global to support old-style plotly.js libs
bmaranville Oct 5, 2022
2695eea
use shared list of panels
bmaranville Oct 5, 2022
a8f1cd7
Set title from parent element, rather than from child in tab panel
bmaranville Oct 5, 2022
aa3cb5b
typing updates
bmaranville Oct 5, 2022
eef0e52
cleanup
bmaranville Oct 5, 2022
7e4f5a7
get title from props instead of from child components
bmaranville Oct 5, 2022
86eccae
support serialization of MixedExperiment
bmaranville Oct 5, 2022
a36a5d3
don't store inflections as part of state, as they are derived from dz…
bmaranville Oct 5, 2022
2824a84
fix Material class serialization - need to store input formula
bmaranville Oct 5, 2022
8c95a69
minor cleanup on web components
bmaranville Oct 5, 2022
2b18527
merging fixed FitOptions
bmaranville Oct 6, 2022
c22ece8
add mime type hints to files to be served as static
bmaranville Oct 6, 2022
96269bd
send local file path to client
bmaranville Oct 6, 2022
50e8159
Merge branch 'webview' of github.com:reflectometry/refl1d into webview
bmaranville Oct 6, 2022
f216af7
retrieve local file path from server, to populate file browser
bmaranville Oct 6, 2022
728385f
Merge branch 'webview' of github.com:reflectometry/refl1d into webview
bmaranville Oct 6, 2022
5d9673b
change event names to be more consistent with existing wx gui
bmaranville Oct 7, 2022
a3f266b
include intensity and background in probe plottable data, for calcula…
bmaranville Oct 7, 2022
645d763
move reflectivity plot types to DataView, and implement view switcher
bmaranville Oct 7, 2022
adb73e4
add TODO for generating view plots in python
bmaranville Oct 7, 2022
7b197fd
simplify plotly plotting to use just Plotly.react, and add uirevision…
bmaranville Oct 7, 2022
54ff8e9
add REST GET endpoints for other clients, and refactor message bus
bmaranville Oct 11, 2022
53c7df5
use new topics bus (sending most messages directly instead of empty s…
bmaranville Oct 11, 2022
b933046
implement model reload (and add to menu)
bmaranville Oct 11, 2022
8a93982
add model selector for profile plot
bmaranville Oct 11, 2022
6bcac0f
allow setting initially active tab in PanelTabContainer
bmaranville Oct 11, 2022
5a894a2
add function to initiate fit from client
bmaranville Oct 11, 2022
1d300c4
add method to get profile data instead of plot, and start a fitter
bmaranville Oct 26, 2022
7aa044f
start without plotting because data won't be ready
bmaranville Oct 26, 2022
8485565
add drawing busy flag
bmaranville Oct 28, 2022
7a9d509
update actions
bmaranville Oct 31, 2022
ffd92c6
add new model view based on profile xy instead of matplotlib
bmaranville Oct 31, 2022
345529d
make min, max and value editable in summary view (and add scroll inte…
bmaranville Nov 1, 2022
aa41119
adding Parameter tab
bmaranville Nov 3, 2022
178cd41
refactor get_parameters to support summary and parameters view
bmaranville Nov 3, 2022
7daefbc
add Parameter tab to app
bmaranville Nov 3, 2022
7123338
modify Summary tab to work with parameters by id
bmaranville Nov 3, 2022
2ac7c8c
Merge branch 'webview' of github.com:reflectometry/refl1d into webview
bmaranville Nov 3, 2022
1c3ec79
adding profile plot tab that uses plotly instead of mpld3
bmaranville Nov 3, 2022
6ba59a7
Merge branch 'webview' of github.com:reflectometry/refl1d into webview
bmaranville Nov 3, 2022
46041a5
fix margins for plots, and make them responsive to container size (\!)
bmaranville Nov 3, 2022
53c8e9c
convert summary to table, and add nowrap
bmaranville Nov 3, 2022
7d488bc
fix height and make panels scrollable
bmaranville Nov 3, 2022
4608d38
update x,y labels on profile plot
bmaranville Nov 3, 2022
b40a3be
use combined paths list instead of path and link columns
bmaranville Nov 3, 2022
52981a0
return parameters list with all paths for a single parameter, rather …
bmaranville Nov 3, 2022
cf7b15c
use updated CDN for mathjax
bmaranville Nov 3, 2022
2fbafd9
make app full-width
bmaranville Nov 3, 2022
e5b8c2a
add custom handler for legend, tying visibility of plots of smooth an…
bmaranville Nov 3, 2022
bae6a22
turns out plotly can group traces together in the legend already. Re…
bmaranville Nov 3, 2022
99da3ef
adding Log view panel
bmaranville Nov 30, 2022
9675a89
use LogView panel
bmaranville Nov 30, 2022
c8c8b53
adding main entrypoint for webview/server
bmaranville Nov 30, 2022
f72e622
working fit_thread
bmaranville Nov 30, 2022
1dcfba0
adding fit_thread for webserver
bmaranville Nov 30, 2022
03e63df
build in local dist dir now
bmaranville Nov 30, 2022
9919b84
allow passing fig object to show_errors (for GUI)
bmaranville Dec 2, 2022
8ae8b17
adding new panels to webview client
bmaranville Dec 2, 2022
ef73d3e
send the correct options to the fitter (wasn't working before)
bmaranville Dec 2, 2022
f97cfbc
use new fit results view panels in GUI
bmaranville Dec 2, 2022
bae215f
working ConvergenceMonitor, composed of old GUIProgressMonitor mashed…
bmaranville Dec 2, 2022
760be0b
add new plot renderers (mpld3) for DREAM output interpretation, e.g. …
bmaranville Dec 2, 2022
ef9e3ab
update fit_progress_handler to recognize more types of message, and u…
bmaranville Dec 2, 2022
382ebbc
update imports
bmaranville Dec 2, 2022
b539171
enable connecting to socket.io even when behind a proxy
bmaranville Dec 7, 2022
e785ac5
don't navigate page to href=# with menu links or in filebrowser
bmaranville Dec 7, 2022
0891f43
add command line options to pass port to server
bmaranville Dec 7, 2022
4209eff
serve index.html directly from / route
bmaranville Dec 7, 2022
b661db7
add webview to packages in setup.py
bmaranville Dec 7, 2022
44fd46f
Merge branch 'webview' of github.com:reflectometry/refl1d into webview
bmaranville Dec 7, 2022
958d79c
add client files to MANIFEST.in
bmaranville Dec 8, 2022
86f1e32
include all source files needed for building the webview client
bmaranville Dec 8, 2022
9da99dc
adding npmignore, needed for building npm packages cleanly
bmaranville Dec 9, 2022
d33bd17
ignore packed webview clients
bmaranville Dec 9, 2022
3cf0b18
add build_prod script, creates unmangled paths for builds to be publi…
bmaranville Dec 9, 2022
9ac8361
write unhashed filenames for production mode
bmaranville Dec 9, 2022
997a175
check version of locally-built client, and use it if there's a match,…
bmaranville Dec 9, 2022
ba0b8d8
add template for fallback CDN client
bmaranville Dec 12, 2022
7ea1bbf
include index template in manifest
bmaranville Dec 12, 2022
5c7af27
Merge branch 'dataclass_overlay' into webview
bmaranville Dec 20, 2022
3f60f5e
Update .gitignore
acaruana2009 Jan 4, 2023
cef1f3a
FIX: add probe labels to plotly refl plot
acaruana2009 Jan 4, 2023
e13619c
use node to put package version in VERSION file
bmaranville Jan 5, 2023
25be800
DEV: New plotly SLD profile plot
acaruana2009 Jan 5, 2023
bf5589b
Merge branch 'webview' into webview_profileplot
acaruana2009 Jan 5, 2023
9bef133
Update plotly SLD profile style
acaruana2009 Jan 5, 2023
754d545
plotly version of varplot
bmaranville Jan 9, 2023
4797ee4
use new plotly varplot for uncertainty plot
bmaranville Jan 9, 2023
b685bb2
use new plotly uncertainty plot
bmaranville Jan 9, 2023
735e43c
automatically filter data points that contain nan in any column
bmaranville Dec 14, 2021
68242d8
density should not be in Material class schema, it is a derived param…
bmaranville Jan 10, 2023
38f7939
convert dQ to regular property, create ProbeSchema
bmaranville Jan 10, 2023
3b39192
remove debug message
bmaranville Jan 10, 2023
35d88fe
add Save functionality to webview (saves json)
bmaranville Jan 10, 2023
9d35a90
add full filename as tooltip
bmaranville Jan 10, 2023
eeb27f6
use random available port for server if not specified with -p, and st…
bmaranville Jan 13, 2023
4d6631a
fix scrolling within panels (don't scrol nav tabs at top)
bmaranville Jan 13, 2023
6884ee3
don't need MML MathJax
bmaranville Jan 18, 2023
1421ad4
use unicode axis labels instead of latex, for speed
bmaranville Jan 19, 2023
972fae4
use Vue to show/hide panels instead of Tab function from Bootstrap
bmaranville Jan 19, 2023
419e39d
use getter function instead of message event to populate current file…
bmaranville Jan 19, 2023
cdc67b4
patch socketio to add asyncEmit method, can await results
bmaranville Jan 19, 2023
c50f18d
apply asyncEmit socketio patch
bmaranville Jan 19, 2023
f4f461d
add standardized method for setting up the drawing loop in the client…
bmaranville Jan 19, 2023
c86ae91
use new setupDrawLoop function in panels
bmaranville Jan 19, 2023
431fa61
minor Logging refactor - get log messages on instantiation
bmaranville Jan 19, 2023
78705d3
convert topics in webserver to deque objects (ring buffer)
bmaranville Jan 19, 2023
22c7275
adding plotcache
bmaranville Jan 19, 2023
130f777
convert profile plot labels from latex to unicode (until can figure o…
bmaranville Jan 19, 2023
59fba44
remove matplotlib plotting routines from plotly implementation
bmaranville Jan 19, 2023
4f05dc9
convert labels on ModelViewPlotly to UTF as well
bmaranville Jan 19, 2023
3df01b3
add layout options, including left-right, top-bottom and full
bmaranville Jan 19, 2023
07219f1
add summary structure in log viewer for messages with title defined
bmaranville Jan 26, 2023
51aebdc
send structured log messages (with optional title)
bmaranville Jan 26, 2023
f6bc631
give _HashableModel a name based on index if one is not provided
bmaranville Feb 1, 2023
f538432
trigger server quit on Quit in client
bmaranville Feb 1, 2023
7cfc3a1
make abort_queue required argument to FitThread
bmaranville Feb 1, 2023
465635a
set reuseaddr flag on socket, so we can reuse the port on quick restarts
bmaranville Feb 1, 2023
fd971d1
add shutdown method to API for server
bmaranville Feb 1, 2023
983bc8b
fix callbacks from fit events to be async/threadsafe
bmaranville Feb 7, 2023
5deb33e
send update_model signal when model parameters list changes
bmaranville Feb 7, 2023
3223c4f
adding class-based state for webserver
bmaranville Feb 7, 2023
693a103
add save as... functionality to file browser in client
bmaranville Feb 7, 2023
e050b34
fix filebrowser ok button logic, and fix overwrite logic in app
bmaranville Feb 9, 2023
6ebd7c9
clean up shutdown tasks
bmaranville Feb 10, 2023
4194ac7
move state classes to separate module (to enable other implementations)
bmaranville Feb 10, 2023
a838bde
add plain server state implementation
bmaranville Feb 10, 2023
4ea98e3
add cleanup stub to State, needed for other implementations
bmaranville Feb 10, 2023
ff9673b
use hdf-backed state
bmaranville Feb 10, 2023
0f6ed2f
state backed by hdf5 file
bmaranville Feb 10, 2023
c6e1e57
add command line options to load a file, start a fit, and autoexit on…
bmaranville Feb 10, 2023
6acf9e5
allow in-memory use of hdf5 core driver
bmaranville Feb 10, 2023
4773e89
store flag for autoterminate in fit thread, to be applied on fit comp…
bmaranville Feb 10, 2023
9ed729d
send chisq with progress updates
bmaranville Feb 13, 2023
ef9da02
fix retrieving active fitter from topics
bmaranville Feb 13, 2023
74b5185
add fit progress events
bmaranville Feb 14, 2023
8552a3a
history requires requires two steps?
bmaranville Feb 14, 2023
1061fe3
adding chisq to data plot
bmaranville Feb 14, 2023
92af059
adding 'save and start' button to fit options
bmaranville Feb 14, 2023
0a6ed36
get rid of extraneous 'Fitting'
bmaranville Feb 14, 2023
7336102
add help text to DREAM options for calculating steps from samples
bmaranville Feb 14, 2023
87e70e9
add method to calculate dream steps
bmaranville Feb 14, 2023
f530e44
add progress bar to fit status
bmaranville Feb 14, 2023
b0aa331
move fitting options to labeled button with gear icon
bmaranville Feb 15, 2023
970624a
merging in changes from upstream dataclass_overlay branch
bmaranville Feb 16, 2023
d8e7df1
make_probe should use new dQo init parameter for Probe
bmaranville Feb 26, 2023
302c1dd
fix breakpoint so navbar doesn't collapse to burger menu too early, a…
bmaranville Feb 27, 2023
59f5ae3
add requirements file for running webview server
bmaranville Feb 27, 2023
c4e86b7
allow opening store file in read_only mode
bmaranville Mar 2, 2023
32a06c0
fix retrieving last message from fitter_active topic
bmaranville Mar 2, 2023
79aa34a
cleanup docs, one less TODO
bmaranville Mar 2, 2023
910c378
adding client panel for new plotly correlations view
bmaranville Mar 2, 2023
a6a75ae
use new plotly correlation panel
bmaranville Mar 2, 2023
63bd80c
new plotly correlation plotter (python)
bmaranville Mar 2, 2023
c479f52
use new plotly correlation plotter
bmaranville Mar 2, 2023
de523fc
use vite plugin to generate VERSION file
bmaranville Mar 6, 2023
a1d7331
allow override of backend server URL in client url search params
bmaranville Mar 6, 2023
5ff1421
version bump on webview client
bmaranville Mar 6, 2023
0e3f7f2
include inline 48x48 icon for refl1d in template
bmaranville Mar 6, 2023
cc0e339
remind myself how to publish updates to the client
bmaranville Mar 6, 2023
2988e3a
adding script to build conda-packed environment (linux, osx)
bmaranville Mar 7, 2023
f028c3c
fix conda packed build, need to preserve symlinks so use tar instead …
bmaranville Mar 7, 2023
7da099e
use simple to_json_compatible_dict locally, instead of model serializ…
bmaranville Mar 10, 2023
4a9fd95
need to allow MixedExperiment and Experiment classes, so check for Ex…
bmaranville Mar 10, 2023
77a5c18
add some typings and cleanup varplot (to be moved to bumps)
bmaranville Mar 10, 2023
fe326a0
don't show R if it is not defined in data view
bmaranville Mar 13, 2023
8a1d0f1
pass sample names to MixedExperiment parts
bmaranville Mar 13, 2023
b2bd144
refactor profile plots, and get_model_names, to support MixedExperiment
bmaranville Mar 13, 2023
2dbb04f
version bump: change to plot_profile interface
bmaranville Mar 13, 2023
f71b87f
add monkey patch for plotly, to address issue https://github.com/plot…
bmaranville Mar 13, 2023
7d0e722
merging hdf5-backed state feature
bmaranville Mar 14, 2023
a839265
merging in hdf5-backed state changes to webserver
bmaranville Mar 14, 2023
3071725
add type hints for command-line arguments
bmaranville Mar 14, 2023
343edef
adding panels module to define which panels to show in webview
bmaranville Mar 15, 2023
750af67
get main app from bumps-webview-client
bmaranville Mar 15, 2023
d0bad67
use imported App from bumps-webview-client
bmaranville Mar 15, 2023
4325c4b
remove components that were moved to base app in bumps-webview-client
bmaranville Mar 15, 2023
b755fd6
import almost all functions from bumps webview, leaving only refl1d-s…
bmaranville Mar 16, 2023
4c33d97
removing componnents that were moved to bumps.webview.server
bmaranville Mar 16, 2023
b6e9894
put back in the get_model_names method, which is needed!
bmaranville Mar 20, 2023
58a659f
fix import of bumps main
bmaranville Mar 20, 2023
20f2088
rename data panel to reflectivity
bmaranville Mar 20, 2023
8b71c17
update plotly
bmaranville Mar 22, 2023
2f4db58
register bumps plugin so model_uncertainty plot will work
bmaranville Mar 22, 2023
5e5b4e6
version bump to pull in latest bumps client version
bmaranville Mar 22, 2023
8ee2107
adding __init__.py for registering packages
bmaranville Mar 22, 2023
148f9f8
need h5py for file-backed state in webview
bmaranville Mar 28, 2023
7347aec
rework material classes, eliminate fitby
bmaranville Mar 29, 2023
2f235ba
add class factory function to match old usage
bmaranville Mar 29, 2023
29e4d9a
revert to 'density' keyword for Material
bmaranville Mar 29, 2023
fe3f680
add parameters() aggregator for new Material classes
bmaranville Mar 29, 2023
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
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
# pure python wheels

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.config.py }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.config.py }}

Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
# See the following for how to upload to a release
# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
Expand All @@ -80,7 +80,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Retrieve all artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: artifacts

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
# all using to stable abi

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.config.py }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.config.py }}

Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
# See the following for how to upload to a release
# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
Expand All @@ -71,7 +71,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Retrieve all artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: artifacts

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
.idea
*.pyd
*.pyc
**/__pycache__/
**/node_modules/
/refl1d/webview/client/dist/
*.swp
*.so
*.bak
refl1d-webview-client*.tgz
/build/
/dist/
/refl1d.egg-info/
Expand Down
7 changes: 6 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ include master_builder.py
include refl1d.iss
include setup_py2exe.py
include refl1d/lib/*.h refl1d/lib/erf.c

recursive-include refl1d/webview/client/dist *.html *.js *.css *.svg *.png
recursive-include refl1d/webview/client/src *.html *.js *.css *.svg *.png *.vue
include refl1d/webview/client/*.html
include refl1d/webview/client/*.js
include refl1d/webview/client/*.json
include refl1d/webview/client/*.txt
# Delete files
#prune this that
32 changes: 32 additions & 0 deletions extra/build_conda_packed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

ENV_NAME="isolated-base"
PYTHON_VERSION="3.10"
DIRNAME="refl1d"

eval "$(conda shell.bash hook)"
conda activate base || { echo 'failed: conda not installed'; exit 1; }

conda install -y conda-pack
conda create -n "$ENV_NAME" -y "python=$PYTHON_VERSION"
conda-pack -n "$ENV_NAME" -f -o "$ENV_NAME.tar.gz"

# unpack the new environment, that contains only python + pip
tmpdir=$(mktemp -d)
destdir="$tmpdir/$DIRNAME"
mkdir "$destdir"
tar -xzf "$ENV_NAME.tar.gz" -C "$destdir"

# activate the unpacked environment and install pip packages
conda deactivate
WORKING_DIRECTORY=$(pwd)
cd "$tmpdir"
source "$DIRNAME/bin/activate"
pip install --no-input numba
pip install --no-input git+https://github.com/bumps/bumps@dataclass_overlay
pip install --no-input git+https://github.com/reflectometry/refl1d@webview
pip install -r https://raw.githubusercontent.com/reflectometry/refl1d/webview/webview-requirements
source "$DIRNAME/bin/deactivate"

# zip it back up
tar -czf "$WORKING_DIRECTORY/refl1d-webview-$(uname -s)-$(uname -m).tar.gz" "$DIRNAME"
115 changes: 65 additions & 50 deletions refl1d/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def calc_errors(problem, points):
# TODO: return sane datastructure
# Make a hashable version of model which just contains the name
# attribute, which is all that the rest of this code accesses.
models = [_HashableModel(m) for m in _experiments(problem)]
models = [_HashableModel(m, i) for i, m in enumerate(_experiments(problem))]

profiles = {h: [v[k] for v in profiles] for k, h in enumerate(models)}
slabs = {h: [v[k] for v in slabs] for k, h in enumerate(models)}
Expand All @@ -179,8 +179,8 @@ def calc_errors(problem, points):

class _HashableModel:
name: str
def __init__(self, model):
self.name = model.name
def __init__(self, model, index):
self.name = model.name if model.name is not None else f"M{index}"
def __str__(self):
return f"model {self.name}"

Expand Down Expand Up @@ -229,7 +229,7 @@ def align_profiles(profiles, slabs, align):
for m in profiles.keys())

def show_errors(errors, contours=CONTOURS, npoints=200,
align='auto', plots=1, save=None):
align='auto', plots=1, save=None, fig=None):
"""
Plot the aligned profiles and the distribution of the residuals for
profiles and residuals returned from calc_errors.
Expand Down Expand Up @@ -259,15 +259,20 @@ def show_errors(errors, contours=CONTOURS, npoints=200,
"""
import matplotlib.pyplot as plt

if fig is not None and plots != 1:
raise ValueError("can only pass in a figure object if exactly 1 plot is requested")

if plots == 0: # Don't create plots, just save the data
_save_profile_data(errors, contours=contours, npoints=npoints,
align=align, save=save)
_save_residual_data(errors, contours=contours, save=save)
elif plots == 1: # Subplots for profiles/residuals
plt.subplot(211)
show_profiles(errors, contours=contours, npoints=npoints, align=align)
plt.subplot(212)
show_residuals(errors, contours=contours)
if fig is None:
fig = plt.gcf()
ax_profiles = fig.add_subplot(211)
show_profiles(errors, contours=contours, npoints=npoints, align=align, axes=ax_profiles)
ax_residuals = fig.add_subplot(212)
show_residuals(errors, contours=contours, axes=ax_residuals)
if save:
plt.savefig(save+"-err.png")
elif plots == 2: # Separate plots for profiles/residuals
Expand Down Expand Up @@ -296,24 +301,24 @@ def show_errors(errors, contours=CONTOURS, npoints=200,
plt.savefig(save+"-err%d.png"%fignum)
fignum += 1

def show_profiles(errors, align, contours, npoints):
def show_profiles(errors, align, contours, npoints, axes=None):
profiles, slabs, _, _ = errors
if align is not None:
profiles = align_profiles(profiles, slabs, align)

if contours:
_profiles_contour(profiles, contours, npoints)
_profiles_contour(profiles, contours, npoints, axes=axes)
else:
_profiles_overplot(profiles)
_profiles_overplot(profiles, axes=axes)


def show_residuals(errors, contours):
def show_residuals(errors, contours, axes=None):
_, _, Q, residuals = errors

if False and contours:
_residuals_contour(Q, residuals, contours=contours)
else:
_residuals_overplot(Q, residuals)
_residuals_overplot(Q, residuals, axes=axes)


def _save_profile_data(errors, align, contours, npoints, save):
Expand Down Expand Up @@ -376,34 +381,36 @@ def _write_file(path, data, title, columns):
def dark(color):
return dhsv(color, dv=-0.2)

def _profiles_overplot(profiles):
def _profiles_overplot(profiles, axes=None):
for model, group in profiles.items():
name = model.name
absorbing = any((L[2] != 1e-4).any() for L in group)
magnetic = (len(group[0]) > 3)
# Note: Use 3 colours per dataset for consistency
_draw_overplot(group, 1, name + ' rho')
_draw_overplot(group, 1, name + ' rho', axes=axes)
if absorbing:
_draw_overplot(group, 2, name + ' irho')
_draw_overplot(group, 2, name + ' irho', axes=axes)
else:
next_color()
next_color(axes=axes)
if magnetic:
_draw_overplot(group, 3, name + ' rhoM')
_draw_overplot(group, 3, name + ' rhoM', axes=axes)
else:
next_color()
_profile_labels()
next_color(axes=axes)
_profile_labels(axes=axes)

def _draw_overplot(group, index, label):
def _draw_overplot(group, index, label, axes=None):
import matplotlib.pyplot as plt
if axes is None:
axes = plt.gca()
alpha = 0.1
color = next_color()
color = next_color(axes=axes)
for L in group[1:]:
plt.plot(L[0], L[index], '-', color=color, alpha=alpha)
axes.plot(L[0], L[index], '-', color=color, alpha=alpha)
# Plot best
L = group[0]
plt.plot(L[0], L[index], '-', label=label, color=dark(color))
axes.plot(L[0], L[index], '-', label=label, color=dark(color))

def _profiles_contour(profiles, contours=CONTOURS, npoints=200):
def _profiles_contour(profiles, contours=CONTOURS, npoints=200, axes=None):
for model, group in profiles.items():
name = model.name if model.name is not None else 'model'
absorbing = any((L[2] > 1e-4).any() for L in group)
Expand All @@ -412,46 +419,52 @@ def _profiles_contour(profiles, contours=CONTOURS, npoints=200):
z = np.hstack([line[0] for line in group])
zp = np.linspace(np.min(z), np.max(z), npoints)
# Note: Use 3 colours per dataset for consistency
_draw_contours(group, 1, name + ' rho', zp, contours)
_draw_contours(group, 1, name + ' rho', zp, contours, axes=axes)
if absorbing:
_draw_contours(group, 2, name + ' irho', zp, contours)
_draw_contours(group, 2, name + ' irho', zp, contours, axes=axes)
else:
next_color()
next_color(axes=axes)
if magnetic:
_draw_contours(group, 3, name + ' rhoM', zp, contours)
_draw_contours(group, 3, name + ' rhoM', zp, contours, axes=axes)
else:
next_color()
_profile_labels()
next_color(axes=axes)
_profile_labels(axes=axes)

def _draw_contours(group, index, label, zp, contours):
def _draw_contours(group, index, label, zp, contours, axes=None):
import matplotlib.pyplot as plt
color = next_color()
if axes is None:
axes = plt.gca()
color = next_color(axes=axes)
# Interpolate on common z
fp = np.vstack([np.interp(zp, L[0], L[index]) for L in group])
# Plot the quantiles
plot_quantiles(zp, fp, contours, color)
plot_quantiles(zp, fp, contours, color, axes=axes)
# Plot the best
plt.plot(zp, fp[0], '-', label=label, color=dark(color))
axes.plot(zp, fp[0], '-', label=label, color=dark(color))

def _profile_labels():
def _profile_labels(axes=None):
import matplotlib.pyplot as plt
plt.legend()
plt.xlabel(u'z (Å)')
plt.ylabel(u'SLD (10⁻⁶/Ų)')
if axes is None:
axes = plt.gca()
axes.legend()
axes.set_xlabel(u'z (Å)')
axes.set_ylabel(u'SLD (10⁻⁶/Ų)')

def _residuals_overplot(Q, residuals):
def _residuals_overplot(Q, residuals, axes=None):
import matplotlib.pyplot as plt
if axes is None:
axes = plt.gca()
alpha = 0.4
shift = 0
for m, r in residuals.items():
color = next_color()
plt.plot(Q[m], shift+r[:, 1:], '.', markersize=1, color=color, alpha=alpha)
plt.plot(Q[m], shift+r[:, 0], '.', label=m.name, markersize=1, color=dark(color))
color = next_color(axes=axes)
axes.plot(Q[m], shift+r[:, 1:], '.', markersize=1, color=color, alpha=alpha)
axes.plot(Q[m], shift+r[:, 0], '.', label=m.name, markersize=1, color=dark(color))
# Use 3 colours from cycle so reflectivity matches rho for each dataset
next_color()
next_color()
next_color(axes=axes)
next_color(axes=axes)
shift += 5
_residuals_labels()
_residuals_labels(axes=axes)

def _residuals_contour(Q, residuals, contours=CONTOURS):
import matplotlib.pyplot as plt
Expand All @@ -466,11 +479,13 @@ def _residuals_contour(Q, residuals, contours=CONTOURS):
shift += 5
_residuals_labels()

def _residuals_labels():
def _residuals_labels(axes=None):
import matplotlib.pyplot as plt
plt.legend()
plt.xlabel(u'Q (1/Å)')
plt.ylabel(u'Residuals')
if axes is None:
axes = plt.gca()
axes.legend()
axes.set_xlabel(u'Q (1/Å)')
axes.set_ylabel(u'Residuals')

# ==== Helper functions =====

Expand Down
2 changes: 1 addition & 1 deletion refl1d/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def __init__(self, samples=None, ratio=None, probe=None,
self.probe = probe
self.ratio = [Parameter.default(r, name="ratio %d"%i)
for i, r in enumerate(ratio)]
self.parts = [Experiment(s, probe, **kw) for s in samples]
self.parts = [Experiment(s, probe, name=s.name, **kw) for s in samples]
self.coherent = coherent
self.interpolation = interpolation
self._substrate = self.samples[0][0].material
Expand Down
Loading