Skip to content

Commit 8cc4b4c

Browse files
committed
Update tract/patch search demo; add tract_patch_search function to dunder init
1 parent f5c0998 commit 8cc4b4c

File tree

2 files changed

+66
-134
lines changed

2 files changed

+66
-134
lines changed

docs/notebooks/tract_patch_search.ipynb

Lines changed: 63 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,10 @@
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
18-
"# Client for Dask distributed computing\n",
1918
"from dask.distributed import Client\n",
20-
"\n",
21-
"# For reading the HATS catalogs and performing the cross-match\n",
2219
"import lsdb\n",
23-
"\n",
24-
"# For reading and working with skymaps for tract and patch searches\n",
25-
"import lsst.skymap\n",
26-
"import pickle\n",
27-
"\n",
28-
"# For accessing Rubin-specific lsdb methods; in this case, tract_patch_search\n",
29-
"from lsdb_rubin import tract_patch_search\n",
30-
"\n",
31-
"lsdb.catalog.Catalog.tract_patch_search = tract_patch_search"
20+
"import skymap_convert\n",
21+
"from lsdb_rubin import tract_patch_search"
3222
]
3323
},
3424
{
@@ -60,7 +50,7 @@
6050
"# Load GAIA DR3 data.\n",
6151
"\n",
6252
"gaia = lsdb.read_hats(\n",
63-
" \"https://data.lsdb.io/hats/gaia_dr3/gaia\", margin_cache=\"https://data.lsdb.io/hats/gaia_dr3/gaia_10arcs\"\n",
53+
" \"https://data.lsdb.io/hats/gaia_dr3/gaia\", margin_cache=\"https://data.lsdb.io/hats/gaia_dr3/gaia_10arcs\", columns=[\"ra\", \"dec\", \"source_id\"]\n",
6454
")\n",
6555
"gaia"
6656
]
@@ -74,118 +64,95 @@
7464
"source": [
7565
"# Load the LSST skymap.\n",
7666
"\n",
77-
"lsst_skymap_path = \"/sdf/home/o/olynn/LINCC/Skymaps/skyMap_lsst_cells_v1_skymaps.pickle\"\n",
67+
"import skymap_convert\n",
7868
"\n",
79-
"with open(lsst_skymap_path, \"rb\") as f:\n",
80-
" lsst_skymap = pickle.load(f)\n",
81-
" print(lsst_skymap)"
69+
"lsst_skymap = skymap_convert.ConvertedSkymapReader(preset=\"lsst_skymap\")"
8270
]
8371
},
8472
{
8573
"cell_type": "markdown",
86-
"id": "bb4bac82",
74+
"id": "e68839f6",
8775
"metadata": {},
8876
"source": [
89-
"## Use RA/Dec to get tract and patch IDs"
77+
"## Search by tract ID"
9078
]
9179
},
9280
{
9381
"cell_type": "code",
9482
"execution_count": null,
95-
"id": "e4595bbb",
83+
"id": "4ae3dcb6",
9684
"metadata": {},
9785
"outputs": [],
9886
"source": [
99-
"# Get tract and patch numbers for a given RA and Dec.\n",
100-
"\n",
101-
"ra_float = 42.0\n",
102-
"dec_float = 2.0\n",
103-
"\n",
104-
"longitude = lsst.geom.Angle(ra_float, lsst.geom.degrees)\n",
105-
"latitude = lsst.geom.Angle(dec_float, lsst.geom.degrees)\n",
106-
"sphere_point = lsst.geom.SpherePoint(longitude, latitude)\n",
107-
"\n",
108-
"tract_patch_list = lsst_skymap.findTractPatchList([sphere_point])\n",
109-
"tract_patch_list\n",
110-
"\n",
111-
"tract_index = tract_patch_list[0][0]._id\n",
112-
"patch_index = tract_patch_list[0][1][0]._sequentialIndex\n",
113-
"\n",
114-
"print(f\"Tract: {tract_index}, Patch: {patch_index}\")"
87+
"tract_index = 10_000"
11588
]
11689
},
11790
{
11891
"cell_type": "code",
11992
"execution_count": null,
120-
"id": "e9009c07",
93+
"id": "c06826c7",
12194
"metadata": {},
12295
"outputs": [],
12396
"source": [
124-
"# Get tract and patch numbers for a given RA and Dec.\n",
125-
"\n",
126-
"ra_float = 300\n",
127-
"dec_float = -15\n",
128-
"\n",
129-
"longitude = lsst.geom.Angle(ra_float, lsst.geom.degrees)\n",
130-
"latitude = lsst.geom.Angle(dec_float, lsst.geom.degrees)\n",
131-
"sphere_point = lsst.geom.SpherePoint(longitude, latitude)\n",
132-
"\n",
133-
"tract_patch_list = lsst_skymap.findTractPatchList([sphere_point])\n",
134-
"tract_patch_list\n",
135-
"\n",
136-
"tract_index = tract_patch_list[0][0]._id\n",
137-
"patch_index = tract_patch_list[0][1][0]._sequentialIndex\n",
97+
"# Only specify the tract (and not patch) to search by tract.\n",
13898
"\n",
139-
"print(f\"Tract: {tract_index}, Patch: {patch_index}\")\n",
99+
"lsdb.catalog.Catalog.tract_patch_search = tract_patch_search\n",
140100
"\n",
141-
"# TODO : Account for multiple tracts/patches (eg, ra: 42, dec: 3)"
101+
"gaia_tract = gaia.tract_patch_search(\n",
102+
" skymap_reader=lsst_skymap,\n",
103+
" tract=tract_index\n",
104+
")\n",
105+
"gaia_tract"
142106
]
143107
},
144108
{
145-
"cell_type": "markdown",
146-
"id": "e68839f6",
109+
"cell_type": "code",
110+
"execution_count": null,
111+
"id": "dc2fb6a5",
147112
"metadata": {},
113+
"outputs": [],
148114
"source": [
149-
"## Search by tract and patch IDs"
115+
"gaia_tract.plot_pixels(\n",
116+
" plot_title=\"Gaia DR3 Tract Search\",\n",
117+
" fc=\"#00000000\",\n",
118+
" ec=\"red\",\n",
119+
" alpha=0.5,\n",
120+
")"
150121
]
151122
},
152123
{
153124
"cell_type": "markdown",
154-
"id": "97bfbbfc",
125+
"id": "734b21fc",
155126
"metadata": {},
156127
"source": [
157-
"### Search by tract"
128+
"### Plot the points within our tract search"
158129
]
159130
},
160131
{
161132
"cell_type": "code",
162133
"execution_count": null,
163-
"id": "c06826c7",
134+
"id": "f0393287",
164135
"metadata": {},
165136
"outputs": [],
166137
"source": [
167-
"# Only specify the tract (and not patch) to search by tract.\n",
168-
"\n",
169-
"gaia_tract = gaia.tract_patch_search(\n",
170-
" skymap=lsst_skymap,\n",
171-
" tract=tract_index,\n",
172-
" fine=True,\n",
173-
")\n",
174-
"gaia_tract"
138+
"df = gaia_tract.compute()\n",
139+
"df"
175140
]
176141
},
177142
{
178143
"cell_type": "code",
179144
"execution_count": null,
180-
"id": "dc2fb6a5",
145+
"id": "97c9e7d3",
181146
"metadata": {},
182147
"outputs": [],
183148
"source": [
184-
"gaia_tract.plot_pixels(\n",
185-
" plot_title=\"Gaia DR3 Tract Search\",\n",
186-
" fc=\"#00000000\",\n",
187-
" ec=\"red\",\n",
188-
" alpha=0.5,\n",
149+
"from lsdb.core.plotting import plot_points\n",
150+
"\n",
151+
"plot_points.plot_points(\n",
152+
" df,\n",
153+
" ra_column=\"ra\",\n",
154+
" dec_column=\"dec\",\n",
155+
" title=\"Gaia DR3 Tract Search\",\n",
189156
")"
190157
]
191158
},
@@ -194,7 +161,18 @@
194161
"id": "c5fe192e",
195162
"metadata": {},
196163
"source": [
197-
"### Search by tract and patch"
164+
"## Search by patch ID"
165+
]
166+
},
167+
{
168+
"cell_type": "code",
169+
"execution_count": null,
170+
"id": "88c3d2fd",
171+
"metadata": {},
172+
"outputs": [],
173+
"source": [
174+
"tract_index = 12_345\n",
175+
"patch_index = 67"
198176
]
199177
},
200178
{
@@ -207,10 +185,9 @@
207185
"# Specify both tract and patch to search by tract and patch.\n",
208186
"\n",
209187
"gaia_tract_patch = gaia.tract_patch_search(\n",
210-
" skymap=lsst_skymap,\n",
188+
" skymap_reader=lsst_skymap,\n",
211189
" tract=tract_index,\n",
212190
" patch=patch_index,\n",
213-
" fine=True,\n",
214191
")\n",
215192
"gaia_tract_patch"
216193
]
@@ -230,6 +207,14 @@
230207
")"
231208
]
232209
},
210+
{
211+
"cell_type": "markdown",
212+
"id": "6f0b05b7",
213+
"metadata": {},
214+
"source": [
215+
"### Plot the points within our patch search"
216+
]
217+
},
233218
{
234219
"cell_type": "code",
235220
"execution_count": null,
@@ -257,67 +242,11 @@
257242
" title=\"Gaia DR3 Tract and Patch Search\",\n",
258243
")"
259244
]
260-
},
261-
{
262-
"cell_type": "markdown",
263-
"id": "898e778d",
264-
"metadata": {},
265-
"source": [
266-
"### Set `user_inner` to True to search the \"inner\" region of the tract or patch"
267-
]
268-
},
269-
{
270-
"cell_type": "markdown",
271-
"id": "2b72add3",
272-
"metadata": {},
273-
"source": [
274-
"Read more at the [LSST Skymap Docs](https://github.com/lsst/skymap/blob/main/doc/main.dox):\n",
275-
"\n",
276-
"> Tracts contain an inner region described by a collection of vertices. The inner regions exactly tile the portion of sky covered by the sky map. All pixels beyond the inner region provide overlap with neighboring tracts.\n",
277-
"\n",
278-
"> Patches contain rectangular inner and outer regions. The inner regions exactly tile the tract, and all patches in a tract have the same inner dimensions. Each patch has a border around the inner region to provide some overlap with adjacent patches, but there is no border on patch edges that lie against tract boundaries."
279-
]
280-
},
281-
{
282-
"cell_type": "markdown",
283-
"id": "098369c0",
284-
"metadata": {},
285-
"source": [
286-
"Note that `use_inner` may be specified for either a tract or a patch search."
287-
]
288-
},
289-
{
290-
"cell_type": "code",
291-
"execution_count": null,
292-
"id": "2f2819d7",
293-
"metadata": {},
294-
"outputs": [],
295-
"source": [
296-
"gaia_tract_patch_outer = gaia.tract_patch_search(\n",
297-
" skymap=lsst_skymap,\n",
298-
" tract=tract_index,\n",
299-
" patch=patch_index,\n",
300-
" fine=True,\n",
301-
" use_inner=True,\n",
302-
")\n",
303-
"gaia_tract_patch_outer"
304-
]
305-
},
306-
{
307-
"cell_type": "code",
308-
"execution_count": null,
309-
"id": "cac0bf23",
310-
"metadata": {},
311-
"outputs": [],
312-
"source": [
313-
"df = gaia_tract_patch_outer.compute()\n",
314-
"df"
315-
]
316245
}
317246
],
318247
"metadata": {
319248
"kernelspec": {
320-
"display_name": "Python 3 (ipykernel)",
249+
"display_name": "p311",
321250
"language": "python",
322251
"name": "python3"
323252
},
@@ -331,7 +260,7 @@
331260
"name": "python",
332261
"nbconvert_exporter": "python",
333262
"pygments_lexer": "ipython3",
334-
"version": "3.12.9"
263+
"version": "3.11.13"
335264
}
336265
},
337266
"nbformat": 4,

src/lsdb_rubin/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .tract_patch_search import tract_patch_search
2+
3+
__all__ = ["tract_patch_search"]

0 commit comments

Comments
 (0)