[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [netcdf-java] Linear algebra on data read from a netCDF file (fwd)
- Subject: Re: [netcdf-java] Linear algebra on data read from a netCDF file (fwd)
- Date: Sun, 18 Oct 2009 09:25:09 -0600 (MDT)
===============================================================================
Robb Kambic Unidata Program Center
Software Engineer III Univ. Corp for Atmospheric Research
address@hidden WWW: http://www.unidata.ucar.edu/
===============================================================================
---------- Forwarded message ----------
Date: Sun, 18 Oct 2009 13:13:12 +0200
From: Konrad Hinsen <address@hidden>
To: address@hidden
Subject: Re: [netcdf-java] Linear algebra on data read from a netCDF file
On 16 Oct 2009, at 14:06, Konrad Hinsen wrote:
Thanks! This should at least be efficient. I quickly checked the Colt
implementation, which does have a constructor for its array class that takes
the plain Java array plus the shape information, so at least in theory this
should be simple. If/when I get it to work, I'll post my solution here.
Here is a working example (Clojure source code) for inverting a matrix read
from a netCDF file using Colt:
(ns netcdf-read
(:import (ucar.nc2 NetcdfFile)
(cern.colt.matrix.tdouble.impl DenseDoubleMatrix2D)
(cern.colt.matrix.tdouble.algo DenseDoubleAlgebra)))
(defn unidata-to-colt
[#^ucar.ma2.ArrayDouble$D2 array]
(let [java-array-1d (.get1DJavaArray array Double)
[rows, cols] (.getShape array)]
(new DenseDoubleMatrix2D rows cols java-array-1d 0 0 cols 1 false)))
(let [matrix (with-open [ncfile (NetcdfFile/open
"/Users/hinsen/Temp/matrix.nc")]
(.read (.findVariable ncfile "matrix")))
colt-matrix (unidata-to-colt matrix)
la (new DenseDoubleAlgebra)
inverse (.inverse la colt-matrix)]
(prn inverse))
For my current needs, conversion of 2D double arrays is sufficient, but this
could of course be generalized to ranks 1 and 3 (that's all there is in Colt)
and other element types.
Konrad.
_______________________________________________
netcdf-java mailing list
address@hidden
For list information or to unsubscribe, visit:
http://www.unidata.ucar.edu/mailing_lists/