czml3 icon indicating copy to clipboard operation
czml3 copied to clipboard

Support JupyterLab

Open astrojuanlu opened this issue 4 years ago • 44 comments

Edit: See current status in this comment.

At the moment, czml3.widget.CZMLWidget has a straightforward _repr_html_ that prints some HTML. However, this is not how custom widgets are supposed to be implemented [citation needed]

We should write our own custom Jupyter widget so it's compatible, at least, with modern JupyterLab.

Edit: Adding more information to this description for completeness

Rather than a JupyterLab extension, if I understand correctly we would need to create a custom Jupyter widget. Therefore, we should be using either https://github.com/jupyter-widgets/widget-cookiecutter (JavaScript, barebones) or https://github.com/jupyter-widgets/widget-ts-cookiecutter (TypeScript + bells & whistles), which are described in https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Low%20Level.html

However, we should wait for the TypeScript one to be updated: https://github.com/jupyter-widgets/widget-ts-cookiecutter/pull/83

These cookiecutters already make use of https://github.com/jupyter/jupyter-packaging.

For inspiration, we could also have a look at https://github.com/bloomberg/bqplot, https://github.com/jovyan/pythreejs, https://github.com/ellisonbg/ipyleaflet or https://github.com/matplotlib/ipympl.

With this and https://www.npmjs.com/package/c137.js shared by @TJKoury above, we should have everything we need already.

astrojuanlu avatar Apr 09 '20 11:04 astrojuanlu

According to this post, it could be necessary to get a webpack of Cesium: https://github.com/jupyterlab/jupyterlab/issues/5566

A new webpack of Cesium will come soon: https://github.com/DigitalArsenal/webpack-cesium/issues/7

GorgiAstro avatar Apr 09 '20 22:04 GorgiAstro

Oh wow, Jon Mease already worked on it :flushed: perhaps we'll have more luck this time!

astrojuanlu avatar Apr 09 '20 22:04 astrojuanlu

Yes, but I could not find where he published his ipywidget. Maybe we can ask him in a chat or by tagging him here?

GorgiAstro avatar Apr 10 '20 09:04 GorgiAstro

Hi @jonmmease! We noticed your comment from a couple of years ago about making a Cesium widget. @GorgiAstro found that there will be a new version of webpack-cesium soon. Do you have any code you can share so we can pick up from there and perhaps finish the work? Or do you think we should start from scratch?

astrojuanlu avatar Apr 10 '20 15:04 astrojuanlu

Hi @astrojuanlu, thanks for reaching out. Sorry to say that I can't share the code, but that said it wasn't very far along. Most of the time spent was in tinkering to try to get cesium building as an ipywidget. Sounds like a webpack-cesium would make that much easier!

In terms of the widget itself, all that I got working was a proof-of-concept where I made a Python/JavaScript model that stored a single lat/lon/altitude coordinate. Updating that coordinate from python triggered the Cesium API to move the sphere around the earth.

Had I stuck with it, I was picturing adopting the approach that bqplot uses (https://github.com/bloomberg/bqplot), where you create a matching hierarchy of nested Python and JavaScript models. But that idea is as far as I got. Hope that helps a little. Good luck!

jonmmease avatar Apr 10 '20 16:04 jonmmease

@jonmmease @astrojuanlu We have a new build that works great, and will be kept up to date with the latest in core Cesium.

As I am sure you are aware, the packing process is non-trivial, and in our case represents a significant investment to maintain. We are trying to keep it open for community use but have not decided on a licensing model yet.

Would any of the companies represented on this project consider sponsoring the work?

TJKoury avatar Jun 26 '20 13:06 TJKoury

Thanks for chiming in @TJKoury! That's great news.

Would any of the companies represented on this project consider sponsoring the work?

poliastro and czml3 are a community effort, unfortunately the only support we can offer is integrating webpack-cesium in czml3 and try to make it work for a broader audience.

astrojuanlu avatar Jun 26 '20 13:06 astrojuanlu

@astrojuanlu Understood. How do you think the community would respond to a 'non-commercial' license?

TJKoury avatar Jun 26 '20 14:06 TJKoury

@TJKoury It's a good question. There are many forms of "non-commercial" licensing, for example what Qt does. If you decide use a copyleft license, we'll have to evaluate how to use it from czml3 (MIT, hence non-copyleft) without infringing the terms (and I might need a lawyer for this...). Other than that, I don't know how that can affect adoption.

astrojuanlu avatar Jun 26 '20 15:06 astrojuanlu

Also, we are about to release a commercial package for the library behind Celestrak Orbit Viz.

TJKoury avatar Jun 26 '20 15:06 TJKoury

After some consideration, I think we will probably just release it under MIT and ask for donations.

TJKoury avatar Jun 26 '20 16:06 TJKoury

After some consideration, I think we will probably just release it under MIT and ask for donations.

That's great news :) Let me suggest https://opencollective.com/ for the donations part in case you don't know it. Looking forward for the release :muscle:

astrojuanlu avatar Jun 26 '20 16:06 astrojuanlu

Here it is, C137.js.

Decided to go with CC BY 4.0 as freeware, since source-wise it is already open.

Left some crypto addresses at the bottom if people are feeling generous.

TJKoury avatar Sep 25 '20 20:09 TJKoury

Awesome @TJKoury, thanks a lot! We'll soon try to figure out how to use, if @jonmmease doesn't beat us to it :)

astrojuanlu avatar Sep 26 '20 04:09 astrojuanlu

It should be fairly straightforward, use an es6 import any bundler will take care of the rest. Let me know if you have any issues.

TJKoury avatar Sep 26 '20 11:09 TJKoury

... if @jonmmease doesn't beat us to it :)

No risk of that for the foreseeable future :slightly_smiling_face:

jonmmease avatar Sep 26 '20 11:09 jonmmease

Seems like JupyterLab 3.0 and webpack 5.0 will change some things? See lengthy discussion at https://github.com/jupyterlab/jupyterlab/issues/7468, keyword "Module Federation" https://module-federation.github.io/

astrojuanlu avatar Oct 12 '20 19:10 astrojuanlu

@astrojuanlu It will not change the need to pack it up, or mess with our implementation. The issue is not dependency management, it is trying to load external resources like workers at runtime as if they were compile time assets.

TJKoury avatar Oct 12 '20 20:10 TJKoury

I edited the first comment to add some extra information.

astrojuanlu avatar Jan 05 '21 12:01 astrojuanlu

Hi, was playing a bit with this, would like to get the old CesiumWidget up and running again.. Did a test with c137.js and cookiecutter widget, now showing the widget nothing else. https://github.com/petrushy/CesiumWidget3/tree/c137_version

I would however like to transition to the "official" cesium where all steps are reproducable, but c137.js was indeed very smooth to get running.

petrushy avatar Feb 09 '21 09:02 petrushy

That's great news @petrushy ! I think it's pointless to have two widgets, so one option would be that we remove our widget.py from czml3 and we lend a hand with the maintenance of CesiumWidget3, what do you think?

astrojuanlu avatar Feb 09 '21 10:02 astrojuanlu

Thanks for the vote of confidence @petrushy, and make sure to check out our soon-to-be decentralized notebook app, mapshot.app. Still in beta but you get the idea.

TJKoury avatar Feb 09 '21 14:02 TJKoury

@astrojuanlu I am very happy to collaborate on this, the one currently in czml is working but does not fully meet the needs of a widget for other purposes. I am thinking to also add a bit of higher level easy-plotting for quick visualizations.

@TJKoury , sorry I may express myself unclear, I do not see a future using closed source, your package is very nice and the example was a quick confirmation of that, but we need unfortunately to have transparency of the full process of the items that goes into it.

petrushy avatar Feb 09 '21 19:02 petrushy

@petrushy No problem! The source is available, it’s just the build process that is proprietary. Seems like this project does not have issues using libraries built with closed-source IDE’s or operating systems, but if this is where you draw the line I understand.

TJKoury avatar Feb 09 '21 19:02 TJKoury

It's open source now, Apache 2.0 licensed:

Github - c137.js

TJKoury avatar Nov 04 '21 18:11 TJKoury

Thanks a lot @TJKoury !

By the way, this discussion is very relevant: https://github.com/jupyter/notebook/issues/6210 basically we are in the same situation as many other extensions. Doing what czml3 does in Classic Notebook is easy, but it turns out that doing it in JupyterLab requires an entirely different set of skills. I added my two cents to that discussion, and it looks like there are some ideas to make tinkering with JupyterLab easier. But if we want this migration to happen in the short term, we will have to bite the bullet and figure out how to do it. Undoubtedly, having c137.js open sourced makes everything easier.

astrojuanlu avatar Nov 04 '21 18:11 astrojuanlu

@astrojuanlu Sounds good, let us know if there's anything on our end that we can do to help.

TJKoury avatar Nov 04 '21 19:11 TJKoury

It's open source now, Apache 2.0 licensed:

Many Thanks!!!

petrushy avatar Nov 04 '21 20:11 petrushy

PSA: I'm learning webpack. I might tackle this myself 😉

astrojuanlu avatar Dec 16 '21 13:12 astrojuanlu

Inspiration: https://github.com/damianavila/RISE/pull/605

astrojuanlu avatar Dec 16 '21 13:12 astrojuanlu