<jupyter_start><jupyter_text>This notebook demostrates the effect of input catalog ordering in NWayMatch and MultiMatchIt assumes that you:    1. Have downloaded the data here:  https://lsst.ncsa.illinois.edu/~yusra/nway-matcher/    2. Use the script pq2afw.py to make afw source catalogs for MultiMatch<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import glob
import os
import numpy as np
from nway import NWayMatch<jupyter_output><empty_output><jupyter_text>Set up the inputs<jupyter_code>DATADIR = "."
SOURCE_TABLEFILES = glob.glob(os.path.join(DATADIR, "sourceTable-00*.parq"))
SOURCE_CATFILES = glob.glob(os.path.join(DATADIR, "sourceTable-*.fits"))
VISIT_IDS = np.arange(len(SOURCE_TABLEFILES))

REF_DIR = (150., 2.)   # RA, DEC in deg
REGION_SIZE = (3., 3.) # in Deg
CELL_SIZE = 1. / (3600*2) # in Deg = 0.5"
SUBREGION_SIZE = 1350 # in Pixels
PIXEL_R2CUT = 1.<jupyter_output><empty_output><jupyter_text>Create two NWayMatch matchersGive the the same data, but reverse the order of the input files in one case<jupyter_code>nWay = NWayMatch.create(REF_DIR, REGION_SIZE, CELL_SIZE, pixelR2Cut=PIXEL_R2CUT, subRegionSize=SUBREGION_SIZE)
nWay2 = NWayMatch.create(REF_DIR, REGION_SIZE, CELL_SIZE, pixelR2Cut=PIXEL_R2CUT, subRegionSize=SUBREGION_SIZE)
nWay.reduceData(SOURCE_TABLEFILES, VISIT_IDS)
nWay2.reduceData(SOURCE_TABLEFILES[::-1], VISIT_IDS[::-1])
oDict = nWay.analyzeSubregion(10, 10, True)
oDict2 = nWay2.analyzeSubregion(10, 10, True)<jupyter_output><empty_output><jupyter_text>Show that they have the same number of clusters and objects<jupyter_code>print(oDict['srd'].nClusters, oDict2['srd'].nClusters) 
print(oDict['srd'].nObjects, oDict2['srd'].nObjects)<jupyter_output><empty_output><jupyter_text>Set up a function to run MultiMatch<jupyter_code>import lsst.afw.table as afwTable
import lsst.geom as geom
from astropy import table
from astropy.table import Table

def runMultiMatch(inputCats, outFile):
    match_radius = geom.Angle(0.5, geom.arcseconds)
    
    schema = afwTable.SourceTable.makeMinimalSchema()
    mmatch = afwTable.MultiMatch(schema, dataIdFormat={'iCat': np.int32},
                                 radius=match_radius,
                                 RecordClass=afwTable.SimpleRecord)

    for i, catFile in enumerate(inputCats):
        print("Adding %s" % catFile)
        cat = afwTable.SourceCatalog.readFits(catFile)
        mmatch.add(catalog=cat, dataId=dict(iCat=i))

    matchCat = mmatch.finish()
    matchCat.writeFits(outFile)<jupyter_output><empty_output><jupyter_text>Run it twice, once with the catalogs in reverse order<jupyter_code>mm1 = runMultiMatch(SOURCE_CATFILES[0:5], 'mm_orig.fits')
tt1 = Table.read('mm_orig.fits')
mm2 = runMultiMatch(SOURCE_CATFILES[0:5][::-1], 'mm_revr.fits')
tt2 = Table.read('mm_revr.fits')<jupyter_output><empty_output><jupyter_text>Show that the number of associations changes<jupyter_code>print(len(tt1), len(tt2))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11336717428087986, 'fraction_numerical': 0.02030456852791878, 'mean_word_length': 5.598214285714286, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '99250', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1074, 'n_words': 216, 'path': 'nb/Reproducibility.ipynb', 'repo_name': 'KIPAC/NWayMatch', 'size': '2955'}