<jupyter_start><jupyter_text>MaskIn this notebook, we will be creating and applying a mask to the part of the SN1 filter of M33 field 7.Let's start with importing `LUCI`. Just as described on the *readthedocs* page, we need to point our system path to our install location of the **LUCI** folder.<jupyter_code># Imports
import sys
sys.path.insert(0, '/home/carterrhea/Documents/LUCI/')  # Location of Luci
from LuciBase import Luci
import LUCI.LuciPlotting as lplt
import matplotlib.pyplot as plt
import numpy as np<jupyter_output>WARNING: Astrometry.net API key not found in configuration file [astroquery.astrometry_net.core]
WARNING: You need to manually edit the configuration file and add it [astroquery.astrometry_net.core]
WARNING: You may also register it for this session with AstrometryNet.key = '<KEY>' [astroquery.astrometry_net.core]<jupyter_text>We now will set the required parameters. We are also going to be using our machine learning algorithm to get the initial guesses.<jupyter_code>#Set Parameters
# Using Machine Learning Algorithm for Initial Guess
Luci_path = '/home/carterrhea/Documents/LUCI/'
cube_dir = '/home/carterrhea/Documents/M33/SN1'  # Path to data cube
cube_name = 'SN1_Field7'  # don't add .hdf5 extension
object_name = 'M33_Field7'
redshift = -0.0006  # Redshift of M33
resolution = 1000<jupyter_output><empty_output><jupyter_text>Note that here we have set both `ML_ref` and `ML_model` to None. This tells **LUCI** NOT to use the machine learning algorithm.We intialize our LUCI object<jupyter_code># Create Luci object
cube = Luci(Luci_path, cube_dir+'/'+cube_name, cube_dir, object_name, redshift, resolution)<jupyter_output>0%|          | 0/9 [00:00<?, ?it/s]<jupyter_text>Let's quickly create a deep frame  Make MaskNow we will examine the deep image, choose a region to make a mask out of, and make the mask in numpy. Please note that you can make a mask any way you would like! Just be sure that the mask that you pass to `LUCI` for fitting is a numpy boolean array.<jupyter_code># Create Deep Image
cube.create_deep_image()
plt.imshow(cube.deep_image)
plt.clim(1e-4*np.max(cube.deep_image), 2e-3*np.max(cube.deep_image))
plt.colorbar()<jupyter_output><empty_output><jupyter_text>We are going to mask out the regions where the deep image value is less than 3e-16<jupyter_code>mask = np.ma.masked_where(cube.deep_image > 3e-16, cube.deep_image).mask<jupyter_output><empty_output><jupyter_text>Let us visualize the mask. The regions that are yellow are unmasked regions.<jupyter_code>plt.imshow(mask)<jupyter_output><empty_output><jupyter_text>FittingNow we will use are mask in a fit! Let's extract a background region and take a look at it. The background region is defined in a ds9 region file.<jupyter_code>bkg_axis, bkg_sky = cube.extract_spectrum_region(cube_dir+'/bkg.reg', mean=True)  # We use mean=True to take the mean of the emission in the region instead of the sum
plt.plot(bkg_axis, bkg_sky)
# Fit!
vel_map, broad_map, flux_map, chi2_fits, mask = cube.fit_region(['OII3726', 'OII3729'], 'gaussian', [1, 1], [1, 1], mask, bkg=bkg_sky, binning=2)<jupyter_output>100%|██████████| 1032/1032 [03:17<00:00,  5.23it/s]<jupyter_text>Let's take a look at the flux map.<jupyter_code>lplt.plot_map(flux_map[:,:,0], 'flux', cube_dir, cube.header, clims=[1e-20, 1e-18])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10053859964093358, 'fraction_numerical': 0.02573309395571514, 'mean_word_length': 5.794715447154472, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '313922', 'license': 'MIT', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1142, 'n_words': 378, 'path': 'Examples/Mask.ipynb', 'repo_name': 'benjaminvigneron/LUCI', 'size': '3345'}