ChessAnalysisPipeline 0.0.15__py3-none-any.whl → 0.0.16__py3-none-any.whl

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.

Potentially problematic release.


This version of ChessAnalysisPipeline might be problematic. Click here for more details.

CHAP/common/reader.py CHANGED
@@ -128,6 +128,8 @@ class MapReader(Reader):
128
128
  # Local modules
129
129
  from CHAP.common.models.map import MapConfig
130
130
 
131
+ raise RuntimeError('MapReader is obsolete, use MapProcessor')
132
+
131
133
  if filename is not None:
132
134
  if map_config is not None:
133
135
  raise RuntimeError('Specify either filename or map_config '
@@ -161,13 +163,14 @@ class MapReader(Reader):
161
163
  attrs={'spec_file': str(scans.spec_file)})
162
164
 
163
165
  # Add sample metadata
164
- nxentry[map_config.sample.name] = NXsample(**map_config.sample.dict())
166
+ nxentry[map_config.sample.name] = NXsample(
167
+ **map_config.sample.dict())
165
168
 
166
169
  # Set up default data group
167
170
  nxentry.data = NXdata()
168
171
  if map_config.map_type == 'structured':
169
172
  nxentry.data.attrs['axes'] = map_config.dims
170
- for i, dim in enumerate(map_config.independent_dimensions[::-1]):
173
+ for i, dim in enumerate(map_config.independent_dimensions):
171
174
  nxentry.data[dim.label] = NXfield(
172
175
  value=map_config.coords[dim.label],
173
176
  units=dim.units,
@@ -387,7 +390,7 @@ class NXfieldReader(Reader):
387
390
 
388
391
  class SpecReader(Reader):
389
392
  """Reader for CHESS SPEC scans"""
390
- def read(self, filename=None, spec_config=None, detector_names=[],
393
+ def read(self, filename=None, config=None, detector_names=None,
391
394
  inputdir=None):
392
395
  """Take a SPEC configuration filename or dictionary and return
393
396
  the raw data as a Nexus NXentry object.
@@ -396,15 +399,17 @@ class SpecReader(Reader):
396
399
  to read from to pass onto the constructor of
397
400
  `CHAP.common.models.map.SpecConfig`, defaults to `None`.
398
401
  :type filename: str, optional
399
- :param spec_config: A SPEC configuration to be passed directly
402
+ :param config: A SPEC configuration to be passed directly
400
403
  to the constructor of `CHAP.common.models.map.SpecConfig`,
401
404
  defaults to `None`.
402
- :type spec_config: dict, optional
403
- :param detector_names: Detector prefixes to include raw data
404
- for in the returned NeXus NXentry object, defaults to `[]`.
405
- :type detector_names: list[str], optional
405
+ :type config: dict, optional
406
+ :param detector_names: Detector names/prefixes to include raw
407
+ data for in the returned NeXus NXentry object,
408
+ defaults to `None`.
409
+ :type detector_names: Union(int, str, list[int], list[str]),
410
+ optional
406
411
  :return: The data from the provided SPEC configuration.
407
- :rtype: nexusformat.nexus.NXentry
412
+ :rtype: nexusformat.nexus.NXroot
408
413
  """
409
414
  # Third party modules
410
415
  from json import dumps
@@ -413,14 +418,15 @@ class SpecReader(Reader):
413
418
  NXdata,
414
419
  NXentry,
415
420
  NXfield,
421
+ NXroot,
416
422
  )
417
423
 
418
424
  # Local modules
419
425
  from CHAP.common.models.map import SpecConfig
420
426
 
421
427
  if filename is not None:
422
- if spec_config is not None:
423
- raise RuntimeError('Specify either filename or spec_config '
428
+ if config is not None:
429
+ raise RuntimeError('Specify either filename or config '
424
430
  'in common.SpecReader, not both')
425
431
  # Read the map configuration from file
426
432
  if not isfile(filename):
@@ -431,22 +437,62 @@ class SpecReader(Reader):
431
437
  else:
432
438
  raise RuntimeError('input file has a non-implemented '
433
439
  f'extension ({filename})')
434
- spec_config = reader.read(filename)
435
- elif not isinstance(spec_config, dict):
436
- raise RuntimeError('Invalid parameter spec_config in '
437
- f'common.SpecReader ({spec_config})')
440
+ config = reader.read(filename)
441
+ elif not isinstance(config, dict):
442
+ raise RuntimeError('Invalid parameter config in '
443
+ f'common.SpecReader ({config})')
438
444
 
439
445
  # Validate the SPEC configuration provided by constructing a
440
446
  # SpecConfig
441
- spec_config = SpecConfig(**spec_config, inputdir=inputdir)
447
+ config = SpecConfig(**config, inputdir=inputdir)
448
+
449
+ # Validate the detector names/prefixes
450
+ if config.experiment_type == 'EDD':
451
+ if detector_names is not None:
452
+ if isinstance(detector_names, (int, str)):
453
+ detector_names = [str(detector_names)]
454
+ for i, detector_name in enumerate(detector_names):
455
+ if isinstance(detector_name, int):
456
+ detector_names[i] = str(detector_name)
457
+ elif not isinstance(detector_name, str):
458
+ raise ValueError('Invalid "detector_names" parameter '
459
+ f'({detector_names})')
460
+ else:
461
+ # Local modules
462
+ from CHAP.utils.general import is_str_series
442
463
 
443
- # Set up NXentry and add misc. CHESS-specific metadata
444
- # as well as all spec_motors, scan_columns, and smb_pars
445
- nxentry = NXentry(name=spec_config.experiment_type)
446
- nxentry.spec_config = dumps(spec_config.dict())
447
- nxentry.attrs['station'] = spec_config.station
464
+ if detector_names is None:
465
+ raise ValueError(
466
+ 'Missing "detector_names" parameter')
467
+ if isinstance(detector_names, str):
468
+ detector_names = [detector_names]
469
+ if not is_str_series(detector_names, log=False):
470
+ raise ValueError(
471
+ 'Invalid "detector_names" parameter ({detector_names})')
472
+
473
+ # Create the NXroot object
474
+ nxroot = NXroot()
475
+ nxentry = NXentry(name=config.experiment_type)
476
+ nxroot[nxentry.nxname] = nxentry
477
+ nxentry.set_default()
478
+
479
+ # Set up NXentry and add misc. CHESS-specific metadata as well
480
+ # as all spec_motors, scan_columns, and smb_pars, and the
481
+ # detector info and raw detector data
482
+ nxentry.config = dumps(config.dict())
483
+ nxentry.attrs['station'] = config.station
484
+ if config.experiment_type == 'EDD':
485
+ if detector_names is None:
486
+ detector_indices = None
487
+ else:
488
+ nxentry.detector_names = detector_names
489
+ detector_indices = [int(d) for d in detector_names]
490
+ else:
491
+ if detector_names is not None:
492
+ nxentry.detector_names = detector_names
448
493
  nxentry.spec_scans = NXcollection()
449
- for scans in spec_config.spec_scans:
494
+ # nxpaths = []
495
+ for scans in config.spec_scans:
450
496
  nxscans = NXcollection()
451
497
  nxentry.spec_scans[f'{scans.scanparsers[0].scan_name}'] = nxscans
452
498
  nxscans.attrs['spec_file'] = str(scans.spec_file)
@@ -454,25 +500,45 @@ class SpecReader(Reader):
454
500
  for scan_number in scans.scan_numbers:
455
501
  scanparser = scans.get_scanparser(scan_number)
456
502
  nxscans[scan_number] = NXcollection()
457
- if hasattr(scanparser, 'spec_positioner_values'):
503
+ try:
458
504
  nxscans[scan_number].spec_motors = dumps(
459
505
  {k:float(v) for k,v
460
506
  in scanparser.spec_positioner_values.items()})
461
- if hasattr(scanparser, 'spec_scan_data'):
507
+ except:
508
+ pass
509
+ try:
462
510
  nxscans[scan_number].scan_columns = dumps(
463
511
  {k:list(v) for k,v
464
512
  in scanparser.spec_scan_data.items() if len(v)})
465
- if hasattr(scanparser, 'pars'):
513
+ except:
514
+ pass
515
+ try:
466
516
  nxscans[scan_number].smb_pars = dumps(
467
517
  {k:v for k,v in scanparser.pars.items()})
468
- if detector_names:
518
+ except:
519
+ pass
520
+ if config.experiment_type == 'EDD':
469
521
  nxdata = NXdata()
470
522
  nxscans[scan_number].data = nxdata
523
+ # nxpaths.append(
524
+ # f'spec_scans/{nxscans.nxname}/{scan_number}/data')
525
+ nxdata.data = NXfield(
526
+ value=scanparser.get_detector_data(detector_indices))
527
+ else:
528
+ nxdata = NXdata()
529
+ nxscans[scan_number].data = nxdata
530
+ # nxpaths.append(
531
+ # f'spec_scans/{nxscans.nxname}/{scan_number}/data')
471
532
  for detector_name in detector_names:
472
533
  nxdata[detector_name] = NXfield(
473
534
  value=scanparser.get_detector_data(detector_name))
474
535
 
475
- return nxentry
536
+ if config.experiment_type == 'EDD' and detector_names is None:
537
+ nxentry.detector_names = [
538
+ str(i) for i in range(nxdata.data.shape[1])]
539
+
540
+ #return nxroot, nxpaths
541
+ return nxroot
476
542
 
477
543
 
478
544
  class URLReader(Reader):
CHAP/common/writer.py CHANGED
@@ -105,6 +105,8 @@ def write_filetree(data, outputdir, force_overwrite=False):
105
105
  raise TypeError('Cannot write object of type'
106
106
  f'{type(data).__name__} as a file tree to disk.')
107
107
 
108
+ # FIX: Right now this can bomb if MultiplePipelineItem
109
+ # is called simultaneously from multiple nodes in MPI
108
110
  if not os_path.isdir(outputdir):
109
111
  makedirs(outputdir)
110
112
 
@@ -328,19 +330,26 @@ class NexusWriter(Writer):
328
330
  :return: The data written to file.
329
331
  :rtype: nexusformat.nexus.NXobject
330
332
  """
333
+ # System modules
334
+ import os
335
+
331
336
  # Third party modules
332
337
  from nexusformat.nexus import (
333
- NXentry,
334
338
  NXFile,
339
+ NXentry,
340
+ NXobject,
335
341
  NXroot,
336
342
  )
337
- import os
343
+
338
344
  data = self.unwrap_pipelinedata(data)[-1]
345
+ if not isinstance(data, NXobject):
346
+ return data
347
+
339
348
  nxname = data.nxname
340
349
  if not os.path.isfile(filename) and nxpath is not None:
341
350
  self.logger.warning(
342
- f'{filename} does not yet exist. Argument for nxpath ({nxpath}) '
343
- + 'will be ignored.')
351
+ f'{filename} does not yet exist. Argument for nxpath '
352
+ '({nxpath}) will be ignored.')
344
353
  nxpath = None
345
354
  if nxpath is None:
346
355
  nxclass = data.nxclass
@@ -365,7 +374,8 @@ class NexusWriter(Writer):
365
374
  self.logger.debug(f'Full path for object to write: {full_nxpath}')
366
375
  if nxfile.get(full_nxpath) is not None:
367
376
  self.logger.debug(
368
- f'{os.path.join(nxpath, nxname)} already exists in {filename}')
377
+ f'{os.path.join(nxpath, nxname)} already exists in '
378
+ f'{filename}')
369
379
  if force_overwrite:
370
380
  self.logger.warning(
371
381
  'Deleting existing NXobject at '
CHAP/edd/__init__.py CHANGED
@@ -2,6 +2,7 @@
2
2
  processing workflows.
3
3
  """
4
4
  from CHAP.edd.reader import (EddMapReader,
5
+ EddMPIMapReader,
5
6
  ScanToMapReader,
6
7
  SetupNXdataReader,
7
8
  UpdateNXdataReader,
@@ -13,8 +14,7 @@ from CHAP.edd.processor import (DiffractionVolumeLengthProcessor,
13
14
  MCADataProcessor,
14
15
  MCAEnergyCalibrationProcessor,
15
16
  MCACalibratedDataPlotter,
16
- StrainAnalysisProcessor,
17
- CreateStrainAnalysisConfigProcessor)
17
+ StrainAnalysisProcessor)
18
18
  # from CHAP.edd.writer import
19
19
 
20
20
  from CHAP.common import MapProcessor