diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py index 57ed6652..5a307e53 100644 --- a/WrightTools/data/_data.py +++ b/WrightTools/data/_data.py @@ -1891,7 +1891,14 @@ def smooth(self, factors, channel=None, verbose=True) -> "Data": print("smoothed data") def split( - self, expression, positions, *, units=None, parent=None, verbose=True + self, + expression, + positions, + *, + units=None, + parent=None, + inherit_attrs=False, + verbose=True, ) -> wt_collection.Collection: """ Split the data object along a given expression, in units. @@ -1928,7 +1935,7 @@ def split( # axis ------------------------------------------------------------------------------------ old_expr = self.axis_expressions old_units = self.units - out = wt_collection.Collection(name="split", parent=parent) + out = wt_collection.Collection(name=f"{self.natural_name}_split", parent=parent) if isinstance(expression, int): if units is None: units = self._axes[expression].units @@ -1962,7 +1969,7 @@ def split( omasks.append(None) cuts.append(None) for i in range(len(positions) - 1): - out.create_data("split%03i" % i) + out.create_data(f"{self.natural_name}_{i:0>3}") for var in self.variables: for i, (imask, omask, cut) in enumerate(zip(masks, omasks, cuts)): @@ -2037,6 +2044,10 @@ def split( for ax, u in zip(self.axes, old_units): ax.convert(u) + if inherit_attrs: + for d in out.values(): + {d.attrs[k]: self.attrs[k] for k in self.attrs.keys() if k not in d.attrs.keys()} + return out def transform(self, *axes, verbose=True): diff --git a/tests/data/split.py b/tests/data/split.py index 5b2e8b61..fd4fbb44 100755 --- a/tests/data/split.py +++ b/tests/data/split.py @@ -122,7 +122,7 @@ def test_split_parent(): a = wt.data.from_PyCMDS(p) parent = wt.Collection() split = a.split(1, [1500], parent=parent) - assert "split" in parent + assert f"{a.natural_name}_split" in parent assert split.filepath == parent.filepath assert len(split) == 2 a.close()