Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 9b197b2

Browse files
authored
Merge pull request #34 from rubin-dp0/main
Merge to prod
2 parents 696a37d + d688050 commit 9b197b2

1 file changed

Lines changed: 45 additions & 2 deletions

File tree

02_Intermediate_TAP_Query.ipynb

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,50 @@
427427
"print(f'There are {results[results[\"truth_type\"] == 3].shape[0]} SNe')"
428428
]
429429
},
430+
{
431+
"cell_type": "markdown",
432+
"metadata": {},
433+
"source": [
434+
"#### 2.4. Simple histogram to bin categorical data. \n",
435+
"\n",
436+
"Now we will create a simple categorical histogram of the number of each truth_type in the dataset. We will use the 'GROUP BY' ADQL command to group the Objects in the truth_match catalog by type (1: galaxies, 2:stars, 3: SNe), and the 'COUNT' command to count the number of Objects in each category. Finally we will use the 'ORDER' command to order the results by ascending order of truth_type. "
437+
]
438+
},
439+
{
440+
"cell_type": "code",
441+
"execution_count": null,
442+
"metadata": {},
443+
"outputs": [],
444+
"source": [
445+
"query_histogram = \"SELECT truth_type, count(truth_type) \" \\\n",
446+
" \" FROM dp01_dc2_catalogs.truth_match \" \\\n",
447+
" \" GROUP BY truth_type \" \\\n",
448+
" \" ORDER BY truth_type\"\n",
449+
"print(query_histogram)"
450+
]
451+
},
452+
{
453+
"cell_type": "code",
454+
"execution_count": null,
455+
"metadata": {},
456+
"outputs": [],
457+
"source": [
458+
"object_type_histogram = service.search(query_histogram).to_table().to_pandas()"
459+
]
460+
},
461+
{
462+
"cell_type": "code",
463+
"execution_count": null,
464+
"metadata": {},
465+
"outputs": [],
466+
"source": [
467+
"# Map the numerical values for each type to a more descriptive name\n",
468+
"object_map = {1: 'galaxy', 2: 'star', 3: 'SNe'}\n",
469+
"object_type_histogram['truth_type'] = \\\n",
470+
" object_type_histogram['truth_type'].map(object_map)\n",
471+
"object_type_histogram"
472+
]
473+
},
430474
{
431475
"cell_type": "markdown",
432476
"metadata": {},
@@ -473,7 +517,6 @@
473517
"\n",
474518
"# We will want to filter on the truth type later\n",
475519
"# We will convert the truth_type integer to a more descriptive string\n",
476-
"object_map = {1: 'galaxy', 2: 'star', 3: 'SNe'}\n",
477520
"source.data['truth_type'] = results['truth_type'].map(object_map)"
478521
]
479522
},
@@ -783,7 +826,7 @@
783826
"\n",
784827
"# Assert that the results are the same as obtained from\n",
785828
"# executing synchronous queries\n",
786-
"assert len(async_results) == 14424\n",
829+
"assert len(async_results) == 14424 \n",
787830
"assert_frame_equal(results, async_results.to_table().to_pandas())"
788831
]
789832
},

0 commit comments

Comments
 (0)