New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS map calculation update and docs #221

Merged
merged 2 commits into from Dec 15, 2014

Conversation

Projects
None yet
2 participants
@adonath
Member

adonath commented Dec 12, 2014

Modified command line tool to work with different pixels sizes. Added some documentation and brief tutorial.

N : int (default = 3)
Exponent of two.
"""
shape_x = shape[1] + (2 ** N - np.mod(shape[1], 2 ** N))

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

Can you call this shape_1 and shape_0 here?
Which one is x / y is always confusing and irrelevant in this code.

So it's not possible to just make this a numpy array expression with input np.array(shape)?

>>> kernel = Gaussian2DKernel(5)
>>> result = compute_ts_map(maps['On'].data, maps['Background'].data, maps['ExpGammaMap'].data, kernel, debug=True, threshold=0)
By setting ``debug=True`` not only a TS map but also a flux amplitude map and a number of iterations map is returned. See

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

As discussed ... remove the debug option and also from the description here.

@cdeil

This comment has been minimized.

Member

cdeil commented Dec 12, 2014

I would prefer to have the 63kB file ./docs/detect/fermi_survey_ts.png removed from the repo and Sphinx page and instead for nice plots point people to the IPython notebook. OK?

@cdeil

This comment has been minimized.

Member

cdeil commented Dec 12, 2014

This will make the Sphinx build fail on travis-ci:

/Users/deil/code/gammapy/docs/detect/index.rst:89: SEVERE: Title level inconsistent:

gammapy.detect Module
---------------------

checking consistency... /Users/deil/code/gammapy/docs/api/gammapy.image.shape_2N.rst:: WARNING: document isn't included in any toctree
done

@@ -28,3 +88,5 @@ Reference/API
.. automodapi:: gammapy.detect
:no-inheritance-diagram:
.. automodapi:: gammapy.detect.test_statistics

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

Adding this here leads to the content being listed twice in the API docs:
screen shot 2014-12-12 at 15 24 58

You should remove it.
If something doesn't show up in the sphinx docs it's because it's missing in the __all__ list.

.. code:: bash
$ gammapy-ts-image all.fits.gz --threshold 0 --scale 0 --residual --model model.fits.gz

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

This errors on Python 3:

$ gammapy-ts-image all.fits.gz --threshold 0 --scale 0
WARNING: AstropyDeprecationWarning: Use of an 'eval' method when defining subclasses of FittableModel is deprecated; please rename this method to 'evaluate'.  Otherwise its semantics remain the same. [astropy.modeling.core]
WARNING - AstropyDeprecationWarning: Use of an 'eval' method when defining subclasses of FittableModel is deprecated; please rename this method to 'evaluate'.  Otherwise its semantics remain the same.
INFO - Reading all.fits.gz
INFO - Computing (residual) TS map for scale 0.0 deg
INFO - Using down sampling factor of 1
INFO - No down sampling used.
INFO - Using correlation radius of 6.5 pix to estimate initial flux.
INFO - Using 8 cores to compute TS map.
Traceback (most recent call last):
  File "/Users/deil/Library/Python/3.4/bin/gammapy-ts-image", line 4, in <module>
    __import__('pkg_resources').run_script('gammapy==0.2.dev1086', 'gammapy-ts-image')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources.py", line 517, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources.py", line 1436, in run_script
    exec(code, namespace, namespace)
  File "/Users/deil/Library/Python/3.4/lib/python/site-packages/gammapy-0.2.dev1086-py3.4.egg/EGG-INFO/scripts/gammapy-ts-image", line 102, in <module>
    logging.info('TS map computation took {0:.1f} s'.format(ts_results.runtime))
TypeError: non-empty format string passed to object.__format__
In [4]: type(ts_results.runtime)
Out[4]: NoneType

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

Another error from the command line tool on Python 3:

$ gammapy-ts-image all.fits.gz --threshold 0 --scale 0
WARNING: AstropyDeprecationWarning: Use of an 'eval' method when defining subclasses of FittableModel is deprecated; please rename this method to 'evaluate'.  Otherwise its semantics remain the same. [astropy.modeling.core]
WARNING - AstropyDeprecationWarning: Use of an 'eval' method when defining subclasses of FittableModel is deprecated; please rename this method to 'evaluate'.  Otherwise its semantics remain the same.
INFO - Reading all.fits.gz
INFO - Computing (residual) TS map for scale 0.0 deg
INFO - Using down sampling factor of 1
INFO - No down sampling used.
INFO - Using correlation radius of 6.5 pix to estimate initial flux.
INFO - Using 8 cores to compute TS map.
INFO - Writing ts_map_0.00.fits
Traceback (most recent call last):
  File "/Users/deil/Library/Python/3.4/bin/gammapy-ts-image", line 4, in <module>
    __import__('pkg_resources').run_script('gammapy==0.2.dev1086', 'gammapy-ts-image')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources.py", line 517, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pkg_resources.py", line 1436, in run_script
    exec(code, namespace, namespace)
  File "/Users/deil/Library/Python/3.4/lib/python/site-packages/gammapy-0.2.dev1086-py3.4.egg/EGG-INFO/scripts/gammapy-ts-image", line 123, in <module>
    dict_to_hdulist(results, maps['ExpGammaMap'].header).writeto(filename, clobber=args.clobber)
  File "/Users/deil/Library/Python/3.4/lib/python/site-packages/gammapy-0.2.dev1086-py3.4.egg/gammapy/image/utils.py", line 391, in dict_to_hdulist
    for name, image in image_dict.iteritems():
AttributeError: 'OrderedDict' object has no attribute 'iteritems'

You can get a simultaneous Python 2 and 3 installation from apt-get or conda for local testing.

# Sample down if required
downsampled = False
if args.downsample == 'auto':
args.downsample = np.select([args.scale < 0.1, args.scale < 0.2, args.scale < 0.4], [1, 2, 4], 8)
args.downsample = np.select([args.scale < 5 * BINSZ, args.scale < 10 * BINSZ, args.scale < 20 * BINSZ], [1, 2, 4], 8)

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

Add line break!

psf_parameters = json.load(open(args.psf))
kernel = multi_gauss_psf_kernel(psf_parameters, NEW_BINSZ=BINSZ, mode='oversample', x_size=21)
kernel = multi_gauss_psf_kernel(psf_parameters, BINSZ=BINSZ, NEW_BINSZ=BINSZ * factor, mode='oversample', x_size=21)

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

Add line break!

@cdeil

This comment has been minimized.

Member

cdeil commented Dec 12, 2014

I've left quit a few comments inline above ... let me know when I should have another look ... hopefully we can get this merged quickly!

estimate, that the pixel is processed at all. The function returns a `~gammapy.detect.TSMapResult` object, that bundles all relevant
data. E.g. the time needed for the TS map computation can be checked by:
>>> print result.runtime

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

Always use the print function so that this works with Python 2 and 3.

Maybe a result.info() or a nice print(result) by implementing some summary info in info or __str__ would be nice?
(e.g. how many pixels were fitted, how many cash evaluations, maybe even print min / max of the arrays)
Obviously this is not needed if you don't want to spend time on this.

The TS map itself can bes accessed using the ``ts`` attribute of the `~gammapy.detect.TSMapResult` object:
>>> print result.ts.max()

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

Again ... always use the print function to make this work on Python 3.

>>> print result.ts.max()
Gammapy also provides a command line tool ``gammapy-ts-image`` for TS map computation, which can be run by:

This comment has been minimized.

@cdeil

cdeil Dec 12, 2014

Member

Add a sub-section called Command line tool.

Maybe put cd gammapy-extra/datasets/fermi_survey as the first command to let people know where they have to go to try this out themselves?

@adonath adonath force-pushed the adonath:ts_map_calculator_parallel_rev2 branch 2 times, most recently from 0619fd0 to d6d04ce Dec 12, 2014

@adonath adonath force-pushed the adonath:ts_map_calculator_parallel_rev2 branch from d6d04ce to 909062b Dec 13, 2014

@cdeil

This comment has been minimized.

Member

cdeil commented Dec 15, 2014

Travis-ci fails are unrelated ... merging this now.

cdeil added a commit that referenced this pull request Dec 15, 2014

@cdeil cdeil merged commit d212a64 into gammapy:master Dec 15, 2014

0 of 2 checks passed

continuous-integration/appveyor AppVeyor build failed
Details
continuous-integration/travis-ci The Travis CI build failed
Details

@cdeil cdeil changed the title from TS map calculator update and docs to TS map calculation update and docs Apr 8, 2015

@cdeil cdeil added the feature label Apr 8, 2015

@cdeil cdeil added this to the 0.2 milestone Apr 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment