#python

waynerad@diasp.org

Pyodide + JupyterLite. This is pretty impressive -- check out my screenshot.

Pyodide is Python running in your web browser -- more specifically, it is a port of CPython to WebAssembly, using Emscripten, which is a compiler toolchain based on LLVM (the compiler toolchain used by Apple languages and Rust) that compiles to WebAssembly. JupyterLite, in turn, enables Python Jupyter notebooks to run insider your browser. The "notebook" interface was pioneered by Mathematica in 1988 and is based on the the idea of creating a document that contains explanatory text, software code, and visualizations, all in the same document, in such a way that the computer actually runs the code and produces the visualizations. The document is divided into "cells" where each cell is text or code along with output produced by the code, such as a visualization.

As you can see, I imported SymPy (symbolic math system for Python) and asked it to figure out a few integrals. Remember, the ** operator means exponentiation in Python, not ^ like you may be used to.

The thing that really amazes me about this is, this is all running in the browser -- and not "in the browser" in the sense of, connecting to a server and running Python and Jupyter on the server and displaying the results in a browser -- no, once all the code is downloaded, everything you see is running in the browser. Python is running in the browser, SymPy is running in the browser, all the calculations to determine the integrals I asked for are done in the browser, and all the code for the "notebook" display and that generates the nice mathematical notation is running in the browser. Yes, I checked in Chrome developer tools and verified no network requests are being made -- everything really is running in the browser.

Try it yourself.

#solidstatelife #python #jupyter #wasm

https://jupyterlite.github.io/demo/lab/index.html

danie10@squeet.me

You can develop native apps for Android using Python

Old CRT monitor with a hand extending out of it. Above the hand is hovering a Python logo. On the left and right sides of the monitor are green Android robotos. In the background can be seen some random Python coding statements.
Python’s simplicity and readability make it an attractive choice for developers looking to quickly develop and deploy applications. Although Java and Kotlin are the traditional languages for Android development, Python offers a streamlined alternative that leverages Python’s rich ecosystem of libraries and frameworks. Using Python on Android can accelerate development and enable the integration of advanced functionalities like data analysis and machine learning.

Five different options are covered in the linked article:

  1. Kivy
  2. BeeWare
  3. Chaquopy
  4. PySide for Android
  5. Pydroid 3

And interestingly, you can use Buildozer for Kivy, Briefcase for BeeWare, or PyQtDeploy for PySide to package your Python app into an APK as well. That makes the app distribution and installation identical to any other Android app.

See analyticsinsight.net/python-2/…
#Blog, #android, #python, #technology

anonymiss@despora.de

The Shameful #Defenestration of Tim

On #TimPeters' recent #suspension as a #Python core #developer

Source: https://chrismcdonough.substack.com/p/the-shameful-defenestration-of-tim

I’m disappointed in the decision of the Steering Council. Questioning authority when you’ve previously had such authority for such a long time should be valued. But I am not surprised to see their decision, because apparently today’s world does not possess the same values that made Python what it is today. Instead, Python is now a grey, humorless, corporate place.

#Software #Problem #floss #foss #politics #news #future #OpenSource

danie10@squeet.me

The Julia programming language: a missed opportunity for AI

A laptop suspended in the air by 6 colourful balloons. The screen shows the word JULIA.
Admittedly, it was the headline that caught my attention, and I’ve only briefly looked a bit into Julia. Of course, there is also more to a language than just speed, such as wealth of libraries, wealth of documentation and tutorials, cross-platform compatibility, etc.

Its creators, in a 2012 blog post, stated they aimed to combine the speed of C with the ease of use of Python, while adopting additional positive qualities from various other leading programming languages.

On the face of it, Julia is pretty easy to pick up if you know any high-level language well. Python users could quite easily adapt to using it once you know some of the minor differences such as indexing of arrays starting at 1 instead of 0, concatenation of strings is with a “*” and not a “+”, etc. Julia’s syntax is straightforward and intuitive, similar to that of Python, meaning it can be used extensively for exploratory programming and data analysis. They have a good FAQ itemising the differences to many other common languages such as Python, Common Lisp, C/C++, MATLAB, and R.

A FAQ is often why they did not just plug a Matlab or Python front-end into a Julia back-end (or “transpile” code to Julia) in order to get all the performance benefits of Julia without requiring programmers to learn a new language. Julia’s performance advantage derives almost entirely from its front-end: its language semantics allow a well-written Julia program to give more opportunities to the compiler to generate efficient code and memory layouts. If you tried to compile Matlab or Python code to Julia, the compiler would be limited by the semantics of Matlab or Python to producing code no better than that of existing compilers for those languages (and probably worse).

There is also a build_executable function, but it is noted that this compatible across Windows and macOS, but not on Linux. To increase the portability, they suggest you use an older “cpu_target” target as “core2” instead of “native”.

Importantly, too, the language is open-source and not affiliated to any company. That said, one programmer who no longer recommends Julia, state it was because the community swept some problems under the rug.

It is already used in many areas, for example NASA has deployed Julia to calculate the courses of spacecraft. It excels is financial analysis, weather forecasting and car crash simulations, etc. Its creators, in a 2012 blog post, stated they aimed to combine the speed of C with the ease of use of Python, while adopting additional positive qualities from various other leading programming languages.

Given that Julia’s big advantage over Python is where speed, becomes a primary factor, it would be well suited you’d think for AI. If you need to scale your workload, Julia should offer a strong basis to keep growing. But Python has a mass adoption and people don’t change languages just for the sake of it, especially when there is such a wealth of documentation and assistance out there for Python. Still, if speed is a primary factor, then it may well be worth considering Julia, especially given that is also quite easy to learn.

See techzine.eu/blogs/devops/11851…
#Blog, #Julia, #opensource, #programming, #python, #technology

rhysy@diaspora.glasswings.com

Another day, another Streamlit app. This one isn't of much use for public outreach, but is potentially quite the time-saver for me. It takes raw photometric measurements of galaxies (e.g. apparent magnitude, but also photon counts) and turns them into physical estimates of their stellar masses. Given an inclination angle estimate it also applies a correction for internal extinction (that is, all the gas and dust obscuring the stars as we look through the galaxy itself). It can even look up the extinction within our own Galaxy as well, given the sky coordinates.

All this is very simple to apply in practice, but there are so many little steps that it's very easy to make a mistake in one of them, which rapidly gets tedious. And if you just want a single measurement this can be no fun at all, so not having to do any of this - replacing it all with entering a couple of numbers in a table - is quite handy. I should probably write a version that can process multiple inputs as well, but this is at least a useful reference source for that.

Just how accurate these prescriptions are I know not. It's quite interesting to see how the mass estimates vary, even using the same photometric measurements gives values differing by a factor two or so according to different methods. As I understand it, these simple estimates are from fitting to different models of stellar populations; don't ask me how that works. Another major factor is that different wavebands (filters) often have different sensitivity levels... so using different colours can easily give estimates which differ by a factor of a few. Still, it's probably better than not doing it at all.

#Science
#Space
#Astronomy
#Python

https://photcalc.streamlit.app/

rhysy@diaspora.glasswings.com

Why Gravity-Powered Helicopters Aren't A Thing

Here's another little Streamlit app to ease the burden on my ageing calculator. This one calculates the dynamical mass of a galaxy given rotation speed at a known distance. Or indeed, it will calculate the unknown variable from any of the two supplied, e.g. radius if you already know the mass and speed. It converts between different units (you can even use mph if you're so inclined) but doesn't account for relativistic effects. For galaxies, which is what I actually need this for, this isn't a problem : rotation speeds tend to be <0.1% c. For compact objects like neutron stars and black holes this will give meaningless results, but the scales are about a dozen orders of magnitude different, so that doesn't matter.

The dynamical mass is basically how much mass you'd need to cause the observed speed from gravity alone. In some cases gravity is all you need : the orbits of the planets and the dynamics of star clusters are perfectly consistent with pure gravitational motions, with thermal effects in solar system bodies being important only as matters of detail. In some galaxies it also seems that their dynamics is dominated by the visible matter, but in most cases you need about ten times more mass than we see to explain their rotation speeds.

What's quite fun about this one is that you can input everyday numbers as well as astronomical ones. So for instance, if you spin your arms at a quite achievable 1 m/s with a length of 1 m, that's a dynamical mass of nearly fifteen million tonnes. A helicopter spinning its 5 m long blades at 125 m/s (from some quick Google searching) would have a dynamical mass of over one trillion tonnes ! To make a gravity-powered helicopter, you'd need it to have the mass of a mountain.

Which just goes to show how negligible gravitational fields from little objects like people and helicopters really are : they're completely dominated by non-gravitational effects (except, of course from the much larger external field of the Earth). If you were to plot the dynamics of helicopters in comparison with galaxies you'd find that helicopters would seems like far weirder, crazier outliers than any of the galaxies ever observed. The helicopter would have an apparent "missing mass" ratio of something like a trillion. For galaxies most have ratios of order a few, with some exceptional cases in the hundreds.

Of course, helicopters are easy to explain because we know their motion has bugger all to do with gravity. But nobody has proposed any plausible non-gravitational mechanism which would explain how to make stars and gas spin so much faster than expected. Either there's a fair bit of extra material there, or, much less likely, gravity itself does funky things at low accelerations.

#Science
#Python
#Astronomy
#Space

https://dynamicalmasspy.streamlit.app/