Metadata-Version: 2.4
Name: xsptools
Version: 1.0.0
Summary: xsptools - Collection of python packages to process data originating from X-Spectrum detectors
Author-email: Emanuele Besana <emanuele.besana@x-spectrum.de>
Maintainer-email: Emanuele Besana <emanuele.besana@x-spectrum.de>
License: Copyright (c) 2025 X-Spectrum GmbH, Germany. All Rights Reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are
        met:
        
          1. Redistributions of source code must retain the above copyright notice,
             this list of conditions and the following disclaimer.
        
          2. Redistributions in binary form must reproduce the above copyright
             notice, this list of conditions and the following disclaimer in the
             documentation and/or other materials provided with the distribution.
        
          3. The name of the author may not be used to endorse or promote products
             derived from this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY X-SPECTRUM "AS IS" AND ANY EXPRESS OR IMPLIED
        WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
        MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
        EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
        SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
        PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
        OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
        WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
        OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
        OF THE POSSIBILITY OF SUCH DAMAGE.
        
        
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.6.0
Dynamic: license-file

# xsptools

`xsptools` is a collection of python packages for the processing of data originating
from X-Spectrum detectors. Therefore, each package should be used in conjunction with
a library that allows access to a detector, such as `pyxsp` [1].

## Installation

`xsptools` requires:

* Python >= 3.8
* Numpy >= 1.6

The package itself can be installed with pip:

```bash
$ pip install xsptools
```

## Supported packages

The following packages are supported by `xsptools`:

* [xsptools.binning](#xsptoolsbinning)

Each package can be imported specifying its name, for example:

```python 
from xsptools import binning
```

## xsptools.binning

`xsptools.binning` is a package that is used to perform 3x3 binning of
frames generated by X-Spectrum detectors. The only supported detector at the moment
is a Lambda CdTe 750k.
The main object is the `Processor`, which is instantiated by passing the frame
dimensions:

```python
from xsptools import binning
p = binning.Processor(516,1554)
```

Its functionality is to bin frames, which must be passed as 2-dimensional
numpy arrays with the same dimensions as those passed to the `Processor`. It is
also possible to add to the `Processor` the detector pixel mask, which is used to
interpolate bad pixels (before binning, each bad pixel is set to be the
average of its neighbors). This procedure is generally recommended as it results in
better looking binned frames.
The `Processor`'s full API can be exposed via:

```python
from xsptools import binning
help(binning.Processor)
```

The following is a complete code example that shows how to use the package:

```python
from xsptools import binning
import numpy as np
import matplotlib.pyplot as plt


p = binning.Processor(frame_height=516, frame_width=1556)

# Mock pixel mask
pixel_mask = np.zeros(shape=(516,1554), dtype=np.uint32)
p.add_pixel_mask(pixel_mask)

# Mock frame
frame = np.random.randint(0, 256, size=(516,1554), dtype=np.uint8)
binned_frame = p.bin_frame(frame)

height = p.binned_frame_height
width = p.binned_frame_width
plt.imshow(binned_frame, extent=(0,width,height,0))
plt.show()
```

## Licensing

The `xsptools` package is licensed under the terms of the BSD  3-clause license 
(also known as Modified BSD License).

## References

[1] pyxsp User Manual, Version 3.3, March 2024, X-Spectrum

