glassure.pattern module
- exception glassure.pattern.BkgNotInRangeError(pattern_name: str)
Bases:
Exception
- pydantic model glassure.pattern.Pattern
Bases:
BaseModelA Pattern is a set of x and y values. It can be loaded from a file or created from scratch and can be modified by different methods. It builds the basis for all calculations in glassure.
- Parameters:
x – x values of the pattern
y – y values of the pattern
name – name of the pattern
Show JSON schema
{ "title": "Pattern", "description": "A Pattern is a set of x and y values.\nIt can be loaded from a file or created from scratch and can be modified by\ndifferent methods.\nIt builds the basis for all calculations in glassure.\n\n:param x: x values of the pattern\n:param y: y values of the pattern\n:param name: name of the pattern", "type": "object", "properties": { "x": { "title": "X" }, "y": { "title": "Y" }, "name": { "default": "", "title": "Name", "type": "string" } }, "required": [ "x", "y" ] }
- Config:
arbitrary_types_allowed: bool = True
- Fields:
- Validators:
_validate_lengths»all fields
- field name: str = ''
- Validated by:
_validate_lengths
- field x: PydanticNpArray [Required]
- Constraints:
func = <function serialize at 0x71c7641865c0>
json_schema_input_type = typing.Any
return_type = PydanticUndefined
when_used = always
- Validated by:
_validate_lengths
- field y: PydanticNpArray [Required]
- Constraints:
func = <function serialize at 0x71c7641865c0>
json_schema_input_type = typing.Any
return_type = PydanticUndefined
when_used = always
- Validated by:
_validate_lengths
- extend_to(x_value: float, y_value: float) Pattern
Extends the current pattern to a specific x_value by filling it with the y_value. Does not modify inplace but returns a new filled Pattern
- Parameters:
x_value – Point to which extending the pattern should be smaller than the lowest x-value in the pattern or
vice versa :param y_value: number to fill the pattern with :return: extended Pattern
- static from_dict(json_dict: dict) Pattern
Creates a new Pattern from a dictionary representation of a Pattern.
- Parameters:
json_dict – dictionary representation of a Pattern
- Returns:
new Pattern
- static from_file(filename: str, skip_rows: int = 0) Pattern
Loads a pattern from a file. The file can be either a .xy or a .chi file. The .chi file will be loaded with skiprows=4 by default.
- Parameters:
filename – path to the file
skip_rows – number of rows to skip when loading the data (header)
- Returns:
Pattern object loaded from the file
- Raises:
PatternLoadError – if the file cannot be loaded
- limit(x_min: float, x_max: float) Pattern
Limits the pattern to a specific x-range. Does not modify inplace but returns a new limited Pattern
- Parameters:
x_min – lower limit of the x-range
x_max – upper limit of the x-range
- Returns:
limited Pattern
- load(filename: str, skiprows: int = 0)
Loads a pattern from a file. The file can be either a .xy or a .chi file. The .chi file will be loaded with skiprows=4 by default.
- Parameters:
filename – path to the file
skiprows – number of rows to skip when loading the data (header)
- Raises:
PatternLoadError – if the file cannot be loaded
- rebin(bin_size: float) Pattern
Returns a new pattern, which is a rebinned version of the current one.
- Parameters:
bin_size – Size of the bins
- Returns:
rebinned Pattern
- save(filename: str, header: str = '')
Saves the Pattern to a two-column xy file.
- Parameters:
filename – path to the file
header – header to be written to the file
- smooth(amount: float) Pattern
Smoothing the pattern by applying a gaussian filter. Returns the smoothed pattern. :param amount: amount of smoothing to be applied
- to_dict() dict
Returns a dictionary representation of the pattern with x and y as plain lists. For JSON serialization with base64-encoded arrays, use model_dump() instead.
- Returns:
dictionary representation of the pattern
- property data: tuple[ndarray, ndarray]
Returns the data of the pattern as a tuple of x and y values.
- Returns:
tuple of x and y values
- exception glassure.pattern.PatternLoadError(filename: str, reason: str)
Bases:
ExceptionException raised when a pattern file cannot be loaded.
- glassure.pattern.serialize(value)
Serializes a numpy array to a base64 encoded string. If the value is a numpy array, it is saved to a compressed bytes buffer and then encoded to a base64 string. If the value is a list, it is converted to a numpy array and then serialized. If the value is a string, it is decoded from a base64 encoded string and then deserialized. If the value is already a numpy array, it is returned as is.
- Parameters:
value – The value to serialize
- Returns:
The serialized numpy array
- glassure.pattern.validate(value)
Validates a numpy array. If the value is a list, it is converted to a numpy array. If the value is a string, it is decoded from a base64 encoded string. If the value is already a numpy array, it is returned as is.
- Parameters:
value – The value to validate
- Returns:
The validated numpy array