CompressSkipperProcess
is the class used to compress an skipper image. This class allow to use any statistical function from numpy to reduce the single skip images into a unique one by computing the arithmetic function along the 3rd axis of RawData.image
(see how to I). As a reminder, the CCD image is loaded as a data member of an instance of the RawData
class as an array of dimension 3:
(Nrows, Ncols, Nskips)
Where $Nskips$ is the number of non-destructive measurement the charge have been done.
This process will create a new data member of the raw data object under the name image_<func>_compressed
where <func>
is the function name used to reduce the set of non-destructive measurement per pixel into a single one. This new data memeber is an array of dimension 2:
(Nrows, Ncols)
CompressSkipImage
¶image
config param¶Is the image to be compressed. By default is the raw data.
func_to_compress
config param¶List of arithmetic functions to compress the non-destructive measurements. One image for each function will be created and added as a data member of the RawData
instance. The default funciton is mean.
id_skip_start
config param¶To create the compressed image, it is not mandatory to use the full set of non-destructive measurements. This parameters should point to the first measurement to take into account. Note that the first value is 0.
id_skip_end
config param¶To create the compressed image, it is not mandatory to use the full set of non-destructive measurements. This parameters should point to the last measurement to take into account. Negative values means the last one.
In this howto there are two sections:
In both cases, we will do the same (fit the dark current), but using two different approaches. The first option allows yo to get to know and go deeper into the different sub-modules of pysimdamicm
as a black box through the panaSKImg
script.
pysimdamicm
and some other useful packages¶%matplotlib inline
# loading damicm module
import pysimdamicm as ccd
# loading other packages
import numpy as np
from matplotlib import pyplot as plt
import ROOT
# variable pointing where my#### data is
path_to_raw_data = "/data/workdir/compton/data/calidaq_backup/DataTaking/Am241/skip_2000_img/"
# pattern file name
img_pattern_file_name = "Image_Am241_Source_55_{}.fits"
# absolute path to the file name
file_name = "{}/{}".format(path_to_raw_data,img_pattern_file_name)
print("\nMy images follows the patter file name:\n {}\n".format(file_name.format("*")))
For this example I will use the default configuration file panaSKImg_configuration.json
that can be found at pysimdamicm.json
.
To load this configuration file you can use the class Config
provided by pysimdamicm.utils.config
. This class reads and interpret JSON files to configure simulations and data.
# path where our JSON file is
cfg_file = "{}/json/panaSKImg_configuration.json".format(ccd.__path__[0])
# False to interpret the JSON file as a configuration for data instead of simulations (default one)
cfg = ccd.utils.config.Config(cfg_file, simulations=False)
print(" 'cfg' contains a dictionary {} with two main sections: ".format(type(cfg.configuration)))
for k in cfg.configuration.keys(): print("\t * ", k)
print("\n Where each section contains a set of sections: ")
_ = [[print("\t {}: {}".format(k,sk)) for sk in cfg.configuration[k]] for k in sorted(cfg.configuration.keys())]
For now we will just focus on section input that corresponds to our input data, i.e. our image. Relevant for this exercise are the sections:
print(ccd.utils.config.json.dumps(cfg.configuration['input'], indent=4, sort_keys=True))
From the image section:
The class BuilderRawData
provided by pysimdamicm.io.rawdata
is used to create an object with our data from the input file (in this example, as a fits file object).
This class can use the default configuration to properly set our data object as an instance of RawData
.
# unset verbose for the fits file header
ccd.io.rawdata.__verbose__ = False
rdata = ccd.io.rawdata.BuilderRawData(file_name.format('skip_1'), cfg.configuration['input'])
Internally what this function does is the creation of a boolean array for each region. This boolean array with the same size than the full image, should be used against the object rdata.image_mean_compressed
to select only regions we are insterested in by using numpy.ma.array
. The object rdata.image_mean_compressed
is the averaged skip image (see next steps).
rdata.prepare_data()
The attribute image
of rdata
contains our data image. It is an array of 3 dimensions if the input file corresponds to an skipper image, and a 2D is is the already averaged image.
The dimensions are for:
rdata.image.shape
This image has 60 rows, 275 columns and each pixels has been measured 2000 times.
$\color{red}{\text{CompressSkipperProcess}}$ is a process used to compute the averaged skipper image
To compress the image we will use the class CompressSkipperProcess
provided by pysimdamicm.process.skiper_analysis
.
comp = ccd.processes.skipper_analysis.CompressSkipperProcess()
The user can change the following configuration parameters:
comp.info()
The parameters id_XXX_start
and id_XXX_col
can be used to limit a region of the image where the process will be executed. The user can limit the columns, rows or skips. These parameters are from the abstract classs abps
, any process will have them, but not always have sense to delimit. Be careful on using it! If no region is defined, the one by default will be selected. If these parameters have been defined through the configuration JSON filethis parameters on the JSON file when loading data, these will be used.
func_to_compress
is a list of statistical functions (that must exist on numpy
) to create the image. A compressed image for each function will be created and added as a new attribute on the RawData
with the name: image_FUNC_compressed
where FUNC
is the used function name.
save_img
to save the compressed image as a fits file
save_plots
to save the debug plotsSet __verbose__
to see online the debug plots.
%matplotlib inline
comp.func_to_compress = ['mean']
comp.__verbose__ = True
comp.id_skip_start = 10
comp.execute_process(rdata)
print("Total pixel charge: ", rdata.image_mean_compressed.sum())
comp.__verbose__ = True
comp.id_skip_start = 3
comp.execute_process(rdata)
print("Total pixel charge: ", rdata.image_mean_compressed.sum())
comp.__verbose__ = True
comp.func_to_compress = ['mean','median','std']
comp.id_skip_start = 3
comp.execute_process(rdata)
The main script for analysis is panaSKImg
also provided by pysimdamicm
. It is a python3 script to apply a chain of processes over a real data CCD image. Find more information here.
To $\color{green}{\text{compress}}$ a set of skipper images we can also use panaSKImg
. We will only need
Here is an example of how to run the same as in Sect. A (How to from a Python Interpreter), but with panaSKImg
:
panaSKImg --json <config_file.json> "image_files*fits" --display --verbose -o .
Use display
and verbose
only to display all plots created along the process.
Two possible ways:
It is possible to use both the json file and command lines. $\color{green}{\text{The command lines have preference over those of the json file.}}$
This has to be done in the configuration file. Here you can find information about the full JSON file.
"CompressSkipperProcess":
{
"func_to_compress":["mean"],
"id_skip_start":3,
"id_skip_end":-1
},
All these parameters have been explained along this howto.
Almost all parameters has a command line to be pass as an argument of panaSKImg
. Run
panaSKImg --help
for help on the command lines. Here the output of the help related with CompressSkipperProcess
--skip-start ID_SKIP_START
First skip to start with (for all processes, if a
process use an specific starting point include
id_skip_start in its scope in the json file)
--skip-end ID_SKIP_END
First skip to start with (for all processes, if a
process use an specific starting point include
id_skip_start in its scope in the json file). Note
that -1 means last value
*** For Process CompressSkipperProcess ************************** :
--func-to-compress FUNC_TO_COMPRESS [FUNC_TO_COMPRESS ...]
CompressSkipperProcess. List of functions to reduce
the single skipper images into a single one (functions
must exist in the numpy package)
sequence
is mandatory¶Remember that the parameter sequence
of the process
section of the JSON file must be informed. You can do that using the command line -s as follows
panaSKImg --json <config_file.json> "image_file*fits" --display --verbose -o . -s CompressSkipperProcess
To list all possible process you can just run
panaSKImg --list-process help
To compress a set of images located at /data/compton/run045 that follows the file name patter ImageSourcefits and store its compressed image in the current working directory just do
panaSKImg --json <config_file.json> -s CompressSkipperProcess "/data/compton/run045/Image*Source*fits" -o .
where <config_file.json>
points to the configuration json file.