public class MarsTable extends org.scijava.table.AbstractTable<org.scijava.table.Column<?>,java.lang.Object> implements org.scijava.table.GenericTable, JsonConvertibleRecord
DoubleColumn
). Convenience methods and
constructors are provided for common operations (min, max, mean, std,
variance, linearRegression, sorting, filtering, etc), for saving and opening
tables in csv or json format, and retrieval of values in many formats.
Throughout (org.apache.commons.math3
) is used for common operations
where possible.
GenericColumns containing Strings can also be added to MarsTables. Their primary intended use is for generating output tables that need to combine numbers and strings or static data storage of tables composed entirely of strings (for example, with frame metadata information for time points as rows).
More complex row filtering operations can be accomplished using the rowStream
method and java 8 stream framework. The optimal implementation would return
an ArrayList<Integer>
with a set of rows to remove or keep. This list
can then be used with the deleteRows or keepRows methods.
All sorting and filtering operations are performed in place. This allows for
processing of larger tables in memory without requiring enough memory for a
copy. If a copy is desired. For example, if several filtering and sorting
steps are performed from the same primary table, prior to each operation a
copy can be made using the
clone()
method.
Constructor and Description |
---|
MarsTable()
Creates an empty results table.
|
MarsTable(java.io.File file)
Opens a results table from the file provided.
|
MarsTable(java.io.File file,
org.scijava.app.StatusService statusService)
Opens a results table from the file provided.
|
MarsTable(int columnCount,
int rowCount)
Creates a results table with the given row and column dimensions.
|
MarsTable(java.lang.String name)
Creates an empty results table with the name given.
|
MarsTable(java.lang.String name,
int columnCount,
int rowCount)
Creates a results table with the given name and column and row dimensions.
|
MarsTable(java.lang.String name,
java.lang.String... headers)
Creates a results table with the name given and column headers.
|
MarsTable(org.scijava.table.Table<org.scijava.table.Column<?>,java.lang.Object> table)
Creates a results table with the given a scijava Table.
|
Modifier and Type | Method and Description |
---|---|
MarsTable |
addRow(MarsTableRow row)
Add MarsTableRow to the end of the table.
|
MarsTable |
clone()
Create a copy of the MarsTable.
|
protected org.scijava.table.DoubleColumn |
createColumn(java.lang.String header) |
MarsTable |
deleteRows(int[] rows)
Remove rows at the positions specified in the ordered list given.
|
MarsTable |
deleteRows(java.util.List<java.lang.Integer> rows)
Remove rows at the positions specified in the ordered list given.
|
java.lang.String |
dumpJSON()
Get the record in Json string format.
|
void |
fromJSON(com.fasterxml.jackson.core.JsonParser jParser)
JSON deserialization of table values.
|
double[] |
getColumnAsDoubles(java.lang.String column)
Returns an array of double values for the column given.
|
double[] |
getColumnAsDoublesNoNaNs(java.lang.String column)
Returns an array of double values for the column given.
|
double[] |
getColumnAsDoublesNoNaNs(java.lang.String column,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Returns an array of double values for the column within the range given for
a rowSelectionColumn (inclusive of bounds).
|
java.util.List<java.lang.String> |
getColumnHeadingList()
Returns the column headings as an ArrayList of strings.
|
java.lang.String[] |
getColumnHeadings()
Returns the column headings as an array of strings.
|
java.io.File |
getFile() |
java.util.function.Predicate<com.fasterxml.jackson.core.JsonGenerator> |
getJsonGenerator(java.lang.String field)
Get the JsonGenerator for a field.
|
java.util.function.Predicate<com.fasterxml.jackson.core.JsonParser> |
getJsonParser(java.lang.String field)
Get the JsonParser for a field.
|
java.lang.String |
getName()
Retrieves the name of the table.
|
java.util.List<java.lang.Object> |
getRowAsList(int row)
Returns the row specified as a List of Objects.
|
java.lang.String |
getRowAsString(int row)
Returns a comma delimited string of the values in the row specified.
|
java.lang.String |
getStringValue(int col,
int row)
Returns the string value at the column and row indices specified.
|
java.lang.String |
getStringValue(java.lang.String column,
int row)
Returns the string value for the column header and row index specified.
|
double |
getValue(int col,
int row)
Returns the double value at the column and row indices specified.
|
double |
getValue(java.lang.String column,
int row)
Returns the double value at the column header and row index specified.
|
MarsTableWindow |
getWindow()
Returns a reference to the window containing the table if there is one.
|
boolean |
hasColumn(java.lang.String colName)
Returns true if the table contains a column with the name specified.
|
MarsTable |
keepRows(int[] rows)
Remove rows at the positions specified in the ordered list given.
|
MarsTable |
keepRows(java.util.List<java.lang.Integer> rows)
Keep rows at the positions specified in the ordered list given.
|
double[] |
linearRegression(java.lang.String xColumn,
java.lang.String yColumn)
Calculates the linear fit given an xColumn and yColumn pair.
|
double[] |
linearRegression(java.lang.String xColumn,
java.lang.String yColumn,
double lowerBound,
double upperBound)
Calculates the linear fit given an xColumn and yColumn pair.
|
double |
mad(java.lang.String column)
Calculates the median absolute deviation.
|
double |
mad(java.lang.String madColumn,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Calculates the median absolute deviation of the values for the madColumn
within the range given for a rowSelectionColumn (inclusive of bounds).
|
double |
max(java.lang.String column)
Finds the maximum of the column values.
|
double |
max(java.lang.String maxColumn,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Finds the max of the values for the maxColumn within the range given for a
rowSelectionColumn (inclusive of bounds).
|
double |
mean(java.lang.String column)
Calculates the mean of the values for the column given.
|
double |
mean(java.lang.String meanColumn,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Calculates the mean of the values for the meanColumn within the range given
for a rowSelectionColumn (inclusive of bounds).
|
double |
median(java.lang.String column)
Calculates the median of the column values.
|
double |
median(java.lang.String medianColumn,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Finds the median of the values for the medianColumn within the range given
for a rowSelectionColumn (inclusive of bounds).
|
double |
min(java.lang.String column)
Finds the minimum of the column values.
|
double |
min(java.lang.String minColumn,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Finds the min of the values for the maxColumn within the range given for a
rowSelectionColumn (inclusive of bounds).
|
java.util.stream.Stream<MarsTableRow> |
rows()
Returns a stream of MarsTableRow.
|
boolean |
saveAs(java.io.File file)
Saves the table to the file path in smile encoded json format.
|
void |
saveAsCSV(java.lang.String path)
Saves the table to the string file path specified in csv format.
|
void |
saveAsJSON(java.lang.String path)
Saves the table to the file path specified in json format.
|
void |
saveAsYAMT(java.lang.String path)
Saves the table to the file path specified in yamt format.
|
double |
sem(java.lang.String column)
Calculates the standard error of the mean for the column given.
|
double |
sem(java.lang.String meanColumn,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Calculates the standard error of the mean for the meanColumn within the
range given for a rowSelectionColumn (inclusive of bounds).
|
void |
setFile(java.io.File file) |
void |
setJsonField(java.lang.String field,
MarsUtil.ThrowingConsumer<com.fasterxml.jackson.core.JsonGenerator,java.io.IOException> output,
MarsUtil.ThrowingConsumer<com.fasterxml.jackson.core.JsonParser,java.io.IOException> input) |
void |
setName(java.lang.String name)
Sets the name of the table.
|
MarsTable |
setPrecision(int decimalPlacePrecision) |
void |
setShowWarnings(boolean showWarnings) |
void |
setValue(int col,
int row,
double value)
Set the double value for a pair of column and row indices.
|
void |
setValue(int col,
int row,
java.lang.String value)
Set the String value for a pair of column and row indices.
|
void |
setValue(java.lang.String column,
int row,
double value)
Set the double value for the column heading and row index specified.
|
void |
setValue(java.lang.String column,
int row,
java.lang.String value)
Set the String value for the column heading and row index specified.
|
MarsTableWindow |
setWindow(MarsTableWindow win)
Sets a reference to the window holding the table.
|
MarsTable |
sort(boolean ascending,
java.lang.String... columns)
Sort the table on one or more columns either in ascending or descending
order.
|
MarsTable |
sort(java.lang.String... columns)
Sort the table in ascending order on one or more columns.
|
double |
std(java.lang.String column)
Calculates the standard deviation of the column.
|
double |
std(java.lang.String stdColumn,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Calculates the standard deviation of the values for the stdColumn within
the range given for a rowSelectionColumn (inclusive of bounds).
|
double |
sum(java.lang.String column)
Calculates the sum of the values for the column given.
|
double |
sum(java.lang.String sumColumn,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Calculates the sum of the values for the sumColumn within the range given
for a rowSelectionColumn (inclusive of bounds).
|
void |
toJSON(com.fasterxml.jackson.core.JsonGenerator jGenerator)
JSON serialization of table values.
|
java.lang.String |
toString() |
double |
variance(java.lang.String varianceColumn)
Calculates the variance for the column given.
|
double |
variance(java.lang.String varianceColumn,
java.lang.String rowSelectionColumn,
double lowerBound,
double upperBound)
Calculates the variance for the varianceColumn within the range given for a
rowSelectionColumn (inclusive of bounds).
|
static MarsTable |
wrap(org.scijava.table.Table<org.scijava.table.Column<?>,java.lang.Object> table)
Wraps a scijava table or anything implementing the scijava Table interface
inside a MarsTable without copying.
|
add, add, addAll, addAll, getRowCount, getRowHeader, insertColumns, removeRows, set, setColumnCount, setRowCount, setRowHeader
clear, contains, forEach, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
finalize, getClass, notify, notifyAll, wait, wait, wait
add, add, addAll, addAll, appendColumn, appendColumn, appendColumns, appendColumns, appendRow, appendRow, appendRows, appendRows, clear, contains, containsAll, get, get, get, get, getColumnCount, getColumnHeader, getColumnIndex, getRowCount, getRowHeader, getRowIndex, indexOf, insertColumn, insertColumn, insertColumns, insertColumns, insertRow, insertRow, insertRows, insertRows, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeColumn, removeColumn, removeColumns, removeColumns, removeRow, removeRow, removeRows, removeRows, retainAll, set, set, set, setColumnCount, setColumnHeader, setDimensions, setRowCount, setRowHeader, size, subList, toArray, toArray
public MarsTable()
public MarsTable(java.lang.String name)
name
- Table name.public MarsTable(java.lang.String name, java.lang.String... headers)
name
- Table name.headers
- Names of column headers to initialize.public MarsTable(java.io.File file) throws com.fasterxml.jackson.core.JsonParseException, java.io.IOException
file
- File to load table from.com.fasterxml.jackson.core.JsonParseException
- Thrown if unable to parse Json.java.io.IOException
- Thrown if unable to read file.public MarsTable(java.io.File file, org.scijava.app.StatusService statusService) throws com.fasterxml.jackson.core.JsonParseException, java.io.IOException
file
- File to load the table from.statusService
- StatusService from the current Context to provide the
user with progress updates.java.io.IOException
- If unable to load the file.com.fasterxml.jackson.core.JsonParseException
- If a problem is encountered when parsing Json.public MarsTable(int columnCount, int rowCount)
columnCount
- Number of columns.rowCount
- Number of rows.public MarsTable(org.scijava.table.Table<org.scijava.table.Column<?>,java.lang.Object> table)
table
- Something implementing the Table interface.public MarsTable(java.lang.String name, int columnCount, int rowCount)
name
- Table name.columnCount
- Number of columns.rowCount
- Number of rows.public static MarsTable wrap(org.scijava.table.Table<org.scijava.table.Column<?>,java.lang.Object> table)
table
- Something implementing the Table interface.public void setName(java.lang.String name)
name
- Name of the table.public java.lang.String getName()
public MarsTable setPrecision(int decimalPlacePrecision)
public java.lang.String[] getColumnHeadings()
public java.util.List<java.lang.String> getColumnHeadingList()
public MarsTableWindow getWindow()
public MarsTableWindow setWindow(MarsTableWindow win)
win
- The window containing the table if working with a gui.public double[] getColumnAsDoubles(java.lang.String column)
column
- Header of the column to retrieve.public double[] getColumnAsDoublesNoNaNs(java.lang.String column)
column
- Header of the column to retrieve.public double[] getColumnAsDoublesNoNaNs(java.lang.String column, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
column
- Header of the column to retrieve.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public java.lang.String getRowAsString(int row)
row
- The row index to retrieve as a string.public java.util.List<java.lang.Object> getRowAsList(int row)
row
- The row index to retrieve as a string.public boolean saveAs(java.io.File file)
file
- File where the table is written.public void saveAsCSV(java.lang.String path) throws java.io.IOException
path
- The string path for saving.java.io.IOException
- Thrown if unable to write the file.public void toJSON(com.fasterxml.jackson.core.JsonGenerator jGenerator) throws java.io.IOException
toJSON
in interface JsonConvertibleRecord
jGenerator
- JsonGenerator stream the table should be serialized to.java.io.IOException
- Thrown if unable to write to the JsonGenerator stream.public void fromJSON(com.fasterxml.jackson.core.JsonParser jParser) throws java.io.IOException
fromJSON
in interface JsonConvertibleRecord
jParser
- JsonParser stream to read objects and fields from.java.io.IOException
- Thrown if unable to read from the JsonParser stream.public void saveAsJSON(java.lang.String path) throws java.io.IOException
path
- String path for writing.java.io.IOException
- Thrown if unable to write to the path given.public void saveAsYAMT(java.lang.String path) throws java.io.IOException
path
- String path for writing.java.io.IOException
- Thrown if unable to save to path given.public java.lang.String toString()
toString
in class java.util.AbstractCollection<org.scijava.table.Column<?>>
public void setValue(int col, int row, double value)
col
- Index of the column that contains the value to set.row
- Index of the row that contains the value to set.value
- The new value to set at the position given.public void setValue(int col, int row, java.lang.String value)
col
- Index of the column that contains the value to set.row
- Index of the row that contains the value to set.value
- The new String value to set at the position given.public void setValue(java.lang.String column, int row, double value)
column
- Heading of the column that contains the value to set.row
- Index of the row that contains the value to set.value
- The new double value to set at the position given.public void setValue(java.lang.String column, int row, java.lang.String value)
column
- Heading of the column that contains the value to set.row
- Index of the row that contains the value to set.value
- The new double value to set at the position given.public double getValue(int col, int row)
col
- Index of the column that contains the value.row
- Index of the row that contains the value.public double getValue(java.lang.String column, int row)
column
- Header of the column that contains the value.row
- Index of the row that contains the value.public java.lang.String getStringValue(java.lang.String column, int row)
column
- Header of the column that contains the value.row
- Index of the row that contains the value.public java.lang.String getStringValue(int col, int row)
col
- Index of the column that contains the value.row
- Index of the row that contains the value.public boolean hasColumn(java.lang.String colName)
colName
- String column header to check for.public double max(java.lang.String column)
column
- name of the column.public double max(java.lang.String maxColumn, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
maxColumn
- name of the column used for finding the max.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public double min(java.lang.String column)
column
- name of the column.public double min(java.lang.String minColumn, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
minColumn
- name of the column used for finding the min.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public double mean(java.lang.String column)
column
- name of the column.public double mean(java.lang.String meanColumn, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
meanColumn
- name of the column used for calculating the mean.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public double sum(java.lang.String column)
column
- name of the column.public double sum(java.lang.String sumColumn, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
sumColumn
- name of the column used for calculating the mean.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public double median(java.lang.String column)
column
- name of the column.public double median(java.lang.String medianColumn, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
medianColumn
- name of the column used for finding the median.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public double std(java.lang.String column)
column
- name of the column.public double std(java.lang.String stdColumn, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
stdColumn
- name of the column to use for the standard deviation
calculation.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public double mad(java.lang.String column)
column
- name of the column.public double mad(java.lang.String madColumn, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
madColumn
- Name of the column used to calculate the median absolute
deviation.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public double sem(java.lang.String column)
column
- Name of the column used to calculate the median absolute
deviation.public double sem(java.lang.String meanColumn, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
meanColumn
- Name of the column used to calculate the standard error
of the mean.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public double variance(java.lang.String varianceColumn)
varianceColumn
- Name of the column used to calculate the variance.public double variance(java.lang.String varianceColumn, java.lang.String rowSelectionColumn, double lowerBound, double upperBound)
varianceColumn
- Name of the column used to calculate the variance.rowSelectionColumn
- name of the column used for filtering a range of
values.lowerBound
- smallest value included in the row selection range.upperBound
- largest value included in the row selection range.public double[] linearRegression(java.lang.String xColumn, java.lang.String yColumn)
xColumn
- Name of the column containing the x values.yColumn
- Name of the column containing the y values.public double[] linearRegression(java.lang.String xColumn, java.lang.String yColumn, double lowerBound, double upperBound)
xColumn
- Name of the column containing the x values.yColumn
- Name of the column containing the y values.lowerBound
- LowerBound of fitting region in x values.upperBound
- UpperBound of fitting region in x values.public MarsTable sort(java.lang.String... columns)
columns
- Comma separated list of columns to sort by.public MarsTable sort(boolean ascending, java.lang.String... columns)
ascending
- Determines sort order.columns
- Comma separated list of columns to sort by.public java.util.stream.Stream<MarsTableRow> rows()
public MarsTable addRow(MarsTableRow row)
row
- A MarsTableRow that should be added to the end of the table.public MarsTable deleteRows(int[] rows)
rows
- The list of rows to remove.public MarsTable deleteRows(java.util.List<java.lang.Integer> rows)
rows
- An ArrayList containing the rows to remove.public MarsTable keepRows(int[] rows)
rows
- The list of rows to remove.public MarsTable keepRows(java.util.List<java.lang.Integer> rows)
rows
- A List containing the rows to keep.protected org.scijava.table.DoubleColumn createColumn(java.lang.String header)
createColumn
in class org.scijava.table.AbstractTable<org.scijava.table.Column<?>,java.lang.Object>
public java.lang.String dumpJSON()
dumpJSON
in interface JsonConvertibleRecord
public java.io.File getFile()
public void setFile(java.io.File file)
public MarsTable clone()
clone
in class java.util.ArrayList<org.scijava.table.Column<?>>
public void setShowWarnings(boolean showWarnings)
setShowWarnings
in interface JsonConvertibleRecord
public void setJsonField(java.lang.String field, MarsUtil.ThrowingConsumer<com.fasterxml.jackson.core.JsonGenerator,java.io.IOException> output, MarsUtil.ThrowingConsumer<com.fasterxml.jackson.core.JsonParser,java.io.IOException> input)
setJsonField
in interface JsonConvertibleRecord
public java.util.function.Predicate<com.fasterxml.jackson.core.JsonGenerator> getJsonGenerator(java.lang.String field)
JsonConvertibleRecord
getJsonGenerator
in interface JsonConvertibleRecord
field
- Json field.public java.util.function.Predicate<com.fasterxml.jackson.core.JsonParser> getJsonParser(java.lang.String field)
JsonConvertibleRecord
getJsonParser
in interface JsonConvertibleRecord
field
- Json field.