Struct rubbl_casatables::Table

source ·
pub struct Table { /* private fields */ }
Expand description

A CASA data table.

Implementations§

A Rust wrapper for a casacore table.

For details on the casacore table concepts as expressed in the underlying C++ implementation, see the documentation.

Create a new casacore table.

To open an existing table, use Table::open.

Read more about the casacore tables C++ interface here.

Examples

Creating a table:

use std::path::PathBuf;
use tempfile::tempdir;
use rubbl_casatables::{
    ColumnDescription, GlueDataType, Table,
    TableCreateMode, TableDesc, TableDescCreateMode,
};

// tempdir is only necessary to avoid writing to disk each time this example is run
let tmp_dir = tempdir().unwrap();
let table_path = tmp_dir.path().join("test.ms");

// First create a table description for our base table.
// Use TDM_SCRATCH to avoid writing a `.tabdsc` file to disk.
let mut table_desc = TableDesc::new("", TableDescCreateMode::TDM_SCRATCH).unwrap();

// Define the columns in your table description:
table_desc.add_array_column(
    GlueDataType::TpDouble,                           // the data type
    "UVW",                                            // the column name
    Some("Vector with uvw coordinates (in meters)"),  // an optional comment about the column
    Some(&[3]),                                       // a required vector shape for the volumn
    true,                                             // "direct": whether data are stored in the table
    false,                                            // Whether some scalar values are treated as undefined
).unwrap();

// Create your new table with 0 rows.
Table::new(&table_path, table_desc, 0, TableCreateMode::New).unwrap();

Open an existing casacore table.

To create a table, use Table::new. Do not use TableOpenMode::Create with this function — it will not do what you want.

Read more about the casacore tables C++ interface here.

Examples

Creating a table, writing a cell, opening it and reading the cell.

use std::path::PathBuf;
use tempfile::tempdir;
use rubbl_casatables::{ColumnDescription, GlueDataType, Table, TableCreateMode, TableDesc, TableDescCreateMode, TableOpenMode};

// tempdir is only necessary to avoid writing to disk each time this example is run
let tmp_dir = tempdir().unwrap();
let table_path = tmp_dir.path().join("test.ms");

// First create a table description for our base table.
// Use TDM_SCRATCH to avoid writing the .tabdsc to disk.
let mut table_desc = TableDesc::new("", TableDescCreateMode::TDM_SCRATCH).unwrap();

// Define the columns in your table description:
table_desc.add_array_column(
    GlueDataType::TpDouble,                           // the data type
    "UVW",                                            // the column name
    Some("Vector with uvw coordinates (in meters)"),  // an optional comment about the column
    Some(&[3]),                                       // a required vector shape for the volumn
    true,                                             // "direct": whether data are stored in the table
    false,                                            // Whether some scalar values are treated as undefined
).unwrap();

// Create the new table with 1 row.
let mut table = Table::new(&table_path, table_desc, 1, TableCreateMode::New).unwrap();

// Write to the first row in the uvw column
let cell_value: Vec<f64> = vec![1.0, 2.0, 3.0];
table.put_cell("UVW", 0, &cell_value).unwrap();

// This writes the table to disk and closes the file pointer:
drop(table);

// Now open the table:
let mut table = Table::open(&table_path, TableOpenMode::ReadWrite).unwrap();

// ... and extract the cell value we wrote earlier:
let extracted_cell_value: Vec<f64> = table.get_cell_as_vec("UVW", 0).unwrap();
assert_eq!(cell_value, extracted_cell_value);
Errors

Can raise CasacoreError if there was an issue invoking casacore.

Get the number of rows in the table.

Get the number of columns in the table.

Get the filesystem path associated with the table.

This function should only fail of the underlying C++ throws an exception, which should basically never happen for this operation.

Get a vector containing all of the column names in the table.

Errors

Can raise CasacoreError if there was an issue invoking casacore

Remove a column from the table.

Errors

Can raise CasacoreError if there was an issue invoking casacore. To check: this probably returns an error if the named column was not present?

Add a scalar column to the table.

col_name - column name, must be unique

comment - optional string field describing how to use the column.

direct - Whether the underyling data are stored directly in the table. This should almost always be true.

Errors

Can raise CasacoreError if there was an issue invoking casacore

Add an array column to the Table

If dimensions (dims) are provided, then the column has fixed dimensions, other wise the column is not fixed.

Return all of the names of keywords whose values are type TpTable.

Return all of the names of keywords for a given column

Define a keyword of type TpTable in this table

Add a “keyword” to be associated with the table.

A keyword is essentially a name-value pair, where the associated value need not be a simple data type: it can be a record or even a sub-table.

See also Self::put_column_keyword.

Add a “keyword” to be associated with a particular column of the table.

A keyword is essentially a name-value pair, where the associated value need not be a simple data type: it can be a record or even a sub-table.

See also Self::put_keyword for table-level keywords.

Return a TableRecord containing all keyword / value pairs for this table.

Return a TableRecord containing all keyword / value pairs for the named column.

Get the description of the named column.

The returned ColumnDescription handle provides access to column’s data type, required vector shape, keywords, and other such metadata.

Get all of the data in a column as one vector.

The underlying data type of the column must be scalar. Use this function wisely since some CASA tables may contain millions of rows.

Get the value of one cell of the table.

Get the contents of one cell of the table as a simple Rust vector.

This function discards shape information and won’t accept scalars.

Put a value for one cell of the table.

Add additional, empty rows to the table.

Get an object for read-only access to individual rows of the table.

The row reader can be used to iterate through the rows of the table efficiently.

See also Self::get_row_writer.

Get an object for read-write access to individual rows of the table.

The row writer can be used to iterate through the rows of the table efficiently.

See also Self::get_row_reader.

Populate a TableRow accessor object with data from the specified row.

Perform func on each row of the table.

Perform func on each row in the range row_range.

Perform func on each row indicated by rows.

Copy all rows from this table to another table.

Copy the “description” of this table to a new filesystem path, without copying any of the actual data contents.

Trait Implementations§

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.