How do I read and write files?
CIAO comes with a number of Python modules, including the pycrates module, and the I/O in Python page has more details.
As an example, we can filter an image just to read the filtered data, and then operate on the data values using NumPy methods:
import numpy as np import pycrates cr = pycrates.read_file("img.fits[sky=circle(260, 2175, 60)]") print(cr)
Crate Type: <IMAGECrate> Crate Name: SENSITY Image Axes: ['SKY', 'EQPOS']
ivals = pycrates.get_piximgvals(cr) ngood = np.isfinite(ivals).sum() print(f"Number of pixels: {ivals.size} good: {ngood}") print(f"Minimum: {np.nanmin(ivals)}") print(f"Maximum: {np.nanmax(ivals)}") print(f"Sum: {np.nansum(ivals)}")
Number of pixels: 256 good: 247 Minimum: 0.0 Maximum: 9.246890158465249e-06 Sum: 0.00028823673187616805