Scientific Computing

pgrep pkill fulltext process name search

Adding the -f option to pgrep and pkill searches the whole command line, instead of the default first 15 characters. This is useful for example with chromium-browser that actually lists in ps as /usr/lib/chromium-browser/chromium-browser–too long for pgrep and pkill default to find.

pgrep -f chromium

works, while

pgrep chromium

does not work with default settings.

Make this change persistent by adding these lines to ~/.bash_aliases

alias pgrep="pgrep -f"
alias pkill="pkill -f"

Examples for Chromium:

  • find running process by name: pgrep chromium returns the PID (integer).
  • SIGTERM running process by name: pkill chromium

Raspberry Pi camera RAW images with Python

The PiCamera Python module acquires RAW Bayer masked data from the color Raspberry Pi camera module. Getting raw Bayer images from the camera into 2592 x 1944 pixels for the V1 camera, 3280 x 2464 for the V2 camera requires a program as simple as:

import picamera
import picamera.array

with picamera.PiCamera() as cam:
    with picamera.array.PiBayerArray(cam) as stream:
        cam.capture(stream, 'jpeg', bayer=True)
        img = stream.array

Python code for Raspberry Pi camera Bayer non-demasked image

It takes several seconds to load and process the first image. Acquiring an image series is much faster.

References:

Control Dropbox from Linux Terminal

If a remote PC with the graphical Dropbox client isn’t syncing, it may be due to a reboot where the Dropbox dæmon didn’t restart because there was no remote login to the graphical desktop. Dropbox can be remotely restarted over SSH with the command

dropbox start

(no & needed)

More Dropbox Linux Terminal commands can be found here.

When starting Dropbox this way, the Dropbox dæmon will stop when logging out over SSH. Therefore, ensure that when issuing the command over SSH

dropbox status

the reply is

Up to date

before disconnecting from the remote PC SSH session.

Red Pitaya HF ionospheric radar

This procedure describes setting up a Red Pitaya with the PiRadar code.

Get the radar code:

git clone https://github.com/pavel-demin/red-pitaya-notes
git switch develop

Get the development build virtual machine

Compile & create the SD card image. A general example is from the LED Blinker, which of course must be modified to fit PiRadar.

image → SD card

Format a micro SD card to FAT32 (find the SD card device name from df – be sure you don’t overwrite your hard drive!). Let’s suppose you found your SD card at /dev/mmcblk0, then:

umount /dev/mmcblk0
mkdosfs -F 32 -n piradar /dev/mmcblk0

Unzip the PiRadar image you created to this SD card

mount /dev/mmcblk0 /mnt/piradar
unzip ecosystem-*-piradar.zip -d /mnt/piradar
umount /mnt/piradar

Boot the Red Pitaya with this SD card. Connect to Red Pitaya via Ethernet using SSH (login/password root/root) using Avahi

ssh root@redpitaya.local

or via serial port


Related: PiRadar HF ionospheric radar

Setup Red Pitaya for NMR pulsed transmission

Setup Red Pitaya NMR image: format a micro SD card to FAT32 (find the SD card device name from df – be sure you don’t overwrite your hard drive!). Let’s suppose you found your SD card at /dev/mmcblk0, then:

umount /dev/mmcblk0

mkdosfs -F 32 -n NMR /dev/mmcblk0

Unzip Pavel Demin SD Card image to this SD card

mount /dev/mmcblk0 /mnt/NMR

unzip ecosystem-*-pulsed-nmr.zip -d /mnt/NMR

umount /mnt/NMR

Boot the Red Pitaya with this SD card.

Connect to Red Pitaya via Ethernet using SSH (login/password root/root) using Avahi

ssh root@redpitaya.local

or via serial port


Setup laptop: get NMR code

cd ~
git clone https://github.com/pavel-demin/red-pitaya-notes

Run the NMR control program

cd red-pitaya-notes/projects/pulsed_nmr/client
python3 pulsed_nmr.py

You should see some perturbation (even if essentially zero amplitude) in the NMR trace plot.

  • If “start” button doesn’t change to “stop” when clicked, that can indicate that the Red Pitaya NMR dæmon is not running. Be sure you copied over the correct image to the SD card when you did the unzip step.

pulsed-nmr consumes about 8% CPU when generating a waveform and 5% CPU when idle.

Recompile server code: this is precompiled and running as a service in Pavel’s image. TODO: Does it take rewriting the image since the SD card filesystem is read-only?

apt install gcc-arm-linux-gnueabihf

arm-linux-gnueabihf-gcc -static -O3 -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard server/pulsed-nmr.c -o pulsed-nmr -lm

Related: Red Pitaya GNURadio image setup

Install LibSVM in Matlab, GNU Octave and Python

Matlab and Octave are popular for machine learning prototypes due to their easier to learn (vs. R) interface. Python via scikit-learn is also a top choice for machine learning. Here’s how to install LibSVM for Matlab and GNU Octave.

Prereqs:

apt install make git g++

Compile LibSVM

git clone https://github.com/cjlin1/libsvm

cd libsvm

make

Creates executables svm-train svm-predict svm-scale. Compile the Matlab/Octave and Python modules, for which the API is similar.

Compile LibSVM Matlab/Octave module

cd libsvm/matlab

Open Matlab or Octave, and from that internal Terminal, type (this uses make.m)

make

which creates a few .mex files. See the matlab/README for examples of using LibSVM from Matlab and Octave.

Compile LibSVM Python module

cd libsvm/python

make

See the python/README for examples of using LibSVM from Python.

Install PMTK3 in Matlab / GNU Octave

The authors estimate about 75% of PMTK3 is available from Octave, while Matlab support is comprehensive. PMTK3 has been in maintenance mode for a few years, as the world has moved on Python in significant numbers. Nonetheless, PMTK3 should not be neglected for easy access to a wide variety of machine learning methods.

Install PMTK3:

git clone https://github.com/probml/pmtk3

cd pmtk3

From Matlab or Octave:

initPmtk3

which downloads supplementary files (one-time). Run programs like demos/bigO.m