# HOW-TO Create a global astrometric solution¶

To derive a global astrometric solution, a GAstromTask object is used. Before this can be done, GAstromSourceLists must be made (see HOW-TO Create global astrometric SourceLists).

An astrometric solution can be improved by using overlapping sources of multiple chips and multiple pointings. This is known as a global astrometric solution and is derived using the GAstromTask. The most ideal way to run this task is with the DPU and is illustrated below:

awe> dpu.run('GAstrom', i='WFI', o='2df_I_5, f='#879', C=0)


where i is the instrument name (mandatory argument), o is the object name or wildcard pattern, f is the filter name, and C is the commit switch used to commit the results to the database. Remember, the GAstromSourceLists required for the global astrometric solution (GAS) should be created before this task is run. Without the DPU, the task would be run like:

awe> task = GAstromTask(instrument='WFI', object='2df_I_5', filter='#879', commit=0)


where instrument is the instrument name, object is the object name or wildcard pattern, filter is the filter name and commit is the commit switch.

After the GAstrometric object is created, it may not be easy to find. This is because of the nature of the GAstrometric object. It creates the astrometric solution, but does not store it. The results are stored individually in the AstrometricParameters objects, one per input ReducedSceinceFrame. There are also limitations on the number and type of attributes it contains.

The simplest way to find a GAstrometric object is to start with the ReducedScienceFrames that went into the solution. You can use the same parameters used in the GAstromTask to do this:

awe> query = ReducedScienceFrame.select(instrument='WFI', object='2df_I_5', filter='#879')
awe> len(query)
40


Once you have the ReducedScienceFrames that went into the GAstrometric solution, you can query for one of the AstrometricParameters objects and use this to locate the GAstrometric solution and all the associated AstrometricParameters objects.

awe> red = query[0]
awe> ap = (AstrometricParameters.reduced == red).max('creation_date')
awe> gas = GAstrometric.residuals == ap.residuals
awe> len(gas)
0


Here, we choose the most recent AstrometricParameters object for one of the ReducedScienceFrames in the query, and use the residuals attribute to query for the GAstrometric object (the individual solutions all use the same global residuals file). In this example, no GAstrometric object exists because the above task was run with commit=0.

## Getting the best GAstrometric solution¶

Blindly combining exposures taken over large spans of time or greatly varying observing conditions will likely result in a poor GAstrometric solution. Understanding the concept of fixed focal-plane geometry is vital for high-quality solutions in Astro-WISE.

Global astrometry in Astro-WISE takes advantage of fixed focal-plane geometry applicable under certain conditions for certain telescopes. This means that any difference in the focal-plane geometry from pointing to pointing is assumed to change in a linear fashion only, with higher order distortions remaining constant (e.g., only relative translations of the entire focal plane in RA and Dec are corrected for). When valid, this assumption of fixed focal-plane geometry adds information to the system, benefitting the astrometric solution. Generally, only closely matched sets of exposures taken within strict temporal limits [1] (generally less than one hour between first and last exposure) will demonstrate a fixed focal-plane geometry. This condition minimizes differences in telescope flexure caused by different altitude and azimuth locations.

The standard method in Astro-WISE of combining multiple sets of closely matched exposures is to obtain global solution for each set independently instead of blindly combining them all at once. The independently derived solutions can be applied to the source frames to create frames regridded to the same grid target (spatial reference point on a fixed grid). These regridded frames can then be coadded together to create the final combination (e.g., using SWarp, Eclipse, or PyFITS/NumPy for the image combination).

 [1] Strict spatial limits also aid in the global solution, but are not a condition for a fixed focal-plane geometry. The most optimal results are derived from sets of exposures with greater than 90% overlap due to the larger number of sources common to all exposures.