Skip to content

Commit 043acd8

Browse files
committed
preserve event_id == number_of_events (#43)
1 parent fe657e4 commit 043acd8

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

pyxlma/lmalib/io/read.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ def reorder_stations(dataset, index_mapping):
181181
# merge all the data from this file with the previously-known data
182182
combined_event_data = xr.merge([lma_station_data, lma_event_data])
183183
all_data = combined_event_data
184-
# Sort the data by file_start_time
185-
all_data = all_data.sortby('file_start_time')
186184
# Update the global attributes
187185
all_data.attrs.update(final_attrs)
188186
# To reduce complexity and resource usage, if the 'number_of_files' dimension is the same for all variables, then the dimension is unnecessary
@@ -236,6 +234,10 @@ def dataset(filenames, sort_time=True):
236234
except:
237235
raise
238236
ds = combine_datasets(lma_data)
237+
if sort_time:
238+
ds = ds.sortby('event_time')
239+
if 'file_start_time' in ds.dims:
240+
ds = ds.sortby('file_start_time')
239241
ds = ds.reset_index(('number_of_events', 'number_of_stations'))
240242
if 'number_of_events_' in ds.coords:
241243
# Older xarray versions appended a trailing underscore. reset_coords then dropped
@@ -252,8 +254,6 @@ def dataset(filenames, sort_time=True):
252254
resetted = ('number_of_events', 'number_of_stations')
253255
ds = ds.reset_coords(resetted)
254256
ds = ds.rename_vars({resetted[0]:'event_id'})
255-
if sort_time:
256-
ds = ds.sortby('event_time')
257257
return ds, starttime
258258

259259
def to_dataset(lma_file, event_id_start=0):

0 commit comments

Comments
 (0)