Parsing NRRD fields

nrrd.parse_number_auto_dtype(x)

Parse number from string with automatic type detection.

nrrd.parse_number_list(x[, dtype])

Parse NRRD number list from string into (N,) numpy.ndarray.

nrrd.parse_vector(x[, dtype])

Parse NRRD vector from string into (N,) numpy.ndarray.

nrrd.parse_optional_vector(x[, dtype])

Parse optional NRRD vector from string into (N,) numpy.ndarray or None.

nrrd.parse_matrix(x[, dtype])

Parse NRRD matrix from string into (M,N) numpy.ndarray.

nrrd.parse_optional_matrix(x)

Parse optional NRRD matrix from string into (M,N) numpy.ndarray of float.

nrrd.parse_matrix(x: str, dtype: Optional[Type[Union[int, float]]] = None) Any][source]

Parse NRRD matrix from string into (M,N) numpy.ndarray.

See int matrix and double matrix for more information on the format.

Parameters
xstr

String containing NRRD matrix

dtypedata-type, optional

Datatype to use for the resulting Numpy array. Datatype can be float, int or None. If dtype is None, then it will be automatically determined by checking any of the elements for fractional numbers. If found, then the matrix will be converted to float, otherwise int. Default is to automatically determine datatype.

Returns
matrix(M,N) numpy.ndarray

Matrix that is parsed from the x string

nrrd.parse_number_auto_dtype(x: str) Union[int, float][source]

Parse number from string with automatic type detection.

Parses input string and converts to a number using automatic type detection. If the number contains any fractional parts, then the number will be converted to float, otherwise the number will be converted to an int.

See int and double for more information on the format.

Parameters
xstr

String representation of number

Returns
resultint or float

Number parsed from x string

nrrd.parse_number_list(x: str, dtype: Optional[Type[Union[int, float]]] = None) Any][source]

Parse NRRD number list from string into (N,) numpy.ndarray.

See int list and double list for more information on the format.

Parameters
xstr

String containing NRRD number list

dtypedata-type, optional

Datatype to use for the resulting Numpy array. Datatype can be float, int or None. If dtype is None, then it will be automatically determined by checking for fractional numbers. If found, then the string will be converted to float, otherwise int. Default is to automatically determine datatype.

Returns
vector(N,) numpy.ndarray

Vector that is parsed from the x string

nrrd.parse_optional_matrix(x: str) Any]][source]

Parse optional NRRD matrix from string into (M,N) numpy.ndarray of float.

Function parses optional NRRD matrix from string into an (M,N) numpy.ndarray of float. This function works the same as parse_matrix() except if a row vector in the matrix is none, the resulting row in the returned matrix will be all NaNs.

See double matrix for more information on the format.

Parameters
xstr

String containing NRRD matrix

Returns
matrix(M,N) numpy.ndarray of float

Matrix that is parsed from the x string

nrrd.parse_optional_vector(x: str, dtype: Optional[Type[Union[int, float]]] = None) Any]][source]

Parse optional NRRD vector from string into (N,) numpy.ndarray or None.

Function parses optional NRRD vector from string into an (N,) numpy.ndarray. This function works the same as parse_vector() except if x is ‘none’, vector will be None

See int vector and double vector for more information on the format.

Parameters
xstr

String containing NRRD vector or ‘none’

dtypedata-type, optional

Datatype to use for the resulting Numpy array. Datatype can be float, int or None. If dtype is None, then it will be automatically determined by checking any of the vector elements for fractional numbers. If found, then the vector will be converted to float, otherwise int. Default is to automatically determine datatype.

Returns
vector(N,) numpy.ndarray or None

Vector that is parsed from the x string or None if x is ‘none’

nrrd.parse_vector(x: str, dtype: Optional[Type[Union[int, float]]] = None) Any][source]

Parse NRRD vector from string into (N,) numpy.ndarray.

See int vector and double vector for more information on the format.

Parameters
xstr

String containing NRRD vector

dtypedata-type, optional

Datatype to use for the resulting Numpy array. Datatype can be float, int or None. If dtype is None, then it will be automatically determined by checking any of the vector elements for fractional numbers. If found, then the vector will be converted to float, otherwise int. Default is to automatically determine datatype.

Returns
vector(N,) numpy.ndarray

Vector that is parsed from the x string