Skip to content

Commit

Permalink
fix: catalog (de-)serialization issues with missing required values
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidni committed Sep 9, 2024
1 parent 75bbbb8 commit e266741
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion seismostats/catalogs/catalog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
import os
import uuid
from collections import defaultdict
Expand Down Expand Up @@ -104,7 +105,7 @@ def __init__(
if self.columns.empty:
self = self.reindex(self.columns.union(
REQUIRED_COLS_CATALOG), axis=1)

self.logger = logging.getLogger(__name__)
self.name = name
self.mc = mc
self.b_value = b_value
Expand Down Expand Up @@ -200,6 +201,18 @@ def from_dict(cls,
if not isinstance(df, Catalog):
df = Catalog(df)

full_len = len(df)

df = df.dropna(subset=['latitude',
'longitude',
'time',
'magnitude',
'magnitude_type'])

if len(df) < full_len:
df.logger.info(
f"Dropped {full_len - len(df)} rows with missing values")

if df.empty:
df = Catalog(columns=REQUIRED_COLS_CATALOG + ['magnitude_type'])

Expand Down Expand Up @@ -484,6 +497,14 @@ def to_quakeml(self, agencyID=' ', author=' ') -> str:

df = self.copy()
df = df._create_ids()
df = df.dropna(subset=['latitude',
'longitude',
'time',
'magnitude',
'magnitude_type'])
if len(df) != len(self):
self.logger.info(
f"Dropped {len(self) - len(df)} rows with missing values")

secondary_mags = self._secondary_magnitudekeys()

Expand Down

0 comments on commit e266741

Please sign in to comment.