cohere-core 4.3__tar.gz → 4.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {cohere_core-4.3/src/cohere_core.egg-info → cohere_core-4.5.0}/PKG-INFO +7 -5
  2. {cohere_core-4.3 → cohere_core-4.5.0}/README.md +2 -2
  3. {cohere_core-4.3 → cohere_core-4.5.0}/pyproject.toml +5 -3
  4. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/controller/features.py +22 -53
  5. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/controller/op_flow.py +16 -16
  6. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/controller/phasing.py +205 -156
  7. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/data/alien_tools.py +4 -0
  8. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/lib/cohlib.py +38 -27
  9. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/lib/cplib.py +47 -58
  10. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/lib/nplib.py +46 -36
  11. cohere_core-4.5.0/src/cohere_core/lib/torchlib.py +583 -0
  12. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/utilities/config_errors_dict.py +2 -5
  13. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/utilities/config_verifier.py +26 -61
  14. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/utilities/dvc_utils.py +104 -45
  15. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/utilities/utils.py +1 -1
  16. cohere_core-4.5.0/src/cohere_core/utilities/view_utils.py +138 -0
  17. {cohere_core-4.3 → cohere_core-4.5.0/src/cohere_core.egg-info}/PKG-INFO +7 -5
  18. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core.egg-info/SOURCES.txt +2 -2
  19. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core.egg-info/requires.txt +2 -2
  20. cohere_core-4.3/src/cohere_core/lib/aflib.py +0 -393
  21. cohere_core-4.3/src/cohere_core/lib/torchlib.py +0 -478
  22. {cohere_core-4.3 → cohere_core-4.5.0}/LICENSE +0 -0
  23. {cohere_core-4.3 → cohere_core-4.5.0}/setup.cfg +0 -0
  24. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/controller/AI_guess.py +0 -0
  25. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/controller/__init__.py +0 -0
  26. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/data/__init__.py +0 -0
  27. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/data/standard_preprocess.py +0 -0
  28. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/lib/__init__.py +0 -0
  29. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/lib/check_libs.py +0 -0
  30. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/utilities/__init__.py +0 -0
  31. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core/utilities/ga_utils.py +0 -0
  32. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core.egg-info/dependency_links.txt +0 -0
  33. {cohere_core-4.3 → cohere_core-4.5.0}/src/cohere_core.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cohere_core
3
- Version: 4.3
3
+ Version: 4.5.0
4
4
  Summary: cohere reconstruction tools
5
5
  Author-email: Barbara Frosik <bfrosik@anl.gov>, Ross Harder <rharder@anl.gov>
6
6
  License: Copyright © 2019, UChicago Argonne, LLC
@@ -22,25 +22,27 @@ License: Copyright © 2019, UChicago Argonne, LLC
22
22
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
23
  ***************************************************************************************************
24
24
  Project-URL: Homepage, https://github.com/AdvancedPhotonSource/cohere
25
+ Project-URL: Documentation, https://readthedocs.org
26
+ Project-URL: Repository, https://github.com//AdvancedPhotonSource/cohere.git
25
27
  Classifier: Programming Language :: Python :: 3
26
28
  Classifier: Operating System :: OS Independent
27
29
  Requires-Python: >=3.11
28
30
  Description-Content-Type: text/markdown
29
31
  License-File: LICENSE
30
- Requires-Dist: numpy<2
32
+ Requires-Dist: numpy
31
33
  Requires-Dist: scikit-learn
32
34
  Requires-Dist: tifffile
33
35
  Requires-Dist: psutil
34
36
  Requires-Dist: tqdm
35
37
  Requires-Dist: matplotlib
36
- Requires-Dist: scipy==1.14.1
38
+ Requires-Dist: scipy
37
39
  Requires-Dist: sphinx
38
40
  Requires-Dist: sphinx-pyproject
39
41
  Dynamic: license-file
40
42
 
41
- [![Documentation Status](https://readthedocs.org/projects/cohere/badge/?version=latest)](http://cohere.readthedocs.io/en/latest/?badge=latest)
43
+ [![Documentation Status](https://readthedocs.org/projects/cohere-dev/badge/?version=latest)](http://cohere-dev.readthedocs.io/en/latest/?badge=latest)
42
44
 
43
- Project home page: [https://cohere.readthedocs.io/](https://cohere.readthedocs.io/)
45
+ Project home page: [https://cohere.readthedocs.io/](https://cohere-dev.readthedocs.io/)
44
46
 
45
47
  The cohere package provides tools for reconstruction of image of a nanoscale structures from data obtained using Bragg Coherent Diffraction Imaging technique.
46
48
 
@@ -1,6 +1,6 @@
1
- [![Documentation Status](https://readthedocs.org/projects/cohere/badge/?version=latest)](http://cohere.readthedocs.io/en/latest/?badge=latest)
1
+ [![Documentation Status](https://readthedocs.org/projects/cohere-dev/badge/?version=latest)](http://cohere-dev.readthedocs.io/en/latest/?badge=latest)
2
2
 
3
- Project home page: [https://cohere.readthedocs.io/](https://cohere.readthedocs.io/)
3
+ Project home page: [https://cohere.readthedocs.io/](https://cohere-dev.readthedocs.io/)
4
4
 
5
5
  The cohere package provides tools for reconstruction of image of a nanoscale structures from data obtained using Bragg Coherent Diffraction Imaging technique.
6
6
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cohere_core"
7
- version = "4.3"
7
+ version = "4.5.0"
8
8
  authors = [
9
9
  { name="Barbara Frosik", email="bfrosik@anl.gov" },
10
10
  { name="Ross Harder", email="rharder@anl.gov" }
@@ -19,13 +19,13 @@ classifiers = [
19
19
  license = { file = "LICENSE" }
20
20
 
21
21
  dependencies = [
22
- 'numpy<2',
22
+ 'numpy',
23
23
  'scikit-learn',
24
24
  'tifffile',
25
25
  'psutil',
26
26
  'tqdm',
27
27
  'matplotlib',
28
- 'scipy==1.14.1',
28
+ 'scipy',
29
29
  'sphinx',
30
30
  'sphinx-pyproject'
31
31
  ]
@@ -35,6 +35,8 @@ dependencies = [
35
35
 
36
36
  [project.urls]
37
37
  Homepage = "https://github.com/AdvancedPhotonSource/cohere"
38
+ Documentation = "https://readthedocs.org"
39
+ Repository = "https://github.com//AdvancedPhotonSource/cohere.git"
38
40
 
39
41
  [tool.sphinx-pyproject]
40
42
  extensions = [
@@ -77,6 +77,28 @@ class Pcdi:
77
77
  self.kernel, self.iterations)
78
78
 
79
79
 
80
+ class LowPassFilter():
81
+ def __init__(self, params):
82
+ iter_range = [params['lowpass_filter_trigger'][0], params['lowpass_filter_trigger'][2]]
83
+ iter_diff = params['lowpass_filter_trigger'][2] - params['lowpass_filter_trigger'][0]
84
+ if len(params['lowpass_filter_range']) == 1:
85
+ end_sigma = 1.0
86
+ else:
87
+ end_sigma = params['lowpass_filter_range'][1]
88
+ sigma_diff = end_sigma - params['lowpass_filter_range'][0]
89
+ self.filter_sigmas = [sigma_diff / iter_diff * iter + params['lowpass_filter_range'][0]
90
+ for iter in range(iter_range[0], iter_range[1])]
91
+
92
+
93
+ def apply_trigger(self, *args):
94
+ # The filter is applied on data
95
+ data = args[0]
96
+ iter = args[1]
97
+
98
+ filter_sigma = self.filter_sigmas[iter]
99
+ return devlib.gaussian_filter(data, filter_sigma)
100
+
101
+
80
102
  class TriggeredOp(ABC):
81
103
  """
82
104
  Base class for Triggered operation. This class creates feature objects and manages the trigger or subtrigger depending on
@@ -266,7 +288,6 @@ class ShrinkWrap(TriggeredOp):
266
288
  raise ValueError(msg)
267
289
 
268
290
 
269
-
270
291
  class PhaseConstrain(TriggeredOp):
271
292
  def __init__(self, trig_op):
272
293
  super().__init__(trig_op)
@@ -304,63 +325,11 @@ class PhaseConstrain(TriggeredOp):
304
325
  return self.PhasePHC(phase_min, phase_max)
305
326
 
306
327
 
307
- class LowPassFilter(TriggeredOp):
308
- def __init__(self, trig_op):
309
- super().__init__(trig_op)
310
-
311
- class Filter:
312
- def __init__(self, filter_range, iter_range, threshold):
313
- self.iter_offset = iter_range[0]
314
- self.filter_sigmas = [(filter_range[1] - filter_range[0]) / (iter_range[1] - iter_range[0]) *
315
- (iter - self.iter_offset) + filter_range[0]
316
- for iter in range(iter_range[0], iter_range[1])]
317
- self.threshold = threshold
318
-
319
- def apply_trigger(self, *args):
320
- # The filter is applied on data
321
- # simultaneously the sigma used in shrink wrap is changing to be reverse of the filter_sigma
322
- data = args[0]
323
- iter = args[1]
324
- ds_image = args[2]
325
- filter_sigma = self.filter_sigmas[iter - self.iter_offset]
326
- return (devlib.gaussian_filter(data, filter_sigma), dvut.shrink_wrap(ds_image, self.threshold, 1/filter_sigma))
327
-
328
-
329
- def create_obj(self, params, index=None, beg=None, end=None):
330
- if 'lowpass_filter_sw_threshold' not in params:
331
- msg = 'lowpass_filter_sw_threshold parameter not defined'
332
- raise ValueError(msg)
333
- if 'lowpass_filter_range' not in params:
334
- msg = 'lowpass_filter_range parameter not defined'
335
- raise ValueError(msg)
336
- # in case of a all_iteration configuration the lowpass filter
337
- # iteration can be read from lowpass_filter_trigger
338
- if index is None:
339
- iter_range = (params['lowpass_filter_trigger'][0], params['lowpass_filter_trigger'][2])
340
- filter_range = params['lowpass_filter_range']
341
- threshold = params['lowpass_filter_sw_threshold']
342
- # otherwise the iterations to apply this instance are given as arguments
343
- else:
344
- iter_range = (beg, end)
345
- if len(params['lowpass_filter_range']) - 1 < index:
346
- msg = f'lowpass_filter_range not defined for sub-trigger {index}'
347
- raise ValueError(msg)
348
- filter_range = params['lowpass_filter_range'][index]
349
- if len(params['lowpass_filter_sw_threshold']) - 1 < index:
350
- msg = f'lowpass_filter_sw_threshold not defined for sub-trigger {index}'
351
- raise ValueError(msg)
352
- threshold = params['lowpass_filter_sw_threshold'][index]
353
- if len(filter_range) == 1:
354
- filter_range.append(1.0)
355
- return self.Filter(filter_range, iter_range, threshold)
356
-
357
328
  def create(trig_op, params, trig_op_info):
358
329
  if trig_op == 'shrink_wrap':
359
330
  to = ShrinkWrap(trig_op)
360
331
  if trig_op == 'phc':
361
332
  to = PhaseConstrain(trig_op)
362
- if trig_op == 'lowpass_filter':
363
- to = LowPassFilter(trig_op)
364
333
 
365
334
  # this function sets self.objs and self.f and creates all objects
366
335
  # It may throw exception
@@ -22,8 +22,7 @@ algs = {'ER': ('to_reciprocal_space', 'modulus', 'to_direct_space', 'er'),
22
22
  # defined by preceding algorithm. The key is the trigger name and value is the mnemonic. The mnemonic is used in the
23
23
  # configuration.
24
24
  sub_triggers = {'SW' : 'shrink_wrap_trigger',
25
- 'PHC' : 'phc_trigger',
26
- 'LPF' : 'lowpass_filter_trigger'}
25
+ 'PHC' : 'phc_trigger'}
27
26
 
28
27
  # This list contains triggers that will be active at the last iteration defined by trigger, despite
29
28
  # not being a trigger calculated by the step formula.
@@ -197,7 +196,8 @@ def fill_sub_trigger_row(sub_iters, sub_trigs, iter_no, last_trig):
197
196
  # create array indicating with index which sub-triggered operation may happen in the iterations
198
197
  sub_trig_idx_row = np.zeros(iter_no, dtype=int)
199
198
  # for each defined sub iteration chunk apply corresponding sub-trigger
200
- for (b, e, idx) in sub_iters:
199
+ for i, sub_iter in enumerate(sub_iters):
200
+ (b, e, idx) = sub_iter
201
201
  index = int(idx)
202
202
  sub_trig_idx_row[b:e] = index + 1
203
203
  if len(sub_trigs) - 1 < index:
@@ -209,6 +209,8 @@ def fill_sub_trigger_row(sub_iters, sub_trigs, iter_no, last_trig):
209
209
  trigger.append(e)
210
210
  elif len(trigger) == 3:
211
211
  trigger[2] = min(e, trigger[0] + trigger[2])
212
+ # update the sub_iters
213
+ sub_iters[i] = (b, trigger[2], idx)
212
214
  sub_trig_row = fill_trigger_row(trigger, iter_no, last_trig, sub_trig_row)
213
215
 
214
216
  return sub_trig_row * sub_trig_idx_row
@@ -244,22 +246,15 @@ def get_flow_arr(params, flow_items_list, curr_gen=None):
244
246
  # do some checks to find if the sequence and configuration are runnable
245
247
  # and special cases
246
248
 
247
- # this array is a mask blocking shrink wrap when low pass filter is active
248
- apply_sw_row = np.ones(iter_no, dtype=int)
249
249
  last_lpf = None
250
250
  if 'lowpass_filter_trigger' in params:
251
- if 'lowpass_filter_trigger' in sub_iters:
252
- for b, e, i in sub_iters['lowpass_filter_trigger']:
253
- apply_sw_row[b:e] = 0
254
- last_lpf = e
255
- elif len(params['lowpass_filter_trigger']) < 2:
251
+ if len(params['lowpass_filter_trigger']) < 2:
256
252
  print('Low pass trigger misconfiguration error. This trigger should have upper bound.')
257
253
  raise
258
254
  elif params['lowpass_filter_trigger'][2] >= iter_no:
259
255
  print('Low pass trigger misconfiguration error. The upper bound should be less than total iterations.')
260
256
  raise
261
257
  else:
262
- apply_sw_row[params['lowpass_filter_trigger'][0]:params['lowpass_filter_trigger'][2]] = 0
263
258
  last_lpf = params['lowpass_filter_trigger'][2]
264
259
 
265
260
  if pc_start is not None:
@@ -297,16 +292,21 @@ def get_flow_arr(params, flow_items_list, curr_gen=None):
297
292
  if trigger_name in sub_iters.keys():
298
293
  # may throw exception
299
294
  flow_arr[i] = fill_sub_trigger_row(sub_iters[trigger_name], params[trigger_name], iter_no, last_trig)
295
+ # special case
296
+ if flow_item == 'phc_operation':
297
+ reset = [l[1] for l in list(sub_iters[trigger_name])]
298
+ flow_arr[i-1][reset] = 1
299
+
300
300
  # add entry to sub trigger operation dict with key of the trigger mnemonic
301
301
  # and the value of a list with the row and sub triggers iterations chunks
302
302
  sub_trig_op[trigger_name] = (flow_arr[i], sub_iters[trigger_name])
303
303
  else:
304
304
  flow_arr[i] = fill_trigger_row(params[trigger_name], iter_no, last_trig)
305
-
306
- # handle special cases
307
- if flow_item == 'shrink_wrap_operation':
308
- # shrink wrap is blocked by low pass filter
309
- flow_arr[i] = flow_arr[i] * apply_sw_row
305
+ # special case
306
+ if flow_item == 'phc_operation':
307
+ # Assuming phc trigger is configured with upper limit
308
+ reset_iter = min(iter_no - 1, params[trigger_name][2] + 1)
309
+ flow_arr[i-1][reset_iter] = 1
310
310
  elif flow_item == 'set_prev_pc' and pc_start is not None:
311
311
  # set_prev_pc is executed one iteration before pc_trigger
312
312
  pc_row = flow_items_list.index('pc_operation')