Restructure spectrum package and command line tool #436
Conversation
@joleroi - Now that you've made a change in gammapy-extra, but this PR from gammapy hasn't landed yet, the build is broken: I really need to change the setup, so that gammapy-extra is a git submodule ... this will give us versioning for gammapy-extra and sanity. |
@cdeil Sorry for breaking everything Can you please have a look at gammapy/spectrum/results.py (and for now only at this). There are not test yet (only one example) but next I want to add a test that runs an entire crab analysis and does stuff with the results, so the results classes will be tested in this high-level test (You said: High-level tests over unit-tests). Is there any functionality in spectrum/spectrum_results.py that you need and is not covered in the new stuff? Otherwise I would think about removing it, because having spectrum_results.py and results.py is confusing (Luigi already stumbled over this). |
You only want to do the tutorial once this PR is merged, right? |
I had a quick look. It's super-hard to review this in isolation and give useful feedback. I'd much prefer to merge in master, and let me just use this for an hour tomorrow and look around the docs and code. Then I can give suggestions like I did in #419. @joleroi - Would this be OK for you?
Yes, I don't think unit tests make sense as long as the API is still heavily changing. That's not just me ... you can find many opinions that unit tests don't make sense during prototyping, because you'd spend so much time refactoring the tests over and over as the API changes.
I'm not sure ... could you leave it in for now and I'll have a detailed look tomorrow? |
assert fit.result.spectral_model == 'PowerLaw' | ||
|
||
|
||
def test_spectral_fit_using_config(tmpdir): |
cdeil
Feb 7, 2016
Member
Add this here:
@requires_dependency('sherpa')
@requires_data('gammapy-extra')
Add this here:
@requires_dependency('sherpa')
@requires_data('gammapy-extra')
from astropy.tests.helper import pytest | ||
from numpy.testing import assert_allclose | ||
|
||
from gammapy.spectrum import run_spectrum_extraction_using_config |
cdeil
Feb 7, 2016
Member
Use relative imports within Gammapy ... this needs to be changed in several files in this PR.
Use relative imports within Gammapy ... this needs to be changed in several files in this PR.
joleroi
Feb 7, 2016
Author
Contributor
Stupid PyCharm ...
Stupid PyCharm ...
+1,937 −1,409 lines -> "looks fine" :-) |
Restructure spectrum package and command line tool
What about this docs page? Has it been superceded by this one? Or do you want to keep both? When I wanted to try out the new spectrum fitting code, https://gammapy.readthedocs.org/en/latest/spectrum/spectral_fitting.html is what I found first,
|
No this is in fact outdated. I would like to keep it for "low-level" docs. I will remove the broken part in the next PR. Could you try the new tutorial? |
I'm trying the new tutorial now ... can you come by so that we discuss a bit? ... I think it's easier than via Github for this. |
table.add_row(new_row) | ||
|
||
l.append(self[key].to_table(**kwargs)) | ||
table = vstack(l, join_type='outer') | ||
table.add_column(analyses, index=0) |
cdeil
Feb 9, 2016
Member
With Python 3 and Astropy and Gammapy master I'm getting this error when I follow along the new tutorial:
$ gammapy-spectrum display crab_analysis/spectrum_stats.yaml spectrum_stats_23592.yaml
Traceback (most recent call last):
File "/Users/deil/Library/Python/3.4/bin/gammapy-spectrum", line 9, in <module>
load_entry_point('gammapy', 'console_scripts', 'gammapy-spectrum')()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/Users/deil/code/gammapy/gammapy/scripts/spectrum.py", line 99, in display_spectrum
t = master.to_table(format=format)
File "/Users/deil/code/gammapy/gammapy/spectrum/results.py", line 762, in to_table
table.add_column(analyses, index=0)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/table/table.py", line 1387, in add_column
self.add_columns([col], [index], rename_duplicate=rename_duplicate)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/table/table.py", line 1495, in add_columns
self._init_from_cols(newcols)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/table/table.py", line 685, in _init_from_cols
lengths = set(len(col) for col in cols)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/table/table.py", line 685, in <genexpr>
lengths = set(len(col) for col in cols)
TypeError: len() of unsized object
With Python 3 and Astropy and Gammapy master I'm getting this error when I follow along the new tutorial:
$ gammapy-spectrum display crab_analysis/spectrum_stats.yaml spectrum_stats_23592.yaml
Traceback (most recent call last):
File "/Users/deil/Library/Python/3.4/bin/gammapy-spectrum", line 9, in <module>
load_entry_point('gammapy', 'console_scripts', 'gammapy-spectrum')()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/Users/deil/code/gammapy/gammapy/scripts/spectrum.py", line 99, in display_spectrum
t = master.to_table(format=format)
File "/Users/deil/code/gammapy/gammapy/spectrum/results.py", line 762, in to_table
table.add_column(analyses, index=0)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/table/table.py", line 1387, in add_column
self.add_columns([col], [index], rename_duplicate=rename_duplicate)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/table/table.py", line 1495, in add_columns
self._init_from_cols(newcols)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/table/table.py", line 685, in _init_from_cols
lengths = set(len(col) for col in cols)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/table/table.py", line 685, in <genexpr>
lengths = set(len(col) for col in cols)
TypeError: len() of unsized object
This is the template render package I mentioned: As I said, I'd start by adding the code to make a webpage with the most common plot and numbers for a single analysis, with the plots FitSpectrum generates and prints on the console. |
this PR changes
the structure of gammapy.spectrum
the structire of the gammapy-spectrum command line tool