Package: maskfill
maskfillFill in masked values in an image.The method description can be found in van Dokkum & Pasha (2024) (PASP).Examples in
example_synthetic/
example_m51/InstallationThemaskfillcode can be installed fromPyPIviapip install maskfillor the latest version from github can be retrieved viagit clone https://github.com/dokkum/maskfill.git
cd maskfill 
pip install . # or pip install -e .Its dependencies are onlynumpy,scipy,astropy(for fits handling), andPython>=3.6for type annotation an f-fstrings. If you wish, you can create a minimal working environment for this code viacondaormamba, e.g.,mamba create -n maskfill python=3.10 numpy scipy astropy
mamba activate maskfillLegacyIf you have a version of Python<3.6, we have tested maskfill as far back as Python 2.7 and it appears to work for the current version.
To install a Python 2.7 - Python 3.5.9 compatible version (the only difference is type annotations and print statement formatting), checkout the branch:git clone --branch python<3.6 --single-branch https://github.com/dokkum/maskfill.git
cd maskfill 
pip install . # or pip install -e .(assuming you have the three dependencies in a working configuration).UsageMaskfillcan be used either from the command line via a command line interface (CLI), or imported in Python as a function.CLIWhen you installmaskfillit will create amaskfillexecutable callable from the shell. You can print the usage viamaskfill -hThe simplest call is something likemaskfill im.fits mask.fits out.fitsormaskfill im mask out #file extension assumed to be .fitsin which you provide the input image, mask image, and name of the output file (if the.fitsis omitted,maskfillwill add it, though if your files have alternate extensions like.fityou should specify the full name). There are also several optional arguments and flags.-e Xor--extension X: if the image and mask are not in the 0th fits extension, specify it here-s Xor--size X: if you want a larger window kernel than the minimum 3x3, specify it here (faster, but less accurate results)-o medianor--operator median: either 'median' or 'mean', defines how masked pixels are filled in based on their neighbors-nor--nosmooth: disable a final-step boxcar smoothing of the filled in mask pixels-wor--writesteps: write_iter_Nfits files after each iteration of the algorithm (default is False)-vor--verbose: verbose output (shows the progress of iterations and number of remaining masked pixels).The output is saved in the fits file with the provided output name. By default, after infilling, a smoothing step (using the same window, but ameanfilter) is used to reduce sharp edges introduced by the iterative infilling. When enabled, the output fits file will contain the smoothed output image in the 0th extension, and the unsmoothed version post infilling in the 1st extension. Ifnosmoothis flagged, the 0th extension will contain the unsmoothed output. Information about which type of output is in which extension is added to the header.Python FunctionIn python, import themaskfillfunction viafrommaskfillimportmaskfillThe function supports all the same features as the CLI. We can provide either file paths or arrays directly, e.g.,fromastropy.ioimportfitsim=fits.getdata('/path/to/im.fits')mask=fits.getdata('/path/to/mask.fits')result=maskfill(im,mask)# or, equivalently,result=maskfill('/path/to/im.fits','/path/to/mask.fits')When providing filepaths, theextargument allows non 0th extensions to be queried. Like the CLI, all other arguments are optional, but unlike the CLI, theoutput_fileargument is also optional ---maskfillreturns the filled image(s) as arrays directly, but a `fits`` file can be written if desired by providing a filename (same goes for the intermediate steps).Thus, a "maximally verbose" run might look likeresult=maskfill('im.fits','mask.fits',writesteps=True,output_file='res.fits',verbose=True)which would not only print to screen the iteration progress but write both intermediate and final fits files to disk.Theresultsoutput by the function are a tuple containing either:(output_smoothed,output)if the smoothing step is enabled, or(output, None)if the smoothing step is disabled.Thus to access or plot the smoothed image from a default run, we would either runresults[0], or run withresults,_=maskfill(im,mask)Citing MaskfillIf you findmaskfilluseful in your research or image handlings, please cite the code:@ARTICLE{2023arXiv231203064V,
       author = {{van Dokkum}, Pieter},
        title = "{A robust method for filling in masked data in astronomical images}",
      journal = {arXiv e-prints},
     keywords = {Astrophysics - Instrumentation and Methods for Astrophysics, Astrophysics - Astrophysics of Galaxies},
         year = 2023,
        month = dec,
          eid = {arXiv:2312.03064},
        pages = {arXiv:2312.03064},
          doi = {10.48550/arXiv.2312.03064},
archivePrefix = {arXiv},
       eprint = {2312.03064},
 primaryClass = {astro-ph.IM},
       adsurl = {https://ui.adsabs.harvard.edu/abs/2023arXiv231203064V},
      adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}