UNPKG

@seismo/core

Version:

This is the package for the core library of Seismo, a JavaScript library for seismic data processing and visualization. It provides utilities for handling seismic data, including FDSN web services, waveform processing, and event handling. The library is d

367 lines (366 loc) 15 kB
import { DateTime, Duration, Interval } from "luxon"; import { FDSNSourceId, NslcId } from "../fdsn/source-id"; import * as seedcodec from "../waveform/seed-codec"; import { DistAzOutput } from "../utils/distaz"; import { Network, Station, Channel, InstrumentSensitivity } from "../stations/stationxml"; import { Quake } from "../events/quakeml"; import { AMPLITUDE_MODE, MinMaxable } from "../waveform/scale"; import { SeismogramSegment } from "./seismogram-segment"; import type { TraveltimeJsonType, TraveltimeArrivalType } from "../travel-time"; export declare const COUNT_UNIT = "count"; export type HighLowType = { xScaleDomain: Array<Date>; xScaleRange: Array<number>; secondsPerPixel: number; samplesPerPixel: number; highlowArray: Array<number>; }; import type { MarkerType } from "../waveform/marker"; /** * Represents time window for a single channel that may * contain gaps or overlaps, but is otherwise more or less * continuous, or at least adjacent data from the channel. * Each segment within * the Seismogram will have the same units, channel identifiers * and sample rate, but cover different times. */ export declare class Seismogram { _segmentArray: Array<SeismogramSegment>; _interval: Interval; _y: null | Int32Array | Float32Array | Float64Array; constructor(segmentArray: SeismogramSegment | Array<SeismogramSegment>); checkAllSimilar(): void; checkSimilar(f: SeismogramSegment, s: SeismogramSegment): void; findStartEnd(): Interval; findMinMax(minMaxAccumulator?: MinMaxable): MinMaxable; /** * calculates the mean of a seismogrma. * * @returns mean value */ mean(): number; get start(): DateTime; get startTime(): DateTime; get end(): DateTime; get endTime(): DateTime; get timeRange(): Interval; get networkCode(): string | null; get stationCode(): string | null; get locationCode(): string | null; get channelCode(): string | null; /** * return FDSN source id as a string. * * @returns FDSN source id */ get sourceId(): FDSNSourceId; set sourceId(sid: FDSNSourceId); get sampleRate(): number; get samplePeriod(): number; get yUnit(): string | null; isYUnitCount(): boolean; get numPoints(): number; hasCodes(): boolean; /** * return network, station, location and channels codes as one string. * Uses this.channel if it exists, this.seismogram if not. * * @returns net.sta.loc.chan */ get nslc(): string; get nslcId(): NslcId; codes(): string; get segments(): Array<SeismogramSegment>; append(seismogram: SeismogramSegment | Seismogram): void; /** * Cut the seismogram. Creates a new seismogram with all datapoints * contained in the time window. * * @param timeRange start and end of cut * @returns new seismogram */ cut(timeRange: Interval): null | Seismogram; /** * Creates a new Seismogram composed of all seismogram segments that overlap the * given time window. If none do, this returns null. This is a faster but coarser * version of cut as it only removes whole segments that do not overlap the * time window. For most seismograms that consist of a single contiguous * data segment, this will do nothing. * * @param timeRange time range to trim to * @returns new seismogram if data in the window, null otherwise * @see cut */ trim(timeRange: Interval): null | Seismogram; break(duration: Duration): void; isContiguous(): boolean; /** * Merges all segments into a single array of the same type as the first * segment. No checking is done for gaps or overlaps, this is a simple * congatination. Be careful! * * @returns contatenated data */ merge(): Int32Array | Float32Array | Float64Array; /** * Gets the timeseries as an typed array if it is contiguous. * * @throws {NonContiguousData} if data is not contiguous. * @returns timeseries as array of number */ get y(): Int32Array | Float32Array | Float64Array; set y(val: Int32Array | Float32Array | Float64Array); clone(): Seismogram; cloneWithNewData(newY: Int32Array | Float32Array | Float64Array): Seismogram; /** * factory method to create a single segment Seismogram from either encoded data * or a TypedArray, along with sample rate and start time. * * @param yArray array of encoded data or typed array * @param sampleRate sample rate, samples per second of the data * @param startTime time of first sample * @param sourceId optional source id * @returns seismogram initialized with the data */ static fromContiguousData(yArray: Array<seedcodec.EncodedDataSegment> | Int32Array | Float32Array | Float64Array, sampleRate: number, startTime: DateTime, sourceId?: FDSNSourceId): Seismogram; } export declare class NonContiguousData extends Error { constructor(message?: string); } export declare function ensureIsSeismogram(seisSeismogram: Seismogram | SeismogramSegment): Seismogram; export declare class SeismogramDisplayData { /** @private */ _seismogram: Seismogram | null; _id: string | null; _sourceId: FDSNSourceId | null; label: string | null; markerList: Array<MarkerType>; traveltimeList: Array<TraveltimeArrivalType>; channel: Channel | null; _instrumentSensitivity: InstrumentSensitivity | null; quakeList: Array<Quake>; quakeReferenceList: Array<string>; timeRange: Interval; alignmentTime: DateTime; doShow: boolean; _statsCache: SeismogramDisplayStats | null; constructor(timeRange: Interval); static fromSeismogram(seismogram: Seismogram): SeismogramDisplayData; /** * Create a Seismogram from the segment, then call fromSeismogram to create * the SeismogramDisplayData; * @param seisSegment segment of contiguous data * @returns new SeismogramDisplayData */ static fromSeismogramSegment(seisSegment: SeismogramSegment): SeismogramDisplayData; /** * Useful for creating fake data from an array, sample rate and start time * * @param yArray fake data * @param sampleRate samples per second * @param startTime start of data, time of first point * @param sourceId optional source id * @returns seismogramdisplaydata */ static fromContiguousData(yArray: Array<seedcodec.EncodedDataSegment> | Int32Array | Float32Array | Float64Array, sampleRate: number, startTime: DateTime, sourceId?: FDSNSourceId): SeismogramDisplayData; static fromChannelAndTimeWindow(channel: Channel, timeRange: Interval): SeismogramDisplayData; static fromChannelAndTimes(channel: Channel, startTime: DateTime, endTime: DateTime): SeismogramDisplayData; static fromSourceIdAndTimes(sourceId: FDSNSourceId, startTime: DateTime, endTime: DateTime): SeismogramDisplayData; static fromCodesAndTimes(networkCode: string, stationCode: string, locationCode: string, channelCode: string, startTime: DateTime, endTime: DateTime): SeismogramDisplayData; addQuake(quake: Quake | Array<Quake>): void; /** * Adds a public id for a Quake to the seismogram. For use in case where * the quake is not yet available, but wish to retain the connection. * @param publicId id of the earthquake assocated with this seismogram */ addQuakeId(publicId: string): void; addMarker(marker: MarkerType): void; addMarkers(markers: MarkerType | Array<MarkerType>): void; getMarkers(): Array<MarkerType>; addTravelTimes(ttimes: TraveltimeJsonType | TraveltimeArrivalType | Array<TraveltimeArrivalType>): void; hasQuake(): boolean; get quake(): Quake | null; hasSeismogram(): this is { _seismogram: Seismogram; }; append(seismogram: SeismogramSegment | Seismogram): void; hasChannel(): this is { channel: Channel; }; hasSensitivity(): this is { _instrumentSensitivity: InstrumentSensitivity; }; /** * Allows id-ing a seismogram. Optional. * * @returns string id */ get id(): string | null; /** * Allows iding a seismogram. Optional. * * @param value string id */ set id(value: string | null); /** * return network code as a string. * Uses this.channel if it exists, this.seismogram if not. * * @returns network code */ get networkCode(): string; /** * return station code as a string. * Uses this.channel if it exists, this.seismogram if not. * * @returns station code */ get stationCode(): string; /** * return location code a a string. * Uses this.channel if it exists, this.seismogram if not. * * @returns location code */ get locationCode(): string; /** * return channels code as a string. * Uses this.channel if it exists, this.seismogram if not. * * @returns channel code */ get channelCode(): string; /** * return FDSN source id as a string. * Uses this.channel if it exists, this.seismogram if not. * * @returns FDSN source id */ get sourceId(): FDSNSourceId; /** * return network, station, location and channels codes as one string. * Uses this.channel if it exists, this.seismogram if not * * @returns net.sta.loc.chan */ get nslc(): string; get nslcId(): NslcId; /** * return network, station, location and channels codes as one string. * Uses this.channel if it exists, this.seismogram if not. * * @param sep separator, defaults to '.' * @returns nslc codes separated by sep */ codes(sep?: string): string; get startTime(): DateTime; get start(): DateTime; get endTime(): DateTime; get end(): DateTime; get numPoints(): number; associateChannel(nets: Array<Network>): void; alignStartTime(): void; alignOriginTime(): void; alignPhaseTime(phaseRegExp: RegExp | string): void; /** * Create a time window relative to the alignmentTime if set, or the start time if not. * Negative durations are allowed. * @param alignmentOffset offset duration from the alignment time * @param duration duration from the offset for the window * @returns time window as an Interval */ relativeTimeWindow(alignmentOffset: Duration, duration: Duration): Interval; get sensitivity(): InstrumentSensitivity | null; set sensitivity(value: InstrumentSensitivity | null); get min(): number; get max(): number; get mean(): number; get middle(): number; get seismogram(): Seismogram | null; set seismogram(value: Seismogram | null); get segments(): Array<SeismogramSegment>; calcStats(): SeismogramDisplayStats; /** * Calculates distance and azimuth for each event in quakeList. * * @returns Array of DistAzOutput, empty array if no quakes. */ get distazList(): Array<DistAzOutput>; /** * Calculates distance and azimuth for the first event in quakeList. This is * a convienence method as usually there will only be one quake. * * @returns DistAzOutput, null if no quakes. */ get distaz(): null | DistAzOutput; clone(): SeismogramDisplayData; cloneWithNewSeismogram(seis: Seismogram | null): SeismogramDisplayData; /** * Cut the seismogram. Creates a new seismogramDisplayData with the cut * seismogram and the timeRange set to the new time window. * * @param timeRange start and end of cut * @returns new seismogramDisplayData */ cut(timeRange: Interval): null | SeismogramDisplayData; /** * Coarse trim the seismogram. Creates a new seismogramDisplayData with the * trimmed seismogram and the timeRange set to the new time window. * If timeRange is not given, the current time range of the * SeismogramDisplayData is used, effectively trimming data to the current * window. * * @param timeRange start and end of cut * @returns new seismogramDisplayData */ trim(timeRange?: Interval): null | SeismogramDisplayData; /** * Coarse trim the seismogram in place. The seismogram is * trimmed to the given time window. * If timeRange is not given, the current time range of the * SeismogramDisplayData is used, effectively trimming data to the current * window. * * @param timeRange start and end of cut */ trimInPlace(timeRange?: Interval): void; toString(): string; } export declare class SeismogramDisplayStats { min: number; max: number; mean: number; trendSlope: number; constructor(); get middle(): number; } export declare function findStartEnd(sddList: Array<SeismogramDisplayData>): Interval; export declare function findMaxDuration(sddList: Array<SeismogramDisplayData>): Duration; /** * Finds max duration of from one of starttime of sdd, origin time * of earthquake, or alignmentTime. * * @param type one of start, origin or align * @param sddList list of seis data * @returns max duration */ export declare function findMaxDurationOfType(type: string, sddList: Array<SeismogramDisplayData>): Duration; /** * Finds the min and max amplitude over the seismogram list, considering gain * and how to center the seismograms, either Raw, MinMax or Mean. * * @param sddList list of seismogramdisplaydata * @param doGain should gain be used * @param amplitudeMode centering style * @returns min max */ export declare function findMinMax(sddList: Array<SeismogramDisplayData>, doGain?: boolean, amplitudeMode?: AMPLITUDE_MODE): MinMaxable; export declare function findMinMaxOverTimeRange(sddList: Array<SeismogramDisplayData>, timeRange?: Interval | null, doGain?: boolean, amplitudeMode?: AMPLITUDE_MODE): MinMaxable; export declare function findMinMaxOverRelativeTimeRange(sddList: Array<SeismogramDisplayData>, alignmentOffset: Duration, duration: Duration, doGain?: boolean, amplitudeMode?: AMPLITUDE_MODE): MinMaxable; export declare function calcMinMax(sdd: SeismogramDisplayData, timeRange?: Interval | null, doGain?: boolean, amplitudeMode?: AMPLITUDE_MODE): MinMaxable | null; export declare function findStartEndOfSeismograms(data: Array<Seismogram>, accumulator?: Interval): Interval; export declare function findMinMaxOfSeismograms(data: Array<Seismogram>, minMaxAccumulator?: MinMaxable): MinMaxable; export declare function findMinMaxOfSDD(data: Array<SeismogramDisplayData>, minMaxAccumulator?: MinMaxable): MinMaxable; export declare function uniqueStations(seisData: Array<SeismogramDisplayData>): Array<Station>; export declare function uniqueChannels(seisData: Array<SeismogramDisplayData>): Array<Channel>; export declare function uniqueQuakes(seisData: Array<SeismogramDisplayData>): Array<Quake>;