<jupyter_start><jupyter_text>FITS File EditorThe purpose of this tutorial is to create and append a new column into an existing FITS file table.<jupyter_code>import numpy as np 
import pandas as pd 
from astropy.table import Table<jupyter_output><empty_output><jupyter_text>Read in all files as Astropy Table objects.<jupyter_code>pd.set_option('display.max_columns', None)

filename_1 = "path_to_file/filename"
filename_2 = "path_to_file/filename"

catalog_matcha = Table.read(filename_1)
catalog_gold= Table.read(filename_2)
print(f"Number of rows:{len(catalog_matcha)}")
print(f"Number of columns:{len(catalog_matcha.colnames)}")
catalog_matcha[0:5]
print(f"Number of rows:{len(catalog_gold)}")
print(f"Number of columns:{len(catalog_gold.colnames)}")
catalog_gold[0:5]<jupyter_output>Number of rows:21092
Number of columns:69<jupyter_text>Now that we have both tables, let's go ahead and create a new table called `catalog_cross1` made up of rows in common between the `MEM_MATCH_ID` column in both tables. We use `np.isin()` method to return an array of booleans which we then pass to the `catalog_matcha` such that we keep all of its columns and return a subset of rows. Thought process:* Table1 & Table2* Check if values in columnA from Table1 are in columnB from Table2.* If yes, then keep that row in Table1. If no, don't keep.<jupyter_code>catalog_cross1 = catalog_matcha[np.isin(catalog_matcha['MEM_MATCH_ID'], catalog_gold['MEM_MATCH_ID'])]

print(f'Dimensions of df_cross2 {len(catalog_cross1.colnames)} and {len(catalog_cross1)}.')
catalog_cross1[0:5]<jupyter_output>Dimensions of df_cross2 111 and 501.<jupyter_text>Similar process as above is applied here in reverse.<jupyter_code>catalog_cross2 = catalog_gold[np.isin(catalog_gold['MEM_MATCH_ID'], catalog_matcha['MEM_MATCH_ID'])]

print(f'Dimensions of df_cross2 {len(catalog_cross2.colnames)} and {len(catalog_cross2)}.')
catalog_cross2[0:5]<jupyter_output>Dimensions of df_cross2 69 and 501.<jupyter_text>Below we will create a boolean array using `np.isin()` method. The condition we use is whether a value in column `MEM_MATCH_ID` from `catalog_matcha` is in the column `MEM_MATCH_ID` from `catalog_gold`. Once we have the boolean array, we create a column called `isin_Vol_Lim` and give it the array as it's column values. Notice we use `astype(np.int64)`, this is used to convert the boolean values to numerical values of '0 and 1'.<jupyter_code>bucket_2 = np.isin(catalog_matcha['MEM_MATCH_ID'], catalog_gold['MEM_MATCH_ID'])

catalog_matcha["isin_Vol_Lim"] = bucket_2.astype(np.int64)

catalog_matcha[0:3]<jupyter_output><empty_output><jupyter_text>Now we save our work using `catalog.write("filepath/filename.fits", format='fits')`<jupyter_code>catalog_matcha.write("./filename.fits", format='fits')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10263720598717035, 'fraction_numerical': 0.020669992872416252, 'mean_word_length': 7.506060606060606, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '470175', 'license': 'MIT', 'n_tokens_mistral': 970, 'n_tokens_neox': 923, 'n_words': 272, 'path': 'tutorials/Vol_Lim_MATCha_No_Pandas.ipynb', 'repo_name': 'jjobel/Flexible_Image_Transport_System_Tutorials', 'size': '2806'}