Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Isken committed Oct 26, 2023
1 parent 9a1c9e0 commit df248f9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lassie/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def init_boundaries(self) -> None:
if self.window_length < 2 * self._window_padding + self._shift_range:
raise ValueError(
f"window length {self.window_length} is too short for the "
f"theoretical shift range {self._shift_range} and "
f"theoretical travel time range {self._shift_range} and "
f"cummulative window padding of {self._window_padding}."
" Increase the window_length time."
)
Expand Down Expand Up @@ -265,10 +265,10 @@ async def start(self, force_rundir: bool = False) -> None:
else:
percent_processed = 0.0
logger.info(
"%s%% processed - batch %s in %s",
"%s%% processed - batch %s in (%s/s)",
f"{percent_processed:.1f}" if percent_processed else "??",
batch.log_str(),
processing_time,
batch.cumulative_duration / processing_time.total_seconds(),
)
if batch.n_batches:
remaining_time = (
Expand Down
12 changes: 12 additions & 0 deletions lassie/waveforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ class WaveformBatch:
def duration(self) -> timedelta:
return self.end_time - self.start_time

@property
def cumulative_duration(self) -> timedelta:
"""Cumulative duration of the traces in the batch.
Returns:
timedelta: Cumulative duration of the traces in the batch.
"""
seconds = 0.0
for tr in self.traces:
seconds += tr.tmax - tr.tmin
return timedelta(seconds=seconds)

def is_empty(self) -> bool:
"""Check if the batch is empty.
Expand Down
21 changes: 14 additions & 7 deletions test/test_fast_marching.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
def stations_inside(
model: VelocityModel3D,
nstations: int = 20,
depth_range: float | None = None,
seed: int = 0,
depth: float | None = None,
) -> Stations:
stations = []
rng = np.random.RandomState(seed)
Expand All @@ -48,7 +48,11 @@ def stations_inside(
north_shift=model.center.north_shift + rng.uniform(*model.north_bounds),
east_shift=model.center.east_shift + rng.uniform(*model.east_bounds),
depth=model.center.depth
+ (depth if depth is not None else rng.uniform(*model.depth_bounds)),
+ (
rng.uniform(depth_range)
if depth_range is not None
else rng.uniform(*model.depth_bounds)
),
)
station = station.shifted_origin()
stations.append(station)
Expand Down Expand Up @@ -249,10 +253,10 @@ async def test_non_lin_loc_travel_times(data_dir: Path, octree: Octree) -> None:
)
model_3d = tracer.velocity_model.get_model(octree)
octree = octree_cover(model_3d)
stations = stations_inside(model_3d, depth=0.0)
stations = stations_inside(model_3d, depth_range=500.0)
await tracer.prepare(octree, stations)

volume = tracer.get_travel_time_volume(stations.stations[0])
volume = tracer.get_travel_time_volume(stations.stations[3])

# 3d figure of velocity model
fig = plt.figure()
Expand All @@ -263,13 +267,16 @@ async def test_non_lin_loc_travel_times(data_dir: Path, octree: Octree) -> None:
cmap = ax.scatter(
coords[0],
coords[1],
coords[2],
-coords[2],
c=volume.travel_times.ravel(),
alpha=0.2,
)
ax.set_xlabel("East (m)")
ax.set_ylabel("North (m)")
ax.set_zlabel("Depth (m)")
fig.colorbar(cmap)

station_offet = volume.station.offset_from(volume.center)
print(station_offet)
ax.scatter(*station_offet, s=100, c="r")
fig.colorbar(cmap)
ax.scatter(*station_offet, s=1000, c="r")
plt.show()

0 comments on commit df248f9

Please sign in to comment.