Scientific Computing

Python PyPI typing not recommended

Some older Python projects may have typing as a package prerequisite. This can break Python itself from running. The “typing” PyPI module is not needed as all currently maintained Python versions have “typing” built in. Errors can result from having PyPI “typing” installed over factory Python “typing”.

Disable Siri on macOS

Older hardware, particularly those with spinning hard drives, benefit from disabling unused services just as with any operating system. On older Macs, Siri can be so slow as to be not that usable anyway.

This change is persistent even after rebooting.

  1. click Apple icon in upper left system menu bar and select System Preferences → Siri
  2. clear the “Enable Ask Siri” checkbox. The Siri icon also disappears from the top right system menu bar.

Developer computer how big hard drive

Developer computer purchases today should have at least a 512 GB hard drive (solid state drive) and preferably 1 TB or larger. Less than 256 GB hard drive may not be usable for today’s developers. Particularly for macOS and Windows, where Xcode or Visual Studio respectively take about 50 GB of storage, and other developer libraries and toolchains can easily take another 50-100 GB, this leaves even a 256 GB system drive nearly unusably full. To help future proof and avoid installing and uninstalling and moving around files, just get a 1 TB or larger PC if a computer is intended for software development. Computer OEMs make larger storage computers non-linearly increase in price perhaps as a bit of a developer / creator tax. The workaround for this is to get a computer that has replaceable hard drive, but there’s time and risk involved in swapping hard drives as well, as well as typically larger laptop size.

Fortran development in Visual Studio Code

Visual Studio Code is a free open source code editor with numerous extensions supporting most code languages, including for proprietary languages like Matlab. Fortran is well-supported by Visual Studio Code using the Modern Fortran extension, which supports linting, formatting integration, symbol navigation, and works well with fortls.

Typical setup:

  1. Install a Fortran compiler such as GFortran.
  2. Install the Modern Fortran extension.
  3. Install fortls for improved language-server features:
python -m pip install fortls

If GFortran is on PATH, Modern Fortran can use it for linting automatically.

Matlab / Python 3D meshgrid scatter plot

Simulations with spatial grids in 3D can be visualized via scatter plots. The grid may have irregular spacing such that each of the x, y, z dimensions is itself a 3-dimensional array. This can be visualized in Matlab or Python by reshaping the 3D arrays to a vector in the plotting command.

Scatter plots are one way to visualize 3D data in Matlab.

scatter3(x(:), y(:), z(:))

Python Matplotlib has several 3D visualization methods. Matplotlib scatter() also requires 1D vectors, which can be obtained at O(0) cost by the Numpy ndarray ravel method.

from matplotlib.pyplot import figure, show

ax = figure().gca()
ax.scatter(x.ravel(), y.ravel(), z.ravel())
show()

GitHub Python dependency check

GitHub CodeQL semantically analyzes Python code for security issues. Also, CVE Lists are checked vs. your GitHub repo’s dependency graph. CodeQL can install the Python package for more fidelity.

This approach finally fixes the concerns we had with the previous implementation that simply did CVE scans versus dependency graphs. The prior method of extracting dependencies did not work for modern Python packages. The new CodeQL method is much more robust and useful.

Logitech on Linux with Solaar

The Solaar program manages connections with Logitech Unifying receiver on Linux, including pairing/unpairing. This means wireless keyboards and mice, including wireless trackballs work well on Linux. Logitech wireless firmware updates are provided seamlessly in Linux. The Unifying receiver “just works” on Linux upon plugging in, with trackballs being recognized as an HID device.

Solaar provides a GUI for: pairing/unpairing, configuring buttons, monitoring battery level, and checking firmware version of Unifying receiver and connected devices. Logitech Unifying receivers can be paired with multiple devices. This allows one to carry a laptop from home to office without dragging the wireless keyboard or mouse along.

scipy.integrate.cumulative_trapezoid vs. Matlab cumtrapz

The 0-based indexing of Python / Numpy versus the 1-based indexing of Matlab is perhaps the most obvious difference when working between the languages. Other, more subtle defaults come into play and may not be immediately caught within functions except by manual checks.

In atmospheric science among other fields, cumulative integration implemented as cumulative trapezoidal numerical integration is a common function named “cumtrapz”. Distinctive behavior between Matlab cumtrapz and scipy.integrate.cumulative_trapezoid might not be immediately caught inside a function, although it’s obvious when manually checking. Specifically, SciPy scipy.integrate.cumulative_trapezoid needs the initial=0 argument to match Matlab. Let’s show this by example:

Example: given input:

x = [-2.5, 5, 10]

Matlab (or GNU Octave) outputs:

y = cumtrapz(x)

[0, 1.25, 8.75]

scipy.integrate.cumulative_trapezoid output one element less than the input by default:

scipy.integrate.cumulative_trapezoid(x)

[1.25, 8.75]

To match Matlab output from SciPy, add the initial=0 argument:

scipy.integrate.cumulative_trapezoid(x, initial=0)

[0, 1.25, 8.75]