However this manual makes no attempt to introduce the OO terminology, and its complete understanding is not really necessary in order to use the AstroAsciiData module . The user can simply stick to a strictly phenomenological approach by looking at the examples and transferring them to his/her own applications. Nevertheless the OO terms are used to structure this section of the manual.
Usage
open(filename, null=None, delimiter=None, comment_char=None)
Parameters
Name | Type | Default | Description |
filename | string | - | the name of the ASCII |
table file to be loaded | |||
null | string | ['*','NULL', 'Null', 'None'] | the character/string |
representing a null-entry | |||
delimiter | string | `` `` | the delimiter separating |
columns | |||
comment_char | string | '#' | the character/string |
indicating a comment |
Return
- an AsciiData object
Examples
# # Some objects in the GOODS field # unknown 189.2207323 62.2357983 26.87 0.32 galaxy 189.1408929 62.2376331 24.97 0.15 star 189.1409453 62.1696844 25.30 0.12 galaxy 188.9014716 62.2037839 25.95 0.20The command sequence is:
>>> example = asciidata.open('example.txt') >>> print example # # Some objects in the GOODS field # unknown 189.2207323 62.2357983 26.87 0.32 galaxy 189.1408929 62.2376331 24.97 0.15 star 189.1409453 62.1696844 25.30 0.12 galaxy 188.9014716 62.2037839 25.95 0.20
@ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20
Load and print:
>>> example2 = asciidata.open('example2.txt', null='*', \ delimiter='$', comment_char='@') >>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20
This function creates an empty AsciiData object in the 'plain' format, which means that the column information is not part of the default output. The dimension of the AsciiData object as well as the delimiter separating the elements is specified as input.
Usage
create(ncols, nrows, null=None, delimiter=None)
Parameters
Name | Type | Default | Description |
ncols | int | - | number of columns to be created |
nrows | int | - | number of rows to be created |
null | string | 'Null' | the character/string representing a null-entry |
delimiter | string | `` `` | the delimiter separating the columns |
Return
- an AsciiData object in the 'plain' format
Examples
>>> example3 = asciidata.create(3,2) >>> print (example3) Null Null Null Null Null Null
>>> example4 = asciidata.create(3,2,delimiter='|', null='<*>') >>> print (example4) <*> | <*> | <*> <*> | <*> | <*>
Usage
createSEx(ncols, nrows, null=None, delimiter=None)
Parameters
Name | Type | Default | Description |
ncols | int | - | number of columns to be created |
nrows | int | - | number of rows to be created |
null | string | 'Null' | the character/string representing a null-entry |
delimiter | string | `` `` | the delimiter separating the columns |
Return
- an AsciiData object in the SExtractor catalogue format
Examples
>>> example5 = asciidata.createSEx(3,2) >>> print example5 # 1 column1 # 2 column2 # 3 column3 Null Null Null Null Null Null
>>> example6 = asciidata.createSEx(3,2,delimiter='|', null='<*>') >>> print example6 # 1 column1 # 2 column2 # 3 column3 <*>| <*>| <*> <*>| <*>| <*>
Data
filename | string | file name associated to the object |
ncols | int | number of columns |
nrows | int | number of rows |
Examples
>>> example3 = asciidata.create(100,100) >>> for cindex in range(example3.ncols): ... for rindex in range(example3.nrows): ... example3[cindex][rindex] = do_something(rindex, rindex) ...
>>> print example2.filename example2.txt >>> newname = example2.filename + '.old' >>> print newname example2.txt.old >>> example2.writeto(newname)
Usage
adata_column = adata_object[col_spec]
or
adata_column = operator.getitem(adata_object, col_spec)
Parameters
col_spec | string/int | column specification, either by column name or column number |
Return
- an AsciiColumn instance
Examples
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> aad_col = example[1] >>> print aad_col Column: column2 1.0 9.5 3.5 >>>
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> ad_col = operator.getitem(example, 'column1') >>> print ad_col Column: column1 1 2 3 >>> ad_col[1] = 'new!' >>> print ad_col Column: column1 1 new! 3 >>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 new! 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>>
Usage
adata_object[col_spec] = adata_column
or
operator.setitem(adata_object, col_spec, adata_column)
Parameters
col_spec | string/int | column specification, either by column name or column number |
adata_column | AsciiColumn | the AsciiColumn instance to replace the previous column |
Return
-
Examples
>>> exa_1 = asciidata.open('some_objects.cat') >>> exa_2 = asciidata.open('some_objects_2.cat', delimiter='|', comment_char='@', null='*') >>> print exa_1 # # most important objects # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> print exa_2 @ @ @ 10| 0.0| pink | 130.3757| 69.87343 25| 5.3| green | 130.5931| 69.89343 98| 3.5| *| 130.2984| 69.30948 >>> exa_1[2] = exa_2[2] >>> print exa_1 # # most important objects # 1 1.0 pink 23.08932 -19.34509 2 9.5 green 23.59312 -19.94546 3 3.5 Null 23.19843 -19.23571 >>>
By default the header comments are always written to the file, the column info only for the SExtractor format.
Usage
adata_object.writeto(filename, colInfo, headComment)
Parameters
Name | Type | Default | Description |
filename | string | - | the filename to save the AsciiData object to |
colInfo | int | None | write column info () or not() |
headComment | int | None | write header comment () or not() |
Return
-
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2.writeto('newfile.txt') >>> > more newfile.txt @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20
Usage
aad_object.writetofits(fits_name=None)
Parameters
fits_name | string | the name of the fits-file |
Return
- the fits file to which the AsciiData instance was written
Examples
test>ls some_objects.cat test>python Python 2.4.2 (#1, Nov 10 2005, 11:34:38) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import asciidata >>> exa = asciidata.open('some_objects.cat') >>> fits_name = exa.writetofits() >>> fits_name 'some_objects.fits' >>> test>ls some_objects.cat some_objects.fits test>
test>ls some_objects.cat test>python Python 2.4.2 (#1, Nov 10 2005, 11:34:38) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import asciidata >>> exa = asciidata.open('some_objects.cat') >>> fits_name = exa.writetofits('test.fits') >>> fits_name 'test.fits' >>> test>ls some_objects.cat test.fits test>
Usage
aad_object.writetohtml(html_name=None, tr_attr=None, td_attr=None)
Parameters
html_name | string | the name of the html-file |
tr_attr | string | attribute string for the tr-tag |
td_attr | string | attribute string for the td-tag |
Return
- the name of the html-file
Examples
>>> exa = asciidata.open('some_objects.cat') >>> exa.writetohtml() 'some_objects.html' >>> test>more 'some_objects.html' <tr><td> 1</td><td> 1.0</td><td> red</td><td> 23.08932</td><td>-19.34509</td></tr> <tr><td> 2</td><td> 9.5</td><td>blue</td><td> 23.59312</td><td>-19.94546</td></tr> <tr><td> 3</td><td> 3.5</td><td>blue</td><td> 23.19843</td><td>-19.23571</td></tr> test>
>>> exa = asciidata.open('some_objects.cat') >>> html_name = exa.writetohtml('mytab.tab',tr_attr='id="my_tr"',td_attr='bgcolor="RED"') >>> print html_name mytab.tab >>> test>more mytab.tab <tr id="my_tr"><td bgcolor="RED"> 1</td><td bgcolor="RED"> 1.0</td><td bgcolor="RED"> red</td><td bgcolo r="RED"> 23.08932</td><td bgcolor="RED">-19.34509</td></tr> <tr id="my_tr"><td bgcolor="RED"> 2</td><td bgcolor="RED"> 9.5</td><td bgcolor="RED"> blue</td><td bgcolo r="RED"> 23.59312</td><td bgcolor="RED">-19.94546</td></tr> <tr id="my_tr"><td bgcolor="RED"> 3</td><td bgcolor="RED"> 3.5</td><td bgcolor="RED"> blue</td><td bgcolo r="RED"> 23.19843</td><td bgcolor="RED">-19.23571</td></tr> test>
Usage
aad_object.writetolatex(latex_name=None)
Parameters
latex_name | string | the name of the latex-file |
Return
- the name of the latex-file
Examples
>>> exa = asciidata.open('some_objects.cat') >>> latex_name = exa.writetolatex('latex.tb') >>> print latex_name latex.tb >>> test>more latex.tb 1& 1.0& red& 23.08932&-19.34509\\ 2& 9.5&blue& 23.59312&-19.94546\\ 3& 3.5&blue& 23.19843&-19.23571\\ test>
However the fast algorithm can break, e.g. when sorting an already sorted table (e.g. descending) in the opposite direction (ascending). Then the maximum recursion depth of python can be reached, causing a failure. In addition, fast recursive algorithms introduce random swaps of rows, which is counterproductive if the desired result of the sort process can only be reached with consequtive sortings on different columns (see examples 3 and 4 below).
In these cases a slower sorting algorithm must be used which is evoked with the parameter ordered=1.
Usage
adata_object.sort(colname, descending=0, ordered=0)
Parameters
colname | string/integer | the specification of the sort column |
descending | integer | sort in ascending () or descending () order |
ordered | integer | use the fast () algorithm or the slow () |
which avoids unnecessary row swaps |
Return
-
Examples
>>> sort = asciidata.open('sort_objects.cat') >>> print sort 1 0 1 1 2 1 0 3 3 1 2 4 4 0 0 2 5 1 2 1 6 0 0 3 7 0 2 4 8 1 1 2 9 0 1 5 10 1 2 6 11 0 0 6 12 1 1 5 >>> sort.sort(1) >>> print sort 1 0 1 1 6 0 0 3 9 0 1 5 11 0 0 6 7 0 2 4 4 0 0 2 12 1 1 5 2 1 0 3 10 1 2 6 3 1 2 4 5 1 2 1 8 1 1 2 >>>
>>> sort.sort(0, descending=1) >>> print sort 12 1 1 5 11 0 0 6 10 1 2 6 9 0 1 5 8 1 1 2 7 0 2 4 6 0 0 3 5 1 2 1 4 0 0 2 3 1 2 4 2 1 0 3 1 0 1 1 >>>
>>> sort.sort(2, ordered=1) >>> sort.sort(1, ordered=1) >>> print sort 11 0 0 6 6 0 0 3 4 0 0 2 9 0 1 5 1 0 1 1 7 0 2 4 2 1 0 3 12 1 1 5 8 1 1 2 10 1 2 6 5 1 2 1 3 1 2 4 >>>
>>> sort.sort(2, ordered=0) >>> sort.sort(1, ordered=0) >>> print sort 1 0 1 1 4 0 0 2 7 0 2 4 11 0 0 6 9 0 1 5 6 0 0 3 12 1 1 5 2 1 0 3 3 1 2 4 10 1 2 6 5 1 2 1 8 1 1 2 >>>
Usage
len(aad_object)
Parameters
-
Return
- the length of the AsciiData instance
Examples
>>> exa = asciidata.open('some_objects.cat') >>> print exa # # most important objects # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> length = len(exa) >>> print length 5 >>>
Usage
for iter in aad_object:
...
Parameters
-
Return
-
Examples
>>> exa = asciidata.open('sort_objects.cat') >>> for col in exa: ... print col.colname ... column1 column2 column3 column4 >>>
Usage
adata_object.append(col_name)
Parameters
col_name | string | the name of the new column |
Return
- the number of the columns created
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> cnum = example2.append('newcolumn') >>> print cnum 5 >>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 $ * galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 $ * star $ 189.1409453 $ 62.1696844 $ 25.30 $ * $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 $ *
Usage
str(adata_object)
Parameters
-
Return
- the string representing the AsciiData object
Examples
>>> print str(example2) @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20
>>> big_string = str(example2) >>> print big_string @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20
Usage
del adata_obj[col_spec]
Parameters
col_spec | string/int | column specification either by name or by the column number |
Return
-
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> del example2['column5'] >>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 galaxy $ * $ 62.2376331 $ 24.97 star $ 189.1409453 $ 62.1696844 $ 25.30 * $ 188.9014716 $ * $ 25.95
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> del example2[1] >>> print example2 @ @ Some objects in the GOODS field @ unknown $ 62.2357983 $ 26.87 $ 0.32 galaxy $ 62.2376331 $ 24.97 $ 0.15 star $ 62.1696844 $ 25.30 $ * * $ * $ 25.95 $ 0.20
Usage
adata_obj.delete(start, end=start+1)
Parameters
start | int | the first row to be deleted |
end | int | the first row not to be deleted |
Return
-
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2.delete(1) >>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2.delete(0,2) >>> print example2 @ @ Some objects in the GOODS field @ star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20
Usage
adata_obj.strip(x=None)
Parameters
x | int/float/string | filling value which indicates a superfluous entry |
Return
-
Examples
>>> print example # # # Null Null Null Null 0 0 Null 1 Null 9 8 0 Null Null Null Null Null Null Null Null >>> example.strip() >>> print example # # # 0 0 Null 1 Null 9 8 0 >>>
>>> print example # # # -1 -1 -1 -1 0 0 -1 1 -1 9 8 0 -1 -1 -1 -1 -1 -1 -1 -1 >>> example.strip(-1) >>> print example # # # 0 0 -1 1 -1 9 8 0 >>>
Usage
adata_obj.lstrip(x=None)
Parameters
x | int/float/string | filling value which indicates a superfluous entry |
Return
-
Examples
>>> print example # # # Null Null Null Null 0 0 Null 1 Null 9 8 0 Null Null Null Null Null Null Null Null >>> example.lstrip() >>> print example # # # 0 0 Null 1 Null 9 8 0 Null Null Null Null Null Null Null Null
>>> print example # # # -1 -1 -1 -1 0 0 -1 1 -1 9 8 0 -1 -1 -1 -1 -1 -1 -1 -1 >>> example.lstrip(-1) >>> print example # # # 0 0 -1 1 -1 9 8 0 -1 -1 -1 -1 -1 -1 -1 -1 >>>
Usage
adata_obj.rstrip(x=None)
Parameters
x | int/float/string | filling value which indicates a superfluous entry |
Return
-
Examples
>>> print example # # # Null Null Null Null 0 0 Null 1 Null 9 8 0 Null Null Null Null Null Null Null Null >>> example.rstrip() >>> print example # # # Null Null Null Null 0 0 Null 1 Null 9 8 0 >>>
>>> print example # # # -1 -1 -1 -1 0 0 -1 1 -1 9 8 0 -1 -1 -1 -1 -1 -1 -1 -1 >>> example.rstrip(-1) >>> print example # # # -1 -1 -1 -1 0 0 -1 1 -1 9 8 0 >>>
Usage
adata_obj.find(col_name)
Parameters
col_name | string | the name of the column |
Return
- the column number or -1 if the column does not exist
Examples
>>> example2 = asciidata.open('example2.txt', null='*', \ delimiter='$', comment_char='@') >>> cnum = example2.find('column2') >>> cnum 1 >>>
>>> example2 = asciidata.open('example2.txt', null='*', \ delimiter='$', comment_char='@') >>> cnum = example2.find('not_there') >>> cnum -1 >>>Obviously the AsciiData object example2 does not have a column with this name.
Usage
adata_obj.flush()
Parameters
-
Return
-
Examples
work>more example.txt # # Some objects in the GOODS field # unknown 189.2207323 62.2357983 26.87 0.32 galaxy 189.1408929 62.2376331 24.97 0.15 star 189.1409453 62.1696844 25.30 0.12 galaxy 188.9014716 62.2037839 25.95 0.20 work>python Python 2.4.2 (#5, Oct 21 2005, 11:12:03) [GCC 3.3.2] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> import asciidata >>> example = asciidata.open('example.txt') >>> del example[4] >>> example.flush() >>> work>more example.txt # # Some objects in the GOODS field # unknown 189.2207323 62.2357983 26.87 galaxy 189.1408929 62.2376331 24.97 star 189.1409453 62.1696844 25.30 galaxy 188.9014716 62.2037839 25.95
The focus of the method clearly is the use in interactive work. All information provided can be retrieved by AsciiColumn methods in a machine readable format as well.
The overview contains:
Usage
adata_object.info()
Parameters
-
Return
-
Examples
>>> example = asciidata.open('example.txt') >>> print example.info() File: example.txt Ncols: 4 Nrows: 4 Delimiter: None Null value: ['Null', 'NULL', 'None', '*'] Comment: # Column name: column1 Column type: <type 'str'> Column format: ['% 7s', '%7s'] Column null value : ['Null'] Column name: column2 Column type: <type 'float'> Column format: ['% 11.7f', '%12s'] Column null value : ['Null'] Column name: column3 Column type: <type 'float'> Column format: ['% 10.7f', '%11s'] Column null value : ['Null'] Column name: column4 Column type: <type 'float'> Column format: ['% 5.2f', '%6s'] Column null value : ['Null']
Usage
adata_object.insert(nrows, start=0)
Parameters
nrows | int | number of rows to be inserted |
start | int | index position of the first inserted column |
Return
-
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2.insert(2,1) >>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 * $ * $ * $ * $ * * $ * $ * $ * $ * galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20
Usage
adata_object.newcomment_char(comment_char)
Parameters
comment_char | string | the string to indicate a comment |
Return
-
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2.newcomment_char('!!') >>> print example2 !! !! Some objects in the GOODS field !! unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20
Usage
adata_object.newdelimiter(delimiter)
Parameters
delimiter | string | the new delimiter to separate columns |
Return
-
Examples
<>
':
>>> print example2 !! !! Some objects in the GOODS field !! unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2.newdelimiter('<>') >>> print example2 !! !! Some objects in the GOODS field !! unknown <> 189.2207323 <> 62.2357983 <> 26.87 <> 0.32 galaxy <> * <> 62.2376331 <> 24.97 <> 0.15 star <> 189.1409453 <> 62.1696844 <> 25.30 <> * * <> 188.9014716 <> * <> 25.95 <> 0.20
Usage
adata_object.newnull(newnull)
Parameters
newnull | string | the representation for Null-entries |
Return
-
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2.newnull('NaN') >>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ NaN $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ NaN NaN $ 188.9014716 $ NaN $ 25.95 $ 0.20
Change the format of the AsciiData object to 'plain'. As a consequence the column info (names, units and comments) are no longer part of the output when e.g. writing the object to a file.
Usage
adata_object.toplain()
Parameters
-
Return
-
Examples
>>> SExample = asciidata.open('SExample.cat') >>> print SExample # 1 NUMBER Running object number # 2 XWIN_IMAGE Windowed position estimate along x [pixel] # 3 YWIN_IMAGE Windowed position estimate along y [pixel] # 4 ERRY2WIN_IMAGE Variance of windowed pos along y [pixel**2] # 5 AWIN_IMAGE Windowed profile RMS along major axis [pixel] # 6 ERRAWIN_IMAGE RMS windowed pos error along major axis [pixel] # 7 BWIN_IMAGE Windowed profile RMS along minor axis [pixel] # 8 ERRBWIN_IMAGE RMS windowed pos error along minor axis [pixel] # 9 MAG_AUTO Kron-like elliptical aperture magnitude [mag] # 10 MAGERR_AUTO RMS error for AUTO magnitude [mag] # 11 CLASS_STAR S/G classifier output 1 100.523 11.911 2.783 0.0693 2.078 0.0688 -5.3246 0.0416 0.00 19 2 100.660 4.872 7.005 0.1261 3.742 0.0989 -6.4538 0.0214 0.00 27 3 131.046 10.382 1.965 0.0681 1.714 0.0663 -4.6836 0.0524 0.00 17 4 338.959 4.966 11.439 0.1704 4.337 0.1450 -7.1747 0.0173 0.00 25 5 166.280 3.956 1.801 0.0812 1.665 0.0769 -4.0865 0.0621 0.00 25 >>> SExample.toplain() >>> print SExample 1 100.523 11.911 2.783 0.0693 2.078 0.0688 -5.3246 0.0416 0.00 19 2 100.660 4.872 7.005 0.1261 3.742 0.0989 -6.4538 0.0214 0.00 27 3 131.046 10.382 1.965 0.0681 1.714 0.0663 -4.6836 0.0524 0.00 17 4 338.959 4.966 11.439 0.1704 4.337 0.1450 -7.1747 0.0173 0.00 25 5 166.280 3.956 1.801 0.0812 1.665 0.0769 -4.0865 0.0621 0.00 25
This method changes the format of the AsciiData object to 'SExtractor'. This means that for all output to the screen or to a file the column info precedes the table data.
Usage
adata_object.toSExtractor()
Parameters
-
Return
-
Examples
>>> example = asciidata.open('foo.txt') >>> print example 1 stars 1.0 2 galaxies 2.0 3 qsos 3.0 >>> example[0].rename('NUM') >>> example[1].rename('CLASS') >>> example[2].rename('MAG') >>> example.toSExtractor() >>> example.writeto('bar.txt') >>> ~> more bar.txt # 1 NUM # 2 CLASS # 3 MAG 1 stars 1.0 2 galaxies 2.0 3 qsos 3.0
Usage
aad_object.tofits()
Parameters
-
Return
- a table fits extension
Examples
--> catfits exa_table.fits EXT# FITSNAME FILENAME EXTVE DIMENS BITPI OBJECT 0 exa_table.fit 16 1 BINTABLE BEAM_1A 14Fx55R 1 --> exa = asciidata.open('some_objects.cat') --> tab_hdu = exa.tofits() --> tab_all = pyfits.open('exa_table.fits', 'update') --> tab_all.append(tab_hdu) --> tab_all.close() --> catfits exa_table.fits EXT# FITSNAME FILENAME EXTVE DIMENS BITPI OBJECT 0 exa_table.fit 16 1 BINTABLE BEAM_1A 14Fx55R 1 2 BINTABLE 5Fx3R -->
adata_object['diff1']
) or the column index
(such as e.g. adata_object[3]
).
Data
colname | string | file name associated to the object |
Usage
elem = acol_object[row]
or
elem = operator.getitem(acol_object, row)
Parameters
row | int | the row number of the entry to be replaced |
Return
- the requested column element
Examples
>>> exa = asciidata.open('some_objects.cat') >>> print exa # # most important objects # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> elem = exa[2][0] >>> print elem red >>>
Usage
acol_object[row] = an_entry
or
operator.setitem(acol_object, row, adata_column)
Parameters
row | int | the row number of the entry to be replaced |
an_entry | string/integer/float | the data to replace the previous entry |
Return
-
Examples
>>> print exa # # most important objects # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> exa[2][2] = 'green' >>> print exa # # most important objects # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 green 23.19843 -19.23571 >>>
Usage
len(ac_object)
Parameters
-
Return
- the length (= number of rows) of the AsciiColumn
Examples
>>> exa = asciidata.open('some_objects.cat') >>> print exa # # most important objects # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> print len(exa[4]) 3 >>>
Usage
for element in acolumn_object:
...
Parameters
-
Return
-
Examples
>>> print exa # # most important objects # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> acol = exa[4] >>> for element in acol: ... print element ... -19.34509 -19.94546 -19.23571 >>>
Usage
adata_object[colname].copy()
Parameters
-
Return
- the copy of the column
Examples
>>> print example1 # # Some objects in the GOODS field # unknown 189.2207323 62.2357983 26.87 0.32 galaxy * 62.2376331 24.97 0.15 star 189.1409453 62.1696844 25.30 0.12 galaxy 188.9014716 62.2037839 25.95 0.20 >>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example1[1] = example2[4].copy() >>> print example1 # # Some objects in the GOODS field # unknown 0.32 62.2357983 26.87 0.32 galaxy 0.15 62.2376331 24.97 0.15 star * 62.1696844 25.30 0.12 galaxy 0.20 62.2037839 25.95 0.20
Usage
adata_object[colname].get_format()
Parameters
-
Return
- the format of the AsciiColumn object
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2[0].get_format() '% 9s'
Usage
adata_object[colname].get_type()
Parameters
-
Return
- the type of the AsciiColumn
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2[0].get_type() <type 'str'>
Usage
acolumn_object.get_nrows()
Parameters
-
Return
- the number of rows
Examples
>>> exa = asciidata.open('sort_objects.cat') >>> exa['column1'].get_nrows() 12 >>> print exa 1 0 1 1 2 1 0 3 3 1 2 4 4 0 0 2 5 1 2 1 6 0 0 3 7 0 2 4 8 1 1 2 9 0 1 5 10 1 2 6 11 0 0 6 12 1 1 5 >>>
Usage
acolumn_object.get_unit()
Parameters
-
Return
- the unit of the column
Examples
test>more some_objects.cat # 1 NUMBER Running object number # 2 X_Y # 3 COLOUR # 4 RA Barycenter position along world x axis [deg] # 5 DEC Barycenter position along world y axis [deg] # # most important objects # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 test>python Python 2.4.2 (#1, Nov 10 2005, 11:34:38) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import asciidata >>> exa = asciidata.open('some_objects.cat') >>> print exa['RA'].get_unit() deg >>>
Its focus is on interactive work. All information can also be retrieved by other methods in a machine readable format.
Usage
adata_object[colname].info()
Parameters
-
Return
- the overview on the AsciiColumn object
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> print example2[1].info() Column name: column2 Column type: <type 'float'> Column format: ['% 11.7f', '%12s'] Column null value : ['*']
Usage
adata_object[colname].reformat('newformat')
Parameters
new_format | string | the new format of the AsciiColumn |
Return
-
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2[1].reformat('% 6.2f') >>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.22 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.14 $ 62.1696844 $ 25.30 $ * * $ 188.90 $ * $ 25.95 $ 0.20
Usage
adata_object[colname].rename('newname')
Parameters
newname | string | the filename to save the AsciiData object to |
Return
-
Examples
>>> print example2[3].info() Column name: column4 Column type: <type 'float'> Column format: ['% 5.2f', '%6s'] Column null value : ['*'] >>> example2[3].rename('newname') >>> print example2[3].info() Column name: newname Column type: <type 'float'> Column format: ['% 5.2f', '%6s'] Column null value : ['*']
Usage
adata_object[colname].tonumarray()
Parameters
-
Return
- the AsciiColumn content in a numarray object.
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> numarr = example2[3].tonumarray() >>> numarr array([ 26.87, 24.97, 25.3 , 25.95])
Usage
adata_object[colname].tonumpy()
Parameters
-
Return
- the AsciiColumn content in a numpy (-masked) object.
Examples
>>> print example @ @ Some objects in the GOODS field @ unknown $ 189.2207323$ 62.2357983$ 26.87$ 0.32 galaxy $ Null$ 62.2376331$ 24.97$ 0.15 star $ 189.1409453$ 62.1696844$ 25.30$ Null Null$ 188.9014716$ Null$ 25.95$ 0.20 >>> nump = example[3].tonumpy() >>> print nump [ 26.87 24.97 25.3 25.95]
>>> print example @ @ Some objects in the GOODS field @ unknown $ 189.2207323$ 62.2357983$ 26.87$ 0.32 galaxy $ Null$ 62.2376331$ 24.97$ 0.15 star $ 189.1409453$ 62.1696844$ 25.30$ Null Null$ 188.9014716$ Null$ 25.95$ 0.20 >>> nump = example[2].tonumpy() >>> type(nump) <class 'numpy.core.ma.MaskedArray'> >>> nump[3] array(data = 999999, mask = True, fill_value=999999)
Usage
adata_object[colname].set_unit(acol_unit)
Parameters
acol_unit | string | the new column unit |
Return
-
Examples
>>> print sm # 1 NUMBER Running object number # 2 X_IMAGE Object position along x [pixel] # 3 Y_IMAGE Object position along y [pixel] # 4 FLAGS Extraction flags 2 379.148 196.397 3 3 177.377 199.843 4 1 367.213 123.803 8 >>> sm['FLAGS'].set_unit('arbitrary') >>> print sm # 1 NUMBER Running object number # 2 X_IMAGE Object position along x [pixel] # 3 Y_IMAGE Object position along y [pixel] # 4 FLAGS Extraction flags [arbitrary] 2 379.148 196.397 3 3 177.377 199.843 4 1 367.213 123.803 8 >>>
Usage
adata_object[colname].set_colcomment(acol_comment)
Parameters
acol_comment | string | the new column comment |
Return
-
Examples
>>> print sm # 1 NUMBER Running object number # 2 X_IMAGE Object position along x [pixel] # 3 Y_IMAGE Object position along y [pixel] # 4 FLAGS Extraction flags [arbitrary] 2 379.148 196.397 3 3 177.377 199.843 4 1 367.213 123.803 8 >>> sm['FLAGS'].set_colcomment('Quality numbers') >>> print sm # 1 NUMBER Running object number # 2 X_IMAGE Object position along x [pixel] # 3 Y_IMAGE Object position along y [pixel] # 4 FLAGS Quality numbers [arbitrary] 2 379.148 196.397 3 3 177.377 199.843 4 1 367.213 123.803 8 >>>
Usage
adata_object[colname].get_colcomment()
Parameters
-
Return
- the comment string of the column
Examples
>>> cocomm = sm['X_IMAGE'].get_colcomment() >>> print cocomm Object position along x >>>
Usage
header_entry = adata_object.header[index]
or
header_entry = operator.getitem(adata_object.header, index)
Parameters
index | int | the index of the item to retrieve |
Return
- one entry of the header
Examples
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> header_entry = example.header[1] >>> print header_entry most important sources!! >>>
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> example.header[2] '\n' >>>
Usage
adata_object.header[index] = new_entry
or
header_entry = operator.setitem(adata_object.header, index, new_entry)
Parameters
index | int | the index of the item to be set |
new_entry | string | the new content of the header item |
Return
-
Examples
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> example.header[1] = 'a new header entry?' >>> print example # #a new header entry? # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>>
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> example.header[2] = ' >>> dont forget leading spaces if desired!' >>> print example # # most important sources!! # >>> dont forget leading spaces if desired! 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>>
Usage
del adata_object.header[index]
or
operator.delitem(adata_object.header, index)
Parameters
index | int | the index of the item to be deleted |
Return
-
Examples
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> del example.header[1] >>> print example # # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>>
Usage
str(adata_object.header)
Parameters
-
Return
- the string representation of the AsciiHeader instance
Examples
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> print example.header # # most important sources!! # >>>
Usage
len(adata_object.header)
Parameters
-
Return
- the length of the AsciiHeader instance
Examples
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> header_length = len(example.header) >>> header_length 3 >>>
Usage
for element in adata_object.header:
...
Parameters
-
Return
-
Examples
>>> print example @ @Some objects in the GOODS field @ -classification @ -RA @ -DEC @ -MAG @ -extent unknown $ 189.2207323$ 62.2357983$ 26.87$ 0.32 galaxy $ Null$ 62.2376331$ 24.97$ 0.15 star $ 189.1409453$ 62.1696844$ 25.30$ Null Null$ 188.9014716$ Null$ 25.95$ 0.20 >>> for h_entry in example.header: ... print h_entry.strip() ... Some objects in the GOODS field -classification -RA -DEC -MAG -extent >>>
Usage
adata_object.header.reset()
Parameters
-
Return
-
Examples
>>> print example # # most important sources!! # 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>> example.header.reset() >>> print example 1 1.0 red 23.08932 -19.34509 2 9.5 blue 23.59312 -19.94546 3 3.5 blue 23.19843 -19.23571 >>>
Usage
adata_object.header.append(hlist)
Parameters
hlist | string | the list of strings to be appended to the header |
Return
-
Examples
>>> print example2 @ @ Some objects in the GOODS field @ unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2.header.append('Now a header line is appended!') >>> print example2 @ @ Some objects in the GOODS field @ @ Now a header line is appended! unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20 >>> example2.header.append("""And now we try to put ... even a set of lines ... into the header!!""") >>> print example2 @ @ Some objects in the GOODS field @ @ Now a header line is appended! @ And now we try to put @ even a set of lines @ into the header!! unknown $ 189.2207323 $ 62.2357983 $ 26.87 $ 0.32 galaxy $ * $ 62.2376331 $ 24.97 $ 0.15 star $ 189.1409453 $ 62.1696844 $ 25.30 $ * * $ 188.9014716 $ * $ 25.95 $ 0.20