Package: dfisher-2022a
Dfisher_2022A DocumentationThis project is being developed in the course of delivering the DFisher_2022A ADACS Merit Allocation Program project.InstallationPre-requirement:python >=3.8 <3.10HDF5 >= 1.8.4 (>=1.8.15 is strongly recommended)Latest PyPI release$ pip install dfisher_2022aCommon troubleshooting: If installation fails, try to upgradepipby runningpip install --upgrade pipfirst.Latest dev-version on GitHub$ pip install git+https://github.com/ADACS-Australia/dfisher_2022a.git#egg=dfisher_2022aNOTICE: In the dev-version, a faster version oflmfit(light-lmfit-py) is used. This version provides a fitting method, "fast_leastsq" in addition to otherfitting methodsavailable inlmfit(1.0.3). This method can be 2x faster thanleastsq. Checkdev notesfor more details.Getting StartedImport the package>>> import dfisher_2022aRead in data cube>>> cube = dfisher_2022a.ReadCubeFile("single_gaussian_muse_size.fits").cubeIf a separate variance file is provide:>>> cube = dfisher_2022a.ReadCubeFile("single_gaussian_muse_size.fits", "muse_var.fits").cubePrepare data for fitting>>> p = dfisher_2022a.ProcessedCube(cube, z=0.009, snr_threshold=5.)1. De-redshift the cube>>> p.de_redshift()2. Select fitting region for a given line>>> p.select_region("Halpha", left=20, right=20)Keywordsleftandrightset the wavelength cuts around the given line on both sides, e.g. the selected region is [line-left, line+right]. If this region exceeds the cube wavelength range, a nearest value within the cube will be used instead.3. Filter the cube by SNR threshold>>> p.get_snrmap()Select fitting model>>> model = dfisher_2022a.Lm_Const_1GaussModelA single Gaussian model is available within this package.Fit the cube>>> cfl = dfisher_2022a.CubeFitterLM(data=p.data, weight=p.weight, x=p.x, model=model, method='leastsq') # accept lmfit.Model.fit kwargs
>>> cfl.fit_cube()Additional keyword arguments forlmfit.Model.fitcan be passed to the class object as well.Save output>>> out = dfisher_2022a.ResultLM()
>>> out.get_output(p) # get attributes from ProcessedCube object
>>> out.get_output(cfl)
>>> out.save()Anoutdirectory will be generated in the current directory.Read outputIn the.outfolder:result.h5
fitdata/whereresult.h5stores the fitting result, andfitdata/contains processed data used for fitting.To readresult.h5file:>>> import pandas as pd
>>> store = pd.HDFStore("result.h5")
>>> store.keys()
['/Halpha_Const_1GaussModel']
>>> df = store.get("Halpha_Const_1GaussModel")Check available lines>>> dfisher_2022a.EmissionLines
{'Halpha': 6562.819, 'Hb4861': 4861.333, 'Hdelta': 4101.742, ...The line information is included inemission_lines.py. Users can customize this file (e.g. adding more lines or updating the wavelength) before importing this package.A wrapped approachA wrapper function encapsulating steps 1-6 is available:>>> from dfisher_2022a import fit_lm
>>> model = dfisher_2022a.Lm_Const_1GaussModel
>>> fit_lm(cubefile="single_gaussian_muse_size.fits", line="Halpha", model=model, z=0.009, left=20, right=20, snr_threshold=5.)Use the faster version of lmfitIf dev-version of this package is installed, which uses a faster version oflmfitas dependency, a faster fitting method is also available, by usingmethod="fast_leastsq"and adding an argumentfast=True>>> cfl = dfisher_2022a.CubeFitterLM(data=p.data, weight=p.weight, x=p.x, model=model, method='fast_leastsq', fast=True) # accept lmfit.Model.fit kwargs
>>> cfl.fit_cube()In the wrapper function:>>> fit_lm(cubefile="single_gaussian_muse_size.fits", line="Halpha", model=model, z=0.009, left=20, right=20, snr_threshold=5., method="fast_leastsq", fast=True)Create custom modelUsers can create their own models following the descriptions provided bylmfit. To usefast_leastsqmethod in the dev version,eval_fastneeds to be written as a method of the model. See dev notes oflight-lmfit-pyfor more details.