Scientific Computing

Contour on image or pcolor in Matlab 3D plot

To overlay a contour on top of a Matlab “image()” or “pcolor()”, first rasterize the image and then overlay a contour to make it work in a 3-D Matlab figure. This is a bit complex to describe, so we created an example of contour over image in a 3-D Matlab figure: contourImage2.m. This script follows these steps:

  1. flatten the contour onto the image in the default z=0 plane
  2. render as a resized image
  3. make a pcolor plot
  4. manipulate the underlying Surface object to an arbitrary 3-D location.

Doing a contour overlay on a 2-D image or pcolor is much simpler especially in Python.

matplotlib ScalarFormatter mulitple figures

matplotlib.ticker.ScalarFormatter configures the colorbar and axes labels to not have too many decimal places.

ScalarFormatter Problem

If I made a standard line plot using the ScalarFormatter passed into a function, then subsequently passed the ScalarFormatter into another function that used colorbar, the line plot y-axis would be reset to match the limits of the later figure’s colorbar.

I didn’t think the ScalarFormatter would be able to feedback like that.

Fix ScalarFormatter

Enclose ScalarFormatter in its own function, then call that function from each of the plotting functions, thereby creating a new/unique ScalarFormatter for each figure.

Matlab fseek bug with uint64 offset

Note: This problem was fixed in Matlab ≥ R2015a.


Matlab R2013 cannot handle uint64 seek offsets. Octave ≥ 3.6 works with uint64 offsets.

offs = uint64(0); %or any number
fid = fopen(tempname);
fser = fseek(fid,offs,'bof');
  • fser == -1 for Matlab R2013a/R2013b (error)
  • fser == 0 for Octave (correct)

LCPFCT solver--accessible from Python

LCPFCT 2D

The venerable NRL Flux-Corrected Transport algorithm for Solving Generalized Continuity Equations has been cited in hundreds of publications.

Updated syntax of the original Fortran code slightly to fit with the FORTRAN 77 standard (not changing algorithm behavior, only syntactical correctness). Plotting code uses f2py to make the LCPFCT run from Python with 50x speedup overall since you don’t have to write output to disk and then read it back in via a custom parsing algorithm.

Motorola quad-band portable radio APX8000

Cross-jurisdictional and intra-jurisdictional radio systems that are incompatible is a problem as old as public safety radio itself. It takes a major catastrophe to suddenly bring together diverse EMS and Police forces on a task needing common radio channels. Yes, preplanned events such as parades and national holiday celebrations also bring EMS and Police in large inter-jurisdictional efforts, but that can be solved with radio system patches or extra radios.

Firefighters mix and match other department resources frequently as big fires can happen anywhere, anytime. One typical solution is to have large numbers of adjoining Fire agencies on common radio technology, such as VHF analog, even when every other public safety resource might be on a P25 digital trunked network system. Another solution is for an incident response van to have a bank of radios that can be patched on-site. In major urban areas, city laws may require installation of distributed antenna systems for local public safety radio–a building-wide built in broadband repeater for public safety in effect.

VHF portable coverage is worse in general compared to higher frequency (shorter wavelength) radio bands due in large part to high on-body attenuation (up to factor of 100-1000 (20-30 dB)) and high noise levels on VHF, particularly in urban areas. Yet, vast swathes of American fire departments are stuck on VHF due to interoperability concerns and budget constraints. The high cost of the APX8000 won’t necessarily be a solution for rural fire departments, but the adjoining large tax base city might afford the APX8000, allowing the city fire department to upgrade to the regional P25 digital system. The APX8000 in that scenario purchased for the city fire department allows mutual aid from adjoining rural fire departments.

Motorola APX8000 cost/benefit breakdown

Of course the Motorola salesperson isn’t pitching the APX8000 to small budget fire departments. The APX8000 sale goes to the adjoining city fire department, who now doesn’t need a $5000 radio patch that might break down, making a single point of failure in the incident response van. Dispatch isn’t tying up repeaters with console patches.

A real value add of the APX8000 is the reduction of need for complex fireground or console patches that tie up channels and break down at the worst possible time. Will the whole city get APX8000? Maybe not, but it depends on the historical patterns. They might choose to only get enough APX8000 to cover say 95% of mutual aid needs, and let console patches handle the last 5%. Also, given noise on VHF and a large site to cover for fire, it’s well possible to get out of radio range of the incident response van with the patch (or the central repeater), leading to the constantly dreaded case where you can’t talk to the person next to you on the radio.

Micro SD mounting read-only

I had a micro SD card that would only mount read-only, in Gparted and everywhere else, even as root. I moved the SD adapter read-only switch to either position, tried it in different readers, different computers.

Then I tried a different SD adapter and read/write worked.