Last active
June 2, 2025 13:53
-
-
Save bmorris3/52034c8acb431799b94d91fde4fe5aff to your computer and use it in GitHub Desktop.
For @Jenneh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "694a8d3b-2965-4b1e-b0c6-0b28f294834b", | |
"metadata": {}, | |
"source": [ | |
"# Solara filter table widget demo\n", | |
"\n", | |
"Query Missions Mast for JWST observations of WR 140:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "d9f48ea2-e7af-4873-8f19-b5154493fbe0", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"!pip install -U solara" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "828c1877-da77-4927-8f9f-210e7199dc10", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import astropy.units as u\n", | |
"from astropy.coordinates import SkyCoord\n", | |
"from astroquery.mast import MastMissions\n", | |
"\n", | |
"target_name = 'WR 140'\n", | |
"mission = 'JWST'\n", | |
"\n", | |
"target = SkyCoord.from_name(target_name)\n", | |
"mast = MastMissions(mission=mission)\n", | |
"obs = mast.query_region(target, radius=0.1 * u.arcsec)\n", | |
"\n", | |
"dataframe = obs.to_pandas()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "bcb9e043-a217-47f4-9833-71a55dfedef2", | |
"metadata": {}, | |
"source": [ | |
"We'll use `solara` to make a [CrossFilterDataFrame widget](https://solara.dev/documentation/api/cross_filter/cross_filter_dataframe):" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "2954e2f4-3349-42a6-b6aa-0f682666c5e2", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import solara\n", | |
"\n", | |
"@solara.component\n", | |
"def Page():\n", | |
" solara.Markdown(f\"# {mission} observations of {target_name}\")\n", | |
"\n", | |
" # the \"report\" is an icon showing how many rows are\n", | |
" # left from the original dataframe after the filters are applied:\n", | |
" solara.CrossFilterReport(dataframe)\n", | |
"\n", | |
" # selection dropdowns are generated from column names:\n", | |
" solara.CrossFilterSelect(dataframe, \"instrume\")\n", | |
" solara.CrossFilterSelect(dataframe, \"opticalElements\")\n", | |
" solara.CrossFilterSelect(dataframe, \"program\")\n", | |
"\n", | |
" # sliders can filter on ==, >, <, >=, <=,\n", | |
" solara.CrossFilterSlider(dataframe, \"duration\", mode=\">=\", configurable=True)\n", | |
"\n", | |
" solara.CrossFilterDataFrame(dataframe)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "bfdecfdc-15cb-4490-8325-3f59007645d0", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# execute the component to see the widget:\n", | |
"Page()" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.12.9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment