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

Restructure and Reorganize project #185

Merged
merged 58 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
482dd22
Begin restructuring project
glass-ships Sep 12, 2024
5aff410
fix some test imports
glass-ships Sep 12, 2024
eb5ddc5
checkpoint before merge
glass-ships Sep 12, 2024
031f5ec
merge main
glass-ships Sep 12, 2024
d1279cc
fix some imports to narrow test failures down
glass-ships Sep 12, 2024
44016b7
fix couple more imports
glass-ships Sep 12, 2024
8d236a6
update bumps, tests pass now. carrying on
glass-ships Sep 12, 2024
b1048e9
fix tests
glass-ships Sep 13, 2024
2a86674
fix docs build, update makefile, add sphinx to pyproject
glass-ships Sep 13, 2024
af0b6fa
fix makefile
glass-ships Sep 13, 2024
f91b191
Merge branch 'master' into restructure
glass-ships Sep 13, 2024
2f573f0
fix makefile again, sorry
glass-ships Sep 13, 2024
a3c6248
fix examples
glass-ships Sep 13, 2024
b19308b
fix examples for real i think
glass-ships Sep 13, 2024
0f7beec
Merge branch 'master' into restructure
glass-ships Sep 16, 2024
174b352
move backends to top level
glass-ships Sep 16, 2024
bdedb5e
fix imports in docs
glass-ships Sep 16, 2024
64a1c6b
fix imports in docs
glass-ships Sep 16, 2024
c88bcc9
fix pip install not including all dirs
glass-ships Sep 16, 2024
2d1ad5c
Merge branch 'master' into restructure
glass-ships Sep 20, 2024
da30308
working on documentation slowly but surely
glass-ships Sep 20, 2024
2fdefda
some updates
glass-ships Sep 23, 2024
8e44b4a
update osx installer section
glass-ships Sep 23, 2024
5333daf
Merge branch 'master' into restructure
glass-ships Sep 25, 2024
f1e37fd
merge master
glass-ships Oct 8, 2024
cbe9451
checkpoint restructure 2.0
glass-ships Oct 9, 2024
09e5215
cant install wx
glass-ships Oct 9, 2024
766a909
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
e444637
update docs, wx tests still failing
glass-ships Oct 9, 2024
7ad5853
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
f3c3e46
update doc tests with new layout
bmaranville Oct 9, 2024
ada6778
fix tests
glass-ships Oct 10, 2024
09d5aa1
fix examples
glass-ships Oct 10, 2024
34bb805
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
02ece4e
fix make docs
glass-ships Oct 10, 2024
c9be29d
merge master
glass-ships Oct 18, 2024
13735f1
Fix docs not building (workaround for now)
glass-ships Oct 18, 2024
42e54ad
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2024
e8f15ba
Put names back
glass-ships Oct 23, 2024
966937e
remove __all__ from models init
glass-ships Oct 23, 2024
c016735
Merge branch 'master' into restructure
glass-ships Oct 25, 2024
f4ac5c4
merge master
glass-ships Oct 30, 2024
dc24bd1
load4 in names.py should be function, not module
bmaranville Nov 5, 2024
16ecace
probe moved to subfolder, need to get probe.probe
bmaranville Nov 5, 2024
2124596
if refl1d api is not imported, functions don't get registered
bmaranville Nov 5, 2024
d775f34
Remove vue-json-viewer
glass-ships Nov 7, 2024
5dce7a5
merge master
glass-ships Nov 11, 2024
d11b4c2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 11, 2024
d1123ef
update references in comments, docs, and docstrings
glass-ships Nov 12, 2024
7cb850d
couple more references updated
glass-ships Nov 12, 2024
eea1067
remove reference to _MaterialStacker
glass-ships Nov 12, 2024
a16310e
merge main
glass-ships Nov 19, 2024
911fa0b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
d68a89b
resolve conflicts
glass-ships Nov 19, 2024
21a8cd9
minor changes
glass-ships Nov 19, 2024
9ce43e7
move subdirs to top level
glass-ships Nov 19, 2024
1bb568d
fix doc gen
glass-ships Nov 19, 2024
5ec0c54
manual merge master
glass-ships Nov 22, 2024
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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ repos:
args: [--allow-multiple-documents]
# - id: end-of-file-fixer
# - id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
hooks:
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ lint: ## Run ruff linting
.PHONY: format
format: ## Run ruff formatting
@ruff format refl1d/ tests/ setup.py

.PHONY: clean
clean: ## Delete some cruft from builds/testing/etc.
rm -f `find . -type f -name '*.py[co]'`
rm -rf `find . -name __pycache__ -o -name "*.egg-info"` \
`find . -name 'output-*'` \
.coverage build dist doc/_build \
.pytest_cache \
.ruff_cache
2 changes: 1 addition & 1 deletion doc/examples/distribution/dist-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from refl1d.names import *
from refl1d.dist import Weights, DistributionExperiment
from refl1d.models.dist import Weights, DistributionExperiment

# Materials
nickel = Material("Ni", fitby="relative_density")
Expand Down
6 changes: 4 additions & 2 deletions doc/examples/four_column/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

# The following is copied directly from the spin value example

from refl1d.names import *
from refl1d.models.experiment import FitProblem
from refl1d.names import air, SLD, Magnetism, MagnetismTwist, Experiment
from refl1d.readers import load4

Si = SLD(name="Si", rho=2.0737, irho=2.376e-5)
Cu = SLD(name="Cu", rho=6.5535, irho=8.925e-4)
Expand Down Expand Up @@ -43,7 +45,7 @@
# Here's the new loader. Much simplified since the reduction computes the
# appropriate $\Delta Q$ for the data points, and we don't need to specify
# the slit openings and distances for the data set. The options to the
# :func:`refl1d.probe.load4` function allow you to override things during
# :func:`refl1d.readers.load4` function allow you to override things during
# load, such as the sample broadening of the resolution.

probe = load4("refl.txt")
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/profile/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# FunctionalProfile and FunctionalMagnetism are already available from
# refl1d.names, but a couple of aliases make them a little easier to access.

from refl1d.flayer import FunctionalProfile as FP
from refl1d.flayer import FunctionalMagnetism as FM
from refl1d.models.sample.flayer import FunctionalProfile as FP
from refl1d.models.sample.flayer import FunctionalMagnetism as FM

# Define the nuclear profile function.
#
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/staj/De2_VATR.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from refl1d.names import *
from refl1d.stajconvert import load_mlayer
from refl1d.readers.stajconvert import load_mlayer

# Load neutron model and data from staj file
# Layer names are ordered from substrate to surface, and defaults to
Expand Down
65 changes: 29 additions & 36 deletions doc/genmods.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
MODULE_TEMPLATE is the template for each api module.
"""

from __future__ import with_statement, print_function

OPTIONS = {
"absolute": False, # True if package.module in table of contents
"dir": "api", # Destination directory for the api docs
Expand All @@ -32,42 +30,37 @@
MODULES = [
# ('__init__', 'Top level namespace'),
# ('interface', 'Interface'),
("abeles", "Pure python reflectivity calculator"),
("anstodata", "Reader for ANSTO data format"),
("cheby", "Freeform - Chebyshev model"),
# ('composition', 'Composition space model'),
# ('corrtest', 'Test for residual structure'),
("dist", "Non-uniform samples"),
("errors", "Plot sample profile uncertainty"),
("experiment", "Reflectivity fitness function"),
# ('deprecated.magnetic', 'Magnetic Models'),
("deprecated.freeform", "Freeform - Parametric B-Spline"),
("fitplugin", "Bumps plugin definition for reflectivity models"),
("flayer", "Functional layers"),
("freeform", "Freeform - Parametric B-Spline"),
("fresnel", "Pure python Fresnel reflectivity calculator"),
("garefl", "Adaptor for garefl models"),
("instrument", "Reflectivity instrument definition"),
# ('interface', 'Models of interfacial roughness'),
# ('magnetic', 'Magnetic Models'),
("magnetism", "Magnetic Models"),
("material", "Material"),
("materialdb", "Materials Database"),
("model", "Reflectivity Models"),
("mono", "Freeform - Monotonic Spline"),
("fitting.abeles", "Pure python reflectivity calculator"),
("fitting.backends", "Backends for low level reflectivity calculations"),
("fitting.fresnel", "Pure python Fresnel reflectivity calculator"),
("fitting.profile", "Model profile"),
("fitting.reflectivity", "Basic reflectivity calculations"),
("fitting.resolution", "Beam resolution calculations"),
("fitting.uncertainty", "Plot sample profile uncertainty"),
("models.dist", "Non-uniform samples"),
("models.experiment", "Reflectivity fitness function"),
("models.instrument", "Reflectivity instrument definition"),
("models.probe", "Instrument probe"),
("models.sample.cheby", "Freeform - Chebyshev model"),
("models.sample.flayer", "Functional layers"),
("models.sample.layers", "Models of Reflectivity Layer Structure"),
("models.sample.magnetism", "Magnetic Models"),
("models.sample.material", "Material"),
("models.sample.materialdb", "Materials Database"),
("models.sample.mono", "Freeform - Monotonic Spline"),
("models.sample.polymer", "Polymer models"),
("names", "Public API"),
("ncnrdata", "NCNR Data"),
# ('plottable', 'Style-based plot definitions'),
("polymer", "Polymer models"),
("probe", "Instrument probe"),
("profile", "Model profile"),
("refllib", "Low level reflectivity calculations"),
("reflectivity", "Reflectivity"),
("resolution", "Resolution"),
("snsdata", "SNS Data"),
("staj", "Staj File"),
("stajconvert", "Staj File Converter"),
("stitch", "Overlapping reflectivity curve stitching"),
("support", "Environment support"),
("util", "Miscellaneous functions"),
("readers.anstodata", "Reader for ANSTO data format"),
("readers.ncnrdata", "NCNR Data"),
("readers.snsdata", "SNS Data"),
("readers.staj", "Staj File"),
("readers.stajconvert", "Staj File Converter"),
("readers.stitch", "Overlapping reflectivity curve stitching"),
("utils.support", "Environment support"),
("utils.util", "Miscellaneous functions"),
]


Expand Down
6 changes: 3 additions & 3 deletions doc/getting_started/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Installing the application
| Windows installer: :slink:`%(winexe)s`
| Source: :slink:`%(srczip)s`

Recent versions of the Refl1D application are available for windows
Recent versions of the Refl1D application are available for Windows
from `github <https://github.com/reflectometry/refl1d/releases/latest>`_.
The file `Refl1D-VERSION-exe.zip` contains python, the application, the
supporting libraries and everything else needed to run the application.
supporting libraries, and everything else needed to run the application.

To install, download and extract the zip file. Go to the extracted directory
and click on `refl1d_gui.bat`. This will open a dialog saying that the
Expand Down Expand Up @@ -79,7 +79,7 @@ You will need a C/C++ compiler. If you already have Microsoft Visual C
installed you are done. If not, you can use the MinGW compiler that is supplied
with your python environment or download your own. You can set MinGW
as the default compiler by creating the file *Lib\distutils\\distutils.cfg*
in your python directory (e.g., *C:\\Python3.8*) with the following content::
in your python directory (e.g., *C:\\Python3.9*) with the following content::

[build]
compiler=mingw32
Expand Down
4 changes: 2 additions & 2 deletions doc/guide/experiment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function to yield reflectivities at intervals of 0.01.
::

>>> from numpy import arange
>>> from refl1d.reflectivity import reflectivity_amplitude as reflamp
>>> from refl1d.reflectivity import convolve
>>> from refl1d.fitting.reflectivity import reflectivity_amplitude as reflamp
>>> from refl1d.fitting.reflectivity import convolve
>>> Qin = arange(0,0.21,0.001)
>>> w,rho,irho,sigma = zip((0,2.07,0,5),(0,0,0,0))
>>> # the last layer has no interface
Expand Down
4 changes: 2 additions & 2 deletions doc/guide/fitting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Next we can reload the the error sample data from the DREAM MCMC sequence::

from bumps.dream.state import load_state
from bumps.errplot import calc_errors_from_state
from refl1d.errors import align_profiles
from refl1d.uncertainty import align_profiles

state = load_state(os.path.join(store, model[:-3]))
state.mark_outliers()
Expand All @@ -419,7 +419,7 @@ Next we can reload the the error sample data from the DREAM MCMC sequence::
aligned_profiles = align_profiles(profiles, slabs, 2.5)
# ... insert profile and residuals uncertainty plots here ...

The function :func:`refl1d.errors.calc_errors` provides details on the data
The function :func:`refl1d.uncertainty.calc_errors` provides details on the data
structures for *profiles*, *Q* and *residuals*. Look at the source in
refl1d/errors.py to see how this data is used to produce the error plots
with _profiles_overplot, _profiles_contour, _residuals_overplot and
Expand Down
2 changes: 1 addition & 1 deletion doc/guide/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Using Refl1D
The Refl1D library is organized into modules. Specific functions and
classes can be imported from a module, such as::

>>> from refl1d.model import Slab
>>> from refl1d.models.sample.layers import Slab

The most common imports have been gathered together in refl1d.names. This
allows you to use names like :class:`Slab <refl1d.model.Slab>` directly::
Expand Down
2 changes: 1 addition & 1 deletion doc/guide/toffset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

from pylab import *
from refl1d.reflectivity import reflectivity
from ornl.refl1d.refl1d.fitting.reflectivity import reflectivity

rho = 2.07 # silicon rho for neutrons
L = 5 # Wavelength 5 angstroms
Expand Down
File renamed without changes.
9 changes: 3 additions & 6 deletions refl1d/refl_tr.py → explore/refl_tr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This program is public domain.
r"""
"""
Optical matrix form of the reflectivity calculation.

This is a pure python implementation of reflectometry which returns the
Expand Down Expand Up @@ -35,10 +34,8 @@
[4] https://en.wikipedia.org/wiki/Prefix_sum
"""

from __future__ import print_function, division

import numpy as np
from numpy import asarray, isscalar, empty, ones, ones_like
from numpy import asarray, isscalar, ones, ones_like
from numpy import sqrt, exp, pi


Expand Down Expand Up @@ -226,7 +223,7 @@ def check():
rho *= 100 # show point below critical edge
print("q", q)
try:
from .abeles import refl
from refl1d.fitting.abeles import refl

r_old = refl(q / 2, depth, rho, irho=irho, sigma=sigma)
print("rold", r_old)
Expand Down
21 changes: 7 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
# "bumps>=0.7.16",
"bumps@git+https://github.com/bumps/bumps.git#egg=master",
"bumps >= 1.0.0a0",
"matplotlib",
"numba",
"numpy",
Expand All @@ -32,9 +31,9 @@ dependencies = [
]

[project.optional-dependencies]
dev = ["pre-commit", "ruff", "pytest", "pytest-cov"]
dev = ["pre-commit", "ruff", "pytest", "pytest-cov", "sphinx"]
full = ["wxpython", "ipython"]
webview = ["bumps[webview]@git+https://github.com/bumps/bumps.git#egg=master"]
webview = ["bumps[webview] >= 1.0.0a0"]

[project.urls]
documentation = "https://refl1d.github.io"
Expand All @@ -47,9 +46,7 @@ build-backend = "setuptools.build_meta"

[tool.ruff]
line-length = 120
exclude = [
"*.txt",
]
exclude = ["*.txt"]

# [tool.ruff.lint]
# select = [
Expand All @@ -65,15 +62,11 @@ exclude = [
version = { attr = "refl1d.__version__" }

[tool.setuptools]
packages = [
"refl1d",
"refl1d.view",
"refl1d.lib.python",
"refl1d.lib.numba",
"refl1d.webview.server",
]
script-files = ["bin/refl1d_cli.py", "bin/refl1d_gui.py"]

[tool.setuptools.packages.find]
include = ["refl1d"]

[project.scripts]
refl1d = "refl1d.main:main"
refl1d-webview = "refl1d.webview.server.webserver:main"
Expand Down
6 changes: 3 additions & 3 deletions refl1d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
def use(backend_name: BACKEND_NAMES):
global BACKEND_NAME
BACKEND_NAME = backend_name
if "refl1d.refllib" in sys.modules:
if "refl1d.fitting.backends" in sys.modules:
# then it's already been imported:
import refl1d.refllib
import refl1d.fitting.backends as backends

refl1d.refllib.set_backend(backend_name)
backends.set_backend(backend_name)
Loading
Loading