Scientific Computing

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.

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()

Extracting a page from PDF

We use the free Poppler tools instead of using Acrobat, despite having a license. Extracting one or more pages from a PDF file can be done with paid Adobe Acrobat. The free Adobe Reader or FoxIt Reader cannot extract pages. Adobe Acrobat is a large and cumbersome program that installs startup daemons that are not trivially disabled.

To extract pages 2 to 3 from in.pdf using Poppler:

pdfseparate -f 2 -l 3 in.pdf out.pdf

Note: you must leave a space after -f and -l as shown.

Poppler is installed by:

  • Linux: apt install poppler-utils
  • macOS: brew install poppler
  • Windows: use WSL poppler

An alternative to Poppler is GhostScript can also extract pages from PDF, but it’s a more complicated command:

gs -sDEVICE=pdfwrite -dFirstPage=2 -dLastPage=3 -dNOPAUSE -dSAFER -dBATCH -sOutputFile=out.pdf in.pdf

Related: extract raw full-quality images from PDF

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]

HDF5 CMake build

CMake is recommended to build HDF5 in general. CMake is required to build HDF5 on Windows. Trying to use Autotools to build HDF5 may encounter needless trouble compared to CMake.

HDF5 builds test executables that don’t pickup CMake environment variables. Set compiler variables CC and FC in the shell, particularly when using non-system-default compilers.

Avoid this issues by building HDF5 with CMake.

This creates static and dynamic HDF5 libraries under the user install prefix–we don’t show the library suffixes for simplicity. Note: the *stub files may not be present.

hdf5/lib/libhdf5
hdf5/lib/libhdf5_fortran
hdf5/lib/libhdf5_hl
hdf5/lib/libhdf5_hl_fortran
hdf5/lib/libhdf5_hl_f90cstub
hdf5/lib/libhdf5_f90cstub

The Fortran .mod files that need to be included are under

hdf5/include/

Tell CMake to use this HDF5 from the user project:

cmake -B build -DHDF5_ROOT=~/.local/hdf5