<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://ubarsc.github.io//feed.xml" rel="self" type="application/atom+xml" /><link href="https://ubarsc.github.io//" rel="alternate" type="text/html" /><updated>2026-11-01T03:17:37+00:00</updated><id>https://ubarsc.github.io//feed.xml</id><title type="html">UBARSC - The UB&amp;amp;A Remote Sensing Centre</title><subtitle>Main website for ubarsc</subtitle><entry><title type="html">RIOS 2.1.1</title><link href="https://ubarsc.github.io//ubarsc/update/rios/2026/11/01/rios-2.1.1.html" rel="alternate" type="text/html" title="RIOS 2.1.1" /><published>2026-11-01T03:15:00+00:00</published><updated>2026-11-01T03:15:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/update/rios/2026/11/01/rios-2.1.1</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/update/rios/2026/11/01/rios-2.1.1.html"><![CDATA[<p>RIOS version 2.1.1 was released on 2026-10-05. This is a minor bug fix release, with no
new features.</p>

<p>See <a href="https://www.rioshome.org/en/latest/releasenotes.html">Release Notes</a>
for more information.</p>]]></content><author><name></name></author><category term="ubarsc" /><category term="update" /><category term="RIOS" /><summary type="html"><![CDATA[RIOS version 2.1.1 was released on 2026-10-05. This is a minor bug fix release, with no new features.]]></summary></entry><entry><title type="html">Introducing a TuiView Plugin for linking RatZarr files</title><link href="https://ubarsc.github.io//ubarsc/tutorial/tuiview/ratzarr/2026/09/21/tuiview-plugin-ratzarr.html" rel="alternate" type="text/html" title="Introducing a TuiView Plugin for linking RatZarr files" /><published>2026-09-21T00:00:00+00:00</published><updated>2026-09-21T00:00:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/tutorial/tuiview/ratzarr/2026/09/21/tuiview-plugin-ratzarr</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/tutorial/tuiview/ratzarr/2026/09/21/tuiview-plugin-ratzarr.html"><![CDATA[<h1 id="introduction">Introduction</h1>

<p>In a <a href="../../../../2026/01/26/tuiview-plugins.html">previous post</a> we looked at the
existing TuiView plugins. There is now a new plugin that allows you
to link Raster Attribute Data in .zarr format created by the 
<a href="https://github.com/ubarsc/ratzarr">RatZarr</a> package.</p>

<h1 id="installation">Installation</h1>

<p>See the <a href="../../../../2026/01/26/tuiview-plugins.html">plugin installation instructions</a>
for more detail. The recommended way of installing <code class="language-plaintext highlighter-rouge">tuiview-plugins</code> is from the <a href="https://github.com/ubarsc/tuiview-plugins">git repo</a>:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pip <span class="nb">install </span>git+https://github.com/ubarsc/tuiview-plugins.git
</code></pre></div></div>

<p>You will need to have TuiView installed in your current environment. You can 
then run <code class="language-plaintext highlighter-rouge">tuiviewpluginmgr</code> on the command line. By enabling “RatZarr Query Window plugin”
you will see what your <code class="language-plaintext highlighter-rouge">TUIVIEW_PLUGINS_PATH</code> environment variable needs to be
set to.</p>

<h1 id="requirements">Requirements</h1>

<p>You must have an existing raster file with a Raster Attribute Table. Ideally
this file will have colour columns as TuiView only displays colours that
are part of a Raster Attribute Table within the file. This file needs to 
be loaded into TuiView.</p>

<p>Additionally you should have a .zarr file created by the <a href="https://github.com/ubarsc/ratzarr">RatZarr</a> 
package. This .zarr file should have the same number of rows as the 
Raster Attribute Table in your raster file.</p>

<h1 id="workflow">Workflow</h1>

<p>Once the above requirements are met you should be ready to go. Once you
have the plugin loaded and a raster file with a Raster Attribute Table
in a viewer you can click on the Query Button (<img src="https://raw.githubusercontent.com/ubarsc/tuiview/refs/heads/master/resources/query.png" alt="Query Window" />).
The Query Window is displayed as normal but there are 3 extra buttons:</p>

<ul>
  <li>Link a RatZarr file (<img src="https://raw.githubusercontent.com/ubarsc/tuiview-plugins/refs/heads/master/tuiview_plugins/ratzarr_querywindow/zarr-pink-stacked.svg" alt="QML" width="32" height="32" />)</li>
  <li>Unlink the RatZarr file (<img src="https://raw.githubusercontent.com/ubarsc/tuiview-plugins/refs/heads/master/tuiview_plugins/ratzarr_querywindow/zarr-pink-stacked-cross.svg" alt="QML" width="32" height="32" />)</li>
  <li>Add a Column to the currently linked RatZarr file (<img src="https://raw.githubusercontent.com/ubarsc/tuiview-plugins/refs/heads/master/tuiview_plugins/ratzarr_querywindow/zarr-pink-stacked-add.svg" alt="QML" width="32" height="32" />)</li>
</ul>

<p>Note that you may need to click the 2 arrows to see all the buttons on the toolbar
if your window is small.</p>

<p>When you attempt to link a RatZarr file you will be asked to provide the path:</p>

<p><img src="https://ubarsc.github.io//images/tuiview_ratzarrlink.png" alt="Link RatZarr" /></p>

<p>Note this can be a <code class="language-plaintext highlighter-rouge">s3://</code> style path for a file on S3, although you will need
to have logged into AWS.</p>

<p>Once you have successfully linked, the extra RatZarr columns will appear
after the columns in the Raster Attribute Table:</p>

<p><img src="https://ubarsc.github.io//images/tuiview_ratzarrcols.png" alt="Query Window RatZarr" /></p>

<h1 id="supported-operations">Supported Operations</h1>

<p>Most of the existing functionality with the Query Window should work with columns
from a RatZarr file.</p>

<p>Columns with <code class="language-plaintext highlighter-rouge">width</code> set to greater than one will show the individual elements
separated by a vertical bar (<code class="language-plaintext highlighter-rouge">|</code>).</p>

<p>You can use the RatZarr columns to select rows in the table by expression. The RatZarr
columns can be used in the expression window just the same as columns in the RAT. If 
you expression contains columns with width&gt;1, you can access individual parts of the
sub array with the <code class="language-plaintext highlighter-rouge">zarrcol[..., 0]</code> syntax to access the first subcolumn for example.</p>

<p>It is possible to add a column to either the RAT or RatZarr. Adding columns to the RAT is using
the same Add Column button (<img src="https://raw.githubusercontent.com/ubarsc/tuiview/refs/heads/master/resources/addcolumn.png" alt="Add Column" />) on the toolbar.
Adding columns to the RatZarr file is done through the “Add Column to RatZarr button” (<img src="https://raw.githubusercontent.com/ubarsc/tuiview-plugins/refs/heads/master/tuiview_plugins/ratzarr_querywindow/zarr-pink-stacked-add.svg" alt="QML" width="32" height="32" />).
When you click this button, you will be presented with a dialog asking you about the data
type (allowing you to choose any of the supported Zarr column types), width and name:</p>

<p><img src="https://ubarsc.github.io//images/tuiview_ratzarraddcol.png" alt="Query Window RatZarr" /></p>

<p>Also, you can move the order of the columns so they are intermixed with the columns from 
the raster file. Saving the column order saves to the raster file. TuiView ignores
columns that are not in the raster’s list of column orders when it loads a file.
When a RatZarr file is loaded with those columns, it will then apply the
previously saved order.</p>

<p>You can update a RatZarr column by going into edit mode (<img src="https://raw.githubusercontent.com/ubarsc/tuiview/refs/heads/master/resources/lock.png" alt="Lock" />) 
and right clicking on a RatZarr column header and selecting “Edit Selected Rows in Column” - the 
same as RAT columns. Other RatZarr columns will appear as
variables just the same as in the expression window.</p>

<p>A RatZarr column can be set to receive to receive keyboard edits, but only for columns
where width=1.</p>

<p>You can export a CSV and this will include all RatZarr columns.</p>

<p>A RatZarr column can also be used as a column table lookup into a surrogate
colour table for columns where width=1.</p>

<h1 id="conclusion">Conclusion</h1>

<p>Linking a RAT from a raster file with a RatZarr file is a handy way to leverage
the benefits of both formats. It also makes it possible to save different types
of statistics in separate RatZarr files and only open the necessary ones for each
task making the management of the columns easier.</p>]]></content><author><name></name></author><category term="ubarsc" /><category term="tutorial" /><category term="TuiView" /><category term="RatZarr" /><summary type="html"><![CDATA[Introduction]]></summary></entry><entry><title type="html">RIOS 2.1.0</title><link href="https://ubarsc.github.io//ubarsc/update/rios/2026/09/17/rios-2.1.0.html" rel="alternate" type="text/html" title="RIOS 2.1.0" /><published>2026-09-17T03:00:00+00:00</published><updated>2026-09-17T03:00:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/update/rios/2026/09/17/rios-2.1.0</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/update/rios/2026/09/17/rios-2.1.0.html"><![CDATA[<p>RIOS version 2.1.0 has been released. Major features include better reprojections on
inputs with very large extent, some improvements in error handling and reporting, and
a new doc page on RIOS’s map projection features.</p>

<p>See <a href="https://www.rioshome.org/en/latest/releasenotes.html">Release Notes</a>
for more information.</p>]]></content><author><name></name></author><category term="ubarsc" /><category term="update" /><category term="RIOS" /><summary type="html"><![CDATA[RIOS version 2.1.0 has been released. Major features include better reprojections on inputs with very large extent, some improvements in error handling and reporting, and a new doc page on RIOS’s map projection features.]]></summary></entry><entry><title type="html">pyshepseg 2.0.6 released</title><link href="https://ubarsc.github.io//ubarsc/update/pyshepseg/2026/09/17/pyshepseg-2.0.6.html" rel="alternate" type="text/html" title="pyshepseg 2.0.6 released" /><published>2026-09-17T02:55:00+00:00</published><updated>2026-09-17T02:55:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/update/pyshepseg/2026/09/17/pyshepseg-2.0.6</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/update/pyshepseg/2026/09/17/pyshepseg-2.0.6.html"><![CDATA[<p>pyshepseg 2.0.6 has been released. This release includes more efficient handling of RATs with
a very large number of columns.
More information can be found in the <a href="https://www.pyshepseg.org/en/latest/ReleaseNotes.html">Release Notes</a>.</p>]]></content><author><name></name></author><category term="ubarsc" /><category term="update" /><category term="PyShepSeg" /><summary type="html"><![CDATA[pyshepseg 2.0.6 has been released. This release includes more efficient handling of RATs with a very large number of columns. More information can be found in the Release Notes.]]></summary></entry><entry><title type="html">RatZarr 1.0.3 released</title><link href="https://ubarsc.github.io//ubarsc/update/ratzarr/2026/09/17/ratzarr-1.0.3.html" rel="alternate" type="text/html" title="RatZarr 1.0.3 released" /><published>2026-09-17T02:40:00+00:00</published><updated>2026-09-17T02:40:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/update/ratzarr/2026/09/17/ratzarr-1.0.3</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/update/ratzarr/2026/09/17/ratzarr-1.0.3.html"><![CDATA[<p><a href="https://github.com/ubarsc/ratzarr">RatZarr</a> 1.0.3 has been released</p>

<p>This release includes some efficiency improvements for RATs with a
very large number of columns, and new functions for accessing the Dtype of
each column, and the Zarr attributes attached to the RAT group.</p>]]></content><author><name></name></author><category term="ubarsc" /><category term="update" /><category term="RatZarr" /><summary type="html"><![CDATA[RatZarr 1.0.3 has been released]]></summary></entry><entry><title type="html">Reading results from PostGreSQL directly into numpy arrays</title><link href="https://ubarsc.github.io//ubarsc/tutorial/postgresql/2026/06/29/postgresql-to-numpy.html" rel="alternate" type="text/html" title="Reading results from PostGreSQL directly into numpy arrays" /><published>2026-06-29T22:00:00+00:00</published><updated>2026-06-29T22:00:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/tutorial/postgresql/2026/06/29/postgresql-to-numpy</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/tutorial/postgresql/2026/06/29/postgresql-to-numpy.html"><![CDATA[<h1 id="introduction">Introduction</h1>

<p>Traditionally, Python programs talk to <a href="https://www.postgresql.org/">PostGreSQL</a> using
a tool like <a href="https://www.psycopg.org/">psycopg</a> and loop over the results of a query
doing whatever processing is required for each row returned.
However, this can be slow when many results are returned. It is also painful when 
you want to be able to process the result with numpy or Numba and just need it
read in as quick as possible.
This is possible using the <a href="https://www.postgresql.org/docs/current/sql-copy.html#SQL-COPY-BINARY-FORMAT">COPY TO BINARY</a>
command and some data manipulation.
Note that what follows is a complex dive into binary formats and is not for the faint hearted.
You will be expected to know the data types that are returned from a query.</p>

<h1 id="using-copy-to-binary">Using COPY TO BINARY</h1>

<p><a href="https://www.psycopg.org/psycopg3/docs/basic/copy.html#binary-copy">psycopg’s documentation</a> is a bit
vague about how to copy a query to a binary object. The trick is to use <a href="https://docs.python.org/3/library/io.html#io.BytesIO">io.BytesIO</a> and write each binary chunk as it is returned
from the <a href="https://www.psycopg.org/psycopg3/docs/api/cursors.html#psycopg.Cursor.copy">cursor.copy</a> function:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">result</span> <span class="o">=</span> <span class="n">io</span><span class="p">.</span><span class="n">BytesIO</span><span class="p">()</span>
<span class="k">with</span> <span class="n">curs</span><span class="p">.</span><span class="n">copy</span><span class="p">(</span><span class="s">"COPY (SELECT * FROM my_table) TO STDOUT BINARY"</span><span class="p">)</span> <span class="k">as</span> <span class="n">copy</span><span class="p">:</span>
    <span class="k">for</span> <span class="n">raw</span> <span class="ow">in</span> <span class="n">copy</span><span class="p">:</span>
        <span class="n">result</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">raw</span><span class="p">)</span>
</code></pre></div></div>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Note: you still have to loop over each result row. 
There doesn't appear to be a way of getting all results in one go.
However - this is still faster than processing each row into a tuple etc
</code></pre></div></div>

<h1 id="processing-the-result-with-numpy">Processing the result with numpy</h1>

<p>In the above example, the binary data will be read in to the <code class="language-plaintext highlighter-rouge">result</code> variable. The format
of the resulted binary data is explained in <a href="https://www.postgresql.org/docs/current/sql-copy.html#SQL-COPY-BINARY-FORMAT">the PostGreSQL documentation</a>. 
The first thing to note is that there is a header before the start of the data and a trailer 
at the end of the data. numpy allows us to specify the size of any header, but not the size
of the trailer. To remove the trailer before further processing, run:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">notrailer</span> <span class="o">=</span> <span class="n">result</span><span class="p">.</span><span class="n">getvalue</span><span class="p">()[:</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span>  <span class="c1"># unread the trailer
</span></code></pre></div></div>

<p>Next, the data can be read into a numpy array using the <code class="language-plaintext highlighter-rouge">numpy.frombuffer</code> function
by specifying the <code class="language-plaintext highlighter-rouge">dtype</code> of the result of your query.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Note: You will need to be sure what types are returned from your query 
before determining the dtype.
</code></pre></div></div>

<p>In addition need to understand how PostGreSQL serialises types before you
can interpret the result as a dtype. The <a href="https://www.postgresql.org/docs/current/sql-copy.html#SQL-COPY-BINARY-FORMAT">documentation</a>
points you to <a href="https://github.com/postgres/postgres/tree/master/src/backend/utils/adt">this directory</a>
in the PostGreSQL sources to work out the types. To get you started, below is a table of
commonly used types and how to interpret them with numpy:</p>

<table>
  <thead>
    <tr>
      <th>PostGreSQL Type</th>
      <th>numpy dtype</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>int</td>
      <td>&gt;u4</td>
    </tr>
    <tr>
      <td>float</td>
      <td>&gt;f8</td>
    </tr>
    <tr>
      <td>array</td>
      <td>&gt;u4 (ndims)</td>
    </tr>
    <tr>
      <td> </td>
      <td>&gt;u4 (has null)</td>
    </tr>
    <tr>
      <td> </td>
      <td>&gt;u4 (element type</td>
    </tr>
    <tr>
      <td> </td>
      <td>For each dimension:</td>
    </tr>
    <tr>
      <td> </td>
      <td>&gt;u4 size of dim</td>
    </tr>
    <tr>
      <td> </td>
      <td>&gt;u4 lower bound</td>
    </tr>
    <tr>
      <td> </td>
      <td>Then for each value</td>
    </tr>
    <tr>
      <td> </td>
      <td>&gt;u4 size of value</td>
    </tr>
    <tr>
      <td> </td>
      <td>Then value itself</td>
    </tr>
  </tbody>
</table>

<p>Unfortunately, variable length string data cannot be interpreted by
<code class="language-plaintext highlighter-rouge">numpy.frombuffer</code>. If all your strings are of fixed length you may 
be able to use the <code class="language-plaintext highlighter-rouge">S</code> format specifier along with the length.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Note: the &gt; character before the type tells numpy the data is in big
endian format. PostGreSQL transmits data as big endian.
We will cover converting back to little endian later, but 
just be sure to specify this character otherwise you may not
be able to understand the result...
</code></pre></div></div>

<p>Currently the file header is 19 bytes (as documented in the PostGreSQL documentation). 
This means that the <code class="language-plaintext highlighter-rouge">offset</code> parameter to <code class="language-plaintext highlighter-rouge">numpy.frombuffer</code> must be set to 19.</p>

<p>Also, each row starts with a 16 bit integer (type <code class="language-plaintext highlighter-rouge">&gt;u2</code>) with a count of the
results for that row. Since we provided the query we should be able to ignore this.</p>

<p>To process a result that has 2 floats for each row (‘x’ and ‘y’):</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">data</span> <span class="o">=</span> <span class="n">numpy</span><span class="p">.</span><span class="n">frombuffer</span><span class="p">(</span><span class="n">notrailer</span><span class="p">,</span> 
    <span class="n">dtype</span><span class="o">=</span><span class="p">[(</span><span class="s">'fields'</span><span class="p">,</span> <span class="s">'&gt;u2'</span><span class="p">),</span> <span class="p">(</span><span class="s">'sizex'</span><span class="p">,</span> <span class="s">'&gt;u4'</span><span class="p">),</span> <span class="p">(</span><span class="s">'x'</span><span class="p">,</span> <span class="s">'&gt;f8'</span><span class="p">),</span> <span class="p">(</span><span class="s">'sizey'</span><span class="p">,</span> <span class="s">'&gt;u4'</span><span class="p">),</span> <span class="p">(</span><span class="s">'y'</span><span class="p">,</span> <span class="s">'&gt;f8'</span><span class="p">)],</span>
    <span class="n">offset</span><span class="o">=</span><span class="mi">19</span><span class="p">)</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">sizex</code> and <code class="language-plaintext highlighter-rouge">sizey</code> fields can be safely ignored (assuming you are actually
reading in 2 floats!).</p>

<p>To process a result that has one float (radius) and one int (count) for each row:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">data</span> <span class="o">=</span> <span class="n">numpy</span><span class="p">.</span><span class="n">frombuffer</span><span class="p">(</span><span class="n">notrailer</span><span class="p">,</span> 
    <span class="n">dtype</span><span class="o">=</span><span class="p">[(</span><span class="s">'fields'</span><span class="p">,</span> <span class="s">'&gt;u2'</span><span class="p">),</span> <span class="p">(</span><span class="s">'sizeradius'</span><span class="p">,</span> <span class="s">'&gt;u4'</span><span class="p">),</span> <span class="p">(</span><span class="s">'radius'</span><span class="p">,</span> <span class="s">'&gt;f8'</span><span class="p">),</span> <span class="p">(</span><span class="s">'sizecount'</span><span class="p">,</span> <span class="s">'&gt;u4'</span><span class="p">),</span> <span class="p">(</span><span class="s">'count'</span><span class="p">,</span> <span class="s">'&gt;u4'</span><span class="p">)],</span>
    <span class="n">offset</span><span class="o">=</span><span class="mi">19</span><span class="p">)</span>
</code></pre></div></div>

<p>Again, <code class="language-plaintext highlighter-rouge">sizeradius</code> and <code class="language-plaintext highlighter-rouge">sizecount</code> can be safely ignored if you know the types.</p>

<p>To read an array of a known size (4 elements in this example):</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">data</span> <span class="o">=</span> <span class="n">numpy</span><span class="p">.</span><span class="n">frombuffer</span><span class="p">(</span><span class="n">notrailer</span><span class="p">,</span> 
    <span class="n">dtype</span><span class="o">=</span><span class="p">[(</span><span class="s">'fields'</span><span class="p">,</span> <span class="s">'&gt;u2'</span><span class="p">),</span> <span class="p">(</span><span class="s">'info_about_array'</span><span class="p">,</span> <span class="s">'&gt;u4'</span><span class="p">,</span> <span class="p">(</span><span class="mi">5</span><span class="p">,)),</span> 
        <span class="p">(</span><span class="s">'array'</span><span class="p">,</span> <span class="p">[(</span><span class="s">'offset'</span><span class="p">,</span> <span class="s">'&gt;u4'</span><span class="p">),</span> <span class="p">(</span><span class="s">'value'</span><span class="p">,</span> <span class="s">'&gt;f8'</span><span class="p">)],</span> <span class="mi">4</span><span class="p">)],</span>
    <span class="n">offset</span><span class="o">=</span><span class="mi">19</span><span class="p">)</span>
</code></pre></div></div>

<p>In this case we can ignore the <code class="language-plaintext highlighter-rouge">ndims</code> etc for the array (see table above,
this is stored in the <code class="language-plaintext highlighter-rouge">info_about_array</code> field. The data for the array
will be stored in the <code class="language-plaintext highlighter-rouge">array</code> field.</p>

<h1 id="converting-to-the-correct-endian">Converting to the correct endian</h1>

<p>As discussed above, PostGreSQL transmits all data as big endian. Most machines
now are little endian. So the data contained in these structured arrays are
likely to wrong for your CPU. You can find which byte order your machine is using
by printing the value of <code class="language-plaintext highlighter-rouge">sys.byteorder</code>:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">sys</span>
<span class="k">print</span><span class="p">(</span><span class="n">sys</span><span class="p">.</span><span class="n">byteorder</span><span class="p">)</span>
</code></pre></div></div>

<p>If this is <code class="language-plaintext highlighter-rouge">little</code> you will need to convert the arrays to little endian with 
code like this:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">data_native</span> <span class="o">=</span> <span class="n">data</span><span class="p">.</span><span class="n">byteswap</span><span class="p">()</span>  <span class="c1"># swap the data
</span><span class="n">data_native</span> <span class="o">=</span> <span class="n">data_native</span><span class="p">.</span><span class="n">view</span><span class="p">(</span><span class="n">data_native</span><span class="p">.</span><span class="n">dtype</span><span class="p">.</span><span class="n">newbyteorder</span><span class="p">())</span>  <span class="c1"># set the little endian data types
</span></code></pre></div></div>

<h1 id="conclusion">Conclusion</h1>

<p>Reading data into a numpy array from a PostGreSQL binary cursor is possible if
you need to get the data directly into numpy as quickly as possible. It is not
without its downsides, but if you are getting back large arrays and numpy is
the only way they can be processed then the method described above is feasible.</p>]]></content><author><name></name></author><category term="ubarsc" /><category term="tutorial" /><category term="PostGreSQL" /><summary type="html"><![CDATA[Introduction]]></summary></entry><entry><title type="html">kealib 2.0.0 (final) Released</title><link href="https://ubarsc.github.io//ubarsc/update/kealib/2026/06/29/kealib-2.0.0.html" rel="alternate" type="text/html" title="kealib 2.0.0 (final) Released" /><published>2026-06-29T00:00:00+00:00</published><updated>2026-06-29T00:00:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/update/kealib/2026/06/29/kealib-2.0.0</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/update/kealib/2026/06/29/kealib-2.0.0.html"><![CDATA[<p><a href="https://kealib.org/">kealib</a> 2.0.0 (final) is now available from 
<a href="https://github.com/ubarsc/kealib/releases/tag/kealib-2.0.0">kealib downloads</a>.</p>

<p>For those building from source: note that <a href="https://github.com/highfive-devs/highfive">HighFive</a> 
is now needed to build <code class="language-plaintext highlighter-rouge">kealib</code>.</p>

<p>For those building the in-tree GDAL driver: you will need the changes in <a href="https://github.com/OSGeo/gdal/pull/14596">GDAL PR 14596</a> to build against kealib 2.0. 
These changes will appear in GDAL 3.14.</p>

<p>For more information see the <a href="https://github.com/ubarsc/kealib/blob/master/Changes.txt">list of changes</a>.</p>

<p>This will soon become the default version on conda forge.</p>]]></content><author><name></name></author><category term="ubarsc" /><category term="update" /><category term="KeaLib" /><summary type="html"><![CDATA[kealib 2.0.0 (final) is now available from kealib downloads.]]></summary></entry><entry><title type="html">RatZarr 1.0.2 released</title><link href="https://ubarsc.github.io//ubarsc/update/ratzarr/2026/06/27/ratzarr-1.0.2.html" rel="alternate" type="text/html" title="RatZarr 1.0.2 released" /><published>2026-06-27T01:00:00+00:00</published><updated>2026-06-27T01:00:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/update/ratzarr/2026/06/27/ratzarr-1.0.2</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/update/ratzarr/2026/06/27/ratzarr-1.0.2.html"><![CDATA[<p><a href="https://github.com/ubarsc/ratzarr">RatZarr</a> 1.0.2 has been released</p>

<p>This release supports the use of multi-valued columns. In effect, this allows
for a single column to be a two dimensional array instead of the usual
one dimension. The second dimension allows for multiple values to be
stored for each row of the RAT. Previously, the only way to do this was
to store them as separate columns, and rely on the column names to indicate
that they are closely related columns. With this new feature, they are stored
as a single RAT column, and read in as a single 2-d array</p>

<p>It is expected that most columns will remain 1-d. However, some suggested use
cases for 2-d columns include:</p>

<ul>
  <li>Lidar waveform data for each image segment</li>
  <li>Multi-year FPC (Foliage Projective Cover) values per-segment</li>
</ul>

<p>It is strongly recommended that when using this multi-valued column feature,
a column attribute also be stored (see 
<a href="https://htmlpreview.github.io/?https://github.com/ubarsc/ratzarr/blob/main/docs/ratzarr.html#RatZarr.getColumnAttributeMapping">getColumnAttributeMapping</a>)
to document the meaning of the sub-columns. For example, if storing FPC
values for multiple years as a single column named FPC, one might also store
a column attribute with the list of years, e.g.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">attrs</span> <span class="o">=</span> <span class="n">rz</span><span class="p">.</span><span class="n">getColumnAttributeMapping</span><span class="p">(</span><span class="s">'FPC'</span><span class="p">)</span>
<span class="n">attrs</span><span class="p">[</span><span class="s">'years'</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1985</span><span class="p">,</span> <span class="mi">1990</span><span class="p">,</span> <span class="mi">1995</span><span class="p">,</span> <span class="mi">2000</span><span class="p">,</span> <span class="mi">2005</span><span class="p">]</span>
</code></pre></div></div>]]></content><author><name></name></author><category term="ubarsc" /><category term="update" /><category term="RatZarr" /><summary type="html"><![CDATA[RatZarr 1.0.2 has been released]]></summary></entry><entry><title type="html">kealib 2.0.0 Release Candidate 1 available</title><link href="https://ubarsc.github.io//ubarsc/update/kealib/2026/05/18/kealib-2.0.0rc1.html" rel="alternate" type="text/html" title="kealib 2.0.0 Release Candidate 1 available" /><published>2026-05-18T21:00:00+00:00</published><updated>2026-05-18T21:00:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/update/kealib/2026/05/18/kealib-2.0.0rc1</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/update/kealib/2026/05/18/kealib-2.0.0rc1.html"><![CDATA[<p><a href="https://kealib.org/">kealib</a> 2.0.0 Release Candidate 1 is now available from 
<a href="https://github.com/ubarsc/kealib/releases/tag/kealib-2.0.0rc1">kealib downloads</a>.</p>

<p>This is a complete re-write using <a href="https://github.com/highfive-devs/highfive">HighFive</a>
C++ bindings for HDF5. Issues on OSX are hopefully now resolved.</p>

<p>For more information see the <a href="https://github.com/ubarsc/kealib/blob/master/Changes.txt">list of changes</a>.</p>

<p>For those building the in-tree GDAL driver, you will need the changes in <a href="https://github.com/OSGeo/gdal/pull/14596">GDAL PR 14596</a>. Please open an issue for any problems
that are found.</p>]]></content><author><name></name></author><category term="ubarsc" /><category term="update" /><category term="KeaLib" /><summary type="html"><![CDATA[kealib 2.0.0 Release Candidate 1 is now available from kealib downloads.]]></summary></entry><entry><title type="html">Using Surrogate Colour Tables in TuiView</title><link href="https://ubarsc.github.io//ubarsc/tutorial/tuiview/2026/05/13/tuiviewwritetable.html" rel="alternate" type="text/html" title="Using Surrogate Colour Tables in TuiView" /><published>2026-05-13T00:00:00+00:00</published><updated>2026-05-13T00:00:00+00:00</updated><id>https://ubarsc.github.io//ubarsc/tutorial/tuiview/2026/05/13/tuiviewwritetable</id><content type="html" xml:base="https://ubarsc.github.io//ubarsc/tutorial/tuiview/2026/05/13/tuiviewwritetable.html"><![CDATA[<h1 id="introduction">Introduction</h1>

<p>One last piece of <a href="https://tuiview.org/">TuiView</a> functionality that has not 
yet been covered in this blog series is the ability to add “surrogate” colour
tables to a file and use them to display images within TuiView.</p>

<p>Normally, a thematic file <a href="../../01/21/tuiview-ratquery.html">is displayed</a>
using the colour table within the Raster Attribute Table. However, in situations
where RAT columns have different classifications which require the image to be
shown in the colour table for that classification it is handy to be able to add
surrogate colour tables and view the image with those.</p>

<h1 id="the-tuiviewwritetable-utility">The tuiviewwritetable utility</h1>

<p>Installed with TuiView, the <code class="language-plaintext highlighter-rouge">tuiviewwritetable</code> command line utility allows 
surrogate colour tables to be added, removed and queried:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ tuiviewwritetable -h
usage: tuiviewwritetable [-h] [-s SOURCE] [-n NAME] [-d DEST] [-p PRINTCT] [-r REMOVE]

options:
  -h, --help            show this help message and exit
  -s SOURCE, --source SOURCE
                        File to read color table from
  -n NAME, --name NAME  name to save the color table under
  -d DEST, --dest DEST  destination file to write color table into
  -p PRINTCT, --print PRINTCT
                        print out available color tables
  -r REMOVE, --remove REMOVE
                        remove table from specified file (must specify --name also)
</code></pre></div></div>

<h1 id="adding-a-surrogate-colour-table">Adding a surrogate colour table</h1>

<p>Because surrogate colour tables are written to the image metadata, we recommend
that only smaller (&lt; 100,000 rows) tables are written using this method. Image
metadata is much less efficient at storing the table information than the RAT.</p>

<p>When adding a surrogate colour table from another file, specify the <code class="language-plaintext highlighter-rouge">--source</code>,
<code class="language-plaintext highlighter-rouge">--dest</code> and <code class="language-plaintext highlighter-rouge">--name</code> parameters. If more than one colour table is added using
this method, TuiView will ask you which colour table you would like to use.</p>

<p>The following command will add a new surrogate colour table named “biomass”
into <code class="language-plaintext highlighter-rouge">myimage.kea</code> from the image <code class="language-plaintext highlighter-rouge">biomassimage.tif</code>:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>tuiviewwritetable <span class="nt">--dest</span> myimage.kea <span class="nt">--source</span> biomassimage.tif <span class="nt">--name</span> biomass
</code></pre></div></div>

<h1 id="querying-surrogate-colour-tables">Querying surrogate colour tables</h1>

<p>If you wish to see which colour tables are available use the <code class="language-plaintext highlighter-rouge">--print</code> option:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>tuiviewwritetable <span class="nt">--print</span> myimage.kea
Name	    Size
<span class="nt">------------------------</span>
biomass	    65537
water       65537
</code></pre></div></div>

<h1 id="deleting-surrogate-colour-tables">Deleting surrogate colour tables</h1>

<p>To remove a surrogate colour table, use the <code class="language-plaintext highlighter-rouge">--remove</code> flag in combination with the 
<code class="language-plaintext highlighter-rouge">--name</code> option:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>tuiviewwritetable <span class="nt">--remove</span> myimage.kea <span class="nt">--name</span> biomass2
</code></pre></div></div>

<h1 id="accessing-surrogate-colour-tables-within-tuiview">Accessing surrogate colour tables within TuiView</h1>

<p>If you load a thematic image with TuiView, it will default to using the colour
table within the Raster Attribute Table. However, if you open the Query Window
and right click on a float or integer column you will see there is an option to
“Set column as Colour Table Lookup”:</p>

<p><img src="https://ubarsc.github.io//images/tuiview_surrogate.png" alt="Query Window" /></p>

<p>If you select this option, the behaviour will be either:</p>
<ol>
  <li>If you have only one surrogate colour table in the current image this column
will be directly used as a lookup into the surrogate colour table.</li>
  <li>If you have more than one surrogate colour table you will be presented
with a dialog allowing you to choose which surrogate colour table to use. This
column will then be used as a lookup into the chosen surrogate colour table.</li>
</ol>

<p>The image will now be displayed using the column as lookup into the surrogate colour
table:</p>

<p><img src="https://ubarsc.github.io//images/tuiview_surrogateapply.png" alt="Query Window Applied" /></p>

<p>Note that a small icon (<img src="https://raw.githubusercontent.com/ubarsc/tuiview/refs/heads/master/resources/arrowup.png" alt="Lookup" />) is now drawn against next to the column header that is being used as a lookup.</p>

<p>To remove the colour table lookup, select the same menu option again and it will
be removed and the original colour table shown.</p>

<h1 id="conclusion">Conclusion</h1>

<p>TuiView surrogate colour tables allow you to view your imagery using multiple colour
tables for different classifications. This can be a handy feature in situations
where you have many different classifications stored in your Raster Attribute Table.</p>]]></content><author><name></name></author><category term="ubarsc" /><category term="tutorial" /><category term="TuiView" /><summary type="html"><![CDATA[Introduction]]></summary></entry></feed>