# HOW-TO MDia (OLD)¶

## Introduction¶

The Munich Difference Imaging Analysis (MDia) package is a tool for photometry in (very) crowded fields. The software is written in C++ and part of the “mupipe” package, which has been developed at the University Observatory in Munich for the use in a pixel-lensing project. The underlying algorithm has been proposed by Alard and Lupton in 1998 (ApJ…503..325A) and later improved by Alard in 2000 (A&AS..144..363A).

## Astro-WISE implementation¶

The MDia pipeline has been incorporated into Astro-WISE by J. Koppenhöfer. This is done by providing a Python wrapper around the C++ programs which stores the input and output to the Astro-WISE database.

Creating light curves with MDia is a two step process. The first step is the creation of a ReferenceFrame using the best seeing images. In the second step, this ReferenceFrame is used to create difference images of all RegriddedFrames one wants to analyze. Using the difference images, precise photometry is obtained via PSF-fitting. In this way, light curves are created and stored in the database for further analysis.

## Compiling and installing the C++ code¶

The MDia code can be found in:

opipe/Experimental/MDIA/MDia.tar.gz


Extract this archive to whatever directory you like. After that follow the instructions given in the README file. Up to now, the code is tested for 32-bit machines only. The MDia code needs the library “ltl” which is usually installed during the awetomatic process.

## Creating a ReferenceFrame¶

The ReferenceFrame is created using the images (typically 10) with the best seeing. These can be selected by using the psf_radius property of any ReducedScienceFrame or RegriddedFrame. Try to reject images with high background in order to get an optimized $$S/N$$ in the ReferenceFrame (very often cloudy images have a small psf_radius, so take care!!!).

In order to get good results the astrometry of all images you want to combine must be as good as possible. Therefore use global astrometry on the best seeing images and regrid again if needed. Having prepared the final list of RegriddedFrames you can create a ReferenceFrame in three different ways:

1. using the DPU:

awe> dpu.run( 'Reference', i='WFI',
...           reg_filenames=['Sci-USER-WFI-#844-Reg-54653.3.fits',...], C=1 )

2. locally using a task:

awe> from astro.recipes.Reference import *
...                        commit=0)

3. locally using the make() method of class ReferenceFrame:

awe> from astro.main.ReferenceFrame import *
awe> ref = ReferenceFrame()
awe> ref.OBJECT = 'OTSF-1c'
awe> ref.regridded_frames = best_frames
awe> ref.make()
awe> ref.store()
awe> ref.commit()


where best_frames is a list of filenames of the RegriddedFrames you want to combine.

## Creating Lightcurves¶

After having created a ReferenceFrame, one can use it together with a number of RegriddedFrames and create light curves of multiple sources simultaneously. The database object of use is an instance of class MDia which takes as input the ReferenceFrame, a list of RegriddedFrames, optionally some SourceLists and a set of process parameters (MDiaParameters). The output consists of $$N$$ lightcurves in ASCII or FITS format with $$N$$ being the number of sources analyzed.

Again, the astrometric accuracy is crucial in this step. The recommended procedure is the following:

• First create a SourceList of the ReferenceFrame.
• Then use this SourceList as a replacement for the USNO catalog and (re-)calculate the AstrometricParameters for all images to be analyzed. Finally, regrid all the individual images using the improved AstrometricParameters. By doing it this way, a very high relative astrometric precision between the ReferenceFrame and the RegriddedFrames is achieved.

To create lightcurves in AWE use one of the following ways:

1. using the DPU:

awe> dpu.run( 'MDia', i='WFI', ref_filename=['Sci-USER-WFI-#844-Ref-54653.3.fits'],
...           reg_filenames=['Sci-USER-WFI-#844-Reg-54653.3.fits',...], C=1 )

2. locally using a task:

awe> from astro.recipes.MDia import *
...                   reg_filenames=['Sci-USER-WFI-#844-Reg-54653.34244.fits',...],
...                   commit=0)

awe> from astro.main.LightCurve import *