/** * DataArray - A labeled, multi-dimensional array * Similar to xarray.DataArray in Python */ import { NDArray, DataValue, DimensionName, Coordinates, Attributes, DataArrayOptions, Selection, CoordinateValue, SelectionOptions, StreamOptions, StreamChunk, RollingOptions } from './types.js'; import { type WhereOptions, type BinaryOpOptions } from './ops/where.js'; export declare class DataArray { private _block; private _dims; private _coords; private _attrs; private _name?; private _shape; private _precision; /** * Mapping from current indices to original indices in the source dataset. * Only used for lazy DataArrays that are results of selections. * Maps each dimension to an array where originalIndexMapping[dim][i] = original_index_j * meaning: data at current index i comes from original index j */ private _originalIndexMapping?; private _dimIndexMap; constructor(data: NDArray, options?: DataArrayOptions); /** * Get the data as a native JavaScript array * NOTE: Returns direct reference for performance. Do not mutate the returned array. */ get data(): NDArray; /** * Get the values (alias for data) */ get values(): NDArray; /** * Get the dimensions */ get dims(): DimensionName[]; /** * Get the shape */ get shape(): number[]; /** * Get the coordinates * NOTE: Returns direct reference for performance. Do not mutate the returned object. */ get coords(): Coordinates; /** * Get the attributes * NOTE: Returns direct reference for performance. Do not mutate the returned object. */ get attrs(): Attributes; /** * Get the name */ get name(): string | undefined; /** * Get the number of dimensions */ get ndim(): number; /** * Get the total size (number of elements) */ get size(): number; /** * Check if the underlying data block is lazy */ get isLazy(): boolean; /** * Materialize the DataArray if it is lazy. Returns the original instance for eager arrays. */ compute(): Promise; /** * Select data by coordinate labels */ sel(selection: Selection, options?: SelectionOptions): Promise; /** * Stream data selection in chunks (useful for large datasets) * @param selection - Selection specification * @param options - Streaming options including chunk size and dimension * @returns AsyncGenerator yielding chunks with progress information * * @example * ```typescript * const stream = dataArray.selStream( * { time: ['2020-01-01', '2020-12-31'] }, * { chunkSize: 50 } // 50MB chunks * ); * * for await (const chunk of stream) { * console.log(`Progress: ${chunk.progress}%`); * processData(chunk.data); * } * ``` */ selStream(selection: Selection, options?: StreamOptions): AsyncGenerator>; /** * Select data by integer position * Supports negative indexing (Python-style): -1 = last, -2 = second-to-last, etc. */ isel(selection: { [dimension: string]: number | number[]; }): Promise; /** * Reduce along a dimension */ sum(dim?: DimensionName): DataArray | number; /** * Mean along a dimension */ mean(dim?: DimensionName): DataArray | number; /** * Apply a condition and choose values between this array (x) and another (y) * Similar to xarray.DataArray.where. Broadcasts across shared dimensions. */ where(cond: DataArray | DataValue, other?: DataArray | DataValue | null, options?: WhereOptions): DataArray; /** * Static version similar to xr.where(cond, x, y) */ static where(cond: DataArray | DataValue, x: DataArray | DataValue, y: DataArray | DataValue, options?: WhereOptions): DataArray; cloneWith(options?: { coords?: Coordinates; attrs?: Attributes; name?: string; }): DataArray; assignCoords(mapping: { [dimension: string]: CoordinateValue[] | DataArray; }): DataArray; squeeze(): DataArray; rolling(dim: DimensionName, window: number, options?: RollingOptions): DataArrayRolling; add(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; subtract(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; sub(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; multiply(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; mul(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; divide(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; div(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; power(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; pow(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; greaterThan(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; gt(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; greaterEqual(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; ge(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; lessThan(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; lt(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; lessEqual(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; le(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; equal(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; eq(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; notEqual(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; ne(other: DataArray | DataValue, options?: BinaryOpOptions): DataArray; /** * Convert to a plain JavaScript object */ toObject(): any; /** * Convert to JSON string */ toJSON(): string; /** * Convert to an array of records with coordinates and values * Each record contains coordinate values and the data value * Time coordinates are automatically converted to ISO datetime strings * Numeric coordinates are rounded to avoid floating-point precision errors * * @param options - Optional configuration * @param options.precision - Number of decimal places to round coordinate values (default: 6) * * @example * ```typescript * // For a 2D array with dims ['time', 'lat'] * dataArray.toRecords() * // Returns: * // [ * // { time: '2020-01-01T00:00:00', lat: 45.5, value: 23.4 }, * // { time: '2020-01-02T00:00:00', lat: 46.0, value: 24.1 }, * // ... * // ] * * // Custom precision * dataArray.toRecords({ precision: 2 }) * // [ * // { time: '2020-01-01T00:00:00', lat: 45.50, lon: -73.25, value: 23.4 }, * // ... * // ] * ``` */ toRecords(options?: { precision?: number; }): Array>; /** * Get the bounding box for spatial coordinates * @param options - Optional configuration * @param options.latDim - Name of the latitude dimension (defaults to 'latitude' or 'lat') * @param options.lonDim - Name of the longitude dimension (defaults to 'longitude' or 'lon') * @param options.precision - Number of decimal places to round to (default: 6, set to null for no rounding) * @returns Bounding box with min/max lat/lon, or undefined if spatial dims not found * * @example * ```typescript * const bounds = dataArray.getBounds(); * // Returns: { latMin: 30, latMax: 50, lonMin: -120, lonMax: -70 } * * const bounds = dataArray.getBounds({ precision: 2 }); * // Returns: { latMin: 30.12, latMax: 50.45, lonMin: -120.34, lonMax: -70.89 } * ``` */ getBounds(options?: { latDim?: string; lonDim?: string; precision?: number | null; }): { latMin: number; latMax: number; lonMin: number; lonMax: number; } | undefined; /** * Get dimension index with O(1) lookup using cached map */ private _getDimIndex; /** * Round a number to the specified precision */ /** * Calculate and determine the time resolution from the time coordinate * Automatically detects if data is hourly, daily, weekly, monthly, yearly, etc. * Uses CF-time utilities to properly handle time units * Stores resolution info in attrs * * @param timeDim - Name of the time dimension (defaults to 'time') * @returns Object with resolution value and type, or undefined if cannot be determined * * @example * ```typescript * const result = dataArray.calculateTimeResolution(); * // Returns: { value: 1, type: 'daily', unit: 'days' } * // attrs.time_resolution = 1 * // attrs.time_resolution_type = 'daily' * // attrs.time_resolution_unit = 'days' * ``` */ calculateTimeResolution(timeDim?: string): { value: number; type: string; unit: string; } | undefined; private _toOperand; private static _normalizeOperand; private _binaryOperation; private static _numericBinary; private static _numericComparison; private static _equalityComparison; private _selectData; private _getCoordinateSlice; private _reduce; /** * Select best dimension to chunk along for streaming */ private _selectChunkDimension; /** * Estimate size in bytes for a DataArray */ private _estimateSize; } declare class DataArrayRolling { private readonly _source; private readonly _dim; private readonly _dimIndex; private readonly _options; private readonly _window; constructor(_source: DataArray, _dim: DimensionName, window: number, options: RollingOptions); mean(): DataArray; sum(): DataArray; private _apply; } export {}; //# sourceMappingURL=DataArray.d.ts.map