30
A user-friendly, object oriented, AO simulation in Python Andrew Reeves

A user-friendly, object oriented, AO simulation in Python

Embed Size (px)

DESCRIPTION

A user-friendly, object oriented, AO simulation in Python. Andrew Reeves. Summary. Another AO Simulation….? Python Programming Language Simulation code Overview Examples of current investigations. Why another Simulation?. Written entirely in Python Object- Oriented Simulation “Toolkit” - PowerPoint PPT Presentation

Citation preview

A user-friendly, object orientated, AO simulation in Python

A user-friendly, object oriented, AO simulation in PythonAndrew Reeves

SummaryAnother AO Simulation.?

Python Programming Language

Simulation code Overview

Examples of current investigationsWhy another Simulation?Written entirely in Python

Object-Oriented Simulation Toolkit

Easy to useRapid development and testing of new, complicated AO conceptsLearning tool to explore AO systemsWritten in python upcoming language used in many applications.also uses accelerated libs

Not intended as end to end sim (though does include all bits if you want to)Each modules an object which is self contained and can be fitted into different systems easily(easy in python lists and so forth)

3PythonInterpreted, high-level, general purpose programming language.

Portable, works out of the box on Windows, Mac OS, Linux etc.

Interpreter can be used interactively, with impressive interactive tools (matplotlib, ipython)

Object-oriented, but can be used as a functional language, or just for scripting

Enormous community support with packages available for almost anything with usage growing very quickly

Python SyntaxDocstrings: Distinct from comments, these are used to document code as the code is written. Can be parsed by various tools to create documentation, or when help(function) is called.Indentation: Code blocks are delimited by the indentation level, no {}s are required. Makes code very easy to read.Python can be used to write Object-Oriented or functional code, or can be used simply to write scripts.Python data-structuresFlexible data structureslists, dictionarys and tuplesCan contain combinations of any type of data or objectCan be dynamically expanded/shrunk as requiredlist1 = ["helloWorld", 1, 10.67, aoSimObject, (10,10)]

NumPy ArraysMulti-dimensional arrays of fixed size and typeFast data access, with many fancy indexing techniquesarray1 = numpy.array([1,2,3], [4,5,6]), slice = array1[1:2, :]

No explicit pointer syntax, though NumPy Arrays will pass pointers automatically and NumPy methods are available which make this more user controllable.Python performancePure python isnt very fastBut..

Many libraries exist which wrap fast C algorithms in python especially for scientific purposes e.g. numPy, sciPy, matplotlib, pyfftw

Multi-processing is very easy

Tools such as Cython exist to accelerate pure python by converting to C and compiling.

C-Python API makes writing extensions in C easy.

http://wiki.scipy.org/PerformancePython#head-a3f4dd816378d3ba4cbdd3d23dc98529e8ad7087Time solving 100 iterations of the Laplace Equation for a 500x500 grid. Code is still high-level, easy to understand Python!Note that this is still the same code just 8The Python AO SimulationAn AO simulation which uses many of pythons features to make it simple to understand and easy to use and expand.

AO components, such as WFSs, DMs, and reconstructors are modelled as self-contained objects, which act in an way which corresponds to the real world items.

Objects can be run in the existing simulation framework, or used independently.

A base class for most component types is available which deals with boiler-plate code. A new type of sub-system can be created quickly by inheriting the base and adding the new, interesting methods.

Using external libraries, acceptable performance can be achieved.SimulationConfigurationWFSsLGSsReconstructorDMsScience Camerasaoinit()makeIMat()aoloop()Class name:

Example Class Attributes:

Example Class Methods:Simulation Class DiagramSimulationConfigurationWFSsLGSsReconstructorDMsScience Camerasaoinit()makeIMat()aoloop()Wave-Front SensorGuide Star PositionwavelengthLGSwfsPhase()makeFocalPlane()frame()Atmosphere

wholeScrnsinterpolatedScrnswindSpeedloadScreens()moveScreens()randomScreens()Science CamerafieldofViewWavelengthpixelssciencePhase()makeFocalPlane()frame()Deformable MirrorsactuatorsdmShapesmakeIMat()frame()Reconstructor

reconstructorModecontrolMatrixloadCMat()saveCMat()Reconstruct()Shack-Hartmannsub-aperturespxlsPerSubapmakeFocalPlane()CalculateSlopes()MVMSCAOcMatConditioningmakeCMat()Reconstruct()Learn & ApplycMatConditioninglearnFramesgetLearnSlopes()Reconstruct()Zernike

dmShapesnModesmakeDMShapes()Piezo-stack

dmShapesnActuatorsmakeDMShapes()Laser Guide StarLGS WavelengthLGS HeightlgsPhase()makeLgsPsf()AABBClass A contains instances of Class BClass B inherits from Class ASimulation FeaturesMultiple Wave-Front SensorsOnly Shack-Hartmann, but easy to create new types.WFS objects stored in a python, so can be easily accessed and examined.

Simulation FeaturesRealistic Laser Guide StarsPhysical propagation of up-link path includes tip-tilt variationsConvolved WFS spotsLGS uplink PSF

Simulation FeaturesRealistic Laser Guide StarsElongation modelled by propagating multiple LGS layers at different heights

8m Primary, 6 subap FOV32x32 subaps90km Sodium Layer, 10km thickness5 elongation layers, Uplink turbulence

Simulation FeaturesUsing IPython console, can inspect and plot simulation data and change simulation parameters in real time

Simulation GUI, showing plotting of simulation data. Console can be used to inspect data and change parameters in real-timeSimulation FeaturesMultiprocessing for multiple WFSsEach WFS assigned to a core.Simple with python

Physical or geometric light propagation for WFSs and LGS.

Variety of reconstructors implemented, including Woofer-Tweeter, Learn and Apply, Artificial Neural Network

Simple configuration from Config fileCurrent InvestigationsArtificial Neural NetworksA potential tomographic reconstructor.

There is evidence to suggest that ANNs are robust against changing turbulence profiles.

ANN must be ``trained on a generic data set, then can be used for any turbulence profile.

Artificial Neural NetworksEasy to adapt the simulation to use an ANN.

Sub-class the Reconstructor class, and override the reconstruct method

Parent Reconstructor takes care of all interfaces and boiler-plate code

Now simulation can use an ANN instead of traditional matrix based reconstructorLGS Up-link PredictionPossible to predict LGS up-link path using tomography?

If each WFS views the path through turbulence of other Lasers perhaps.

Only possible if up-link path is not reciprocal to path down.

Correlation of tip-tilt modes in up and down-link paths through Kolmogorov turbulenceCorrelation of tip-tilt is small for a small aperture concentric with the telescope aperture.DLLT/D: Ratio of LGS launch aperture size to telescope diameter(Wilson & Jenkins, 1996)Correlation of tip-tilt modes in up and down-link paths through Kolmogorov turbulence

Correlation of tip-tilt is small for a small aperture concentric with the telescope aperture.DLLT/D: Ratio of LGS launch aperture size to telescope diameter(Wilson & Jenkins, 1996)LGS Up-link PredictionIf up-link and down-link tip-tilt uncorrelated, then slope measured on WFS is a combination of both effects

Measured slopeComponent of slope due to up-link turbulenceComponent of slope due to down-link turbulenceLGS Up-link PredictionIf 2 LGS, and , the WFS observes the up-link path of LGS .

Can prove that there is a linear relationship between down-link only slopes st, and st and the slopes measured on a WFS s and s.

With st, and st can now reconstruct on-phase correction as usual.

Manuscript on the above in preparationDhH0nLGS Up-link PredictionIf 2 LGS, and , the WFS observes the up-link path of LGS .

Can prove that there is a linear relationship between down-link only slopes st, and st and the slopes measured on a WFS s and s.

With st, and st can now reconstruct on-phase correction as usual.

Manuscript on the above in preparationDhH0nLGS Up-link PredictionSince relationship between up-link slopes and down-link turbulence slopes is linear, can use Learn & Apply algorithm (Vidal, Gendron & Rousset, 2010)

Relies on covariance matrices between off and on axis matrices.

Can simulate this with realistic LGS up-link turbulence using python AO sim.

LGS covariance on on-axis and 4 off-axis LGS for an 8x8 sub-aperture system

Note vertical and horizontal dark lines of negative correlation.

NGSLGS1 LGS2 LGS3 LGS4NGSLGS1 LGS2 LGS3 LGS4

Simulation Parameters512 phase points across aperture16x16 sub-aperture system17x17 actuator DM4 off-axis LGS WFSs on 10 squareLGS at height of 90kmuses on-axis NGS for learn step5 Layer Profile (shown right)

ResultsAlgorithm improves performance over no tip-tilt correction.

Not suited to high resolution imaging applications.

Ground layer not corrected well, NGS could still be required for Ground layer correction

Algorithm shows promise to improve GLAO performance for low resolution spectroscopy applicationsSummaryPython is a great language for scientific applications, including AO simulations.

We have created a python AO simulation which can be run stand-alone, or used as a toolkit to quickly develop new AO ideas.

Simulation already contains many useful features such as multiple WFSs, realistic LGS and different reconstructors.

Code is under heavy development to increase features and performance.

Simulation already being used to develop new, novel, ideas for AO."""Module Description Doc-string"""#defining a class nowclass AO_Object(parentClass):"""Class Description Doc-string"""def AO_Method(self, arg1=None):"""Method Description Doc-string"""if arg1:print("Hello Python!")else:print("Goodbye Python")

AO = AO_Object()result = AO.AO_Method()class ANN(Reconstructor): """ Reconstructs using a neural net Assumes on axis slopes are WFS 0

Net must be set by setting ``sim.recon.net = net`` before loop is run net object must have a ``run`` method, which accepts slopes and returns on Axis slopes """

def reconstruct(self, slopes): """ Determine DM commands using previously made reconstructor from slopes. Uses Artificial Neural Network. Args: slopes (ndarray): array of slopes to reconstruct from Returns: ndarray: array to comands to be sent to DM """ offSlopes = slopes[self.wfsSlopes:] onSlopes = self.net.run(offSlopes) dmCommands = self.controlMatrix.T.dot(onSlopes)

return dmCommands