Table Of Contents

Previous topic

VIS data analysis tools

Supporting Methods

CCD Charge Bleeding

A simple script to test how to simulate CCD bleeding effects.

requires:PyFITS
requires:NumPy
author:Sami-Matias Niemi
contact:smn2@mssl.ucl.ac.uk
support.bleedingtest.writeFITSfile(data, filename, unsigned16bit=False)

Writes out a simple FITS file.

Parameters:
  • data (ndarray) – data to be written
  • filename (str) – name of the output file
  • unsigned16bit (bool) – whether to scale the data using bzero=32768
Returns:

None

File Conversions

A simple script to convert Zemax text file output to FITS format. Copies the meta to the header.

requires:PyFITS
requires:NumPy
version:0.1
author:Sami-Matias Niemi
contact:s.niemi@ucl.ac.uk
support.convertZemaxOutputToFITS.convertToFITS(filename, output, overwrite=True)

Converts Zemax output TXT file to FITS format. Stores the extra information from the Zemax output to the FITS header.

Parameters:
  • filename (str) – name of the Zemax output txt file
  • output (str) – name of the output FITS file
  • overwrite (bool) – whether or not to overwrite the output file if exists
Returns:

None

CCD Cosmetics Maps

A simple script to generate a random location cosmetics map.

requires:NumPy
author:Sami-Matias Niemi
contact:s.niemi@ucl.ac.uk
support.cosmeticsMap.generateCatalogue(deadpixels=280, hotpixels=5, xsize=4096, ysize=4132, output='cosmetics.dat')

Generates a cosmetics catalogue with dead and hot pixels with random locations. The default numbers have been taken from MSSL/Euclid/TR/12003 Issue 2 Draft b.

Results are written to a CSV file.

Parameters:
  • deadpixels (int) – number of dead (QE=0) pixels [280]
  • hotpixels (int) – number of hot (value between 40k and 250ke) pixels [5]
  • xsize (int) – x coordinate values between 0 and xsize [4096]
  • ysize (int) – y coordinate values between 0 and ysize [4132]
  • output (str) – name of the output file
Returns:

None

Cosmic Rays

This simple class can be used to include cosmic ray events to an image. By default the cosmic ray events are drawn from distributions describing the length and energy of the events. Such distributions can be generated for example using Stardust code (http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=04636917). The energy of the cosmic ray events can also be set to constant for testing purposes. The class can be used to draw a single cosmic ray event or up to a covering fraction.

requires:NumPy
requires:SciPy
version:0.2
author:Sami-Matias Niemi
contact:s.niemi@ucl.ac.uk
class support.cosmicrays.cosmicrays(log, image, crInfo=None, information=None)

Cosmic ray generation class. Can either draw events from distributions or set the energy of the events to a constant.

Parameters:
  • log – logger instance
  • image – image to which cosmic rays are added to (a copy is made not to change the original numpy array)
  • crInfo – column information (cosmic ray file)
  • information – cosmic ray track information (file containing track length and energy information) and exposure time.
addCosmicRays(limit=None)

Include cosmic rays to the image given.

Returns:image with cosmic rays
Return type:ndarray
addSingleEvent(limit=None)

Include a single cosmic ray event to the image given.

Returns:image with cosmic rays
Return type:ndarray
addUpToFraction(coveringFraction, limit=None, verbose=False)

Add cosmic ray events up to the covering Fraction.

Parameters:
  • coveringFraction (float) – covering fraction of cosmic rya events in per cent of total number of pixels
  • limit (None or float) – limiting energy for the cosmic ray event [None = draw from distribution]
  • verbose (bool) – print out information to stdout
Returns:

image with cosmic rays

Return type:

ndarray

Image Manipulations

Basic image manipulation algorithms such as Gaussian smoothing and free rebinning.

requires:NumPy
requires:SciPy
author:Sami-Matias Niemi
contact:sniemi@unc.edu
version:0.1
support.imageManipulation.blurImage(im, n, ny=None)

blurs the image by convolving with a gaussian kernel of typical size np. The optional keyword argument ny allows for a different size in the y direction.

support.imageManipulation.congrid(a, newdims, method='linear', centre=False, minusone=False)

Arbitrary resampling of source array to new dimension sizes. Currently only supports maintaining the same number of dimensions. To use 1-D arrays, first promote them to shape (x,1).

Uses the same parameters and creates the same co-ordinate lookup points as IDL’’s congrid routine, which apparently originally came from a VAX/VMS routine of the same name.

method: neighbour - closest value from original data nearest and linear - uses n x 1-D interpolations using scipy.interpolate.interp1d (see Numerical Recipes for validity of use of n 1-D interpolations) spline - uses ndimage.map_coordinates

centre: True - interpolation points are at the centres of the bins False - points are at the front edge of the bin

minusone: For example- inarray.shape = (i,j) & new dimensions = (x,y) False - inarray is resampled by factors of (i/x) * (j/y) True - inarray is resampled by(i-1)/(x-1) * (j-1)/(y-1) This prevents extrapolation one element beyond bounds of input array.

support.imageManipulation.frebin(image, nsout, nlout=1, total=False)

Shrink or expand the size of an array an arbitary amount using interpolation. Conserves flux by ensuring that each input pixel is equally represented in the output array.

Todo

one could do the binning faster if old and new outputs are modulo 0

Note

modelled after the IDL code frebin.pro, so this may not be the fastest solution

Parameters:
  • image – input image, 1-d or 2-d ndarray
  • nsout – number of samples in the output image, numeric scalar
  • nlout – number of lines (ydir) in the output image, numeric scalar
  • total – Use of the total conserves surface flux. If True, the output pixels will be the sum of pixels within the appropriate box of the input image. Otherwise they will be the average.
Returns:

binned array

Return type:

ndarray

support.imageManipulation.gaussianKernel(size, sizey=None)

Returns a normalized 2D gauss kernel array for convolutions.

support.imageManipulation.rebin(a, *args)

rebin ndarray data into a smaller ndarray of the same rank whose dimensions are factors of the original dimensions. eg. An array with 6 columns and 4 rows can be reduced to have 6,3,2 or 1 columns and 4,2 or 1 rows. example usages: >>> a=rand(6,4); b=rebin(a,3,2) >>> a=rand(6); b=rebin(a,2)

support.imageManipulation.rebinFactor(a, newshape)