Skip to content

Commit

Permalink
Refactor code and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Isken committed Jan 2, 2024
1 parent da4649f commit 4772156
Showing 9 changed files with 196 additions and 163 deletions.
16 changes: 9 additions & 7 deletions src/qseek/apps/qseek.py
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ async def extract() -> None:
total=search._detections.n_detections,
):
detection = await result
await detection.dump_detection(update=True)
await detection.save(update=True)

await search._detections.export_detections(
jitter_location=search.octree.smallest_node_size()
@@ -238,10 +238,11 @@ async def extract() -> None:
asyncio.run(extract())

case "corrections":
rundir = Path(args.rundir)
import json

from qseek.corrections.base import StationCorrections

search = Search.load_rundir(rundir)
rundir = Path(args.rundir)

corrections_modules = StationCorrections.get_subclasses()

@@ -257,15 +258,16 @@ async def extract() -> None:
)
corrections_class = corrections_modules[int(module_choice)]
corrections = asyncio.run(corrections_class.prepare(rundir, console))
search.corrections = corrections

search = json.loads((rundir / "search.json").read_text())
search["corrections"] = corrections.model_dump(mode="json")

new_config_file = rundir.parent / f"{rundir.name}-corrections.json"
console.print("writing new config file")
console.print(
"to use this config file, run [bold]`qseek search %s`",
new_config_file,
f"to use this config file, run [bold]qseek search {new_config_file}"
)
new_config_file.write_text(search.model_dump_json(by_alias=False, indent=2))
new_config_file.write_text(json.dumps(search, indent=2))

case "serve":
search = Search.load_rundir(args.rundir)
3 changes: 1 addition & 2 deletions src/qseek/features/ground_motion.py
Original file line number Diff line number Diff line change
@@ -80,7 +80,6 @@ async def add_features(
except Exception:
continue
receiver_motions.append(ground_motion)
receiver.add_feature(ground_motion)

event_ground_motions = EventGroundMotion(
seconds_before=self.seconds_before,
@@ -95,4 +94,4 @@ async def add_features(
gm.peak_ground_velocity for gm in receiver_motions
),
)
event.features.add_feature(event_ground_motions)
event.add_feature(event_ground_motions)
10 changes: 2 additions & 8 deletions src/qseek/magnitudes/local_magnitude.py
Original file line number Diff line number Diff line change
@@ -102,8 +102,8 @@ def n_observations(self) -> int:

def csv_row(self) -> dict[str, float]:
return {
f"ML_{self.model}": self.average,
f"ML_error_{self.model}": self.error,
f"ML-{self.model}": self.average,
f"ML-error-{self.model}": self.error,
}

def plot(self) -> None:
@@ -245,10 +245,4 @@ async def add_magnitude(self, squirrel: Squirrel, event: EventDetection) -> None
logger.warning("Local magnitude is NaN, skipping event %s", event.time)
return

logger.info(
"Ml %.1f (±%.2f) for event %s",
local_magnitude.average,
local_magnitude.error,
event.time,
)
event.add_magnitude(local_magnitude)
4 changes: 2 additions & 2 deletions src/qseek/magnitudes/local_magnitude_model.py
Original file line number Diff line number Diff line change
@@ -384,7 +384,7 @@ class IcelandBardabunga(WoodAnderson, LocalMagnitudeModel):

@staticmethod
def get_amp_attenuation(dist_hypo_km: float, dist_epi_km: float) -> float:
return 1.2534 * np.log10(dist_hypo_km / 17) + 0.0032 * (dist_hypo_km - 17) + 2
return 1.2534 * np.log10(dist_hypo_km / 17) - 0.0032 * (dist_hypo_km - 17) + 2


class IcelandAskjaBardabungaCombined(WoodAnderson, LocalMagnitudeModel):
@@ -395,7 +395,7 @@ class IcelandAskjaBardabungaCombined(WoodAnderson, LocalMagnitudeModel):

@staticmethod
def get_amp_attenuation(dist_hypo_km: float, dist_epi_km: float) -> float:
return 1.1999 * np.log10(dist_hypo_km / 17) + 0.0016 * (dist_hypo_km - 17) + 2
return 1.1999 * np.log10(dist_hypo_km / 17) - 0.0016 * (dist_hypo_km - 17) + 2


class IcelandReykjanes(WoodAnderson, LocalMagnitudeModel):
Loading

0 comments on commit 4772156

Please sign in to comment.