Skip to content
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

Prefix containers #833

Merged
merged 13 commits into from
Jan 23, 2019
Merged

Prefix containers #833

merged 13 commits into from
Jan 23, 2019

Conversation

maxnoe
Copy link
Member

@maxnoe maxnoe commented Nov 22, 2018

This allows writing multiple containers using a prefix for each column in the hdfwriter.

This enables writing duplicated keys (e.g. ReconstructedShower.alt, MCEvent.alt).

By default the prefix is cls.__name__.lower().replace('Container', '')

@codecov
Copy link

codecov bot commented Nov 22, 2018

Codecov Report

Merging #833 into master will increase coverage by 0.06%.
The diff coverage is 98.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #833      +/-   ##
==========================================
+ Coverage   73.52%   73.58%   +0.06%     
==========================================
  Files         211      211              
  Lines       12066    12102      +36     
==========================================
+ Hits         8871     8905      +34     
- Misses       3195     3197       +2
Impacted Files Coverage Δ
ctapipe/io/tests/test_hdf5.py 93.08% <100%> (+0.36%) ⬆️
ctapipe/core/tests/test_container.py 100% <100%> (ø) ⬆️
ctapipe/io/hdf5tableio.py 94.63% <100%> (+1.52%) ⬆️
ctapipe/io/tableio.py 90% <100%> (+0.16%) ⬆️
ctapipe/io/containers.py 100% <100%> (ø) ⬆️
ctapipe/core/container.py 67.32% <90%> (+0.32%) ⬆️
ctapipe/io/nectarcameventsource.py 95.23% <0%> (-4.77%) ⬇️
ctapipe/io/lsteventsource.py 87.02% <0%> (-1.53%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e715248...405da47. Read the comment docs.

vuillaut
vuillaut previously approved these changes Nov 23, 2018
Copy link
Member

@vuillaut vuillaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very useful feature, thank you @maxnoe.

@vuillaut
Copy link
Member

The way I understand it, the user can change the prefix as he likes, right?

@maxnoe
Copy link
Member Author

maxnoe commented Nov 23, 2018

The way I understand it, the user can change the prefix as he likes, right?

Not really intended. The prefix is a class member of the container.
But as this is python, you could change this class member.

from ctapipe.io.containers import HillasParametersContainer

HillasParametersContainer.prefix = 'foobar'

group_name,
add_prefix=False,
mode='w',
root_uep='/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is a "uep" ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The user entry point to the object tree attached to the HDF5 file is represented in the root_uep attribute". From http://www.pytables.org/usersguide/libref/file_class.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to get rid of root_uep. We want to merge it with the group_name.

@kosack
Copy link
Contributor

kosack commented Nov 26, 2018

The way I understand it, the user can change the prefix as he likes, right?

Not really intended. The prefix is a class member of the container.
But as this is python, you could change this class member.

This is definitely the behavior we need - the main use case is that we will have for example multiple image cleanings and multiple hillas parameterizations that will be stored in the output file, so we want to be able to change the prefix for each one. E.g. if you have multiple image cleanings, for example (loose and tight), you might have a dict inside your container like:

cont.hillas['tight'] = hillas_parameters(...)
cont.hillas['loose'] = hillas_parameters(...)

then you want to have outputs like:

tight_length, tight_width (or perhaps tight_hillas_width if you combine multiple prefixes)

I guess that functionality can be in addition to the one added here (both are useful - a global classname prefix, and an "instance" prefix)

ctapipe/io/hdf5tableio.py Outdated Show resolved Hide resolved
@maxnoe maxnoe force-pushed the prefix_containers branch from 9e9c68c to 2351a33 Compare December 4, 2018 13:21
@maxnoe
Copy link
Member Author

maxnoe commented Dec 4, 2018

I updated this to enable instance level prefixes and moved the build_prefix function to the base TableWriter.

Containers now have a class variable containter_prefix which is used to initialize the instance level prefix.

Unfortunately this was not possible differently, since python does not allow class variables to initiliaze __slots__.

@kosack can you review again?

@codecov-io
Copy link

codecov-io commented Dec 12, 2018

Codecov Report

Merging #833 into master will increase coverage by 0.09%.
The diff coverage is 97.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #833      +/-   ##
==========================================
+ Coverage   78.11%   78.21%   +0.09%     
==========================================
  Files         185      185              
  Lines       10557    10593      +36     
==========================================
+ Hits         8247     8285      +38     
+ Misses       2310     2308       -2
Impacted Files Coverage Δ
ctapipe/io/tests/test_hdf5.py 93.08% <100%> (+0.36%) ⬆️
ctapipe/plotting/tests/test_camera.py 100% <100%> (ø) ⬆️
ctapipe/core/tests/test_container.py 100% <100%> (ø) ⬆️
ctapipe/io/hdf5tableio.py 94.63% <100%> (+1.52%) ⬆️
ctapipe/io/tableio.py 90% <100%> (+0.16%) ⬆️
ctapipe/io/containers.py 100% <100%> (ø) ⬆️
ctapipe/core/container.py 67.32% <85.71%> (+0.32%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc12d6b...1f28b34. Read the comment docs.

kosack
kosack previously approved these changes Dec 12, 2018
Copy link
Contributor

@kosack kosack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just minor change - don't use tempdir, rather pytest's fixture instead. Otherwise looks good.

ctapipe/io/tests/test_hdf5.py Show resolved Hide resolved
@dneise dneise merged commit c2efb64 into cta-observatory:master Jan 23, 2019
watsonjj added a commit to watsonjj/ctapipe that referenced this pull request Jan 23, 2019
* master:
  Major coordinate refactoring, fixes cta-observatory#899, cta-observatory#900, cta-observatory#505, cta-observatory#416 (cta-observatory#896)
  speed up is_compatible; makes event_source factory faster (cta-observatory#927)
  Prefix containers (cta-observatory#833)
  remove optional deps in order to fix tests (cta-observatory#925)
  Charge Resolution Update (cta-observatory#827)
  Remove serializer, fixes cta-observatory#887 (cta-observatory#913)
  deleted summary.html - accidentally committed file (cta-observatory#919)

# Conflicts:
#	ctapipe/tools/extract_charge_resolution.py
#	examples/simple_event_writer.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants