|
427 | 427 | "print(f'There are {results[results[\"truth_type\"] == 3].shape[0]} SNe')" |
428 | 428 | ] |
429 | 429 | }, |
| 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 | + }, |
430 | 474 | { |
431 | 475 | "cell_type": "markdown", |
432 | 476 | "metadata": {}, |
|
473 | 517 | "\n", |
474 | 518 | "# We will want to filter on the truth type later\n", |
475 | 519 | "# We will convert the truth_type integer to a more descriptive string\n", |
476 | | - "object_map = {1: 'galaxy', 2: 'star', 3: 'SNe'}\n", |
477 | 520 | "source.data['truth_type'] = results['truth_type'].map(object_map)" |
478 | 521 | ] |
479 | 522 | }, |
|
783 | 826 | "\n", |
784 | 827 | "# Assert that the results are the same as obtained from\n", |
785 | 828 | "# executing synchronous queries\n", |
786 | | - "assert len(async_results) == 14424\n", |
| 829 | + "assert len(async_results) == 14424 \n", |
787 | 830 | "assert_frame_equal(results, async_results.to_table().to_pandas())" |
788 | 831 | ] |
789 | 832 | }, |
|
0 commit comments