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

171 lines (170 loc) 6.21 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.isValidMarker = isValidMarker; exports.createMarkersForTravelTimes = createMarkersForTravelTimes; exports.createMarkerForOriginTime = createMarkerForOriginTime; exports.createFullMarkersForQuakeAtStation = createFullMarkersForQuakeAtStation; exports.createFullMarkersForQuakeAtChannel = createFullMarkersForQuakeAtChannel; exports.createMarkerForQuakePicks = createMarkerForQuakePicks; exports.createMarkerForPicks = createMarkerForPicks; const distaz = __importStar(require("../utils/distaz")); const luxon_1 = require("luxon"); function isValidMarker(v) { if (!v || typeof v !== "object") { return false; } const m = v; return (typeof m.time === "string" && typeof m.name === "string" && typeof m.markertype === "string" && typeof m.description === "string" && (!("link" in m) || typeof m.link === "string")); } /** * Creates Markers for all of the arrivals in ttime.arrivals, relative * to the given Quake. * * @param quake quake the travel times are relative to * @param ttime travel times json object as returned from the * IRIS traveltime web service, or the json output of TauP * @returns array of Markers suitable for adding to a seismograph */ function createMarkersForTravelTimes(quake, ttime) { return ttime.arrivals.map((a) => { return { markertype: "predicted", name: a.phase, time: quake.time.plus(luxon_1.Duration.fromMillis(1000 * a.time)), description: "", }; }); } /** * Creates a Marker for the origin time in ttime.arrivals, for the given Quake. * * @param quake quake the travel times are relative to * @returns Marker suitable for adding to a seismograph */ function createMarkerForOriginTime(quake) { return { markertype: "predicted", name: "origin", time: quake.time, description: "", }; } function createFullMarkersForQuakeAtStation(quake, station) { const markers = []; if (quake.hasOrigin()) { const daz = distaz.distaz(station.latitude, station.longitude, quake.latitude, quake.longitude); let magVal = ""; let magStr = ""; if (quake.hasPreferredMagnitude()) { magVal = quake.preferredMagnitude ? `${quake.preferredMagnitude.mag}` : ""; magStr = quake.preferredMagnitude ? quake.preferredMagnitude.toString() : ""; } markers.push({ markertype: "predicted", name: `M${magVal} ${quake.time.toFormat("HH:mm")}`, time: quake.time, link: `https://earthquake.usgs.gov/earthquakes/eventpage/${quake.eventId}/executive`, description: `${quake.time.toISO()} ${quake.latitude.toFixed(2)}/${quake.longitude.toFixed(2)} ${(quake.depth / 1000).toFixed(2)} km ${quake.description} ${magStr} ${daz.delta.toFixed(2)} deg to ${station.stationCode} (${daz.distanceKm} km) `, }); } return markers; } function createFullMarkersForQuakeAtChannel(quake, channel) { let markers = createFullMarkersForQuakeAtStation(quake, channel.station); if (quake.preferredOrigin) { markers = markers.concat(createMarkerForPicks(quake.preferredOrigin, channel)); } return markers; } /** * Creates a Marker for the picked arrival times in quake.pickList, for the given Quake. * * @param quake quake the travel times are relative to * @param channel channel picks made on * @returns Marker suitable for adding to a seismograph */ function createMarkerForQuakePicks(quake, channel) { const markers = []; if (quake.pickList) { quake.pickList.forEach((pick) => { if (pick && pick.isOnChannel(channel)) { markers.push({ markertype: "pick", name: "pick", time: pick.time, description: "", }); } }); } return markers; } /** * Creates a Marker for the picked arrival times in quake.arrivals, for the given Quake. * * @param origin quake the travel times are relative to * @param channel channel picks made on * @returns Marker suitable for adding to a seismograph */ function createMarkerForPicks(origin, channel) { const markers = []; if (origin.arrivals) { origin.arrivals.forEach((arrival) => { if (arrival && arrival.pick.isOnChannel(channel)) { markers.push({ markertype: "pick", name: arrival.phase, time: arrival.pick.time, description: "", }); } }); } return markers; }