question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add convenience constructors for SkyCube

See original GitHub issue

@leajouvin is presenting the cube tutorial, where she introduced a helper function to create an empty SkyCube, see here.

This was confusing to some people, Gammapy itself should make it easy to create empty sky cubes in common ways. I think we should add one or two classmethods to SkyCube to help with that.

Here’s what we have now:

We do have separate classes / convenience constructors to set up sky images and energy grids already:

Since it’s orthogonal, maybe we should just say that to define an empty cube one always makes an empty sky image, and empty energy or energy bounds object, and then the SkyCube, i.e. like this:

image = SkyImage<some method and parameters>
energy = Energy<some method and parameters>
cube = SkyCube.empty(image, energy)

or if you want to avoid the local variables of image and energy, you could do this:

cube = SkyCube.empty(
    image=SkyImage<some method and parameters>
    energy=Energy<some method and parameters>
)

@kosack @JouvinLea @adonath @registerrier - Thoughts on what API we should put?

Anyone has time to implement something here in the coming days?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
adonathcommented, Feb 22, 2017

Some further thoughts:

I would keep the .empty() method as is. I.e. it just takes a set of float/string parameters to create an empty cube. This is equivalent to SkyImage.empty(). In addition we could add SkyCube.empty_like_skyimage(image, energies), which allows creation with a SkyImage and Energy, EnergyBounds or Quantity object.

0reactions
adonathcommented, Mar 7, 2017

Resolved by #935 . Thanks for all your suggestions!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customizing constructors for correctness and convenience
We can remedy this by defining a convenience constructor whose job is to construct our object with some reasonable default values for some...
Read more >
[Proposal] Create a Dart class convenience constructor for ...
Introduce a convenience boolean constructor parameter called withRestOfOptional and a new super() constructor alternative called ...
Read more >
Is there a convenience constructor in C++? - Stack Overflow
C++11 introduced delegating constructors: class A { public: std::string m_str; A(std::string str) : m_str(str) {} // target constructor ...
Read more >
Creating constructors - IBM
On the Rational Rhapsody browser, right-click either the class or the Operations category under the class and select Add New > Constructor.
Read more >
Using Constructors - C# Programming Guide | Microsoft Learn
This example shows how a class is instantiated by using the new operator in C#. The simple constructor is invoked after memory is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found