{ "cells": [ { "cell_type": "markdown", "id": "3da49051-75c6-4b8f-8894-2d65d4f80112", "metadata": {}, "source": [ "## Using the `rail.projects` analysis component library \n", "\n", "This notebook will show you the basics of using the `rail.projects.library` component library" ] }, { "cell_type": "markdown", "id": "68006889-06ba-46ea-be1a-556d9df7ebaa", "metadata": {}, "source": [ "### Setup and teardown scripts to setup a test area" ] }, { "cell_type": "code", "execution_count": null, "id": "658e46a0-f86b-4421-9d3f-da794efe8ffc", "metadata": {}, "outputs": [], "source": [ "import os\n", "from rail.projects import library\n", "\n", "check_dir = os.path.basename(os.path.abspath(os.curdir))\n", "if check_dir == 'examples':\n", " os.chdir('..')\n", "\n", "setup = library.setup_project_area()\n", "assert setup == 0\n", "\n", "# use this to cleanup\n", "# library.teardown_project_area()" ] }, { "cell_type": "code", "execution_count": null, "id": "b3fdc9ed-884d-49c6-a1c6-4c398210c098", "metadata": {}, "outputs": [], "source": [ "# Import the project library code\n", "from rail.projects import library" ] }, { "cell_type": "markdown", "id": "4eba90e1-a530-404a-8d26-ce1d9c2bcb77", "metadata": {}, "source": [ "### Loading a library from a yaml file\n", "\n", "This will read in a yaml file, and contstuct objects and templates that are described in the yaml file" ] }, { "cell_type": "code", "execution_count": null, "id": "38f5ddba-fa20-4d66-a764-b629232192a4", "metadata": {}, "outputs": [], "source": [ "# Load a particular library\n", "library.load_yaml('tests/ci_project_library.yaml')" ] }, { "cell_type": "code", "execution_count": null, "id": "93f9a7e5-b379-4127-ab47-0b91eece082c", "metadata": {}, "outputs": [], "source": [ "# Print the contents of the loaded library\n", "library.print_contents()" ] }, { "cell_type": "markdown", "id": "730241ec-edc1-4336-bc27-4d24f82842f7", "metadata": {}, "source": [ "### Catalogs, Templates and Interpolats\n", "\n", "Let's get a particular \"CatalogTemplate\", i.e, the one for the \"truth\" catalog" ] }, { "cell_type": "code", "execution_count": null, "id": "6d0c09d9-a8f2-4322-b31c-b7bad329bd3f", "metadata": {}, "outputs": [], "source": [ "a_catalog_template = library.get_catalog_template('truth')" ] }, { "cell_type": "markdown", "id": "dbcfdc9b-d812-4f2a-891c-573dda1f8e63", "metadata": {}, "source": [ "Let's get some information about this template" ] }, { "cell_type": "code", "execution_count": null, "id": "cbe66530-a330-41dd-9ab2-3f1b13cefcf4", "metadata": {}, "outputs": [], "source": [ "print(f\"{type(a_catalog_template)} called '{a_catalog_template.config.name}'\")\n", "print(f\"has path '{a_catalog_template}' and iterates over {a_catalog_template.config.iteration_vars}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "f4afc153-60af-459e-97dc-ad07cd1569cb", "metadata": {}, "outputs": [], "source": [ "#dir(a_catalog_template)\n", "#help(a_catalog_template)" ] }, { "cell_type": "markdown", "id": "c9071304-c579-4680-a654-6e6b9eda6fab", "metadata": {}, "source": [ "Let's use this template to make a particular version of the catalog, " ] }, { "cell_type": "code", "execution_count": null, "id": "e48a09f1-036b-4d65-a4fe-f8f013904a8f", "metadata": {}, "outputs": [], "source": [ "a_catalog_instance = a_catalog_template.make_catalog_instance(\n", " \"truth_cat\", catalogs_dir='tests/temp_dir', project='ci_test', sim_version='test',\n", ")" ] }, { "cell_type": "markdown", "id": "515c4bf0-c280-48c4-a0e0-c8eed50add0f", "metadata": {}, "source": [ "Let's get some information about this catalog" ] }, { "cell_type": "code", "execution_count": null, "id": "1ac8c70a-7b75-47b4-a2b5-9a9ac5fc7e76", "metadata": {}, "outputs": [], "source": [ "print(f\"{type(a_catalog_instance)} called '{a_catalog_instance.config.name}'\")\n", "print(f\"has path '{a_catalog_instance}' and iterates over {a_catalog_instance.config.iteration_vars}\")" ] }, { "cell_type": "markdown", "id": "9085ff11-eafc-4225-b413-e317bf3c8be4", "metadata": {}, "source": [ "Let's get the files associated to this catalog for some particular pixels" ] }, { "cell_type": "code", "execution_count": null, "id": "db62d3bf-f5a9-4f84-b28b-38c64bd85e43", "metadata": {}, "outputs": [], "source": [ "a_catalog_instance.resolve(healpix=[5055, 5051])" ] }, { "cell_type": "markdown", "id": "6b4da081-2cf7-4660-b812-91bfea55a657", "metadata": {}, "source": [ "### Algorithm holders and algorithms" ] }, { "cell_type": "markdown", "id": "d2ca0476-233a-4f19-857d-b123f2695474", "metadata": {}, "source": [ "Let's get the object that hold information about a particular algorithn" ] }, { "cell_type": "code", "execution_count": null, "id": "44e8b1c8-ef03-4280-b716-54ea30c5d0d6", "metadata": {}, "outputs": [], "source": [ "lsst_error_model_holder = library.get_algorithm('ErrorModel', 'lsst')" ] }, { "cell_type": "markdown", "id": "7f470730-735c-45f3-bf44-581f5b62b4d4", "metadata": {}, "source": [ "Let's get some information about this algorithm " ] }, { "cell_type": "code", "execution_count": null, "id": "a5038b76-7fd6-4601-9ebe-58fb45f6776d", "metadata": {}, "outputs": [], "source": [ "print(f\"{type(lsst_error_model_holder)} called '{lsst_error_model_holder.config.name}'\")\n", "print(f\"has classes '{lsst_error_model_holder}'\")" ] }, { "cell_type": "code", "execution_count": null, "id": "997e2ac9-2314-49bf-bf72-3dff380ae71d", "metadata": {}, "outputs": [], "source": [ "lsst_error_model_class = library.get_algorithm_class('ErrorModel', 'lsst', 'ErrorModel')" ] }, { "cell_type": "code", "execution_count": null, "id": "a213467d-5072-44cd-9947-581c4a90e685", "metadata": {}, "outputs": [], "source": [ "lsst_error_model_class.config_options" ] }, { "cell_type": "code", "execution_count": null, "id": "da294b40-3f89-4daf-b8f5-aa61115d13ab", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "3f69ec47-cd1d-4502-b211-0b98489367e5", "metadata": {}, "outputs": [], "source": [ "knn_holder = library.get_algorithm('PZAlgorithm', 'knn')" ] }, { "cell_type": "code", "execution_count": null, "id": "9e74f774-4012-44b2-99e3-a10f8b8af6c6", "metadata": {}, "outputs": [], "source": [ "print(f\"{type(knn_holder)} called '{knn_holder.config.name}'\")\n", "print(f\"has classes '{knn_holder}'\")" ] }, { "cell_type": "code", "execution_count": null, "id": "b1b32ccc-25ed-46f6-999b-fffeddaa8d5e", "metadata": {}, "outputs": [], "source": [ "knn_inform_class = knn_holder.resolve('Inform')\n", "knn_estimate_class = knn_holder.resolve('Estimate')\n", "print(f\"{knn_inform_class} {knn_estimate_class}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "d58e5604-ee43-4f5e-bac9-e5b81f18f843", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "f9f98ccf-cff7-41aa-98d6-e3643048a8b7", "metadata": {}, "source": [ "### Named subsamples\n", "\n", "Let's get the object that holds information about a named subsample of data" ] }, { "cell_type": "code", "execution_count": null, "id": "479ae63b-41b7-4a4e-aad7-bd7727f8ab0b", "metadata": {}, "outputs": [], "source": [ "subsample = library.get_subsample('test_100k')" ] }, { "cell_type": "code", "execution_count": null, "id": "ef3749f8-10d2-4a0f-a275-ea0ae2d12947", "metadata": {}, "outputs": [], "source": [ "print(f\"{type(subsample)} called '{subsample.config.name}'\")\n", "print(f\"has options '{subsample}'\")" ] }, { "cell_type": "code", "execution_count": null, "id": "38628ef0-7e60-4171-8add-9c18db08f99e", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "ad491967-0476-4ff3-a0d6-35b3a9958ec1", "metadata": {}, "source": [ "### Named selections\n", "\n", "Let's get the object that holds information about a named selections of data" ] }, { "cell_type": "code", "execution_count": null, "id": "3eec1138-99da-4244-a086-709ea17505bc", "metadata": {}, "outputs": [], "source": [ "selection = library.get_selection('gold')" ] }, { "cell_type": "code", "execution_count": null, "id": "70b45489-46e6-4fb4-a842-ff5fa8acdd0b", "metadata": {}, "outputs": [], "source": [ "print(f\"{type(selection)} called '{selection.config.name}'\")\n", "print(f\"has {selection}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "2074bf08-dd48-4da7-af9b-2486c27f5789", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "f0d1dd56-f1e2-49cc-af84-12dabcbe078f", "metadata": {}, "outputs": [], "source": [] } ], "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.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }