7
Instructions for using the Phase Wrapping and Unwrapping Code Before you begin The first thing to check is that the correct version of Python is installed on the device. I wrote this in Pycharm 4.5.3 Pro with a Python 2.x interpreter, but the code that I wrote should be easily transferable into Python 3.x. However just make sure that you know which Python version you are using. The other thing to check is whether all the modules that you need to run have been installed. This can either be installed directly on your computer Python root file, using the /python pip install –U ‘module_name’ command in either Windows or Mac OS. If you are using a virtual environment, like Pycharm or Canopy, one can easily check if they are installed, and they should be installed anyway on start-up of the file. Overview of code files Params.py This file contains all the necessary parameters, global variables and functions that are called throughout the process of running this code. Phase_Recovery.py This file contains the phase wrapping process and the writing of the phase recovery file, mask frame, and the frame in use for phase wrapping. Test_Unwrap.py This file contains the phase unwrapping process and iterates the phase unwrapping functions, as well as writing the Map.fits file for viewing purposes. Remove_Flat.py Andrew Miller National Physical Laboratory Page 1

Instructions for using the phase wrapping and unwrapping code

Embed Size (px)

Citation preview

Page 1: Instructions for using the phase wrapping and unwrapping code

Instructions for using the Phase Wrapping and Unwrapping Code

Before you beginThe first thing to check is that the correct version of Python is installed on the device. I wrote this in Pycharm 4.5.3 Pro with a Python 2.x interpreter, but the code that I wrote should be easily transferable into Python 3.x. However just make sure that you know which Python version you are using.

The other thing to check is whether all the modules that you need to run have been installed. This can either be installed directly on your computer Python root file, using the /python pip install –U ‘module_name’ command in either Windows or Mac OS. If you are using a virtual environment, like Pycharm or Canopy, one can easily check if they are installed, and they should be installed anyway on start-up of the file.

Overview of code filesParams.pyThis file contains all the necessary parameters, global variables and functions that are called throughout the process of running this code.Phase_Recovery.pyThis file contains the phase wrapping process and the writing of the phase recovery file, mask frame, and the frame in use for phase wrapping.Test_Unwrap.pyThis file contains the phase unwrapping process and iterates the phase unwrapping functions, as well as writing the Map.fits file for viewing purposes.Remove_Flat.pyThis file is optional as it removes the background noise and flattens the image in the .fits file. It is only required for non-flat interferograms.Mode_Reconstruction.pyThis file generates the Zernike polynomial that represents the interferogram, the corrected map file, and also useful values for mathematical analysis.All_Code.pyThis file runs the entire code set for a file that requires flattening in one go. This means that there is no need to run multiple files, and it is quicker as a result.All_Code_Flat.pyThis file runs the entire code set for a file that does not require flattening in one go. This means that there is no need to run multiple files, so it is therefore quicker.

Andrew Miller National Physical Laboratory Page1

Page 2: Instructions for using the phase wrapping and unwrapping code

Pre-checksDirectories and NamesOne major thing that needs to be checked each time the code is used is the directories of where the files should be saved and also their names. Ensure that the files that need to be read by the code have the same directory on the code, and also has the same name, as this will save time in troubleshooting, should the code have an error. InterferogramsThese images taken using the software on NPL computers will be used to analyse the interferometric techniques. Ensure that the files are named correctly and that the correct phase shift is inputed into the code. This is important as an incorrect interferogram can cause the code to produce multiple errors.EnvironmentIf you’re using a Python environment program to run the code, ensure that the configurations of the Python interpreter and script address are correct. Also use the built-in checker to make sure all references are valid and all paths found in the system are available.Read ThroughIf this is the first time using this version of the code, then have a read through of these instructions and also (more importantly) the commenting in the code itself. I have commented enough on each section and stated its function, its structure and the variables it requires. Then at the bottom of each file, I have put an overall summary, a run time analysis, and also an improvements and future thinking commentary. Also in Params.py, I have put a detailed description of each function and run-time, and the background of each parameter. These will tell you about the reason it is there, and the purpose of the various statements it is attached to.

Structure

Andrew Miller National Physical Laboratory Page

Step 1Check Params.py for parameters, and change where necessaryRun Params.py after checking the image directories are in order

Step 2Check and run Phase_Recovery.pyInspect files generated for errors and adjust where necessary

Step 3Check and run Test_Unwrap.pyInspect file, rerun if necessary and check names of files

Step 4Investigate images to make sure if flat removal is neededCheck and run Remove_Flat.py

Step 5Check and run Mode_Reconstruction.pyView text file for parameters, and inspect generated files

Figure 1

2

Page 3: Instructions for using the phase wrapping and unwrapping code

Notes on StructureThe structure shown overleaf shows the structure of the sections of code that need to be run in that order. If you would like to run the entire code in one sweep, then access the files All_Code.py and All_Code_Flat.py. These files are the entire above code in one single file, and can be run with a click of a button. To do this, first check your images and then select the code depending on the file type: if your interferograms are already flat, then select All_Code_Flat.py, and if not then select All_Code.py.

Parameter Current Value

Other Values Called in… Description

masksize {line 14} 325 338, 326, 275, 322 All files This determines the size of the image that can be investigated

x_offset, y_offset{lines 21 & 22}

560, 397

{537,559,539,502,521,618,612,473,451}{360,399,422,393,385,387,394,405,395}

All files This determines the centre of the image, mask and other things

Maxphasejump{line 33}

pi 2.0*pi/3.0, 2.0*pi Test_Unwrap.py, All_Code.py, All_Code_Flat.py

This defines the maximum distance between pixels

OTTsmoothing{line 43}

1 0 Test_Unwrap.py, All_Code.py, All_Code_Flat.py

This determines whether the mapping is quick or quality

Path Name, Mode_Renconstruction.py, {line17}

Mapnoflat.fits

Map.fits Mode_Renconstruction.py

This determines which file is used in the reconstruction

There are pros and cons of each method, so I’ll start with the sectional method. This method enables the user a lot of control over the process, and at each step of the process, they can inspect the files to ensure that the code and frames are performing as expected. However this method can be slightly slower due to the multiple files, and also the need to change files may be a bit tedious. Now on the other hand, the sandwich method is faster overall and generates a set of images all together at the very end quicker. This however means that if an error occurred during a process, the user could not stop and check it properly until the process is over.

ParametersFor regular users this is probably the most important section as it tells you what may need to be changed in the Params.py file between frames.

All these parameters are important, and each one must be checked before the code is run. Usually most of them can be found by using image-examining programs like SAOImage DS9, but the smoothing extent is up to the preference of the user, and also the purpose of the session. Also if the frames being used in the sectional method are flat, make sure you check the path name (see above) on line 17 of Mode_Reconstruction.py, as it is key that this is the correct path name, otherwise the incorrect file will be flattened.

Andrew Miller National Physical Laboratory Page3

Page 4: Instructions for using the phase wrapping and unwrapping code

Functions and CodeFor all of the functions, as well as the actual code, the path names have to all be checked to ensure the files are being created, or overwritten, in the correct place. This is the first step in the checking process for the remainder of the code.Things to Check

In general ignore the Carre() function: it is not completed fully yet, but when it is fully integrated pay attention to it like the fourbucket() function.

If an additional parameter needs to be added to the text file, edit BOTH the write() function in Params.py and the file creation on Mode_Reconstruction.py, line 103 (and the All_Code.py and All_Code_Flat.py files.)

The iterations of the testsmooth() function in Test_Unwrap.py can be altered according to the frame, so feel free to play around with the order of the function, but ensure that it ends with a testunwrapsquare() function.

Check that the Mapnoflat.fits file, found in Remove_Flat.py line18, has the correct directory to the desired file, as it is different for each set of interferograms.

Make sure that the path name for Mapnoflat.py, found in Mode_Reconstruction.py on line 17, is correct too. Remember that it can be Map.fits depending on the file type you are using.

If you check all these things, then hopefully everything should run smoothly and the code will do its work successfully.

TroubleshootingError: No such file or directory: ‘directory name’This is a common error and is mainly caused by the incorrect directory names are being used. It can easily be fixed by checking the directories in the code files are all correct, and also that the files that are being used are in their location are in order, and their names match those tin the code.Error: name 'variable' is not definedThis error is another common one, and turns up when a function is run and calls a variable that is not defined, either globally or locally in that file. To sort this out, you must first find out what the value is that you are trying to apply the function to. Then check if it is imported from an external module or file, and then adjust the variable where necessary.Error: index 768 is out of bounds for axis 0 with size 768This error will occur if the testunwrapsquare() function has a limit that is too large for the mask/image size. This can be rectified easily by going to the testunwrapsquare() function {line 821}, and changing the limit to a lower value. Currently it is at 330, which is suitable for the files that are being used, but should the set-up be altered majorly, then checking this is worth a look.Python terminal ‘freezes’ on testunwrapsquare() functionThis fault cannot raise an error, as the code it running, but it would run infinitely and not get a result. It may occur when running the Test_Unwrap.py file, and will result in you disconnecting the terminal. This is caused by the parameter Maxphasejump (see table) being a value that is incorrect with respect to the phase it is unwrapping. To solve this, you can either change the limit in the testunwrapsquare() function to the last value printed in the terminal, or change the parameter to a larger value.

Andrew Miller National Physical Laboratory Page4

Page 5: Instructions for using the phase wrapping and unwrapping code

Interferogram (Map.fits) has far too much noiseThis fault has many causes and some are outside the code, so this is to do with the experimental setup. However in the parameters section, it may be caused by a mask size that is not the correct size for the interferogram, or by not re-running the phase recovery code. To rectify this, check the setup of the experiment and ensure it is optimised. Then check that the mask size and centre points are correct, using an image-inspecting program, and finally check that the file Phase_Recovery.py has been run before the unwrapping step has taken place.

Final thoughtsHopefully this set of instructions should be good enough to guide you through using the code created by Matt and myself. If anyone has any ideas on how to improve the code even further, then don’t hesitate to email me at [email protected] and I would be happy to implement it and comment in what I have done.

I’m happy to say that the code written by Matt has now been optimised successfully, and as a result the running time has almost been reduced by half its initial value, which is an achievement in itself. Also the fact that it is now commented and sectioned off effectively means that many people can use this code efficiently, and see how the code progresses simply. Finally it seems that in optimising it, I have also potentially improved the algorithms a little as they produce better results than before in many cases. This means that a clearer, less noisy recovery of an interferogram can be easily produced by anyone.

Andrew Miller National Physical Laboratory Page5