casa
$Rev:20696$
|
00001 # 00002 # This file was generated using xslt from its XML file 00003 # 00004 # Copyright 2009, Associated Universities Inc., Washington DC 00005 # 00006 import sys 00007 import os 00008 from casac import * 00009 import string 00010 from taskinit import casalog 00011 #from taskmanager import tm 00012 import task_imhead 00013 def imhead(imagename='', mode='summary', hdkey='', hdvalue='', hdtype='', hdcomment='', verbose=False): 00014 00015 """List, get and put image header parameters 00016 00017 This task allows the user to manipulate some meta-data parameters in an 00018 image. The mode='list' shows those keywords that are 00019 presently implemented, with their values. The contents associated 00020 with the keywords can be obtained (get) and changed (put). 00021 00022 Additional image parameter listings are available. 00023 00024 [For visibility files, the taskname='vishead' should be used.] 00025 00026 The modes that are available are: 00027 00028 list --- Lists the image header keywords and values. 00029 Use this if 'get' and 'put' are executed. 00030 get --- Get the specified keyword value(s) from the image 00031 put --- Put the specified keyword value(s) into the image 00032 00033 history --- Display the history information in hte CASA logger. 00034 summary --- Information summarizing the CASA image file. 00035 fits --- Lists the header information in a FITS style (not available) 00036 add --- Adds a new header key. Use with caution 00037 del --- Delete a header key, hdkey. Use with caution 00038 00039 Parameters currently implemented are listed using mode = 'list' 00040 00041 beammaj Major axis of the clean beam 00042 beammin Minor axis of the clean beam 00043 beampa Position angle of the clean beam 00044 NOTE: If the image contains multiple beams, use mode="summary" to get 00045 a listing. 00046 bunit Brightness unit (K, Jy/beam, etc) 00047 cdeltn Pixel size, nth axis (max n is 4) 00048 crpixn Pixel coordinate of reference point, nth axis 00049 crvaln Pixel location of reference point, nth axis 00050 ctypen Axis name, nth axis 00051 cunitn Pixel units, nth axis 00052 datamax Maximum pixel value in image 00053 datamin Minimum pixel value in image 00054 date-obs Date of the observation 00055 equinox Reference frame for directional coordinates 00056 imtype Image type: intensity, 00057 minpos 00058 minpixpos 00059 maxpos 00060 maxpixpos 00061 object Source name 00062 observer Observer name 00063 projection Image projection ('SIN','TAN', or 'ZEA') 00064 reffreqtype Reference frame for the spectral coordinates 00065 restfreq Rest Frequency 00066 shape Number of pixels along each axis 00067 telescope Telescope name 00068 00069 Keyword arguments: 00070 00071 imagename --- Name of input image 00072 default: none; example: imagename='ngc5921_task.image' 00073 mode --- Mode: options: 00074 default: none; 'list', 'summary', 'fits', 'history', 00075 'get', 'put', 'add', and 'del' 00076 00077 NOTE: 'add' and 'del' should be used with caution 00078 00079 hdkey --- keyword to use with get, put, add, or del 00080 default: none; example: hdkey='telescope' 00081 hdvalue --- keyword value that is 'got', or to be 'put' or 00082 to be 'added' 00083 default: ''; example: hdvalue='VLA' 00084 hdcomment --- comment to be stored with the keyword for mode='put' or mode='add' 00085 Examples: 00086 hdkey='date-obs';hdvalue='2007/06/20/00:00:00' 00087 hdkey='beammajor';hdvalue='55arcsec' 00088 hdkey='beampa'';hdvalue='0deg' 00089 hdkey='restfrequency';hdvalue='1.421GHz' 00090 hdkey='restfrequency';hdvalue='1.421GHz, 115.272GHz' 00091 hdkey='projection';hdvalue='TAN' 00092 hdkey='cdelt4';hdvalue=24415.05 00093 hdkey='cdelt1';hdvalue='7.75e-5deg' 00094 hdkey='crval1';hdvalue=qa.quantity( '763180', 'arsec') 00095 hdkey='crval1';hdvalue='14:07:58' 00096 hdkey='crval4';hdvalue='6250000Hz' 00097 00098 hdtype --- Used only with 'add' mode. It is the data type that 00099 is used to store the hdkey. It can not be used to 00100 change the data type of an exiting keyword. 00101 options: bool, int, string, doubple, complex 00102 default: none; example hdtype='double' 00103 00104 00105 Note that hdvalue will contain numbers, strings as well as units. 00106 00107 If mode="summary", verbose=True and the image contains multiple beams, the output, 00108 will contain information on every beam in the dataset. If mode="summary", 00109 verbose=False and the image has multiple beams, only a brief summary of 00110 beams for each polarization is listed. In this 00111 case, the beams with the maximum area, the minimum area, and the median area for 00112 each polarization are listed. If mode is not "summary" and/or the image does not 00113 have multiple beams, verbose is not used. 00114 00115 Examples: 00116 00117 1) get the clean beam from one image and put it in a second image 00118 00119 Get the clean beam from image1 into hdvalue 00120 imagename = 'image1.im'; mode = 'get'; hdkey = 'beam' 00121 hdvalue = imhead() 00122 print hdvalue # to see values 00123 00124 To then put the clean beam into image2 00125 imagename = 'image2.im', mode = 'put'; imhead() 00126 00127 2) Most output values are dictionaries: 00128 00129 00130 mode = 'get'; hdkey = 'maxpos'; aa = imhead() 00131 00132 would give for the command print aa 00133 {'value': '03:19:48.160, +41.30.42.103, I, 4.88163e+09Hz', 'unit': ''} 00134 print aa['value'] gives 00135 03:19:48.160, +41.30.42.103, I, 4.88163e+09Hz 00136 print aa['value'[1][0:12] gives 03:19:48.160 00137 00138 00139 mode = 'get'; hdkey = 'crpix1'; aa = imhead() 00140 00141 would give for the command print aa 00142 {'value': '128.0', 'unit': ''} 00143 print aa['value'] gives 00144 128.0 (a string) 00145 00146 3) The use of put is a bit more straight-forward 00147 00148 mode = 'put'; hdkey = 'crpix1'; hdvalue = '200'; imhead() 00149 then 00150 mode = 'get'; hdkey = 'crpix1'; aa = imhead() would give 00151 {'value': '200.0', 'unit': ''} 00152 00153 00154 00155 """ 00156 00157 # 00158 # The following is work around to avoid a bug with current python translation 00159 # 00160 mytmp = {} 00161 00162 mytmp['imagename'] = imagename 00163 mytmp['mode'] = mode 00164 mytmp['hdkey'] = hdkey 00165 mytmp['hdvalue'] = hdvalue 00166 mytmp['hdtype'] = hdtype 00167 mytmp['hdcomment'] = hdcomment 00168 mytmp['verbose'] = verbose 00169 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00170 trec = casac.utils().torecord(pathname+'imhead.xml') 00171 00172 casalog.origin('imhead') 00173 if trec.has_key('imhead') and casac.utils().verify(mytmp, trec['imhead']) : 00174 result = task_imhead.imhead(imagename, mode, hdkey, hdvalue, hdtype, hdcomment, verbose) 00175 00176 else : 00177 result = False 00178 return result