Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eacharles committed May 25, 2021
1 parent f65d6f2 commit 3cc4dfd
Show file tree
Hide file tree
Showing 7 changed files with 2,483 additions and 0 deletions.
500 changes: 500 additions & 0 deletions nb/AssocStats.ipynb

Large diffs are not rendered by default.

683 changes: 683 additions & 0 deletions nb/NWayExample.ipynb

Large diffs are not rendered by default.

244 changes: 244 additions & 0 deletions nb/Reproducibility.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "16d08b9d",
"metadata": {},
"source": [
"# This notebook demostrates the effect of input catalog ordering in NWayMatch and MultiMatch\n",
"\n",
"It assumes that you:\n",
"\n",
" 1. Have downloaded the data here: https://lsst.ncsa.illinois.edu/~yusra/nway-matcher/\n",
" 2. Use the script pq2afw.py to make afw source catalogs for MultiMatch\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97b14652",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad816a25",
"metadata": {},
"outputs": [],
"source": [
"import glob\n",
"import os\n",
"import numpy as np\n",
"from nway import NWayMatch"
]
},
{
"cell_type": "markdown",
"id": "7809cfac",
"metadata": {},
"source": [
"### Set up the inputs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c901f3d7",
"metadata": {},
"outputs": [],
"source": [
"DATADIR = \".\"\n",
"SOURCE_TABLEFILES = glob.glob(os.path.join(DATADIR, \"sourceTable-00*.parq\"))\n",
"SOURCE_CATFILES = glob.glob(os.path.join(DATADIR, \"sourceTable-*.fits\"))\n",
"VISIT_IDS = np.arange(len(SOURCE_TABLEFILES))\n",
"\n",
"REF_DIR = (150., 2.) # RA, DEC in deg\n",
"REGION_SIZE = (3., 3.) # in Deg\n",
"CELL_SIZE = 1. / (3600*2) # in Deg = 0.5\"\n",
"SUBREGION_SIZE = 1350 # in Pixels\n",
"PIXEL_R2CUT = 1."
]
},
{
"cell_type": "markdown",
"id": "106d23c7",
"metadata": {},
"source": [
"#### Create two NWayMatch matchers\n",
"\n",
"Give the the same data, but reverse the order of the input files in one case"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6b03b01",
"metadata": {},
"outputs": [],
"source": [
"nWay = NWayMatch.create(REF_DIR, REGION_SIZE, CELL_SIZE, pixelR2Cut=PIXEL_R2CUT, subRegionSize=SUBREGION_SIZE)\n",
"nWay2 = NWayMatch.create(REF_DIR, REGION_SIZE, CELL_SIZE, pixelR2Cut=PIXEL_R2CUT, subRegionSize=SUBREGION_SIZE)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ab6680f",
"metadata": {},
"outputs": [],
"source": [
"nWay.reduceData(SOURCE_TABLEFILES, VISIT_IDS)\n",
"nWay2.reduceData(SOURCE_TABLEFILES[::-1], VISIT_IDS[::-1])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d6b2385",
"metadata": {},
"outputs": [],
"source": [
"oDict = nWay.analyzeSubregion(10, 10, True)\n",
"oDict2 = nWay2.analyzeSubregion(10, 10, True)"
]
},
{
"cell_type": "markdown",
"id": "ad60aace",
"metadata": {},
"source": [
"### Show that they have the same number of clusters and objects"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33e1fb3c",
"metadata": {},
"outputs": [],
"source": [
"print(oDict['srd'].nClusters, oDict2['srd'].nClusters) \n",
"print(oDict['srd'].nObjects, oDict2['srd'].nObjects)"
]
},
{
"cell_type": "markdown",
"id": "ec94c595",
"metadata": {},
"source": [
"### Set up a function to run MultiMatch"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "34d497d9",
"metadata": {},
"outputs": [],
"source": [
"import lsst.afw.table as afwTable\n",
"import lsst.geom as geom\n",
"from astropy import table\n",
"from astropy.table import Table\n",
"\n",
"def runMultiMatch(inputCats, outFile):\n",
" match_radius = geom.Angle(0.5, geom.arcseconds)\n",
" \n",
" schema = afwTable.SourceTable.makeMinimalSchema()\n",
" mmatch = afwTable.MultiMatch(schema, dataIdFormat={'iCat': np.int32},\n",
" radius=match_radius,\n",
" RecordClass=afwTable.SimpleRecord)\n",
"\n",
" for i, catFile in enumerate(inputCats):\n",
" print(\"Adding %s\" % catFile)\n",
" cat = afwTable.SourceCatalog.readFits(catFile)\n",
" mmatch.add(catalog=cat, dataId=dict(iCat=i))\n",
"\n",
" matchCat = mmatch.finish()\n",
" matchCat.writeFits(outFile)"
]
},
{
"cell_type": "markdown",
"id": "40b35cda",
"metadata": {},
"source": [
"#### Run it twice, once with the catalogs in reverse order"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "06d49874",
"metadata": {},
"outputs": [],
"source": [
"mm1 = runMultiMatch(SOURCE_CATFILES[0:5], 'mm_orig.fits')\n",
"tt1 = Table.read('mm_orig.fits')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4b7bf04a",
"metadata": {},
"outputs": [],
"source": [
"mm2 = runMultiMatch(SOURCE_CATFILES[0:5][::-1], 'mm_revr.fits')\n",
"tt2 = Table.read('mm_revr.fits')"
]
},
{
"cell_type": "markdown",
"id": "eaaa6643",
"metadata": {},
"source": [
"#### Show that the number of associations changes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "41420f91",
"metadata": {},
"outputs": [],
"source": [
"print(len(tt1), len(tt2))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2b8bc45",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
3 changes: 3 additions & 0 deletions python/nway/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
""" Matching algorithm for multiple input source catalogs """

from .nway import *
Loading

0 comments on commit 3cc4dfd

Please sign in to comment.