/usr/share/doc/stilts/sun256/sec4.2.html is in stilts-doc 3.1.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="sun-style.css">
<title>Table I/O</title>
</head>
<body>
<hr>
<a href="jytable.html">Next</a> <a href="jyrun.html">Previous</a> <a href="jystilts.html">Up</a> <a href="index.html">Contents</a> <br> <b>Next: </b><a href="jytable.html">Table objects</a><br>
<b>Up: </b><a href="jystilts.html">JyStilts - STILTS from Python</a><br>
<b>Previous: </b><a href="jyrun.html">Running JyStilts</a><br>
<hr>
<h3><a name="sec4.2">4.2 Table I/O</a></h3>
<p>The <code>tread</code> function reads tables from an external location
into JyStilts. Its arguments are as follows:
<pre>
tread(location, fmt='(auto)', random=False)
</pre>
and its return value is a <a href="jytable.html">table object</a>,
which can be interrogated directly, or used in other JyStilts commands.
Usually, the location argument should be a string which gives the
filename or URL at which a table can be found.
You can alternatively use a readable python file (or file-like) object for
the location, but be aware that this may be less efficient on memory.
As with command-line STILTS, the <code>fmt</code> argument
is one of the options in <a href="inFormats.html">Section 5.2.1</a>, but may be
left as the default if the format auto-detectable,
which currently means if the file is in VOTable, FITS, CDF or GBIN format.
The <code>random</code> argument can be used to ensure that the returned file
has random (i.e. not sequential-only) access;
for some table formats the default way of reading them in means that
their rows can only be accessed in sequence.
Depending on what processing you are doing, that may or may not be
satisfactory.
</p>
<p>Examples of reading a table are:
<pre>
>>> import stilts
>>> t1 = stilts.tread('cat.fits')
>>> t2 = stilts.tread(open('cat.fits', 'rb')) # less efficient
>>> t3 = stilts.tread('data.csv', fmt='csv', random=True)
</pre>
</p>
<p>The most straightforward way to write a table
(presumably the result of one or a sequence of JyStilts commands)
is using the <code>write</code> table method:
<pre>
write(self, location=None, fmt='(auto)')
</pre>
The <code>location</code> gives either a string which is a filename,
or a writable python file (or file-like) object.
Again, use of a filename is preferred as it may(?) be more efficient.
If no location is supplied, the table will be written to standard output
(useful for inspection, but a bad idea for binary formats or very large tables).
The <code>fmt</code> argument is one of the output formats in
<a href="outFormats.html">Section 5.2.2</a>, but may be left as the default if the
format can be guessed from the filename.
</p>
<p>Examples of writing a table are:
<pre>
>>> table.write('out.fits')
>>> table.write(open('out.fits', 'wb')) # less efficient?
>>> table.write('catalogue.dat', fmt='csv')
>>> table.write() # display to stdout
</pre>
</p>
<p>Often it's convenient to combine examining the table with filtering
steps, for instance:
<pre>
>>> table.every(100).write()
</pre>
would write only every hundredth row, and
<pre>
>>> (table.cmd_sorthead(10, 'BMAG')
... .cmd_select('!NULL_VMAG')
... .cmd_keepcols('BMAG VMAG')
... .write())
</pre>
would write only the BMAG and VMAG columns
for the ten rows in which VMAG is non-null with the lowest BMAG values.
</p>
<p>You can also read and write multiple tables, if you use a table
format for which that is appropriate.
This generally means FITS (which can store tables in multiple extensions)
or VOTable (which can store multiple TABLE elements in one document).
This is done using the <code>treads</code> and <code>twrites</code> functions.
The functions look like this:
<pre>
treads(location, fmt='(auto)', random=False)
twrites(tables, location=None, fmt='(auto)')
</pre>
These are similar to the <code>tread</code> and <code>twrite</code> functions,
except that <code>treads</code> returns a list of tables rather than
a single table, and <code>twrites</code>'s <code>tables</code> argument is
an iterable over tables rather than a single table.
Here is an example of reading multiple tables from a multi-extension FITS
file, counting the rows in each, and then writing them out to a multi-TABLE
VOTable file:
<pre>
import stilts
tables = stilts.treads('multi.fits')
print([t.getRowCount() for t in tables])
stilts.twrites(tables, 'multi.vot', fmt='votable')
</pre>
</p>
<hr><a href="jytable.html">Next</a> <a href="jyrun.html">Previous</a> <a href="jystilts.html">Up</a> <a href="index.html">Contents</a> <br> <b>Next: </b><a href="jytable.html">Table objects</a><br>
<b>Up: </b><a href="jystilts.html">JyStilts - STILTS from Python</a><br>
<b>Previous: </b><a href="jyrun.html">Running JyStilts</a><br>
<hr><i>STILTS - Starlink Tables Infrastructure Library Tool Set<br>Starlink User Note256<br>STILTS web page:
<a href="http://www.starlink.ac.uk/stilts/">http://www.starlink.ac.uk/stilts/</a><br>Author email:
<a href="mailto:m.b.taylor@bristol.ac.uk">m.b.taylor@bristol.ac.uk</a><br>Mailing list:
<a href="mailto:topcat-user@jiscmail.ac.uk">topcat-user@jiscmail.ac.uk</a><br></i></body>
</html>
|