<jupyter_start><jupyter_text>Testing the BPT Mask Code<NAME>, <NAME>, <NAME>, <NAME><jupyter_code>import numpy as np
import os, sys

from astropy.table import Table

from time import time
import matplotlib.pyplot as plt

## DESI functions
from desiutil.bitmask import BitMask

sys.path.append('../py/')
from set_agn_masks import create_bpt_mask

import yaml
import warnings
warnings.filterwarnings('ignore')

%matplotlib inline
## Setting up plots

settings = {
    'font.size':22,
    'axes.linewidth':3.0,
    'xtick.major.size':6.0,
    'xtick.minor.size':4.0,
    'xtick.major.width':3.0,
    'xtick.minor.width':1.5,
    'xtick.direction':'in', 
    'xtick.minor.visible':True,
    'xtick.top':True,
    'ytick.major.size':6.0,
    'ytick.minor.size':4.0,
    'ytick.major.width':3.0,
    'ytick.minor.width':1.5,
    'ytick.direction':'in', 
    'ytick.minor.visible':True,
    'ytick.right':True
}

plt.rcParams.update(**settings)
## Loading the BPT bitmask definitions

file = open('../Sandbox/agn_masks.yaml', 'r')
bpt_defs = yaml.safe_load(file)

bpt_type = BitMask('bpt_type', bpt_defs)<jupyter_output><empty_output><jupyter_text>Some examples for working with bitmasks<jupyter_code>bpt_type
bpt_type.names()
bpt_type.NII_SF ## Returns (2**assigned_bit)
bpt_type.mask(5) ## Returns (2**number)
bpt_type.NII_LINER ## NII_LINER has bit = 5
bpt_type.bitname(5)  ## Returns the name assigned for a particular bit
bpt_type.bitnum('OI_SF')   ## Returns the bit assigned for a particular name
bpt_type.comment('SII_QUIES')   ## Returns the comment written for a particular name<jupyter_output><empty_output><jupyter_text>Testing the Code<jupyter_code>start = time()
survey = 'sv3'
faprgrm = 'bright'
specred = 'everest'

# This creates the mask and adds it as a column
tab = create_bpt_mask(survey = survey, faprgrm = faprgrm, specred = specred)

end = time()

print ('Time Taken: ', round(end-start, 2), 'seconds')
bptmask = tab['BPT_MASK']
nii_sf = (bptmask & bpt_type.NII_SF != 0)
nii_sy = (bptmask & bpt_type.NII_SY != 0)
nii_lin = (bptmask & bpt_type.NII_LINER != 0)
nii_comp = (bptmask & bpt_type.NII_COMP != 0)
len(tab), len(tab[nii_sf]), len(tab[nii_sy]), len(tab[nii_lin]), len(tab[nii_comp])
sii_sf = (bptmask & bpt_type.SII_SF != 0)
sii_sy = (bptmask & bpt_type.SII_SY != 0)
sii_lin = (bptmask & bpt_type.SII_LINER != 0)
oi_sf = (bptmask & bpt_type.OI_SF != 0)
oi_sy = (bptmask & bpt_type.OI_SY != 0)
oi_lin = (bptmask & bpt_type.OI_LINER != 0)
xx_bptnii=np.log10(tab['NII_6584_FLUX']/tab['HALPHA_FLUX'])
xx_bptsii = np.log10((tab['SII_6716_FLUX']+tab['SII_6731_FLUX'])/tab['HALPHA_FLUX'])
xx_bptoi = np.log10(tab['OI_6300_FLUX']/tab['HALPHA_FLUX'])

yy_bpt=np.log10(tab['OIII_5007_FLUX']/tab['HBETA_FLUX'])
plt.figure(figsize = (24,8))

plt.subplot2grid((1,3), (0,0))
plt.title('[NII]-BPT')
plt.scatter(xx_bptnii[nii_sf], yy_bpt[nii_sf], color = 'b', s = 10)
plt.scatter(xx_bptnii[nii_sy], yy_bpt[nii_sy], color = 'r', s = 10)
plt.scatter(xx_bptnii[nii_comp], yy_bpt[nii_comp], color = 'g', s = 10)
plt.scatter(xx_bptnii[nii_lin], yy_bpt[nii_lin], color = 'purple', s = 10)
plt.xlabel('log ([NII]/H$\\alpha$)')
plt.ylabel('log ([OIII]/H$\\beta$)')

plt.subplot2grid((1,3), (0,1))
plt.title('[SII]-BPT')
plt.scatter(xx_bptsii[sii_sf], yy_bpt[sii_sf], color = 'b', s = 10)
plt.scatter(xx_bptsii[sii_sy], yy_bpt[sii_sy], color = 'r', s = 10)
plt.scatter(xx_bptsii[sii_lin], yy_bpt[sii_lin], color = 'purple', s = 10)
plt.xlabel('log ([SII]/H$\\alpha$)')
plt.ylabel('log ([OIII]/H$\\beta$)')

plt.subplot2grid((1,3), (0,2))
plt.title('[OI]-BPT')
plt.scatter(xx_bptoi[oi_sf], yy_bpt[oi_sf], color = 'b', s = 10)
plt.scatter(xx_bptoi[oi_sy], yy_bpt[oi_sy], color = 'r', s = 10)
plt.scatter(xx_bptoi[oi_lin], yy_bpt[oi_lin], color = 'purple', s = 10)
plt.xlabel('log ([OI]/H$\\alpha$)')
plt.ylabel('log ([OIII]/H$\\beta$)')

plt.tight_layout()
len(tab), len(tab[nii_sf]), len(tab[nii_sy]), len(tab[nii_lin]), len(tab[nii_comp])
len(tab), len(tab[sii_sf]), len(tab[sii_sy]), len(tab[sii_lin])
len(tab), len(tab[oi_sf]), len(tab[oi_sy]), len(tab[oi_lin])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18968467367391836, 'fraction_numerical': 0.02517721828403813, 'mean_word_length': 5.82, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '160548', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1853, 'n_words': 306, 'path': 'AgnCats/notebooks/01_BPTMask_Tests.ipynb', 'repo_name': 'marmezcua/desigaldev', 'size': '4123'}