Demo

Demonstrate httm image transformations.

Getting Started

Importing matplotlib

To start, we will import matplotlib and increase the figure size so we can reasonably see artifacts in various FITS images we are going to be looking at.


In [1]:
%matplotlib inline
%config InlineBackend.figure_format = 'png'

In [2]:
import matplotlib
matplotlib.rcParams['figure.figsize'] = (8, 8)

Bringing in a FITS File

Assume you have a file:

fits_data/electron_flux_fits/spot50.fits

...containing an idealized FITS image, output from optical simulation.

First, let's just look at it.


In [3]:
import astropy.io.fits as fits
import numpy
spot50=fits.open('fits_data/electron_flux_fits/spot50.fits')
matplotlib.pyplot.imshow(numpy.log10(spot50[0].data),clim=(2,8))
matplotlib.pyplot.gca().invert_yaxis()


Here, we've got a 50 x 200 image. HTTM will assume this is four slices of 50 x 50 by default. We have 1000000 electrons in one pixel in the center of slice 0.

To get started in HTTM, open this file and extract a httm.data_structures.calibrated_converter.SingleCCDCalibratedConverter object.

This is done by calling httm.fits_utilities.calibrated_fits.calibrated_converter_from_fits.


In [4]:
from httm.fits_utilities.electron_flux_fits import electron_flux_converter_from_fits

ideal_data = electron_flux_converter_from_fits('fits_data/electron_flux_fits/spot50.fits')

In [5]:
matplotlib.pyplot.imshow(numpy.log10(ideal_data.slices[0].pixels+1), clim=(0,8),interpolation='none')
matplotlib.pyplot.gca().invert_yaxis()



In [6]:
from httm.transformations.electron_flux_converters_to_raw import introduce_smear_rows

In [7]:
smeared=introduce_smear_rows(ideal_data)

In [8]:
matplotlib.pyplot.imshow(numpy.log10(list(smeared.slices)[0].pixels+1), clim=(0,8),interpolation='none')
matplotlib.pyplot.gca().invert_yaxis()



In [9]:
from httm.transformations.electron_flux_converters_to_raw import add_shot_noise

In [10]:
shot = add_shot_noise(smeared)

In [11]:
matplotlib.pyplot.imshow(numpy.log10(shot.slices[0].pixels+1), clim=(0,8),interpolation='none')
matplotlib.pyplot.gca().invert_yaxis()



In [12]:
from httm.transformations.electron_flux_converters_to_raw import simulate_blooming

In [13]:
bloomed = simulate_blooming(shot)

In [14]:
matplotlib.pyplot.imshow(numpy.log10(bloomed.slices[0].pixels+1), clim=(0,8),interpolation='none')
matplotlib.pyplot.gca().invert_yaxis()



In [15]:
from httm.transformations.electron_flux_converters_to_raw import add_readout_noise

In [16]:
noisy = add_readout_noise(bloomed)

In [17]:
matplotlib.pyplot.imshow(numpy.log10(noisy.slices[0].pixels+40), clim=(0,8),interpolation='none')
matplotlib.pyplot.gca().invert_yaxis()



In [18]:
from httm.transformations.electron_flux_converters_to_raw import simulate_undershoot

In [19]:
undershot=simulate_undershoot(noisy)

In [20]:
matplotlib.pyplot.imshow(numpy.log10(undershot.slices[0].pixels+150), clim=(0,8),interpolation='none')
matplotlib.pyplot.gca().invert_yaxis()



In [21]:
from httm.transformations.electron_flux_converters_to_raw import add_baseline

In [22]:
baselined = add_baseline(undershot)

In [23]:
matplotlib.pyplot.imshow(numpy.log10(baselined.slices[0].pixels-32000), clim=(0,8),interpolation='none')
matplotlib.pyplot.gca().invert_yaxis()



In [24]:
from httm.transformations.electron_flux_converters_to_raw import convert_electrons_to_adu

In [25]:
raw = convert_electrons_to_adu(baselined)

In [26]:
matplotlib.pyplot.imshow(numpy.log10(raw.slices[0].pixels-5099), clim=(0,4),interpolation='none')
matplotlib.pyplot.gca().invert_yaxis()



In [27]:
from httm.fits_utilities.raw_fits import write_raw_converter_to_calibrated_fits

write_raw_converter_to_calibrated_fits(raw,'spot50_raw.fits')