org.gnode.nix.DataArray Maven / Gradle / Ivy
Show all versions of nix Show documentation
package org.gnode.nix;
import org.bytedeco.javacpp.DoublePointer;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.annotation.*;
import org.gnode.nix.base.EntityWithSources;
import org.gnode.nix.internal.DateUtils;
import org.gnode.nix.internal.None;
import org.gnode.nix.internal.OptionalUtils;
import org.gnode.nix.internal.VectorUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.function.Predicate;
/**
* DataArray
* A class that can store arbitrary n-dimensional data along with further
* information.
*
* The {@link DataArray} is the core entity of the NIX data model, its purpose is to
* store arbitrary n-dimensional data. In addition to the common fields id, name, type, and definition
* the DataArray stores sufficient information to understand the physical nature of the stored data.
*
* A guiding principle of the data model is provides enough information to create a
* plot of the stored data. In order to do so, the DataArray defines a property
* {@link DataType} which provides the physical type of the stored data (for example
* 16 bit integer or double precision IEEE floatingpoint number).
* The property {@link DataArray#setUnit(String)} specifies the SI unit of the values stored in the
* DataArray{} whereas the {@link DataArray#setLabel(String)} defines what is given in this units.
* Together, both specify what corresponds to the the y-axis of a plot.
*
* In some cases it is much more efficient or convenient to store data not as
* floating point numbers but rather as (16 bit) integer values as, for example
* read from a data acquisition board.
* In order to convert such data to the correct values, we follow the approach
* taken by the comedi data-acquisition library (http://www.comedi.org)
* and provide {@link DataArray#setPolynomCoefficients(double[])} and an {@link DataArray#setExpansionOrigin(double)}.
*
*
Create a new data array
* A DataArray can only be created at an existing block. Do not use the
* DataArrays constructors for this purpose.
*
* Block b = ...;
* DataArray da = b.createDataArray("array_one", "testdata", DataType.Double, new NDSize(new int[] { 3, 4, 2 }));
*
*
*
Remove a data array from a file
* Deleting a DataArray.
*
* Block b = ...;
* boolean deleted = b.deleteDataArray(some_id);
*
*
* @see Block
* @see DataType
*/
@Properties(value = {
@Platform(include = {""}, link = "nix", preload = "hdf5"),
@Platform(value = "linux"),
@Platform(value = "windows")})
@Namespace("nix")
public class DataArray extends EntityWithSources {
static {
Loader.load();
}
//--------------------------------------------------
// Constructors
//--------------------------------------------------
/**
* Constructor that creates an uninitialized DataArray.
*
* Calling any method on an uninitialized data array will throw a {@link java.lang.RuntimeException}
* exception. The following code illustrates how to check if a data array is initialized:
*/
public DataArray() {
allocate();
}
private native void allocate();
//--------------------------------------------------
// Base class methods
//--------------------------------------------------
public native
@Cast("bool")
boolean isNone();
/**
* Get id of the data array.
*
* @return ID string.
*/
public native
@Name("id")
@StdString
String getId();
private native
@Cast("time_t")
long createdAt();
/**
* Get the creation date of the data array.
*
* @return The creation date of the data array.
*/
public Date getCreatedAt() {
return DateUtils.convertSecondsToDate(createdAt());
}
private native
@Cast("time_t")
long updatedAt();
/**
* Get the date of the last update.
*
* @return The date of the last update.
*/
public Date getUpdatedAt() {
return DateUtils.convertSecondsToDate(updatedAt());
}
/**
* Sets the time of the last update to the current time if the field is not set.
*/
public native void setUpdatedAt();
/**
* Sets the time of the last update to the current time.
*/
public native void forceUpdatedAt();
/**
* Sets the creation time to the current time if the field is not set.
*/
public native void setCreatedAt();
private native void forceCreatedAt(@Cast("time_t") long time);
/**
* Sets the creation date to the provided value even if the attribute is set.
*
* @param date The creation date to set.
*/
public void forceCreatedAt(Date date) {
forceCreatedAt(DateUtils.convertDateToSeconds(date));
}
/**
* Setter for the type of the data array.
*
* @param type The type of the data array.
*/
public native
@Name("type")
void setType(@StdString String type);
/**
* Getter for the type of the data array
*
* @return The type of the data array
*/
public native
@Name("type")
@StdString
String getType();
/**
* Getter for the name of the data array.
*
* @return The name of the data array.
*/
public native
@Name("name")
@StdString
String getName();
private native void definition(@Const @ByVal None t);
private native void definition(@StdString String definition);
/**
* Setter for the definition of the data array. If null is passed definition is removed.
*
* @param definition definition of data array
*/
public void setDefinition(String definition) {
if (definition != null) {
definition(definition);
} else {
definition(new None());
}
}
private native
@ByVal
OptionalUtils.OptionalString definition();
/**
* Getter for the definition of the data array.
*
* @return The definition of the data array.
*/
public String getDefinition() {
OptionalUtils.OptionalString defintion = definition();
if (defintion.isPresent()) {
return defintion.getString();
}
return null;
}
private native
@ByVal
Section metadata();
/**
* Get metadata associated with this entity.
*
* @return The associated section, if no such section exists null is returned.
* @see Section
*/
public
@Name("metadata")
Section getMetadata() {
Section section = metadata();
if (section.isInitialized()) {
return section;
} else {
return null;
}
}
/**
* Associate the entity with some metadata.
*
* Calling this method will replace previously stored information.
*
* @param metadata The {@link Section} that should be associated
* with this entity.
* @see Section
*/
public native
@Name("metadata")
void setMetadata(@Const @ByRef Section metadata);
/**
* Associate the entity with some metadata.
*
* Calling this method will replace previously stored information.
*
* @param id The id of the {@link Section} that should be associated
* with this entity.
* @see Section
*/
public native
@Name("metadata")
void setMetadata(@StdString String id);
private native void metadata(@Const @ByVal None t);
/**
* Removes metadata associated with the entity.
*
* @see Section
*/
public void removeMetadata() {
metadata(new None());
}
/**
* Get the number of sources associated with this entity.
*
* @return The number sources.
* @see Source
*/
public native
@Name("sourceCount")
long getSourceCount();
/**
* Checks if a specific source is associated with this entity.
*
* @param id The source id to check.
* @return True if the source is associated with this entity, false otherwise.
* @see Source
*/
public native
@Cast("bool")
boolean hasSource(@StdString String id);
/**
* Checks if a specific source is associated with this entity.
*
* @param source The source to check.
* @return True if the source is associated with this entity, false otherwise.
* @see Source
*/
public native
@Cast("bool")
boolean hasSource(@Const @ByRef Source source);
private native
@Name("getSource")
@ByVal
Source fetchSource(@StdString String id);
/**
* Returns an associated source identified by its id.
*
* @param id The id of the associated source.
* @see Source
*/
public Source getSource(String id) {
Source source = fetchSource(id);
if (source.isInitialized()) {
return source;
}
return null;
}
private native
@Name("getSource")
@ByVal
Source fetchSource(@Cast("size_t") long index);
/**
* Retrieves an associated source identified by its index.
*
* @param index The index of the associated source.
* @return The source with the given id. If it doesn't exist an exception
* will be thrown.
* @see Source
*/
public Source getSource(long index) {
Source source = fetchSource(index);
if (source.isInitialized()) {
return source;
}
return null;
}
private native
@ByVal
VectorUtils.SourceVector sources();
/**
* Get all sources associated with this entity.
*
* @return All associated sources that match the given filter as a list.
* @see Source
*/
public List