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

limit threads and do not overwrite geometry #267

Merged
merged 1 commit into from
Mar 21, 2024
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
34 changes: 22 additions & 12 deletions ImageD11/sinograms/point_by_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
# Try to build the point-by-point mapping code ...
from __future__ import print_function, division

import multiprocessing
# method = multiprocessing.set_start_method("forkserver")
from ImageD11 import cImageD11 # NO!!! patches to forkserver

from ImageD11 import cImageD11
cImageD11.check_multiprocessing(patch=True) # forkserver
try:
import threadpoolctl
except ImportError:
threadpoolctl = None
import sys, os
import multiprocessing
from multiprocessing.managers import SharedMemoryManager
import time, random
import numpy as np
Expand Down Expand Up @@ -63,6 +66,8 @@ def dtymask(i, j, cosomega, sinomega, dtyi, step, y0):
return dtyi == dty_icalc




def idxpoint(
i,
j,
Expand Down Expand Up @@ -194,6 +199,8 @@ def proxy(args):

def initializer(parfile, symmetry, loglevel=3):
global ucglobal, symglobal, parglobal
if threadpoolctl is not None:
threadpoolctl.threadpool_limits(limits=1)
parglobal = parameters.read_par_file(parfile)
ucglobal = unitcell.unitcell_from_parameters(parglobal)
symglobal = sym_u.getgroup(symmetry)()
Expand Down Expand Up @@ -255,7 +262,8 @@ def setpeaks(self, colf):
"""
# Load the peaks
colf.parameters.loadparameters(self.parfile)
colf.updateGeometry() # for ds
if 'ds' not in colf.titles:
colf.updateGeometry() # for ds
#
uc = unitcell.unitcell_from_parameters(colf.parameters)
uc.makerings(colf.ds.max())
Expand All @@ -269,9 +277,11 @@ def setpeaks(self, colf):
hmax = 0
for i in range(len(uc.ringds)):
ds = uc.ringds[i]
rm = abs(colf.ds - ds) < self.ds_tol
hkls = uc.ringhkls[ds]
if i in self.foridx and rm.sum() > 0:
if i in self.foridx:
rm = abs(colf.ds - ds) < self.ds_tol
if rm.sum() == 0:
continue
icut = np.max(colf.sum_intensity[rm]) * self.ifrac
rm = rm & (colf.sum_intensity > icut)
isel |= rm
Expand All @@ -287,7 +297,7 @@ def setpeaks(self, colf):
)
sel |= rm
else:
print(i, "%.4f" % (ds), hkls[-1], len(hkls), rm.sum(), "skip")
print(i, "%.4f" % (ds), hkls[-1], len(hkls), "skipped")
for hkl in hkls:
hmax = max(np.abs(hkl).max(), hmax)
if self.forgen is None:
Expand Down Expand Up @@ -318,13 +328,13 @@ def setpeaks(self, colf):
)
self.hmax = hmax

def iplot(self):
def iplot(self, skip=1):
import pylab as pl

f, ax = pl.subplots(2, 1)
ax[0].plot(self.colf.tth, self.colf.sum_intensity, ",")
ax[0].plot(self.icolf.tth, self.icolf.sum_intensity, ",")
ax[0].set(yscale="log", ylabel="sum intensity", xlabel="tth")
ax[0].plot(self.colf.ds[::skip], self.colf.sum_intensity[::skip], ",")
ax[0].plot(self.icolf.ds[::skip], self.icolf.sum_intensity[::skip], ",")
ax[0].set(yscale="log", ylabel="sum intensity", xlabel="d-star")
histo = self.dset.sinohist(
omega=self.icolf.omega, dty=self.icolf.dty, weights=self.icolf.sum_intensity
)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def build_extension(self, ext):
"fast_histogram",
"scikit-image",
"tqdm",
'threadpoolctl ; python_version >= "3" ',
]


Expand Down
Loading