Skip to content

Commit

Permalink
Merge pull request #156 from fact-project/preserve_order
Browse files Browse the repository at this point in the history
Preserve order in astropy table joins
  • Loading branch information
maxnoe authored May 5, 2021
2 parents fa057dc + ad80c19 commit 441490f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aict_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.27.0"
__version__ = "0.27.1"
11 changes: 10 additions & 1 deletion aict_tools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ def read_cta_dl1(path, aict_config, key=None, columns=None, first=None, last=Non
# columns=columns
tel_table = read_table(path, tel)[first:last]

# astropy table joins do not preserve input order
# but sort by the join keys, we add this simple index
# so we can restore the input order after joining
tel_table["__index"] = np.arange(len(tel_table))

# Pointing information has to be loaded from the monitoring tables and interpolated
# We also need the trigger tables as monitoring is based on time not events
if columns:
Expand Down Expand Up @@ -543,9 +548,13 @@ def read_cta_dl1(path, aict_config, key=None, columns=None, first=None, last=Non
if columns:
# True / Simulation columns are still missing, so only use the columns already present
tel_table = tel_table[
list(set(columns).intersection(tel_table.columns))
list(set(columns).intersection(tel_table.columns)) + ['__index']
].copy()

# restore the input order that was changed by astropy.table.join
# and remove the additional column
tel_table.sort('__index')
tel_table.remove_column('__index')
tel_tables.append(tel_table)

# Monte carlo information is located in the simulation group
Expand Down

0 comments on commit 441490f

Please sign in to comment.