Skip to content

Commit

Permalink
normalize index column name in subarray table (#1065)
Browse files Browse the repository at this point in the history
* normalize column name in subarray table

* fix display_summed_images

* fix subarray peek and added missing test

* use tel_id instead of id in example
  • Loading branch information
kosack authored May 7, 2019
1 parent 91b95e8 commit fea8a57
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
4 changes: 2 additions & 2 deletions ctapipe/instrument/subarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def to_table(self, kind="subarray"):
tel_coords = self.tel_coords

tab = Table(dict(
id=np.array(ids, dtype=np.short),
tel_id=np.array(ids, dtype=np.short),
pos_x=tel_coords.x,
pos_y=tel_coords.y,
pos_z=tel_coords.z,
Expand Down Expand Up @@ -236,7 +236,7 @@ def peek(self):

with quantity_support():
for tel_type in types:
tels = tab[tab['tel_description'] == str(tel_type)]['id']
tels = tab[tab['tel_description'] == str(tel_type)]['tel_id']
sub = self.select_subarray(tel_type, tels)
tel_coords = sub.tel_coords
radius = np.array([
Expand Down
3 changes: 3 additions & 0 deletions ctapipe/instrument/tests/test_subarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def test_subarray_description():
tel_descriptions=tel
)

sub.peek()

assert len(sub.telescope_types) == 1

assert str(sub) == "test array"
Expand All @@ -52,5 +54,6 @@ def test_subarray_description():
assert len(sub.to_table(kind='optics')) == 1



if __name__ == '__main__':
test_subarray_description()
2 changes: 1 addition & 1 deletion ctapipe/tools/display_summed_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def setup(self):
break

group = camtypes.groups[self.telgroup]
self._selected_tels = list(group['id'].data)
self._selected_tels = list(group['tel_id'].data)
self._base_tel = self._selected_tels[0]
self.log.info(
"Telescope group %d: %s", self.telgroup,
Expand Down
24 changes: 5 additions & 19 deletions docs/examples/InstrumentDescription.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"outputs": [],
"source": [
"tab = subarray.to_table()\n",
"sc_tels = tab[tab['num_mirrors'] == 2]['id'] # select tel_id of entries where the mirror type is SC\n",
"sc_tels = tab[tab['num_mirrors'] == 2]['tel_id'] # select tel_id of entries where the mirror type is SC\n",
"newsub = subarray.select_subarray(\"SCTels\", sc_tels)\n",
"newsub.info()"
]
Expand All @@ -111,7 +111,7 @@
"source": [
"gtab = tab.group_by('num_mirrors')\n",
"sc = gtab.groups[0]\n",
"newsub = subarray.select_subarray(\"SCTels\", sc['id'])\n",
"newsub = subarray.select_subarray(\"SCTels\", sc['tel_id'])\n",
"newsub.info()"
]
},
Expand Down Expand Up @@ -241,7 +241,7 @@
"outputs": [],
"source": [
"df = subarray.to_table().to_pandas()\n",
"df.set_index('id')"
"df.set_index('tel_id')"
]
},
{
Expand Down Expand Up @@ -278,25 +278,11 @@
"metadata": {},
"outputs": [],
"source": [
"lsts = subarray.select_subarray(\"LSTs\", df.loc[g.groups['LST:LSTCam']]['id'])\n",
"lsts = subarray.select_subarray(\"LSTs\", df.loc[g.groups['LST:LSTCam']]['tel_id'])\n",
"lsts.info()\n",
"lsts.peek()\n",
"lsts.footprint"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -315,7 +301,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit fea8a57

Please sign in to comment.