Skip to content

Commit

Permalink
Merge branch 'master' into py37-sasgui
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Kienzle committed Mar 6, 2019
2 parents cb64d86 + f205d3a commit 82d88d5
Show file tree
Hide file tree
Showing 86 changed files with 1,586 additions and 1,169 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Thumbs.db
/docs/sphinx-docs/node-package.json

# test outputs
/.eggs
/test/pr_inversion/test/test_output.txt
/test/sasdataloader/test/plugins.zip
/test/sasdataloader/test/test_log.txt
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2009-2018, SasView Developers
Copyright (c) 2009-2019, SasView Developers
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
7 changes: 7 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Pytest configuration file.
"""

# Prepare the runtime environment for the tests
import run
run.prepare()
Binary file modified docs/sasview/Tutorial.pdf
Binary file not shown.
Binary file modified docs/sasview/Tutorial.pptx
Binary file not shown.
Binary file added docs/sasview/Tutorial_SV4.pdf
Binary file not shown.
Binary file added docs/sasview/Tutorial_SV4.pptx
Binary file not shown.
15 changes: 11 additions & 4 deletions docs/sphinx-docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
print("-- path --")
print("\n".join(sys.path))

#need to import src.sas.sasview init to access version number and dates
#use abspath as above to locate then import
sasview_path = os.path.abspath('../../../src/sas')
sys.path.append(sasview_path)
import sas.sasview

# -- General configuration -----------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down Expand Up @@ -70,17 +76,18 @@
master_doc = 'index'

# General information about the project.
copyright_date = sas.sasview.__release_date__
project = u'SasView'
copyright = u'2018, The SasView Project'
copyright = u'%s, The SasView Project' % copyright_date

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '4.2'
# The full version, including alpha/beta/rc tags.
release = '4.2.0'
version = ".".join(sas.sasview.__version__.split(".", 2)[0:2])
# The full version, including ax/bx tags Note strict version is enforced.
release = sas.sasview.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
32 changes: 31 additions & 1 deletion docs/sphinx-docs/source/user/RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,36 @@ Release Notes
Features
========

New in Version 4.2.1
--------------------
The major changes for this point release were to fix several problems with using
the built in editor to create new models and to bring the NXcanSAS reader into
compliance with the final published specification. The orignal reader was
based on a draft version of the specification. As an early adopter,
interpretation and implementation of the spec was iterated with all producers
of NXcanSAS reduced data known to the SasView team in order to ensure
compatibility and verify the implementation. A few other enhancements and bug
fixed were also introduced such as cleaning up the resolution section of the
fitting page GUI, increasing the max size range allowed in the corfunc
analysis, and adding the incomplete gamma function to the python library.

Resolved Issues
^^^^^^^^^^^^^^^
* Fixes # 976: CanSas HDF reader will not read all valid CanSas HDF (NXcanSAS) files
* Fixes # 1074: Add incomplete gamma function to sasmodels
* Fixes # 1111: Convert all input Q units to 1/A
* Fixes # 1129: NXcanSAS writer not writing all meta data
* Fixes # 1142: Plugin framework is broken
* Fixes # 1183: Test from creating new model reset all parameters to default in all open FitPages
* Fixes # 1188: Colons removed from magnetic parameter names to address Python variable issue - done in 4.2. but documented in 4.2.1
* Fixes # 1205: 4.2 set weighting choice seems to be ignored.
* Fixes # 1206: Incorrect (and confusing) presentation of dQ from data in instrumental smearing section
* Fixes # 1212: Bug in Iqxqy plotting non rectangular / square matrices?
* Fixes # 1221: ABS reader does not read in USANS data properly GitHub
* Fixes # 1222: smearing options incorrect on show2D and show1D in fitpage14: Loading a saved project is really really slow
* Fixes # 1223: Expand permitted range of transformed data in Corfunc implementation


New in Version 4.2.0
--------------------
This release heralds many improvements and a host of bug fixes, along with
Expand Down Expand Up @@ -125,7 +155,7 @@ Bug Fixes
* Fixes # 776: angular dispersity
* Fixes # 784: Add 3D integral to Correlation Function analysis
* Fixes # 786: core_shell_parallelepiped 1-D model is incorrect
* Fixes # 818: “report button” followed by “save” makes an empty pdf file???
* Fixes # 818: “report button” followed by “save” makes an empty pdf file???
* Fixes # 830: Check compliance of loader against NXcanSAS-1.0 release
* Fixes # 838: Fix model download from marketplace
* Fixes # 848: can't save analysis when only one fit page
Expand Down
2 changes: 1 addition & 1 deletion installers/license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ may read here: https://github.com/SasView/sasview/blob/master/LICENSE.TXT

SasView is free to download and use, including for commercial purposes.

� 2009-2018 UMD, UTK, NIST, ORNL, ISIS, ESS, ANSTO, ILL, TUD, DLS, BAM
� 2009-2019 UMD, UTK, NIST, ORNL, ISIS, ESS, ANSTO, ILL, TUD, DLS, BAM


If you use SasView to do productive scientific research that leads to
Expand Down
19 changes: 0 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,6 @@
CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
SASVIEW_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build")

# TODO: build step should not be messing with existing installation!!
sas_dir = os.path.join(os.path.expanduser("~"), '.sasview')
if os.path.isdir(sas_dir):
f_path = os.path.join(sas_dir, "sasview.log")
if os.path.isfile(f_path):
os.remove(f_path)
f_path = os.path.join(sas_dir, "categories.json")
if os.path.isfile(f_path):
os.remove(f_path)
f_path = os.path.join(sas_dir, 'config', "custom_config.py")
if os.path.isfile(f_path):
os.remove(f_path)
#f_path = os.path.join(sas_dir, 'plugin_models')
# if os.path.isdir(f_path):
# for f in os.listdir(f_path):
# if f in plugin_model_list:
# file_path = os.path.join(f_path, f)
# os.remove(file_path)


# Optionally clean before build.
dont_clean = 'update' in sys.argv
Expand Down
12 changes: 7 additions & 5 deletions src/sas/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def make_custom_config_path(user_dir):

def setup_custom_config(app_dir, user_dir):
path = make_custom_config_path(user_dir)
#logger.info("custom config path %s", path)
if not os.path.isfile(path):
try:
# if the custom config file does not exist, copy the default from
Expand All @@ -93,18 +94,19 @@ def setup_custom_config(app_dir, user_dir):
except Exception:
logger.error("Could not copy default custom config.")

custom_config = load_custom_config(path)

#Adding SAS_OPENCL if it doesn't exist in the config file
# - to support backcompability
if not "SAS_OPENCL" in open(path).read():
if not hasattr(custom_config, "SAS_OPENCL"):
custom_config.SAS_OPENCL = None
try:
open(config_file, "a+").write("SAS_OPENCL = \"None\"\n")
open(path, "a+").write("SAS_OPENCL = \"None\"\n")
except Exception:
logger.error("Could not update custom config with SAS_OPENCL.")

custom_config = load_custom_config(path)
return custom_config


def load_custom_config(path):
if os.path.exists(path):
try:
Expand All @@ -116,4 +118,4 @@ def load_custom_config(path):

from sas.sasview import custom_config
logger.info("GuiManager custom_config defaults to sas.sasview.custom_config")
return custom_config
return custom_config
6 changes: 5 additions & 1 deletion src/sas/sascalc/calculator/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ def set_size(self, size=[]):
if len(size) == 0:
self.size = 0
else:
self.size = size
# TODO: Make sure detector size is number of pixels
# Could be detector dimensions in e.g., mm, but
# the resolution calculator assumes it is pixels.
# Being pixels, it has to be integers rather than float
self.size = [int(s) for s in size]
validate(size[0])

def set_pix_size(self, size=[]):
Expand Down
8 changes: 4 additions & 4 deletions src/sas/sascalc/calculator/resolution_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,8 @@ def _get_detector_qxqy_pixels(self):
detector_offset = 0
try:
detector_offset = self.sample2detector_distance[1]
except:
logger.error(sys.exc_value)
except Exception as exc:
logger.error(exc)

# detector size in [no of pix_x,no of pix_y]
detector_pix_nums_x = self.detector_size[0]
Expand Down Expand Up @@ -1093,8 +1093,8 @@ def _get_detector_qxqy_pixels(self):
output.data = inten
output.qx_data = qx_value
output.qy_data = qy_value
except:
logger.error(sys.exc_value)
except Exception as exc:
logger.error(exc)

return output

Expand Down
17 changes: 9 additions & 8 deletions src/sas/sascalc/corfunc/corfunc_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@ def __init__(self, f, g, start, stop):
self.g = g
self.start = start
self.stop = stop
self._lastx = []
self._lasty = []
self._lastx = np.empty(0, dtype='d')
self._lasty = None

def __call__(self, x):
# If input is a single number, evaluate the function at that number
# and return a single number
if type(x) == float or type(x) == int:
if isinstance(x, (float, int)):
return self._smoothed_function(np.array([x]))[0]
# If input is a list, and is different to the last input, evaluate
# the function at each point. If the input is the same as last time
# the function was called, return the result that was calculated
# last time instead of explicity evaluating the function again.
elif self._lastx == [] or x.tolist() != self._lastx.tolist():
self._lasty = self._smoothed_function(x)
self._lastx = x
if not np.array_equal(x, self._lastx):
self._lastx, self._lasty = x, self._smoothed_function(x)
return self._lasty

def _smoothed_function(self,x):
Expand Down Expand Up @@ -87,7 +86,7 @@ def set_data(self, data, scale=1):
return
# Only process data of the class Data1D
if not issubclass(data.__class__, Data1D):
raise ValueError("Data must be of the type DataLoader.Data1D")
raise ValueError("Correlation function cannot be computed with 2D data.")

# Prepare the data
new_data = Data1D(x=data.x, y=data.y)
Expand Down Expand Up @@ -245,7 +244,9 @@ def _porod(self, q, K, sigma, bg):
def _fit_guinier(self, q, iq):
"""Fit the Guinier region of the curve"""
A = np.vstack([q**2, np.ones(q.shape)]).T
return lstsq(A, np.log(iq))
# CRUFT: numpy>=1.14.0 allows rcond=None for the following default
rcond = np.finfo(float).eps * max(A.shape)
return lstsq(A, np.log(iq), rcond=rcond)

def _fit_porod(self, q, iq):
"""Fit the Porod region of the curve"""
Expand Down
4 changes: 2 additions & 2 deletions src/sas/sascalc/corfunc/transform_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def compute(self):
# ----- 3D Correlation Function -----
# gamma3(R) = 1/R int_{0}^{R} gamma1(x) dx
# trapz uses the trapezium rule to calculate the integral
mask = xs <= 200.0 # Only calculate gamma3 up to x=200 (as this is all that's plotted)
mask = xs <= 1000.0 # Only calculate gamma3 up to x=1000 (as this is all that's plotted)
# gamma3 = [trapz(gamma1[:n], xs[:n])/xs[n-1] for n in range(2, len(xs[mask]) + 1)]j
# gamma3.insert(0, 1.0) # Gamma_3(0) is defined as 1
n = len(xs[mask])
Expand Down Expand Up @@ -78,7 +78,7 @@ def compute(self):
self.update(msg="Fourier transform completed.")

transform1 = Data1D(xs, gamma1)
transform3 = Data1D(xs[xs <= 200], gamma3)
transform3 = Data1D(xs[xs <= 1000], gamma3)
idf = Data1D(xs, idf)

transforms = (transform1, transform3, idf)
Expand Down
27 changes: 11 additions & 16 deletions src/sas/sascalc/data_util/calcthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,25 @@
#
from __future__ import print_function

import traceback
import sys
import logging
import traceback
from time import sleep

try:
import _thread as thread
except ImportError: # CRUFT: python 2 support
import thread

if sys.platform.count("darwin") > 0:
import time
stime = time.time()

def clock():
return time.time() - stime

def sleep(t):
return time.sleep(t)
else:
from time import clock
from time import sleep
try:
from time import perf_counter as clock
except ImportError: # CRUFT: python < 3.3
if sys.platform.count("darwin") > 0:
from time import time as clock
else:
from time import clock

logger = logging.getLogger(__name__)


class CalcThread:
"""Threaded calculation class. Inherit from here and specialize
the compute() method to perform the appropriate operations for the
Expand Down Expand Up @@ -247,7 +242,7 @@ def exception(self):
try:
self.exception_handler(*sys.exc_info())
return
except Exception:
except Exception as exc:
pass
logger.error(traceback.format_exc())
#print 'CalcThread exception',
Expand Down
12 changes: 6 additions & 6 deletions src/sas/sascalc/data_util/nxsunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ def _caret_optional(s):
"""
Strip '^' from unit names.
* WARNING * this will incorrect transform 10^3 to 103.
* WARNING * this will incorrectly transform 10^3 to 103.
"""
s.update((k.replace('^',''),v)
for k, v in list(s.items())
if '^' in k)
stripped = [(k.replace('^',''),v) for k, v in s.items() if '^' in k]
s.update(stripped)

def _build_all_units():
distance = _build_metric_units('meter','m')
Expand Down Expand Up @@ -135,8 +134,9 @@ def _build_all_units():

sld = { '10^-6 Angstrom^-2': 1e-6, 'Angstrom^-2': 1 }
Q = { 'invA': 1, 'invAng': 1, 'invAngstroms': 1, '1/A': 1,
'1/Angstrom': 1, '1/angstrom': 1, 'A^{-1}': 1, 'cm^{-1}': 1e-8,
'10^-3 Angstrom^-1': 1e-3, '1/cm': 1e-8, '1/m': 1e-10,
'nm^-1': 0.1, '1/nm': 0.1, 'n_m^-1': 0.1 }
'nm^{-1}': 1, 'nm^-1': 0.1, '1/nm': 0.1, 'n_m^-1': 0.1 }

_caret_optional(sld)
_caret_optional(Q)
Expand All @@ -156,7 +156,7 @@ class Converter(object):
# Note: a.u. stands for arbitrary units, which should return the default
# units for that particular dimension.
# Note: don't have support for dimensionless units.
unknown = {None:1, '???':1, '': 1, 'a.u.': 1}
unknown = {None:1, '???':1, '': 1, 'a.u.': 1, 'Counts': 1, 'counts': 1}

def __init__(self, name):
self.base = name
Expand Down
8 changes: 4 additions & 4 deletions src/sas/sascalc/data_util/ordereddicttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ def test_copying(self):
OrderedDict(od),
]):
self.assert_(dup is not od)
self.assertEquals(dup, od)
self.assertEquals(list(dup.items()), list(od.items()))
self.assertEquals(len(dup), len(od))
self.assertEquals(type(dup), type(od))
self.assertEqual(dup, od)
self.assertEqual(list(dup.items()), list(od.items()))
self.assertEqual(len(dup), len(od))
self.assertEqual(type(dup), type(od))

def test_repr(self):
od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])
Expand Down
2 changes: 1 addition & 1 deletion src/sas/sascalc/data_util/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ def load(self, path, format=None):
if last_exc is not None and len(loaders) != 0:
# If file has associated loader(s) and they;ve failed
raise last_exc
raise NoKnownLoaderException(e.message) # raise generic exception
raise NoKnownLoaderException(str(message)) # raise generic exception
2 changes: 1 addition & 1 deletion src/sas/sascalc/data_util/uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import numpy as np

from .import err1d
from . import err1d
from .formatnum import format_uncertainty

__all__ = ['Uncertainty']
Expand Down
Loading

0 comments on commit 82d88d5

Please sign in to comment.