-
Notifications
You must be signed in to change notification settings - Fork 23
refactor: update sasview api for test_sas.py #126
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
Changes from 2 commits
96e1ff3
6112cdd
c68f981
5854969
a2d280a
1bdd326
ac23c4c
29ef13e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Changed:** | ||
|
|
||
| * Refactored code utilizing sasmodels to use the new sasview api. | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |
|
|
||
| from diffpy.srfit.exceptions import ParseError | ||
| from diffpy.srfit.fitbase.profileparser import ProfileParser | ||
| from diffpy.srfit.sas.sasimport import sasimport | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I deleted the import from this file as not used but I haven't deleted |
||
|
|
||
|
|
||
| class SASParser(ProfileParser): | ||
|
|
@@ -102,10 +101,15 @@ def parseFile(self, filename): | |
| Raises IOError if the file cannot be read | ||
| Raises ParseError if the file cannot be parsed | ||
| """ | ||
| import sasdata.dataloader.loader as ld | ||
|
|
||
| Loader = sasimport("sas.dataloader.loader").Loader | ||
| Loader = ld.Loader | ||
|
||
| loader = Loader() | ||
|
|
||
| # Convert Path object to string if needed | ||
|
||
| if not isinstance(filename, str): | ||
|
||
| filename = str(filename) | ||
|
|
||
| try: | ||
| data = loader.load(filename) | ||
| except RuntimeError as e: | ||
|
|
@@ -118,7 +122,16 @@ def parseFile(self, filename): | |
| self._meta["filename"] = filename | ||
| self._meta["datainfo"] = data | ||
|
|
||
| self._banks.append([data.x, data.y, data.dx, data.dy]) | ||
| # Handle case where loader returns a list of data objects | ||
|
||
| if isinstance(data, list): | ||
|
||
| # If it's a list, iterate through each data object | ||
|
||
| for data_obj in data: | ||
| self._banks.append( | ||
| [data_obj.x, data_obj.y, data_obj.dx, data_obj.dy] | ||
| ) | ||
| else: | ||
|
||
| # If it's a single data object, use it directly | ||
| self._banks.append([data.x, data.y, data.dx, data.dy]) | ||
| self.selectBank(0) | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,15 @@ def __init__(self, datainfo): | |
| datainfo | ||
| The DataInfo object this wraps. | ||
| """ | ||
| self._datainfo = datainfo | ||
| # Handle case where datainfo is a list (new sasdata behavior) | ||
|
||
| if isinstance(datainfo, list): | ||
| if len(datainfo) == 0: | ||
| raise ValueError("Empty datainfo list provided") | ||
| # Use the first data object if it's a list | ||
| self._datainfo = datainfo[0] | ||
| else: | ||
| # Single datainfo object (legacy behavior) | ||
| self._datainfo = datainfo | ||
| Profile.__init__(self) | ||
|
|
||
| self._xobs = self._datainfo.x | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,10 @@ | |
| import numpy | ||
| import pytest | ||
|
|
||
| # Use the updated SasView model API to load models | ||
|
||
| from sasmodels.sasview_model import _make_standard_model | ||
|
|
||
| import diffpy.srfit.pdf.characteristicfunctions as cf | ||
| from diffpy.srfit.sas.sasimport import sasimport | ||
|
|
||
| # # Global variables to be assigned in setUp | ||
| # cf = None | ||
|
|
@@ -34,7 +36,7 @@ def testSphere(sas_available): | |
| pytest.skip("sas package not available") | ||
| radius = 25 | ||
| # Calculate sphere cf from SphereModel | ||
| SphereModel = sasimport("sas.models.SphereModel").SphereModel | ||
| SphereModel = _make_standard_model("sphere") | ||
|
||
| model = SphereModel() | ||
| model.setParam("radius", radius) | ||
| ff = cf.SASCF("sphere", model) | ||
|
|
@@ -56,10 +58,10 @@ def testSpheroid(sas_available): | |
| prad = 20.9 | ||
| erad = 33.114 | ||
| # Calculate cf from EllipsoidModel | ||
| EllipsoidModel = sasimport("sas.models.EllipsoidModel").EllipsoidModel | ||
| EllipsoidModel = _make_standard_model("ellipsoid") | ||
| model = EllipsoidModel() | ||
| model.setParam("radius_a", prad) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could not find any mention of the use of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| model.setParam("radius_b", erad) | ||
| model.setParam("radius_polar", prad) | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| model.setParam("radius_equatorial", erad) | ||
| ff = cf.SASCF("spheroid", model) | ||
| r = numpy.arange(0, 100, 1 / numpy.pi, dtype=float) | ||
| fr1 = ff(r) | ||
|
|
@@ -79,7 +81,7 @@ def testShell(sas_available): | |
| radius = 19.2 | ||
| thickness = 7.8 | ||
| # Calculate cf from VesicleModel | ||
| VesicleModel = sasimport("sas.models.VesicleModel").VesicleModel | ||
| VesicleModel = _make_standard_model("vesicle") | ||
| model = VesicleModel() | ||
| model.setParam("radius", radius) | ||
| model.setParam("thickness", thickness) | ||
|
|
@@ -103,7 +105,7 @@ def testCylinder(sas_available): | |
| radius = 100 | ||
| length = 30 | ||
|
|
||
| CylinderModel = sasimport("sas.models.CylinderModel").CylinderModel | ||
| CylinderModel = _make_standard_model("cylinder") | ||
| model = CylinderModel() | ||
| model.setParam("radius", radius) | ||
| model.setParam("length", length) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move to fixed. This is a bug fix not a change. Reserve changes for changes in behavior that a user might need to know about.