Created
November 10, 2015 14:46
-
-
Save ipashchenko/5dd145dd8ad0f10e58ae to your computer and use it in GitHub Desktop.
Using difmap's CLEAN from python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def clean_difmap(fname, outfname, stokes, mapsize_clean, path=None, | |
| path_to_script=None, mapsize_restore=None, beam_restore=None, | |
| outpath=None, shift=None, show_difmap_output=False): | |
| """ | |
| Map self-calibrated uv-data in difmap. | |
| :param fname: | |
| Filename of uv-data to clean. | |
| :param outfname: | |
| Filename with CCs. | |
| :param stokes: | |
| Stokes parameter 'i', 'q', 'u' or 'v'. | |
| :param mapsize_clean: (optional) | |
| Parameters of map for cleaning (map size, pixel size). If ``None`` | |
| then use those of map in map directory (not bootstrapped). | |
| (default: ``None``) | |
| :param path: (optional) | |
| Path to uv-data to clean. If ``None`` then use current directory. | |
| (default: ``None``) | |
| :param path_to_script: (optional) | |
| Path to ``clean`` difmap script. If ``None`` then use current directory. | |
| (default: ``None``) | |
| :param mapsize_restore: (optional) | |
| Parameters of map for restoring CC (map size, pixel size). If | |
| ``None`` then use naitive. (default: ``None``) | |
| :param beam_restore: (optional) | |
| Beam parameter for restore map (bmaj, bmin, bpa). If ``None`` then use | |
| the same beam as in cleaning. (default: ``None``) | |
| :param outpath: (optional) | |
| Path to file with CCs. If ``None`` then use ``path``. | |
| (default: ``None``) | |
| :param shift: (optional) | |
| Iterable of 2 values - shifts in both directions [mas]. If ``None`` then | |
| don't shift. (default: ``None``) | |
| :param show_difmap_output: (optional) | |
| Show difmap output? (default: ``False``) | |
| """ | |
| if path is None: | |
| path = os.getcwd() | |
| if outpath is None: | |
| outpath = os.getcwd() | |
| if not mapsize_restore: | |
| mapsize_restore = mapsize_clean | |
| difmapout = open("difmap_commands", "w") | |
| difmapout.write("observe " + os.path.join(path, fname) + "\n") | |
| if shift is not None: | |
| difmapout.write("shift " + str(shift[0]) + ', ' + str(shift[1]) + "\n") | |
| difmapout.write("mapsize " + str(mapsize_clean[0] * 2) + ', ' + | |
| str(mapsize_clean[1]) + "\n") | |
| difmapout.write("@" + path_to_script + " " + stokes + "\n") | |
| if beam_restore: | |
| difmapout.write("restore " + str(beam_restore[0]) + ', ' + | |
| str(beam_restore[1]) + ', ' + str(beam_restore[2]) + | |
| "\n") | |
| difmapout.write("mapsize " + str(mapsize_restore[0] * 2) + ', ' + | |
| str(mapsize_restore[1]) + "\n") | |
| if outpath is None: | |
| outpath = path | |
| elif not outpath.endswith("/"): | |
| outpath = outpath + "/" | |
| difmapout.write("wmap " + os.path.join(outpath, outfname) + "\n") | |
| difmapout.write("exit\n") | |
| difmapout.close() | |
| shell_command = "difmap < difmap_commands 2>&1" | |
| if not show_difmap_output: | |
| shell_command += " >/dev/null" | |
| os.system(shell_command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment