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
3 changes: 0 additions & 3 deletions src/diffpy/confutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
#
##############################################################################

# some convenience imports
from diffpy.confutils.config import ConfigBase

# package version
from diffpy.srxplanar.version import __version__

Expand Down
18 changes: 9 additions & 9 deletions src/diffpy/confutils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def _configPropertyRW(name):
read and write
"""
rv = property(
fget=lambda self: getattr(self.config, nm),
fset=lambda self, value: setattr(self.config, nm, value),
fdel=lambda self: delattr(self, nm),
fget=lambda self: getattr(self.config, name),
fset=lambda self, value: setattr(self.config, name, value),
fdel=lambda self: delattr(self, name),
doc="attribute forwarded to self.config, read/write",
)
return rv
Expand All @@ -64,9 +64,9 @@ def str2bool(v):

def opt2Str(opttype, optvalue):
"""Turn the value of one option to string, according to the option
type list of values are truned into "value1, value2, value3...".
type list of values are turned into "value1, value2, value3...".

:param opttype: string, type of opitons, for example 'str' or
:param opttype: string, type of options, for example 'str' or
'intlist'
:param optvalue: value of the option
:return: string, usually stored in ConfigBase.config
Expand Down Expand Up @@ -105,15 +105,15 @@ def str2Opt(opttype, optvalue):
"""Convert the string to value of one option, according to the
option type.

:param opttype: string, type of opitons, for example 'str' or
:param opttype: string, type of options, for example 'str' or
'intlist'
:param optvalue: string, value of the option
:return: value of the option, usually stored in ConfigBase.config
"""
# base converter
conv = StrConv(opttype)
if opttype.endswith("list"):
temp = re.split("\s*,\s*", optvalue)
temp = re.split(r"\s*,\s*", optvalue)
rv = map(conv, temp) if len(temp) > 0 else []
else:
rv = conv(optvalue)
Expand Down Expand Up @@ -156,7 +156,7 @@ def checkCRC32(filename):
"""
try:
fd = open(filename, "rb")
except:
except Exception:
return "Read error"
eachLine = fd.readline()
prev = 0
Expand All @@ -175,7 +175,7 @@ def checkMD5(filename, blocksize=65536):
"""
try:
fd = open(filename, "rb")
except:
except Exception:
return "Read error"
buf = fd.read(blocksize)
md5 = hashlib.md5()
Expand Down
6 changes: 3 additions & 3 deletions src/diffpy/srxplanar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
##############################################################################

# some convenience imports
from diffpy.srxplanar.srxplanar import SrXplanar
from diffpy.srxplanar.srxplanarconfig import SrXplanarConfig
from diffpy.srxplanar.srxplanar import SrXplanar # noqa: F401
from diffpy.srxplanar.srxplanarconfig import SrXplanarConfig # noqa: F401

# package version
from diffpy.srxplanar.version import __version__
from diffpy.srxplanar.version import __version__ # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, why are you putting so many # noqa here? I'm not totally sure, but I think that skpkg has a way of silencing pre-commit errors that may be introduced when certain imports are unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I silent it here because now we are not at the stage of real migration, these imports are necessary after we migrate this file into right folder. So, I silence it for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by migrating into the right folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean similar to diffpy.srxplanargui's situation, here we are not at the stage of using these imports? But when we have done the migration this module import might become useful? I'm not very sure for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, this file doesn't matter too much at this point. We can probably keep this and wait for the skpkging

Copy link
Contributor

Choose a reason for hiding this comment

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

it is preferred not to noqa things that will be replaced. it is ok for pre-commit to fail on these as they will be changed later by the packaging step.


# unit tests

Expand Down
52 changes: 33 additions & 19 deletions src/diffpy/srxplanar/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import numpy as np
import scipy.ndimage.filters as snf
import scipy.ndimage.morphology as snm
import scipy.sparse as ssp

from diffpy.srxplanar.srxplanarconfig import _configPropertyR

Expand Down Expand Up @@ -53,7 +51,8 @@ class Calculate(object):
extracrop = _configPropertyR("extracrop")

def __init__(self, p):
# create parameter proxy, so that parameters can be accessed by self.parametername in read-only mode
# create parameter proxy, so that parameters can be
# accessed by self.parametername in read-only mode
self.config = p
self.prepareCalculation()
return
Expand Down Expand Up @@ -106,26 +105,30 @@ def genIntegrationInds(self, mask=None):
:return: self.bin_number
"""
self.maskedmatrix = np.array(self.tthorqmatrix)
if mask == None:
if mask is None:
# mask = np.zeros((self.ydimension, self.xdimension), dtype=bool)
mask = np.zeros((len(self.yr), len(self.xr)), dtype=bool)
ce = self.cropedges
mask = mask[ce[2] : -ce[3], ce[0] : -ce[1]]
self.maskedmatrix[mask] = 1000.0

# extra crop
maskedmatrix = self.getMaskedmatrixPic()
# self.bin_number = np.array(np.histogram(maskedmatrix, self.bin_edges)[0], dtype=float)
self.getMaskedmatrixPic()
# self.bin_number = np.array(
# np.histogram(maskedmatrix, self.bin_edges)[0],
# dtype=float,
# )
# self.bin_number[self.bin_number <= 0] = 1
return # self.bin_number

def intensity(self, pic):
"""2D to 1D image integration, intensity of pixels are binned
and then take average,

:param pic: 2D array, array of raw counts, corrections hould be
already applied :retrun: 2d array, [tthorq, intensity,
unceratinty] or [tthorq, intensity]
:param pic: 2D array, array of raw counts, corrections should be
already applied
:return: 2d array, [tthorq, intensity, unceratinty] or [tthorq,
intensity]
"""

intensity = self.calculateIntensity(pic)
Expand Down Expand Up @@ -159,7 +162,7 @@ def getMaskedmatrixPic(self, pic=None):
)
self.bin_number[self.bin_number <= 0] = 1

if pic != None:
if pic is not None:
ps = [max(s1, s2) for s1, s2 in zip(ce, ec)]
rv = (
self.maskedmatrix[s[2] : s[3], s[0] : s[1]],
Expand All @@ -171,7 +174,8 @@ def calculateIntensity(self, pic):
"""Calculate the 1D intensity.

:param pic: 2D array, array of raw counts, raw counts should be
corrected :retrun: 1d array, 1D integrated intensity
corrected
:return: 1d array, 1D integrated intensity
"""

maskedmatrix, pic = self.getMaskedmatrixPic(pic)
Expand All @@ -182,9 +186,9 @@ def calculateIntensity(self, pic):
def calculateVariance(self, pic):
"""Calculate the 1D intensity.

:param pic: 2D array, array of raw counts, corrections hould be
already applied :retrun: 1d array, variance of integrated
intensity
:param pic: 2D array, array of raw counts, corrections should be
already applied
:return: 1d array, variance of integrated intensity
"""
maskedmatrix = self.getMaskedmatrixPic()

Expand All @@ -196,9 +200,9 @@ def calculateVariance(self, pic):

def calculateVarianceLocal(self, pic):
"""Calculate the variance of raw counts of each pixel are
calculated according to their loacl variance.
calculated according to their local variance.

:param pic: 2d array, 2d image array, corrections hould be
:param pic: 2d array, 2d image array, corrections should be
already applied
:return: 2d array, variance of each pixel
"""
Expand Down Expand Up @@ -251,7 +255,10 @@ def genTTHMatrix(self):
sourceyr = self.distance * sint * sinr
sourcezr = self.distance * cost

# tthmatrix1 = np.zeros((self.ydimension, self.xdimension), dtype=float)
# tthmatrix1 = np.zeros(
# (self.ydimension, self.xdimension),
# dtype=float,
# )
tthmatrix1 = np.zeros((len(self.yr), len(self.xr)), dtype=float)
tthmatrix1 += ((-self.xr + sourcexr) * sourcexr).reshape(
1, len(self.xr)
Expand All @@ -277,7 +284,10 @@ def genQMatrix(self):
sourceyr = self.distance * sint * sinr
sourcezr = self.distance * cost

# tthmatrix1 = np.zeros((self.ydimension, self.xdimension), dtype=float)
# tthmatrix1 = np.zeros(
# (self.ydimension, self.xdimension),
# dtype=float,
# )
tthmatrix1 = np.zeros((len(self.yr), len(self.xr)), dtype=float)
tthmatrix1 += ((-self.xr + sourcexr) * sourcexr).reshape(
1, len(self.xr)
Expand Down Expand Up @@ -322,7 +332,11 @@ def _polarizationCorrection(self):
:return: 2d array, correction matrix to apply on the image
"""
if self.polcorrectionenable:
# tthmatrix = self.tthorqmatrix if self.integrationspace == 'twotheta' else self.genTTHMatrix()
# tthmatrix = (
# self.tthorqmatrix
# if self.integrationspace == "twotheta"
# else self.genTTHMatrix()
# )
tthmatrix = self.tthmatrix
azimuthmatrix = self.azimuthmatrix
p = 0.5 * (1 + (np.cos(tthmatrix)) ** 2)
Expand Down
14 changes: 6 additions & 8 deletions src/diffpy/srxplanar/loadimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@

import fnmatch
import os
import sys
import time

import numpy as np
from tifffile import imsave as saveImage

from diffpy.srxplanar.srxplanarconfig import _configPropertyR

Expand All @@ -30,7 +28,7 @@ def openImage(im):
rv = fabio.openimage.openimage(im)
return rv.data

except:
except ImportError:
import tifffile

def openImage(im):
Expand Down Expand Up @@ -88,7 +86,7 @@ def loadImage(self, filename):
else:
image = openImage(filenamefull)
i = 10
except:
except FileNotFoundError:
i = i + 1
time.sleep(0.5)
image = self.flipImage(image)
Expand Down Expand Up @@ -149,13 +147,13 @@ def genFileSet(
file
:return: set of str, a list of filenames
"""
filenames = self.filenames if filenames == None else filenames
opendir = self.opendirectory if opendir == None else opendir
filenames = self.filenames if filenames is None else filenames
opendir = self.opendirectory if opendir is None else opendir
includepattern = (
self.includepattern if includepattern == None else includepattern
self.includepattern if includepattern is None else includepattern
)
excludepattern = (
self.excludepattern if excludepattern == None else excludepattern
self.excludepattern if excludepattern is None else excludepattern
)
# filter the filenames according to include and exclude pattern
filelist = os.listdir(opendir)
Expand Down