Skip to content

Commit 4a83b9b

Browse files
Add table filter/sorting methods with documentation
1 parent 6169398 commit 4a83b9b

File tree

4 files changed

+93
-6
lines changed

4 files changed

+93
-6
lines changed

docs/reference.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ API reference
44

55
.. automodapi:: firefly_client
66
:no-inheritance-diagram:
7-
:no-heading:
8-
7+
:skip: PackageNotFoundError, Env, FFWs, RangeValues

docs/usage/viewing-tables.rst

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
###############################
12
Visualizing Tables and Catalogs
2-
-------------------------------
3+
###############################
34

45
Tables can be uploaded to the Firefly server with :meth:`FireflyClient.upload_file`,
56
and displayed in a table viewer component with :meth:`FireflyClient.show_table`.
@@ -11,25 +12,58 @@ if the table contains recognizable celestial coordinates.
1112
tval = fc.upload_file('m31-2mass-2412-row.tbl')
1213
fc.show_table(file_on_server=tval, tbl_id='m31-table')
1314
15+
Modifying Table Display Parameters
16+
----------------------------------
17+
1418
If it is desired to overlay the table on an image, or to make plots from it,
1519
without showing the table in the viewer, use :meth:`FireflyClient.fetch_table`:
1620

1721
.. code-block:: py
1822
1923
fc.fetch_table(file_on_server=tval, tbl_id='invisible-table')
2024
25+
Alternatively, you can turn off the `visible` parameter in :meth:`FireflyClient.fetch_table`:
26+
27+
.. code-block:: py
28+
29+
fc.show_table(file_on_server=tval, tbl_id='invisible-table', visible=False)
30+
2131
If the table does not contain celestial coordinates recognized by Firefly,
22-
the image overlay will not appear. BUt if you specifically do not want
23-
the table overlaid on the image, `is_catalog=False` can be specified:
32+
the image overlay will not appear. But if you specifically do not want
33+
the table overlaid on the image, `is_catalog=False` can be specified (it is
34+
`True` by default):
2435

2536
.. code-block:: py
2637
2738
fc.show_table(file_on_server=tval, tbl_id='2mass-tbl', is_catalog=False)
2839
40+
41+
Displaying Table from a URL
42+
---------------------------
43+
2944
If you have the URL of a table, you can pass it directly instead of
3045
downloading it and then uploading it to firefly:
3146

3247
.. code-block:: py
3348
3449
table_url = "http://irsa.ipac.caltech.edu/TAP/sync?FORMAT=IPAC_TABLE&QUERY=SELECT+*+FROM+fp_psc+WHERE+CONTAINS(POINT('J2000',ra,dec),CIRCLE('J2000',70.0,20.0,0.1))=1"
35-
fc.show_table(url=table_url, tbl_id='2mass-point-source-catalog')
50+
tbl_id_2mass_psc = '2mass-point-source-catalog'
51+
fc.show_table(url=table_url, tbl_id=tbl_id_2mass_psc)
52+
53+
Filtering/Sorting a loaded Table
54+
--------------------------------
55+
56+
After displaying a table in firefly, you can also apply filters on it.
57+
You will need to pass the `tbl_id` of that table and specify `filters` as an
58+
SQL WHERE clause-like string with column names quoted:
59+
60+
.. code-block:: py
61+
62+
fc.apply_table_filters(tbl_id=tbl_id_2mass_psc, filters='"j_m">15 and "j_m"<16 and "j_cmsig"<0.06')
63+
64+
You can sort the table by a column in ascending (`ASC`) or descending (`DESC`)
65+
order:
66+
67+
.. code-block:: py
68+
69+
fc.sort_table_column(tbl_id=tbl_id_2mass_psc, column_name='j_m', sort_direction='ASC')

firefly_client/fc_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def ensure3(val, name):
7070
'AddExtension': 'ExternalAccessCntlr/extensionAdd',
7171
'FetchTable': 'table.fetch',
7272
'ShowTable': 'table.search',
73+
'TableFilter': 'table.filter',
74+
'TableSort': 'table.sort',
7375
'ShowXYPlot': 'charts.data/chartAdd',
7476
'ShowPlot': 'charts.data/chartAdd',
7577
'ZoomImage': 'ImagePlotCntlr.ZoomImage',

firefly_client/firefly_client.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,3 +1915,55 @@ def remove_mask(self, plot_id, mask_id):
19151915

19161916
payload = {'plotId': plot_id, 'imageOverlayId': mask_id}
19171917
return self.dispatch(ACTION_DICT['DeleteOverlayMask'], payload)
1918+
1919+
# ----------------------------
1920+
# actions on table
1921+
# ----------------------------
1922+
1923+
def apply_table_filters(self, tbl_id, filters):
1924+
"""
1925+
Apply filters to a loaded table.
1926+
1927+
Parameters
1928+
----------
1929+
plot_id : `str`
1930+
ID of the table where you want to apply filters
1931+
filters : `str`
1932+
SQL WHERE clause-like string specifying filters. Column names must be quoted.
1933+
For e.g. '("ra" > 185 AND "ra" < 185.1) OR ("dec" > 15 AND "dec" < 15.1) AND "band" IN (1,2)'.
1934+
1935+
Returns
1936+
--------
1937+
out : `dict`
1938+
Status of the request, like {'success': True}
1939+
"""
1940+
tbl_req = {'tbl_id': tbl_id, 'filters': filters}
1941+
payload = {'request': tbl_req}
1942+
return self.dispatch(ACTION_DICT['TableFilter'], payload)
1943+
1944+
def sort_table_column(self, tbl_id, column_name, sort_direction=''):
1945+
"""
1946+
Sort a loaded table by a given column name.
1947+
1948+
Parameters
1949+
----------
1950+
plot_id : `str`
1951+
ID of the table where you want to apply sort
1952+
column_name : `str`
1953+
Name of the table column to sort
1954+
sort_direction : {'', 'ASC', 'DESC'}, optional
1955+
Direction of sort: '' for unsorted, 'ASC' for ascending, and 'DESC'
1956+
for descending. Default is ''.
1957+
1958+
Returns
1959+
--------
1960+
out : `dict`
1961+
Status of the request, like {'success': True}
1962+
"""
1963+
sort_directions = ['', 'ASC', 'DESC']
1964+
if sort_direction not in sort_directions:
1965+
raise ValueError(f'Invalid sort_direction. Valid values are {sort_directions}')
1966+
1967+
tbl_req = {'tbl_id': tbl_id, 'sortInfo': f'{sort_direction},{column_name}'}
1968+
payload = {'request': tbl_req}
1969+
return self.dispatch(ACTION_DICT['TableSort'], payload)

0 commit comments

Comments
 (0)