Muscat.Helpers.ParserHelper module

Functions to parse text into different types

CheckIntegrity(GUI: bool = False)[source]
Read(inputData: Any, inout: Any)[source]

Try to convert the data of inputData to the target type of inout the string is treated to search and replace the values of known variable using the global variable space of Muscat. please read py:class:Muscat.Helpers.LocalVariables In the case the inout is a numpy array, we iterate on the inputData. if inputData is a string we split it using the “ “ (space character)

Parameters:
  • inputData (Any) – data to be converted can be a string “2 4 5”

  • inout (Any) – an instance of the target type (we use only type(inout) )

Returns:

the input data converted to the type of inout

Return type:

type(inout)

ReadBool(inputData: Any) bool[source]

Convert the input data can be a string into a bool the following words can be converted to bool: “false”, “no”, “true”, “yes”, “on” the inputData is converted to lowercase before testing

Parameters:

inputData (Any) – a string of other type of data, must be

Returns:

_description_

Return type:

bool

Raises:

ValueError – _description_

ReadBools(inputData: Any) ndarray[source]

return ReadVector(inputData,bool) please read ReadVector documentation

ReadFloat(inputData: Any) float64[source]

return ReadScalar(inputData,MuscatFloat) please read ReadScalar documentation

ReadFloats(inputData: Any) ndarray[source]

return ReadVector(inputData,MuscatFloat) please read ReadVector documentation

ReadInt(inputData: Any) int64[source]

return ReadScalar(inputData,MuscatIndex) please read ReadScalar documentation

ReadInts(inputData: Any) ndarray[source]

return ReadVector(inputData,MuscatIndex) please read ReadVector documentation

ReadProperties(data: Mapping, props: Iterable, obj_or_dic: Mapping | Any, typeConversion: bool = True) None[source]

Read information from “data”, using the mapping interface ([]). the keys are extracted from the iterable “props” if provided,

The data is converted to the type of every member in obj_or_dic with the same name using the Read function. In the presence of a function called Set… (SetAlpha for example), we check if the function Get… (GetAlpha) is present, extract the type of the value and use this type for the conversion, if the getter is absent no conversion is done and the value (of alpha in the example) is passed directly to the Setter.

Parameters:
  • data (Mapping) – Source of the data (dict-like object)

  • props (Iterable) – the properties to parse (list-like object)

  • obj_or_dic (Union[Mapping,Any]) – the destinations of the data, a dictionary or an object

  • typeConversion (bool, optional) –

    if true the data is converted using the Read() function before pushing the information

    to the destination , by default True

ReadScalar(inputData: Any, inputType: Callable[[D], R]) R[source]

Try to convert the data of inputData to the target type of inout if inputData is a string then it is treated to search and replace the values of known variable using the global variable space of Muscat. please read py:class:Muscat.Helpers.LocalVariables

Parameters:
  • inputData (Any) – source data can be a string or a scalar type (int, float, double, …)

  • inputType (Type) – the type to be used to do the conversion ( Callable[[D], Type] )

Returns:

the data in inputData converted to type inputType

Return type:

Type instance

ReadString(inputData: Any) str[source]

if inputData is a string then it is treated to search and replace the values of known variable using the global variable space of Muscat. please read py:class:Muscat.Helpers.LocalVariables

Parameters:

inputData (Any) – input data

Returns:

a string representation of the input data

Return type:

str

ReadStrings(inputData: Any) List[str][source]

Return a list of string (it use the split to cut the string)

ReadVector(inputData: Iterable, dtype: Type) ndarray[source]

Convert inputData to a numpy array of dtype dtype if inputData is a string, first we split it by the spaces then convert every element to dtype

Parameters:
  • inputData (Iterable) – input data to extract every element for the vector

  • dtype (Type) – the target type for the conversion

Returns:

array of type dtype with the converted elements

Return type:

np.ndarray

ReadVectorPhiThetaMag(string, normalized=False) ndarray[source]

Read a vector in phi (in degrees), theta(in degrees) and magnitude

Parameters:
  • inputData (Iterable) – input data. Can be a string if inputData has only 2 elements then magnitude == 1.

  • normalized (bool, optional) – if True the output vector is normalized, by default False

Returns:

a cartesian vector of size 3

Return type:

np.ndarray

ReadVectorXY(inputData: Iterable, normalized=False) ndarray[source]

Read a vector of size 2

Parameters:
  • inputData (Iterable) – input data. Can be a string

  • normalized (bool, optional) – if True the output vector is normalized, by default False

Returns:

a vector of size 2

Return type:

np.ndarray

Raises:

Exception – in the case the input data has more than 2 elements to be parsed

ReadVectorXYZ(inputData, normalized=False) ndarray[source]

Read a vector of size 3

Parameters:
  • inputData (Iterable) – input data. Can be a string

  • normalized (bool, optional) – if True the output vector is normalized, by default False

Returns:

a vector of size 3

Return type:

np.ndarray

Raises:

Exception – in the case the input data has more than 2 elements to be parsed