Skip to content

Commit

Permalink
Make mfdatarray work with miniseed.
Browse files Browse the repository at this point in the history
  • Loading branch information
atrabattoni committed Sep 14, 2024
1 parent 0c24614 commit 3cac1ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
14 changes: 14 additions & 0 deletions tests/io/test_miniseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,17 @@ def test_miniseed():
assert da.coords["network"].values == "DX"
assert da.coords["location"].values == "00"
assert da.coords["channel"].values.tolist() == ["HHZ", "HHN", "HHE"]

# automatically open multiple files
da = xd.open_mfdataarray(f"{dirpath}/*.mseed", dim="station", engine="miniseed")
assert da.shape == (10, 3, 100)
assert da.dims == ("station", "channel", "time")
assert da.coords["station"].values.tolist() == [
f"CH{i:03d}" for i in range(1, 11)
]
assert da.coords["time"].isinterp()
assert da.coords["time"][0].values == np.datetime64("1970-01-01T00:00:00")
assert da.coords["time"][-1].values == np.datetime64("1970-01-01T00:00:00.990")
assert da.coords["network"].values == "DX"
assert da.coords["location"].values == "00"
assert da.coords["channel"].values.tolist() == ["HHZ", "HHN", "HHE"]
4 changes: 2 additions & 2 deletions tests/test_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_incompatible_coords(self):
assert len(dc) == 2
assert dc[0].equals(da1)
assert dc[1].equals(da2)

def test_incompatible_sampling_interval(self):
da1 = DataArray(
np.random.rand(10, 5),
Expand Down Expand Up @@ -192,4 +192,4 @@ def test_expand_scalar_coordinate(self):
dc = combine_by_coords([da1, da2], dim="space", squeeze=True)
assert dc.shape == (2, 10)
assert dc.dims == ("space", "time")
assert dc.coords["space"].values.tolist() == [0, 1]
assert dc.coords["space"].values.tolist() == [0, 1]
3 changes: 2 additions & 1 deletion xdas/core/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ def open_mfdataarray(
"The maximum number of file that can be opened at once is for now limited "
"to 100 000."
)
with ProcessPoolExecutor() as executor:
max_workers = 1 if engine == "miniseed" else None # TODO: dirty fix
with ProcessPoolExecutor(max_workers=max_workers) as executor:
futures = [
executor.submit(open_dataarray, path, engine=engine) for path in paths
]
Expand Down

0 comments on commit 3cac1ac

Please sign in to comment.