Skip to content

Commit

Permalink
Update the analysis demo notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Feb 15, 2024
1 parent 3d86ed8 commit 44cc1c4
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 194 deletions.
21 changes: 21 additions & 0 deletions data/fake_results/results.ecsv

Large diffs are not rendered by default.

150 changes: 71 additions & 79 deletions notebooks/KBMOD_Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -18,7 +18,6 @@
"\n",
"from pathlib import Path\n",
"\n",
"from kbmod.fake_data_creator import *\n",
"from kbmod.run_search import *\n",
"from kbmod.search import *"
]
Expand All @@ -45,17 +44,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['000000.fits', '000001.fits', '000002.fits', '000003.fits', '000004.fits', '000005.fits', '000006.fits', '000007.fits', '000008.fits', '000009.fits']\n"
]
}
],
"outputs": [],
"source": [
"# Define the path for the data.\n",
"im_filepath = \"../data/demo\"\n",
Expand All @@ -64,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -78,64 +69,20 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run KBMOD"
"# Run KBMOD\n",
"\n",
"The standard approach to running KBMOD is to perform a grid search over all starting pixels and a grid of velocities. The velocities are defined by steps in velocity space (in pixels per day) and angles. Let’s do a grid search with:\n",
"* 21 different velocity steps from 0 pixels per day and 20 pixels per day\n",
"* 11 different angles from 0.5 below the default angle (computed based on the ecliptic) to 0.5 above.\n",
"\n",
"We require objects to be found in at least 7 of the time steps."
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"---------------------------------------\n",
"Loading Images\n",
"---------------------------------------\n",
"Loaded 10 images\n",
"Times set\n",
"Starting Search\n",
"---------------------------------------\n",
"Ecliptic Angle = 1.1901\n",
"Min. Search Angle = -0.5000\n",
"Max Search Angle = 0.5000\n",
"Min Velocity = 0.0000\n",
"Max Velocity = 20.0000\n",
"Using in-line GPU sigmaG filtering methods\n",
"sigmaG limits: [15,60]\n",
"sigmaG coeff: 0.7753\n",
"Search finished in 0.057s\n",
"---------------------------------------\n",
"Retrieving Results\n",
"---------------------------------------\n",
"Getting results...\n",
"---------------------------------------\n",
"Chunk Start = 0\n",
"Chunk Max Likelihood = 243.35\n",
"Chunk Min. Likelihood = -1.00\n",
"---------------------------------------\n",
"Extracted batch of 1343 results for total of 1343\n",
"Applying Clipped-sigmaG Filtering\n",
"sigmaG limits: [15,60]\n",
"sigmaG coeff: 0.7753\n",
"0.18s elapsed\n",
"Completed filtering.\n",
"---------------------------------------\n",
"---------------------------------------\n",
"Applying Stamp Filtering\n",
"---------------------------------------\n",
"Stamp filtering 1342 results\n",
"Keeping 588 results\n",
"0.02s elapsed\n",
"Clustering 588 results\n",
"---------------------------------------\n",
"Saving Results\n",
"---------------------------------------\n",
"Time taken for patch: 0.9508676528930664\n"
]
}
],
"outputs": [],
"source": [
"results_suffix = \"DEMO\"\n",
"\n",
Expand Down Expand Up @@ -182,44 +129,89 @@
" # Override the ecliptic angle for the demo data since we\n",
" # know the true angle in pixel space.\n",
" \"average_angle\": 0.0,\n",
" \"result_filename\": \"./fake_results/results.ecsv\",\n",
" \"save_all_stamps\": True,\n",
"}\n",
"\n",
"rs = SearchRunner()\n",
"rs.run_search_from_config(input_parameters)"
"results = rs.run_search_from_config(input_parameters)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check that results were written."
"We then check that results were written to an output directory."
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['results_DEMO.txt', 'lc_DEMO.txt', 'psi_DEMO.txt', 'phi_DEMO.txt', 'lc_index_DEMO.txt', 'times_DEMO.txt', 'filtered_likes_DEMO.txt', 'ps_DEMO.txt', 'all_ps_DEMO.npy']\n"
]
}
],
"outputs": [],
"source": [
"if os.path.exists(res_filepath):\n",
" files = os.listdir(res_filepath)\n",
" print(files)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Analyzing Results\n",
"\n",
"The run function we used returns a `ResultList` containing the individual results of the run. We can perform basic actions on this data structure such as sorting it, extracting individual results, or performing additional filtering."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"Search found {results.num_results()} results.\")\n",
"\n",
"# Sorting one result doesn't do anything.\n",
"results.sort()\n",
"\n",
"# Output the trajectory.\n",
"best_result = results.results[0] \n",
"print(best_result.trajectory)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also plot the different curves for the result."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"fig, axs = plt.subplots(3, 1)\n",
"axs[0].plot(results.all_times, best_result.psi_curve)\n",
"axs[0].set_title(\"Psi\")\n",
"\n",
"axs[1].plot(results.all_times, best_result.phi_curve)\n",
"axs[1].set_title(\"Psi\")\n",
"\n",
"axs[2].plot(results.all_times, best_result.likelihood_curve)\n",
"axs[2].set_title(\"Likelihood\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For additional analysis steps, please refer to the kbmod_analysis_demo notebook which uses the data generated by this notebook."
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 44cc1c4

Please sign in to comment.