Giter VIP home page Giter VIP logo

properimage's Introduction

Proper image treatments

QuatroPe Build Status Documentation Status codecov Python 3.8 License ascl:1904.025 Code style: black

This code is inspired on Zackay & Ofek 2017 papers How to coadd images? (see References below).

  • It can perform a PSF estimation using Karhunen-Löeve expansion, which is based on Lauer 2002 work.

  • It can perform the statistical proper coadd of several images.

  • It can also perform a proper-subtraction of images.

  • Images need to be aligned and registered, or at least astroalign must be installed.

  • Contains a nice plot module for PSF visualization (needs matplotlib)

Installation

To install from PyPI

$ pip install properimage

Quick usage

PSF estimation

>>> from properimage import singleimage as si
>>> with si.SingleImage(frame, smooth_psf=False) as sim:
...     a_fields, psf_basis = sim.get_variable_psf(inf_loss=0.15)

Proper-subtraction of images

To create a proper-subtraction of images:

>>> from properimage.operations import subtract
>>> D, P, Scorr, mask = subtract(ref=ref_path, new=new_path, smooth_psf=False, fitted_psf=True,
...                             align=False, iterative=False, beta=False, shift=False)

Where D, P, Scorr refer to the images defined by the same name in Zackay & Ofek paper.

For the full documentation refer to readthedocs.

Rerefences

Zackay, B., & Ofek, E. O. (2017). How to Coadd Images. I. Optimal Source Detection and Photometry of Point Sources Using Ensembles of Images. The Astrophysical Journal, 836(2), 187. Arxiv version

Zackay, B., & Ofek, E. O. (2017). How to Coadd Images. II. A Coaddition Image that is Optimal for Any Purpose in the Background-dominated Noise Limit. The Astrophysical Journal, 836(2), 188. Arxiv version

Zackay, B., Ofek, E. O., & Gal-Yam, A. (2016). Proper Image Subtrraction-Optimal Transient Detection, Photometry, and Hypothesis Testing. The Astrophysical Journal, 830(1), 27.

Lauer, T. (2002, December). Deconvolution with a spatially-variant PSF. In Astronomical Data Analysis II (Vol. 4847, pp. 167-174). International Society for Optics and Photonics.

properimage's People

Contributors

brunosanchez avatar leliel12 avatar martinberoiz avatar mchalela avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

properimage's Issues

Fill values to array fails.

`
for img in imglist:

        newcat = img._best_srcs['sources']
        newcat = append_fields(newcat, 'sourceid',
                               np.repeat(0, len(newcat)),
                               usemask=False,
                               dtypes=int)

        ids, mask = matching(mastercat, newcat, masteridskey='sourceid',
                             angular=False, radius=1., masked=True)

        for i in range(len(ids[mask])):
            print ids[mask][i]
            newcat[mask]['sourceid'][i] = ids[mask][i]
            print newcat[mask]['sourceid'][i]

newcat[mask]['sourceid'] = np.array(ids[mask])

`

This is on lines 222 of properimage/utils.py

Trying to fill the values of newcat, but there is no traceback, it doesn't fail, but it is not working neither.

Something related to the creation of the field 'sourceid' must be wrong.

Any ideas?

rifft2 should be irfft2

It may be a typo. Numpy.fft has irfft2 but not rifft2

>>> from properimage import single_image as s
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "properimage/single_image.py", line 74, in <module>
    _ifftwn = np.fft.rifft2
AttributeError: 'module' object has no attribute 'rifft2'

Add versioning

Hello,

Would you mind versioning commits? Especially those that break API. It'd be much appreciated if you could do so.

Thanks,
M.

Image Difference as `-`

Implement a default behavior to the difference with the __sub__

So instead of execute img_a.diff(img_b) you can run img_a - img_b

Unused class Bunch

class Bunch is defined in single_image.py and single_image_psfs.py but never used anywhere else? I checked with a cat/grep.

We should delete that if it's really unused.

matplotlib dependency

Installed fresh in a virtualenv, gives the following error when imported:

>>> import ProperImage
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ProperImage
>>> import properimage
>>> from properimage import propersubtract as ps
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "properimage/propersubtract.py", line 30, in <module>
    from . import propercoadd as pc
  File "properimage/propercoadd.py", line 35, in <module>
    from . import utils
  File "properimage/utils.py", line 34, in <module>
    import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot

consider dropping aligning?

Is it necessary for us to align images? I think that should be left to the user to use whichever software is more convenient for the situation.
Same thing with cropping and removal of cosmic rays.
IMHO, it seems too specific and unrelated to proper subtraction/coaddition.

.asarray method

Create a .asarray method to convert an image to a basic np.ndarray

inf_loss is not being updated

After you run
afields, psfbasis = img.get_varpsf(inf_loss)
if you re-run it with new inf_loss value it does nothing.
Which is a bug. This is supposed to work.

Number of hidden dot files

Hi,

I noticed today a bunch of hidden dotted files:

._120634801176SingleImage.dat
._120634801176SingleImage.map
...

Could this be from properimage not cleaning it up?

Deprecate combinator and image_ensemble

If there's anything worth keeping in those two modules, we can move it to utils or single_image.
Transparency could be a function to single_image.

Thumbs up if agree, thumbs down if don't ;)

Black integration

  • Integrate black into tox with flake8-black
  • Ad pyproject.toml to configure black

Change property pixeldata to data

I think the method returning the ndarray pixels from SingleImage should be just data instead of pixeldata, since that seems to be the standard in masked numpy arrays, CCDData, NDData and HDUList.

Likewise it should have a property mask that returns the mask as a ndarray, but I think that is already implemented.

I don't know what you guys think.

`.plot` accessor

Provide a accessor to the most common plot of the image through a plot accesor attribute.

So instead of run (img is a SingleImage instance)

plt.imshow(img)

we can use

img.plot() 
# or
img.plot.imshow()

Another method can be img.plot.background()

Python RestrictedUnpickler issue

We had written code as -

import os
import builtins
import pickle
import sys
sys.tracebacklimit=0
import traceback
import io
from logging import Logger

safe_builtins = {
        'range',
        'complex',
        'set',
        'frozenset'
        }

class RestrictedUnpickler(pickle.Unpickler):
  def find_class(self, module, name):
  # Only allow safe classes from builtins.
   if module == "builtins" and name in safe_builtins:
       return getattr(builtins, name)
    # Forbid everything else.
   raise pickle.UnpicklingError("global '%s.%s' is forbidden" %
   (module, name))

def restricted_loads(s):
    """Helper function analogous to pickle.loads()."""
    return RestrictedUnpickler(io.BytesIO(s)).load()

def func1(a): 
  try: 
    x= restricted_loads(pickle.dumps(a))
    return x 
  except pickle.UnpicklingError : 
    s= pickle.UnpicklingError("unsupported persistent object") 
    return s

def func2(s):
  try:
    x=restricted_loads(pickle.dumps(s))
    return s[x]
  except pickle.UnpicklingError :
    s=traceback.format_exc()
    return s
    
if __name__ == "__main__":
       a=range(int(input())) 
       b=func1(a)
       print(b)
       y=tuple(input())
       z=func2(y)
       print(z)

Getting
TypeError: tuple indices must be integers or slices, not tuple

Input (stdin)

50 
"a", "b", "c", "d", "e", "f", "g", "h"

Your Output (stdout)
range(0, 50)

Expected Output

range(0, 50) 
Traceback (most recent call last): 
_pickle.UnpicklingError: global 'builtins.slice' is forbidden

Safe

Consider rewriting documentation

I think we should reorder the documentation, focusing on the main functionality and leaving SingleImage further down the docs.

Update the used module numpydb to `diskcache` for stamp storage

There is an implementation for a numpy array storage, that uses pickle.
This is critical so we don't keep in memory stamps of every star.
The current implementation though, requires the creation of files, which for many reasons can persist later as garbage in the local directory (see #11).

Using diskcache library could avoid such issue, and clean the base code of additional modules.

Custom `stamp_shape`

If setting the stamp_shape parameter when making an instance of SingleImage, then set to never update it. Related to #8

PSF estimation

Dear developer, thank you very much for this awesome project ! I started to read the mentionned paper (the 2002 one about spatially varying psf, and the newer ones about statistical hypothesis testing on differntial imaging).

It is really outstanding work ! Thank you very much for making it available here !

I am not done yet on reading the paper about the psf decomposition, but I was wondering if it was possible to get a reconstruction of the psf at various location of the image, such that one can then compute some quality metric maps across the image.

Which for instance would include:
-anisotropic gaussian matrix estimation
and from there:
-fwhm map
-ellipticity map

I was eager to see what will be in https://properimage.readthedocs.io/en/latest/topics/PSF.html
But there is nothing yet, what do you intend to put there ?

pickle import

If I understand correctly, apparently since python 3.0 pickle/cpickle is just pickle.

A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with an optional accelerated version implemented as a C extension; for example, pickle and cPickle. This places the burden of importing the accelerated version and falling back on the pure Python version on each user of these modules. In Python 3.0, the accelerated versions are considered implementation details of the pure Python versions. Users should always import the standard version, which attempts to import the accelerated version and falls back to the pure Python version. The pickle / cPickle pair received this treatment.

So these lines

try:
import cPickle as pickle # noqa
except ImportError:
import pickle

Should be just

import pickle

astroscrappy dependency

I have this dependency error right after installation in a clean virtualenv.

>>> from properimage import single_image as s
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "properimage/single_image.py", line 61, in <module>
    from astroscrappy import detect_cosmics
ImportError: No module named astroscrappy

I checked and it seems that astroscrappy is not listed in requirements.txt or setup.py

Remove six from dependencies

If we're dropping support for py2.7 (are we?) we can remove the dependency for six.
It's used only to import range in single_image and single_image_psfs.

Extract tests outside the project

  • Extract properimage.test outside properimage source.
  • Remove pytest as dependency.
  • Rename outside test folder to draft.
  • Add parallel into pytest

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.