fraserwg / elepyant Goto Github PK
View Code? Open in Web Editor NEWelePyant (pronounced elephant) provides a set of tools for compressing netCDF files and xarray Datasets and DataArrays.
License: Apache License 2.0
elePyant (pronounced elephant) provides a set of tools for compressing netCDF files and xarray Datasets and DataArrays.
License: Apache License 2.0
A command line interface allowing operations on NetCDF files (but not xarray objects) could be useful. I'm thinking something that would work along the lines of
ncround -i /path/to/in/file.nc -o /path/to/out/file.nc --UVEL 2 --VVEL 2 --WVEL 6
AFAIK netCDFs default compression algorithm is zlib. Zlib is not bad, but I highly recommend to use Zstandard as I achieve much better compression factors with it. In general benchmarks, Zstd is better than Zlib in every aspect. Could you check whether there is a way that the netCDF python implementation supports it?
Just FYI, the unidata netCDF4 documentation contains the following section: https://unidata.github.io/netcdf4-python/netCDF4/index.html#section9 which has a similar approach to the one of elePyant.
Be aware that rounding in decimal representation does is general not round in binary representation too, as the former is not an integer power of the latter. Currently, you seem to use np.around(x,decimals=d)
, but this does not yield zeroed trailing bits.
import struct
def binary(num):
return ''.join('{:0>8b}'.format(c) for c in struct.pack('!f', num))
In [12]: binary(np.around(np.pi,decimals=2))
Out[12]: '01000000010010001111010111000011'
In [13]: binary(np.around(np.pi,decimals=3))
Out[13]: '01000000010010010001011010000111'
In [14]: binary(np.around(np.pi,decimals=4))
Out[14]: '01000000010010010000111111111001'
Note that you can convert significant digits (i.e. decimal) to significant bits via
"""Number of significant bits `nsb` given the number of significant digits `nsd`."""
nsb(nsd::Integer) = Integer(ceil(log(10)/log(2)*nsd))
which is 7 significant bits to guarantee 2 significant (decimal) digits, 10 for 3, 14 for 3, etc. So what you want is a rounding function that does this:
julia> bitstring(round(Float32(π),sigdigits=7,base=2))
"01000000010010100000000000000000"
julia> bitstring(round(Float32(π),sigdigits=10,base=2))
"01000000010010010000000000000000"
julia> bitstring(round(Float32(π),sigdigits=14,base=2))
"01000000010010010001000000000000"
Question is obviously why the compression still works well? I assume this is because if you round two numbers x,y
that are fairly close to each other, to the same decimal places, you get the same bitpatterns in the significant:
In [15]: binary(np.around(np.pi,decimals=2))
Out[15]: '01000000010010001111010111000011'
In [16]: binary(np.around(np.pi*1.001,decimals=2))
Out[16]: '01000000010010001111010111000011'
Which is presumably also somewhat compressable. But I guess 0's everywhere are more compressible than these seemingly random, but repeating bitpatterns.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.