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
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

*pytest_ignore_collect* skips kernelcl.py if pyopencl cannot be imported.
"""
from __future__ import print_function

import inspect

Expand Down
38 changes: 19 additions & 19 deletions doc/_extensions/dollarmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ def setup(app):


def test_dollar():
assert replace_dollar(u"no dollar")==u"no dollar"
assert replace_dollar(u"$only$")==u":math:`only`"
assert replace_dollar(u"$first$ is good")==u":math:`first` is good"
assert replace_dollar(u"so is $last$")==u"so is :math:`last`"
assert replace_dollar(u"and $mid$ too")==u"and :math:`mid` too"
assert replace_dollar(u"$first$, $mid$, $last$")==u":math:`first`, :math:`mid`, :math:`last`"
assert replace_dollar(u"dollar\$ escape")==u"dollar$ escape"
assert replace_dollar(u"dollar \$escape\$ too")==u"dollar $escape$ too"
assert replace_dollar(u"spaces $in the$ math")==u"spaces :math:`in the` math"
assert replace_dollar(u"emb\ $ed$\ ed")==u"emb\ :math:`ed`\ ed"
assert replace_dollar(u"$first$a")==u"$first$a"
assert replace_dollar(u"a$last$")==u"a$last$"
assert replace_dollar(u"$37")==u"$37"
assert replace_dollar(u"($37)")==u"($37)"
assert replace_dollar(u"$37 - $43")==u"$37 - $43"
assert replace_dollar(u"($37, $38)")==u"($37, $38)"
assert replace_dollar(u"a $mid$dle a")==u"a $mid$dle a"
assert replace_dollar(u"a ($in parens$) a")==u"a (:math:`in parens`) a"
assert replace_dollar(u"a (again $in parens$) a")==u"a (again :math:`in parens`) a"
assert replace_dollar("no dollar")=="no dollar"
assert replace_dollar("$only$")==":math:`only`"
assert replace_dollar("$first$ is good")==":math:`first` is good"
assert replace_dollar("so is $last$")=="so is :math:`last`"
assert replace_dollar("and $mid$ too")=="and :math:`mid` too"
assert replace_dollar("$first$, $mid$, $last$")==":math:`first`, :math:`mid`, :math:`last`"
assert replace_dollar("dollar\$ escape")=="dollar$ escape"
assert replace_dollar("dollar \$escape\$ too")=="dollar $escape$ too"
assert replace_dollar("spaces $in the$ math")=="spaces :math:`in the` math"
assert replace_dollar("emb\ $ed$\ ed")=="emb\ :math:`ed`\ ed"
assert replace_dollar("$first$a")=="$first$a"
assert replace_dollar("a$last$")=="a$last$"
assert replace_dollar("$37")=="$37"
assert replace_dollar("($37)")=="($37)"
assert replace_dollar("$37 - $43")=="$37 - $43"
assert replace_dollar("($37, $38)")=="($37, $38)"
assert replace_dollar("a $mid$dle a")=="a $mid$dle a"
assert replace_dollar("a ($in parens$) a")=="a (:math:`in parens`) a"
assert replace_dollar("a (again $in parens$) a")=="a (again :math:`in parens`) a"

if __name__ == "__main__":
test_dollar()
1 change: 0 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Periodic Table documentation build configuration file, created by
# sphinx-quickstart on Tue Jun 2 11:16:08 2009.
Expand Down
1 change: 0 additions & 1 deletion doc/genapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import with_statement
import os.path

MODULE_TEMPLATE = """.. Autogenerated by genmods.py
Expand Down
22 changes: 5 additions & 17 deletions doc/genmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,17 @@
parallel. More parallelism won't help, and may overwhelm the GPU if you
have one.
"""
from __future__ import print_function

import sys
import os
from os import makedirs
from os.path import basename, dirname, realpath, join as joinpath, exists
import math
import re
import shutil
import argparse
import subprocess

# CRUFT: python 2.7 backport of makedirs(path, exist_ok=False)
if sys.version_info[0] >= 3:
from os import makedirs
else:
def makedirs(path, exist_ok=False):
try:
os.makedirs(path)
except Exception:
if not exist_ok or not exists(path):
raise

import numpy as np

# TODO: Remove this line when genmodel is moved to the sasmodels directory.
Expand All @@ -68,8 +57,7 @@ def makedirs(path, exist_ok=False):
from sasmodels.data import empty_data1D, empty_data2D

try:
from typing import Dict, Any
#from matplotlib.axes import Axes
from typing import Any
from sasmodels.kernel import KernelModel
from sasmodels.modelinfo import ModelInfo
except ImportError:
Expand All @@ -81,7 +69,7 @@ def makedirs(path, exist_ok=False):
TARGET_DIR = "model" # relative to current path

def plot_1d(model, opts, ax):
# type: (KernelModel, Dict[str, Any], Axes) -> None
# type: (KernelModel, dict[str, Any], Axes) -> None
"""
Create a 1-D image.
"""
Expand All @@ -101,7 +89,7 @@ def plot_1d(model, opts, ax):
#ax.legend(loc='best')

def plot_2d(model, opts, ax):
# type: (KernelModel, Dict[str, Any], Axes) -> None
# type: (KernelModel, dict[str, Any], Axes) -> None
"""
Create a 2-D image.
"""
Expand Down Expand Up @@ -143,7 +131,7 @@ def figfile(model_info):
return model_info.id + '_autogenfig.png'

def make_figure(model_info, opts):
# type: (ModelInfo, Dict[str, Any]) -> None
# type: (ModelInfo, dict[str, Any]) -> None
"""
Generate the figure file to include in the docs.
"""
Expand Down
9 changes: 4 additions & 5 deletions doc/gentoc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function

import sys
# make sure sasmodels is on the path
Expand All @@ -9,7 +8,7 @@
from sasmodels.core import load_model_info

try:
from typing import Optional, BinaryIO, List, Dict
from typing import Optional, BinaryIO
except ImportError:
pass

Expand Down Expand Up @@ -46,19 +45,19 @@ def _add_model(file, model_name):
file.write(" ../../model/%s.rst\n"%model_name)

def _maybe_make_category(category, models, cat_files, model_toc):
# type: (str, List[str], Dict[str, BinaryIO], BinaryIO) -> None
# type: (str, list[str], dict[str, BinaryIO], BinaryIO) -> None
if category not in cat_files:
print("Unexpected category %s containing"%category, models, file=sys.stderr)
title = category.capitalize()+" Functions"
cat_files[category] = _make_category(category, category, title, model_toc)

def generate_toc(model_files):
# type: (List[str]) -> None
# type: (list[str]) -> None
if not model_files:
print("gentoc needs a list of model files", file=sys.stderr)

# find all categories
category = {} # type: Dict[str, List[str]]
category = {} # type: dict[str, list[str]]
for item in model_files:
# assume model is in sasmodels/models/name.py, and ignore the full path
model_name = basename(item)[:-3]
Expand Down
3 changes: 1 addition & 2 deletions example/batch_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
If sasmodels, sasview or bumps are not in the path, use the PYTHONPATH
environment variable to set them.
"""
from __future__ import print_function

import sys
import os
Expand Down Expand Up @@ -109,7 +108,7 @@ def fit_dir(filename):
results = {}
par_file = os.path.splitext(model_file)[0] + '.par'
for data_file in data_files:
with open(os.path.join(fit_dir(data_file), par_file), 'r') as fid:
with open(os.path.join(fit_dir(data_file), par_file)) as fid:
for line in fid:
parameter, value = line.split()
results.setdefault(parameter, []).append(float(value))
Expand Down
1 change: 0 additions & 1 deletion example/fit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from bumps.names import FitProblem
Expand Down
1 change: 0 additions & 1 deletion example/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bumps.names import FitProblem
from sasmodels.core import load_model
Expand Down
1 change: 0 additions & 1 deletion example/multiscatfit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Fit model using multiple scattering.

Expand Down
2 changes: 1 addition & 1 deletion example/sesansfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[],
loader = Loader()
data = loader.load(file)[0]
if data is None:
raise IOError("Could not load file %r"%(file))
raise OSError("Could not load file %r"%(file))

except Exception:
raise
Expand Down
2 changes: 1 addition & 1 deletion example/sesansfit_CodeCampIII.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
filename = 'sphere.ses'
data = loader.load(filename)
if data is None:
raise IOError("Could not load file %r"%(filename,))
raise OSError("Could not load file %r"%(filename,))
data.x /= 10
# print data
# data = load_sesans('mydatfile.pz')
Expand Down
1 change: 0 additions & 1 deletion example/weights/maier_saupe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import numpy as np
from numpy import exp, sin, degrees, radians, pi, sqrt

Expand Down
5 changes: 0 additions & 5 deletions explore/angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
or any combination.
"""

from __future__ import print_function

import codecs
import sys
import re

import sympy as sp
Expand All @@ -37,8 +34,6 @@
QC_ONLY = True # show only what is needed for dqc in the symmetric case

# include unicode symbols in output, even if piping to a pager
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment still needed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think so, because the init_printing routine is there to allow printing unicode characters.

if sys.version_info[0] < 3:
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sp.init_printing(use_unicode=True)

def subs(s):
Expand Down
1 change: 0 additions & 1 deletion explore/asymint.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
that the normalization constants are correct for the different algorithms.
"""

from __future__ import print_function, division

import os
import sys
Expand Down
3 changes: 1 addition & 2 deletions explore/beta/sasfit_compare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division, print_function
# Make sasmodels available on the path
import sys
import os
Expand Down Expand Up @@ -375,7 +374,7 @@ def data_file(name):

def load_sasfit(path):
data = np.loadtxt(path, dtype=str, delimiter=';').T
data = np.vstack((map(float, v) for v in data[0:2]))
data = np.vstack(map(float, v) for v in data[0:2])
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be failing. For version 2.2.6 that I happen to have installed, np.vstack(generator) gives
TypeError: arrays to stack must be passed as a "sequence" type such as list or tuple.

This is a bug in the original, which should have used [...] rather than (...) when forming the sequence to send to vstack, so not an error introduced by this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for letting me know, I'll put in a one-liner PR to correct this.

return data

COMPARISON = {} # Type: Dict[(str,str,str)] -> Callable[(), None]
Expand Down
3 changes: 1 addition & 2 deletions explore/beta/sasfit_compare_new.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division, print_function
# Make sasmodels available on the path
import sys
import os
Expand Down Expand Up @@ -579,7 +578,7 @@ def data_file(name):

def load_sasfit(path):
data = np.loadtxt(path, dtype=str, delimiter=';').T
data = np.vstack((list(map(float, v)) for v in data[0:2]))
data = np.vstack(list(map(float, v)) for v in data[0:2])
return data

COMPARISON = {} # Type: Dict[(str,str,str)] -> Callable[(), None]
Expand Down
1 change: 0 additions & 1 deletion explore/check1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
with angle set by -angle=alpha in the qx-qy plane.
"""

from __future__ import print_function, division

import sys
import os
Expand Down
7 changes: 3 additions & 4 deletions explore/precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# There are richardson and shanks series accelerators in both sympy
# and mpmath that may be helpful.
"""
from __future__ import division, print_function

import sys
import os
Expand All @@ -50,7 +49,7 @@

from sasmodels import core, data, direct_model, modelinfo

class Comparator(object):
class Comparator:
def __init__(self, name, mp_function, np_function, ocl_function, xaxis, limits):
self.name = name
self.mp_function = mp_function
Expand Down Expand Up @@ -192,14 +191,14 @@ def plotdiff(x, target, actual, label, diff):
#err = np.clip(err, 0, 1)
pylab.loglog(x, err, '-', label=label, alpha=0.7)
elif diff == "absolute":
err = np.array([abs((t-a)) for t, a in zip(target, actual)], 'd')
err = np.array([abs(t-a) for t, a in zip(target, actual)], 'd')
pylab.loglog(x, err, '-', label=label, alpha=0.7)
else:
limits = np.min(target), np.max(target)
pylab.semilogx(x, np.clip(actual, *limits), '-', label=label, alpha=0.7)

def make_ocl(function, name, source=[]):
class Kernel(object):
class Kernel:
pass
Kernel.__file__ = name+".py"
Kernel.name = name
Expand Down
1 change: 0 additions & 1 deletion explore/realspace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division, print_function

import cmath
from copy import copy
Expand Down
1 change: 0 additions & 1 deletion explore/symint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Explore integration of rotationally symmetric shapes
"""

from __future__ import print_function, division

import os
import sys
Expand Down
1 change: 0 additions & 1 deletion explore/transform_angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

Usage: python explore/transform_angles.py theta phi psi
"""
from __future__ import print_function, division

import sys

Expand Down
11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ line-length = 120
[tool.ruff.lint]
# The ruff rules are available at: https://docs.astral.sh/ruff/rules/
select = ["E", # pycodestyle errors
"F"] # pyflakes

ignore = ["E501"] # line too long (leave to formatter)
"F", # pyflakes
"UP", # pyupgrade
"SIM118", # Use `key in dict` instead of `key in dict.keys()`
"SIM300"] # Yoda condition detected

ignore = ["E501", # line too long (leave to formatter)
"UP008", # Use `super()` instead of `super(__class__, self)`
"UP031"] # Use format specifiers instead of percent format
Loading
Loading