Scientific Computing

Numpy Type Annotation

Numpy type annotation numpy.typing.ArrayLike is often used on the input variables of a function. This doesn’t cover all cases a function might accept. For example, numerous Numpy functions can accept Python datetime that becomes an opaque object when passed to a function. It can be better to pass datetime into Numpy functions as numpy.datetime64, which is a subclass of numpy.ndarray and thus can be annotated as numpy.typing.NDArray[numpy.datetime64], especially as the return type of a function. Currently, Numpy type annotation doesn’t handle the shape of arrays, just the data type.

Set RF Gain in AM, FM, or SSB modes

Setting RF gain and squelch properly are vital to maximize receiver range (how far you can hear) while minimizing listening annoyance (background noise). It’s important to have a radio with NRC digital noise reduction, which can help reduce background noise and make listening more pleasant, especially in AM and SSB modes. CB radios with NRC are the same price or cheaper than 1990’s style CB radio without NRC, despite NRC being such a significant improvement to the listening experience. The technique to optimally adjust RF gain and squelch is distinct for each of the three main modes: AM, FM, and SSB (LSB/USB).

Separate and independent of RF Gain, Squelch, and NRC are the ANL (Automatic Noise Limiter) and NB (Noise Blanker) features. ANL and NB can often be “off” in base station or vehicle engine not running scenarios, which can reduce distortion of received signals, but with the penalty of more background noise. In scenarios with significant engine noise, ANL and NB can be turned on to reduce engine noise, but with the penalty of some possible distortion of received signals - often the benefit of ANL and/or NB outweighs the distortion penalty in noisy environments.

AM setting of RF gain and squelch

For AM, set the squelch to manual and open (you hear noise), then set the RF gain like:

  • knob: starting from fully clockwise RF Gain, turn counterclockwise just until the background noise noticeably drops.
  • menu: starting from “off” RF Gain, increase the number until the background noise noticeably drops.

This is the point where the RF gain is just enough to amplify the desired signal, but not so much that it amplifies the background noise and makes listening annoying. Now, turn up the squelch just till the noise stops - or turn on auto-squelch. This will maximize range on AM while helping reduce background noise. If there are DX signals via skip or a noisy area, adjust the RF gain and squelch accordingly to find the best balance between receiver range and noise reduction.

SSB setting of RF gain and squelch

On SSB modes (LSB / USB), across radio models from inexpensive to top-end, the squelch generally is too aggressive and will reduce receiver range if set to block all noise. It can be a better practice on SSB to not use the squelch if maximum range is desired, using only the RF gain to set noise to a low level. Experiment to find if squelch is useful for your scenario - perhaps if no conversation is happening, just close the squelch, and when a conversation starts, open the squelch to hear at better sensitivity.

FM setting of RF gain and squelch

On FM, the squelch is generally more effective at blocking noise than in AM or SSB modes. You can leave the RF gain as set in AM or SSB modes, or to maximize range, turn up the RF gain until the S-meter begins to indicate a signal, then adjust the squelch to just block the noise - or turn on auto-squelch. For DX communications, opening the squelch on FM will help just like on any FM radio - but of course this will let in noise between voice transmissions. Radios with NRC digital noise reduction will help reduce the noise of open squelch somewhat.

Matlab IDE with VS Code or Jupyter

The official Mathworks MATLAB extension for VS Code brings powerful MATLAB support directly into Visual Studio Code.

  • Edit .m files with rich syntax highlighting, code snippets, folding, and linting/code analysis.
  • Run and debug MATLAB scripts and functions straight from the editor.
  • An integrated MATLAB terminal for interactive commands.

One of the standout productivity features is Go to Definition (also available as Peek Definition and Find All References). For most supported languages in VS Code — and specifically with the MATLAB extension when paired with a full MATLAB installation — Ctrl+Click (or F12) on a function, variable, or class name to instantly jump to its definition, even if it’s in another file or referenced project.

While Matlab has comprehensive Git support built in, VS Code’s rich array of Git extensions and integrations can provide a more seamless experience for version control, especially for users already familiar with VS Code’s interface.

MATLAB in Jupyter Notebooks

Separate from, or along with VS Code, MathWorks provides the MATLAB Integration for Jupyter notebooks:

  • Run MATLAB code cells directly in notebooks.
  • Mix MATLAB with Python (or other kernels) in the same notebook.
  • Access browser-based MATLAB capabilities for interactive tools and apps.

This is ideal for exploratory analysis, documentation, and sharing reproducible workflows. Matlab itself has a script-based notebook feature “Live Scripts” as well.

Internet of Vulnerable Things

People at risk such as stalking victims, executives, VIPs, security staff, defense / aerospace and other at-risk device users should consider risks involved in typical wireless use patterns. The proliferation of BYOD, wearables and IoT devices in everything from alarm clocks to utility meters increases the attack surface. State-level actors consider the value of broad swaths of population collection as well as high-value targets. The CDC 2012 National Intimate Partner and Sexual Violence Survey NISVS notes that about 1 in 6 women in the USA have been stalking victims.

Popular media has depicted “burner phones” as a tactic to avoid tracking. Burner phones can be associated with a victim for subsequent attacks when the attacker knows they’re in proximity of the victim and the victim has the burner phone on. At-risk users should consider the risks of having Bluetooth and WiFi enabled. The attacker typically has the advantage of time, and can patiently attack the weakest victim device and escalate from there. Sniffing devices can be left behind inside innocuous devices such as power strips.

Bluetooth 5 and WPA3 include substantial security benefits over earlier standards. Devices may implement the standards imperfectly across their firmware / software stacks, and some new devices still don’t support WPA3, leading some WiFi routers to support hybrid WPA2 / WPA3 modes. Devices wirelessly beacon information useful to the attacker. An attacker knowing the victim’s device type can implement a spear phishing attack–perhaps a text message pretending to be from the victim’s employer or wireless carrier with a link to a zero-day exploit.

Signal strength can pinpoint a user’s location even in a crowd. Research on Wi-Fi probe request monitoring (e.g., Musa & Eriksson, SenSys 2012) shows that signal strength differences can distinguish devices separated by only a few meters, even when the attacker is 10–20+ meters away under favorable conditions. The typical victim has vulnerable devices including smart TVs, pre-WPA3 WiFi networks, Bluetooth speakers, and WiFi security cameras with old firmware. Multiple WiFi APs in the victim’s vicinity, made popular by consumer WiFi mesh networks provide a passive radar to track the victim’s approximate location in a home or office by a passive attacker.

Signal strength target discrimination vs. attacker distance

Wireless energy knows no borders, with maximum range limited by the inverse square law and obstructions. Microprocessors with weak encryption to save computation / energy and lack of OEM liability leave little supply-side motivation to fix these personal and national security risks.

Bluetooth

Bluetooth speakers commonly found in homes and offices often support auto-reconnect to previously paired devices. Speaker may automatically enter discoverable / pairing mode when powered on and no known paired device is in range. This allows anyone nearby to pair with the speaker without physically interacting with it — a significant privacy risk. See also the Stealtooth attack. The attacker could monitor the audio input in headset mode (for speakers with microphones for two-way audio) without the victim knowing they’re being listened to. Suppose the attacker walks down a street listening for auto-discoverable HSP devices, whether speaker or headphones or other device with microphone. Many neighborhoods have HSP devices left on 24/7, which can be used to determine user occupancy patterns, travel plans and other confidential victim information.

Bluetooth Low Energy

Bluetooth Low Energy (BLE) uses 40 channels in the 2.4 GHz band. It has three primary advertising channels at 2402 MHz, 2426 MHz, and 2480 MHz. These frequencies were specifically chosen to sit between common WiFi channels for reduced interference. The remaining 37 channels are primarily used for data connections, and can be used for secondary advertising with Bluetooth 5.0+. A common attack vector of legacy Bluetooth pairing is when the attacker hears pairing and trivially cracks the key. The attacker can then at any time force unpairing, masquerade the connection and take unwanted actions such as crash the device wirelessly or passively eavesdrop. This attack is mitigated by LE Secure Connections when implemented and enforced by both devices.

Maximum range of detecting BLE can be on order of 1 kilometer with inexpensive high gain antennas. Without special antennas, small BLE devices are typically detectable to 50 meters or so. Inexpensive software defined radio (SDR) devices like HackRF enable passive monitoring of already paired devices (as with Wifi) based on periodic updates (100ms to 10sec).

Android “Smart Lock” is good for attackers, not victims. If connection can be intercepted and masqueraded, an attacker can physically obtain the unlocked device, install malicious software and return the device undetected. Corporate device policies and end users should consider blocking this. Windows has a similar feature where Bluetooth-connected device is used to imply user proximity.

Android Smart Lock--anything but!

Suppose the attacker passively sniffs the victim UUID and learns the BLE simple channel hopping pattern. BLE channel hopping pattern is predictable and the UUID is in the clear. The CRACKLE BLE attack enables an attacker to jam the victim BLE wearable, breaking connection and leading the victim to re-pair the wearable (which is the point of vulnerability). The attacker can crack the pairing exchange and then implement passive monitoring or access email, text, phone, calendar, fine location, apps, etc. from 10-100 meters distance from victim.

WiFi

WiFi devices (smartphones, wearables, laptops) periodically send probe requests to discover nearby networks. While modern operating systems such as Apple macOS and iOS, Android have largely stopped broadcasting lists of previously connected visible SSIDs, they still send probes for “hidden” WiFi networks that a user may have connected to in the past. Windows has been observed to still send probe requests for previously connected visible SSIDs, which can be used to track the victim’s location and movement patterns. These probe requests always include a source MAC address — though most modern devices randomize this MAC for privacy. Operating systems for mobile devices and computers have generally implemented a user option to rotate random device WiFi MAC addresses. A user may disable this random MAC address without realizing the security implications. Even with random MAC, the victim beacon/probe signal strength can still be used as a means to track the victim’s proximity and approximate location.

Homes with smart TVs, WiFi security cameras and baby monitors typically use obsolete pre-WPA3 WiFi networks with weak protocols such as WEP, WPA or WPS. Cheap security cameras often have unencrypted or weakly encrypted password exchange. Once the WiFi password is cracked, the attacker can then exploit the typically insecure WiFi devices throughout the modern home or office. The victim attempted to secure their home with surveillance, but made themselves substantially less secure against wireless attacks.

References

GitHub Actions disable run for forked repositories

Upon forking another project’s repository to make contributions, one might have enabled GitHub Actions for the fork. If there are scheduled actions, then GitHub Actions will keep running on the forked repository, which can consume resources and is probably not desired. The simplest solution is to disable GitHub Actions for the forked repository, which is done from the URL of this form:

https://github.com/<your-username>/<forked-repo-name>/settings/actions

CMake default generator introspection

CMake can tell the default generator for the current platform without configuring a project. This is useful for build scripts that want to detect the generator default for CMake without having to configure a project first.

On Unix-like platforms, the default generator is typically “Unix Makefiles”. On Windows, the default generator is the latest Visual Studio version installed on the system and supported by CMake. With MSYS2 on Windows, the default generator is “MinGW Makefiles”.

Determine the default CMake generator on Unix-like platforms:

cmake --system-information | awk '/^CMAKE_GENERATOR / {print substr($0, index($0,$2))}'

Determine the default CMake generator with PowerShell:

cmake --system-information | Select-String '^CMAKE_GENERATOR ' | % { ($_ -split '^CMAKE_GENERATOR\s+', 2)[1] }

If the environment doesn’t have a C or C++ compiler available, CMake might fail to determine the default generator. A missing compiler would likely only be an issue on Windows or minimal Linux / macOS / Unix environments.

On Unix-like platforms, there may be a working directory named “__cmake_systeminformation” created by CMake when running the above command. This directory can be deleted. To avoid using the current working directory on Unix-like platforms, run the above command in a temporary directory:

( cd "$(mktemp -d)" && cmake --system-information | awk '/^CMAKE_GENERATOR / {print substr($0, index($0,$2))}' )

A platform-independent, self-cleaning temporary directory can be used with Python:

import subprocess
import tempfile

with tempfile.TemporaryDirectory(ignore_cleanup_errors=True, delete=True) as temp_dir:
    result = subprocess.check_output(
        ['cmake', '--system-information'],
        cwd=temp_dir,
        text=True
    )
for line in result.splitlines():
    if line.startswith('CMAKE_GENERATOR '):
        default_generator = line.split(' ', 1)[1].strip().strip('"')
        print(default_generator)
        break

Related: detect CMake cached generator

FITSIO CMake build

From Cygwin, in Octave prompt:

pkg install -verbose cfitsio

This should build and install FITS from C source without errors.


Load the fits package by:

pkg load fits

This enables Octave FITS read/write functions.

Building CFITSIO from source with CMake

Building CFITSIO manually is not necessary; this is just for reference:

curl -O https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio_latest.tar.gz

tar -xf cfitsio*.tar.gz

cmake -Bbuild

cmake --build build

ctest --test-dir build

Interposer to block exec / fork / spawn

While developing a software project, it may be useful to verify the stability of the program or library by denying the ability to execute child processes. This helps ensure the top program is stable in such cases by using an interposer. This technique is demonstrated for Linux, macOS, and Windows on compilers including GCC, Clang, MSVC, NVHPC, and oneAPI. This is not a cybersecurity sandbox, but rather a limited development tool to test stability of the top program when child process launches fails.

Use this interposer demo by:

git clone https://github.com/scivision/interposer-nochild

cd interposer-nochild

cmake --workflow --preset default

Run the interposer with most other programs by:

  • Windows: build/no-children.exe myprogram.exe arg1 args ...
  • macOS: DYLD_INSERT_LIBRARIES=build/libnochild.dylib myprogram arg1 args ...
  • Linux: LD_PRELOAD=build/libnochild.so myprogram arg1 args ...

Actual sandboxing tools can additionally deny access to resources including filesystem, network, and/or child processes such as:

CMake with stdin or pseudo-file

In Unix-like shells, a pseudo-file can be used as input of script for CMake. CMake can read from a pseudo-file or stdin on the command line, allowing one to run CMake script cmake -P ... commands without creating temporary files. This method by design is only for CMake script role; it does not work with other CMake roles like PROJECT.

Pseudo-file example for Unix-like shells and CMake ≥ 4.2:

cmake -P <(printf '%s\n' 'message("${CMAKE_VERSION}")')

stdin standard input example for Unix-like shells across all versions of CMake:

cmake -P /dev/stdin <<< "message('\${CMAKE_VERSION}')"

That’s useful to print the CMake version without parsing the output of cmake --version or creating a temporary file with the CMake script.

On Windows in PowerShell or Windows ComSpec, there isn’t a direct equivalent method to use stdin / CONIN$ or a pseudo-file. Use a temporary file instead, or use WSL to run the above Unix-like shell examples. There was a previous attempt to add cmake -P - support for stdin but as of this writing it was closed without merging.

GUI viewers for HDF5 / NetCDF4 data

HDF5 is a popular data container format, a filesystem within a file. Many programs supporting HDF5 like Matlab can read and plot data. It is useful to have a standalone simple data browser like HDFview, which is a Java-based application to view, create, and modify HDF5, netCDF4 and FITS files in a tabular format. HDFView can also make 1-D (line) plots and 2-D (raster) plots of the data in an HDF5 file. For example data see Neon. To view a plot of data, right click on the dataset name and select “Open As” and then set the parameters to view the data.

HDFview enables editing (writing) as well as reading HDF5.


ViTables is a Python-based HDF5 GUI.


Panoply is available for macOS, Linux and Windows.