Skip to content

Commit

Permalink
Update station variable to stations and add station_corrections prepa…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
Marius Isken committed Jan 16, 2024
1 parent aa1c0ed commit b2f9089
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/qseek/corrections/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np
from rich.console import Console

from qseek.models.station import Station
from qseek.models.station import Stations
from qseek.octree import Octree
from qseek.utils import NSL, PhaseDescription

Expand Down Expand Up @@ -64,7 +64,7 @@ def get_delays(

async def prepare(
self,
station: Station,
stations: Stations,
octree: Octree,
phases: Iterable[PhaseDescription],
) -> None:
Expand Down
4 changes: 4 additions & 0 deletions src/qseek/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ async def prepare(self) -> None:
)
for magnitude in self.magnitudes:
await magnitude.prepare(self.octree, self.stations)
if self.station_corrections:
await self.station_corrections.prepare(
self.stations, self.octree, self.image_functions.get_phases()
)
self.init_boundaries()

async def start(self, force_rundir: bool = False) -> None:
Expand Down
16 changes: 9 additions & 7 deletions test/test_moment_magnitude_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ async def test_peak_amplitude_plot(engine: gf.LocalEngine) -> None:
@pytest.mark.asyncio
async def test_peak_amplitude_surface(engine: gf.LocalEngine) -> None:
import matplotlib.pyplot as plt
from matplotlib.cm import ScalarMappable
from matplotlib.colors import LightSource
from matplotlib.ticker import FuncFormatter

Expand All @@ -104,7 +105,7 @@ async def test_peak_amplitude_surface(engine: gf.LocalEngine) -> None:
plot_amplitude: PeakAmplitude = "absolute"
PeakAmplitudesStore.set_engine(engine)
store = PeakAmplitudesStore.from_selector(peak_amplitudes)
await store.fill_source_depth_range(depth_max=20 * KM)
await store.fill_source_depth_range(depth_max=15 * KM)

distances = np.linspace(0, store.max_distance, 256)
depths = np.linspace(*store.source_depth_range, 256)
Expand All @@ -124,15 +125,14 @@ async def test_peak_amplitude_surface(engine: gf.LocalEngine) -> None:
)
depth_amplitudes.append(amplitudes)

data = [[a.amplitude_median for a in amplitudes] for amplitudes in depth_amplitudes]
data = [[a.median for a in amplitudes] for amplitudes in depth_amplitudes]
data = np.array(data) / NM

data = np.log10(data)

fig, ax = plt.subplots()
ls = LightSource(azdeg=315, altdeg=45)

rgb = ls.shade(data, cmap=plt.cm.get_cmap("viridis"), blend_mode="overlay")
cmap = "viridis"
rgb = ls.shade(np.log10(data), cmap=plt.cm.get_cmap(cmap), blend_mode="overlay")

ax.imshow(
rgb,
Expand All @@ -144,8 +144,10 @@ async def test_peak_amplitude_surface(engine: gf.LocalEngine) -> None:
],
aspect="auto",
)
# cbar = fig.colorbar(cm)
# cbar.set_label("Absolute Displacement [nm]")
cm = ScalarMappable(norm=None, cmap=cmap)
cm.set_array(data)
cbar = fig.colorbar(cm, ax=ax)
cbar.set_label("Absolute Displacement [nm]")

ax.set_xlabel("Epicentral Distance [km]")
ax.set_ylabel("Source Depth [km]")
Expand Down

0 comments on commit b2f9089

Please sign in to comment.