smart_arrays_compress 2.0.9

Smart Arrays Compress #

What the package can do for you #

The compression algorithms provided by this package don't have much to do with audio or video compression. Instead, their purpose is to reduce large arrays to a size suitable for fast interactive viewing on a screen by retaining significant aspects of the array data. For this purpose an array is fragmented into intervals (1D) or submatrices (2D). The minimum and maximum values in these regions constitue the compressed array. You would apply the algorithms to arrays with thousands, ten thousands or even millions of elements. The reduced size should, for example, be chosen to match display resolution if compression is applied for data viewing.

The package also provides a class that expands an array to a larger size by inserting extra points whose values are computed from their neighbours by linear interpolation of the array data.

The major API functionalities #

  • class CompressedArray1D

This example will compress the large specified 1D array to a size of 200 points:

CompressedArray1D c1d = CompressedArray1D.compress(array, 0, array.length - 1, false, 200);

The result is available in c1d.cArray.

  • class CompressedArray2D:

This example will compress the large specified 2D array to a size of 200 x 500 points:

CompressedArray2D c2d = CompressedArray2D();

c2d.compress(matrix, 0, matrix.length - 1, 0, matrix[0].length - 1, 200, 500, true);

The result is available in c2d.cvalsPos and c2d.cvalsNeg.

  • class ArrayInterpolator

Example:

List<double> list = [1.0,5.0,3.0,-10.0, -20.0,6.0,4.0,0.0];

Float64List list64 = new Float64List.fromList(list);

Float64List result = ArrayInterpolator.interpolateArray(list64, 4);

Expands an array to a larger size.

Detailed API #

Please view the detailed API documentation in the API reference of this package (sidebar at the right of this page).

smart_arrays_base: Basic functions for 1D and 2D arrays

smart_arrays_numerics: Numerics with 1D and 2D arrays

smart_arrays_dbstore: Store 1D and 2D arrays along with metadata on the local device.

smart_arrays_peaks: Detect peaks in 1D and 2D arrays.

smart_arrays_lmfit: Fits (x, y) data given as arrays to a specified model function using the Levenberg-Marquardt algorithm.

smart_lorentz-gauss: Compute Lorentz-Gauss (pseudo-Voigt) line shapes.

smart_signal_processing: Fourier transform and more.

smart_dialogs: Easy-to-use dialogs in Web applications

Smart Arrays Compress #

Version history #

2.0.0 - 2019-03-12 First version available on pub site

2.0.1 - 2019-03-12 Improved docs

2.0.2 - 2019-03-14 Minor doc updates

2.0.3 - 2019-03-15 Added class ArrayInterpolator

2.0.4 - 2019-03-15 Link corrected

2.0.5 - 2019-03-24 Updated docs

2.0.6 - 2019-04-04 Updated docs

2.0.7 - 2019-05-06 Updated docs

2.0.8 - 2019-08-01 Fixed health suggestions of pub.dev

2.0.9 - 2019-08-01 Fixed more health suggestions of pub.dev

example/example.dart

// Copyright (c) 2019, Dr. Bruno Guigas. All rights reserved. Use of this source
// code is governed by a BSD-style license that can be found in the LICENSE file.
import 'package:smart_arrays_compress/smart_arrays_compress.dart';
import 'dart:typed_data';
import 'dart:math' as math;

/// Demonstrates the usage of 1D and 2D array compression.
main() {
  math.Random rand = math.Random();

  // Example 1: compress a 1D array
  // Create a large vector with: Acending positive numbers and descending
  // negative numbers. The sign is randomly chosen.
  final int VSIZE = 16000;
  Float64List vector = Float64List(VSIZE);
  for (int i = 0; i < VSIZE; i++) {
    double randSign = (2 * rand.nextDouble() - 1.0).sign;
    vector[i] = i * randSign;
  }

  // compress the vector to 100 min/max pairs
  CompressedArray1D c1d =
      CompressedArray1D.compress(vector, 0, vector.length - 1, false, 100);

  // print the result.
  print("Result 1D: Compression interval length = ${c1d.cpdIndexIncrement}");
  print("Result 1D: cValues.length = ${c1d.cArray.length}");
  print("Result 1D: uIndices.length = ${c1d.uIndices.length}");
  print("Result 1D: cValues = ${c1d.cArray}");
  print("Result 1D: uIndices = ${c1d.uIndices}");
  print("");

  // Example 2: compress a 2D array
  // Create a large matrix with random numbers between -1 and 1.
  final int NROWS = 1234, NCOLS = 2345, NROWS_NEW = 200, NCOLS_NEW = 500;
  List<Float64List> matrix = List(NROWS);
  for (int i = 0; i < NROWS; i++) {
    Float64List row = Float64List(NCOLS);

    for (int k = 0; k < NCOLS; k++) {
      row[k] = 2 * rand.nextDouble() - 1.0;
    }
    matrix[i] = row;
  }

  // fill in some non-random values acting as minima and maxima
  matrix[30][40] = 100;
  matrix[300][400] = 150;
  matrix[303][405] = 250;
  matrix[350][450] = -150;
  matrix[1000][2000] = 200;
  matrix[1050][2100] = -300;

  // compress the matrix
  CompressedArray2D c2d = CompressedArray2D();
  c2d.compress(matrix, 0, matrix.length - 1, 0, matrix[0].length - 1, NROWS_NEW,
      NCOLS_NEW, true);

  // the result are 2 matrices containg positive (or zero) and negative (or zero)
  // values only. Print absolute values > 1, must be the same as above.
  for (int i = 0; i < c2d.cvalsPos.length; i++)
    for (int k = 0; k < c2d.cvalsPos[0].length; k++)
      if (c2d.cvalsPos[i][k] > 1)
        print("Pos. 2D: retained (row,col,val) = $i $k ${c2d.cvalsPos[i][k]}");

  for (int i = 0; i < c2d.cvalsNeg.length; i++)
    for (int k = 0; k < c2d.cvalsNeg[0].length; k++)
      if (c2d.cvalsNeg[i][k] < -1)
        print("Neg. 2D: retained (row,col,val) = $i $k ${c2d.cvalsNeg[i][k]}");
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  smart_arrays_compress: ^2.0.9

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:smart_arrays_compress/smart_arrays_compress.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:smart_arrays_compress/smart_arrays_compress.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
build_runner ^1.6.2 1.6.7
build_web_compilers ^2.0.0 2.2.3
pedantic ^1.5.0 1.8.0+1
smart_arrays_base ^2.0.9 2.0.9
Transitive dependencies
analyzer 0.38.1
archive 2.0.10
args 1.5.2
async 2.3.0
bazel_worker 0.1.21
build 1.1.6
build_config 0.4.1+1
build_daemon 2.0.0
build_modules 2.4.3
build_resolvers 1.0.7
build_runner_core 3.0.9
built_collection 4.2.2
built_value 6.7.0
charcode 1.1.2
checked_yaml 1.0.2
code_builder 3.2.0
collection 1.14.12
convert 2.1.1
crypto 2.1.2
csslib 0.16.1
dart_style 1.2.10
fixnum 0.10.9
front_end 0.1.23
glob 1.1.7
graphs 0.2.0
html 0.14.0+2
http 0.12.0+2
http_multi_server 2.1.0
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 3.0.0
kernel 0.3.23
logging 0.11.3+2
matcher 0.12.5
meta 1.1.7
mime 0.9.6+3
package_config 1.1.0
package_resolver 1.0.10
path 1.6.4
pool 1.4.0
protobuf 0.13.15
pub_semver 1.4.2
pubspec_parse 0.1.5
quiver 2.0.5
scratch_space 0.0.4
shelf 0.7.5
shelf_web_socket 0.2.3
source_maps 0.10.8
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
stream_transform 0.0.19
string_scanner 1.0.5
term_glyph 1.1.0
timing 0.1.1+2
typed_data 1.1.6
watcher 0.9.7+12
web_socket_channel 1.0.15
yaml 2.1.16