Quickstart: Using deepCR
==============

Quick download of a HST ACS/WFC image

.. code-block:: bash
    wget -O jdba2sooq_flc.fits https://mast.stsci.edu/api/v0.1/Download/file?uri=mast:HST/product/jdba2sooq_flc.fits

.. code-block:: python

    from deepCR import deepCR
    from astropy.io import fits
    image = fits.getdata("jdba2sooq_flc.fits")


.. code-block:: python

    mdl = deepCR(mask="ACS-WFC",
                 inpaint="ACS-WFC-F606W-2-32",
                 device="GPU")

    binary_mask = mdl.clean(image, threshold = 0.5, segment=True, patch=1024)
    binary_mask, cleaned_image = mdl.clean(image, threshold = 0.5, inpaint=True, segment=True, patch=1024)

The binary CR mask is generated by applying a threshold [0, 1] to the raw deepCR output, which is a probability map.
The keywords, **segment=True, patch=1024**, directs deepCR to process the image in patches of 1024 by 1024, which
limits memory footprint to ~2gb. Using a smaller patch size slows things down. Make sure your patch size don't result in
edge patches that has dimensions less than 256. For example, using a patch size of 256 for a 300*300 image will result
in a tiny 44*44 patch at the opposite corner.

For CPU, you should specify **n_jobs=-1** to enable multiprocessing unless your *pytorch* code is MKL optimized.
Monitor CPU usage -- if CPU usage for single process is > 100% it means intel MKL is probablly in place. You
should never use this option for GPU which is bottlenecked by memory, not FLOPS.