Skip to content

Commit

Permalink
Add magnitude property to EventDetection class
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Isken committed Dec 31, 2023
1 parent bddbac6 commit 5c8b2c0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/qseek/models/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,15 @@ def set_rundir(cls, rundir: Path) -> None:
"""
cls._rundir = rundir

@property
def magnitude(self) -> EventMagnitude | None:
"""
Returns the magnitude of the event.
If there are no magnitudes available, returns None.
"""
return self.magnitudes[0] if self.magnitudes else None

async def dump_detection(
self, file: Path | None = None, update: bool = False
) -> None:
Expand Down Expand Up @@ -598,7 +607,7 @@ def as_pyrocko_event(self) -> Event:
Returns:
Event: Pyrocko event
"""
magnitude = self.magnitudes[0] if self.magnitudes else None
magnitude = self.magnitude
return Event(
name=self.time.isoformat(sep="T"),
time=self.time.timestamp(),
Expand All @@ -609,6 +618,7 @@ def as_pyrocko_event(self) -> Event:
depth=self.effective_depth,
magnitude=magnitude.average if magnitude else self.semblance,
magnitude_type=magnitude.name if magnitude else "semblance",
extras={"semblance": self.semblance},
)

def get_csv_dict(self) -> dict[str, Any]:
Expand Down Expand Up @@ -691,7 +701,6 @@ def snuffle(self, squirrel: Squirrel, restituted: bool = False) -> None:
snuffle(
traces,
markers=self.get_pyrocko_markers(),
events=[self.as_pyrocko_event()],
stations=[recv.as_pyrocko_station() for recv in self.receivers],
)

Expand Down

0 comments on commit 5c8b2c0

Please sign in to comment.