JCAMPDX

JCAMPDX

class brukerapi.jcampdx.Parameter(key_str, size_str, val_str, version)

Data model of a single jcamp-dx parameter.

It consists of three main parts: - key_str - size_str - val_str

For instance, the following data entry:

##$VisuCoreSize=( 2 ) 192 192

Is stored as:

  • key_str: ##$VisuCoreSize

  • size_str: ( 2 )

  • val_str: 192 192

The value is parsed once it is requested. Parse methods are different for individual subclasses.

__init__(key_str, size_str, val_str, version)
Parameters:
  • key_str – key part of the parameter e.g. ##$ACQ_ReceiverSelect

  • size_str – size part of the parameter e.g. ( 8 )

  • val_str – value part of the parameter Yes Yes Yes Yes No No No No

  • version – version of the parent jcamp-dx file 4.24

__str__()

Return str(self).

__repr__()

Return repr(self).

property nested

Return value as nested list

For example the following entry is nested by default: ##$VisuFGOrderDesc=( 2 ) (6, <FG_ECHO>, <>, 0, 1) (5, <FG_SLICE>, <>, 1, 2)

But this one not: ##$VisuFGOrderDesc=( 2 ) (5, <FG_SLICE>, <>, 1, 2)

This proprerty allows treat the parameter as nested list in all cases.

__weakref__

list of weak references to the object

class brukerapi.jcampdx.GenericParameter(key_str, size_str, val_str, version)
__init__(key_str, size_str, val_str, version)
Parameters:
  • key_str – key part of the parameter e.g. ##$ACQ_ReceiverSelect

  • size_str – size part of the parameter e.g. ( 8 )

  • val_str – value part of the parameter Yes Yes Yes Yes No No No No

  • version – version of the parent jcamp-dx file 4.24

class brukerapi.jcampdx.HeaderParameter(key_str, size_str, val_str, version)
__init__(key_str, size_str, val_str, version)
Parameters:
  • key_str – key part of the parameter e.g. ##$ACQ_ReceiverSelect

  • size_str – size part of the parameter e.g. ( 8 )

  • val_str – value part of the parameter Yes Yes Yes Yes No No No No

  • version – version of the parent jcamp-dx file 4.24

class brukerapi.jcampdx.DataParameter(key_str, size_str, val_str, version)
__init__(key_str, size_str, val_str, version)
Parameters:
  • key_str – key part of the parameter e.g. ##$ACQ_ReceiverSelect

  • size_str – size part of the parameter e.g. ( 8 )

  • val_str – value part of the parameter Yes Yes Yes Yes No No No No

  • version – version of the parent jcamp-dx file 4.24

class brukerapi.jcampdx.JCAMPDX(path, load=None, **kwargs)

Representation of a single jcamp-dx file.

It’s main component is a dictionary of parameters.

Example:

from bruker.jcampdx import JCAMPDX

visu_pars = JCAMPDX("path/visu_pars")
size = visu_pars.get_value("VisuCoreSize")
__init__(path, load=None, **kwargs)

JCAMPDX constructor

JCAMPDX object is constructed by passing a path to a valid jcamp-dx file. It is possible to construct an empty object.

__str__(file=None)

Return str(self).

to_json(path=None)

Save properties to JSON file.

Parameters:
  • pathstr path to a resulting report file

  • nameslist names of properties to be exported

get_value(key, default=None)

Value of parameter key, or default when it is absent.

Which parameters a file carries is ParaVision-version dependent, so a caller that tolerates an absent key would otherwise have to wrap every read in try/except KeyError.

get_list(key)

Idea is to ensure, that a parameter will be a list even if parameter only contains one entry

__weakref__

list of weak references to the object

classmethod read_jcampdx(path, *, with_comments=False)

Parse path into a dict of parameters.

With with_comments=True the comment records that belong to no parameter are returned as well, as (params, comments_before_end, comments_after_end), so that writing the file back reproduces them.

classmethod strip_size_bracket(val_str)

Strip size bracket if it’s found in value string.

Examples of strings with size bracket: ‘( 2 ) Spatial Spatial’ ‘( 1, 20 ) <>’

Parameters:

val_str – value string

Return value:

value string without bracket in case, size bracket is found, otherwise returns unmodified val_str

Return size:

size bracket str

classmethod wrap_lines(line)

Hard-wrap a record the way ParaVision does: by inserting newlines.

Splitting on whitespace and rebuilding, as this used to do, deletes the character it breaks at and collapses runs of blanks, so the value read back differs from the one written (spec 2.2). Wrapping a $$ line is worse still: its tail no longer starts with $$, so on re-read it is parsed as value data of the preceding parameter (spec 2.1).

write(path)

Write JCAMP-DX object into file :param path: :return: