oceanum-js

@oceanum/datamesh


@oceanum/datamesh / Dataset

Class: Dataset<S>

Defined in: packages/datamesh/src/lib/datamodel.ts:344

Type Parameters

S

S extends HttpZarr | TempZarr

Constructors

Constructor

new Dataset<S>(dimensions, variables, attributes, coordkeys, root): Dataset<S>

Defined in: packages/datamesh/src/lib/datamodel.ts:361

Parameters

dimensions

Record<string, number>

variables

S extends TempZarr ? Record<string, DataVar<DataType, TempZarr>> : Record<string, DataVar<DataType, HttpZarr>>

attributes

Record<string, unknown>

coordkeys

Coordkeys

root

S

Returns

Dataset<S>

Properties

attributes

attributes: Record<string, unknown>

Defined in: packages/datamesh/src/lib/datamodel.ts:357


coordkeys

coordkeys: Coordkeys

Defined in: packages/datamesh/src/lib/datamodel.ts:358


dimensions

dimensions: Record<string, number>

Defined in: packages/datamesh/src/lib/datamodel.ts:353

Creates an instance of Dataset.

Param

The dimensions of the dataset.

Param

The data variables of the dataset.

Param

The attributes of the dataset.

Param

The root group of the dataset.

Param

The coordinates map of the dataset.


root

root: S

Defined in: packages/datamesh/src/lib/datamodel.ts:359


variables

variables: S extends TempZarr ? Record<string, DataVar<DataType, TempZarr>> : Record<string, DataVar<DataType, HttpZarr>>

Defined in: packages/datamesh/src/lib/datamodel.ts:354

Methods

asDataframe()

asDataframe(): Promise<Record<string, unknown>[]>

Defined in: packages/datamesh/src/lib/datamodel.ts:602

Converts the dataset into a dataframe format.

Returns

Promise<Record<string, unknown>[]>

A promise that resolves to an array of records, where each record represents a row in the dataframe.

Remarks

This method iterates over the data variables, retrieves their dimensions and data, and then flattens the data into a dataframe structure. Time coordinates are converted to IDO8601 format. BigInt datatypes are coerced to number.

Example

const dataframe = await instance.asDataframe();
console.log(dataframe);

asGeojson()

asGeojson(geometry?): Promise<FeatureCollection<Geometry, GeoJsonProperties>>

Defined in: packages/datamesh/src/lib/datamodel.ts:653

Converts the dataset into a GeoJSON Feature.

Parameters

geometry?

Geometry

Optional GeoJSON geometry to apply to all records, otherwise geometry column is required. Will override geometry column if present.

Returns

Promise<FeatureCollection<Geometry, GeoJsonProperties>>

A promise that resolves to an array of records, where each record represents a row in the dataframe.

Throws

Will throw an error if no geometry is found in data or as a parameter

Remarks

This method iterates over the data variables, retrieves their dimensions and data, and then flattens the data into a dataframe structure.

Example

const dataframe = await instance.asDataframe();
console.log(dataframe);

assign()

assign(varid, dims, data, attrs?, dtype?, chunks?): Promise<void>

Defined in: packages/datamesh/src/lib/datamodel.ts:699

Asynchronously assigns data to a variable in the dataset.

Parameters

varid

string

The identifier for the variable.

dims

string[]

An array of dimension names corresponding to the data.

data

Data

The data to be assigned, which can be a multi-dimensional array.

attrs?

Record<string, unknown>

Optional. A record of attributes to be associated with the variable.

dtype?

DataType

Optional. The data type of the data.

chunks?

number[]

Optional. An array specifying the chunk sizes for the data.

Returns

Promise<void>

A promise that resolves when the data has been successfully assigned.

Throws

Will throw an error if the shape of the data does not match the provided dimensions.

Throws

Will throw an error if an existing dimension size does not match the new data.


fromArrow()

static fromArrow(data, coordkeys): Promise<Dataset<TempZarr>>

Defined in: packages/datamesh/src/lib/datamodel.ts:443

Parameters

data

Table

coordkeys

Coordkeys

Returns

Promise<Dataset<TempZarr>>


fromGeojson()

static fromGeojson(geojson, coordkeys?): Promise<Dataset<TempZarr>>

Defined in: packages/datamesh/src/lib/datamodel.ts:483

Parameters

geojson
FeatureCollection<Geometry, GeoJsonProperties> Feature<Geometry, GeoJsonProperties>
coordkeys?

Coordkeys

Returns

Promise<Dataset<TempZarr>>


init()

static init(datasource, coordkeys?): Promise<Dataset<TempZarr>>

Defined in: packages/datamesh/src/lib/datamodel.ts:555

Initializes an in memory Dataset instance from a data object.

Parameters

datasource

Schema

An object containing id, dimensions, data variables, and attributes.

coordkeys?

Coordkeys

Returns

Promise<Dataset<TempZarr>>


zarr()

static zarr(url, authHeaders, options): Promise<Dataset<HttpZarr>>

Defined in: packages/datamesh/src/lib/datamodel.ts:390

Creates a Dataset instance from a Zarr store.

Parameters

url

string

The URL of the datamesh gateway.

authHeaders

Record<string, string>

The authentication headers.

options

ZarrOptions = {}

Returns

Promise<Dataset<HttpZarr>>

A promise that resolves to a Dataset instance.