Writing about python

2022

Programming screencasts are a popular way to teach programming and demo tools. Typically people will open up their favorite editor and record themselves tapping away. But this has a few problems. A good setup for coding isn't necessarily a good setup for video -- with text too small, a window too …

2021

MicroPython is an implementation of the Python 3 programming language, optimized to run microcontrollers. It's one of the options available for programming your Raspberry Pi Pico and a nice friendly way to get started with microcontrollers.

MicroPython can be installed easily on your Pico, by following the instructions on the …

The SAM Coupé was a British 8 bit home computer that was pitched as a successor to the ZX Spectrum, featuring improved graphics and sound and higher processor speed.

The SAM Coupé's high-color MODE4 could manage 256x192 resolution graphics, with 16 colors from a choice of 128. Each pixel can …

How much game can you fit into 25 pixels? Quite a bit it turns out.

This is a mini clone of arcade classic Space Invaders for the BBC micro:bit microcomputer. Using the accelerometer and two buttons for input, to can beat off wave after wave of aliens that advance …

2020

As the apocalypse rumbles on, I found myself wondering "Is it getting any better?"

Daily updates of spiralling case numbers (and worse, deaths) does little to give a sense of whether we're getting to, or already past, the worst of it.

To answer that question for myself and you, I …

2019

So far we've built the Etch-A-Snap and processed an image to produce a 1 bit image. In this part we’ll look at how to take this image and generate the draw instructions for the plotter.

Etch-A-Sketch is a very simple 2D plotter which is limited to drawing a single …

The image processing produces a 1 bit image (B&W) of 240x144 pixels. The next step is to take this image and convert it into movements for the motors.

An example processed 1 bit image

The way this is done is governed largely by the design of the Etch-A-Sketch — any drawing must be made in one …

Etch-A-Sketch is a very simple 2D plotter which is limited to drawing a single unbroken line, of a single thickness and colour which is dark-ish on a silver-ish screen. To be able to plot a photo onto the Etch-A-Sketch we need to transform the image so that —

  1. the resolution makes …

Etch-A-Snap is (probably) the worlds first Etch-A-Sketch Camera. Powered by a Raspberry Pi Zero (or Zero W) it snaps photos just like any other camera, but outputs them by drawing to an Pocket Etch-A-Sketch screen. Quite slowly.

Photos are processed down to 240x144 pixel 1-bit (black & white) line drawings using …

This little project combines the previous accelerometer-gyroscope code with the 3D rotating OLED cube to produce a 3D cube which responds to gyro input, making it possible to "peek around" the cube with simulated perspective, or make it spin with a flick of the wrist.

Take a look at those …

Measuring acceleration and rotation has a lot of useful applications, from drone or rocket stablisation to making physically interactive handheld games.

An accelerometer measures proper acceleration, meaning the rate of change of velocity relative to it's own rest frame. This is in contrast to coordinate acceleration, which is relative to …

2018

The keys, values and items from a dictionary can be accessed using the .keys(), .values() and .items() methods. These methods return view objects which provide a view on the source dictionary.

The view objects dict_keys and dict_items support set-like operations (the latter only when all values are hashable) which …

An ESP2866 is never going to compete with an actual graphics card. But it has more than enough oomph to explore the fundamentals of 3D graphics. In this short tutorial we'll go through the basics of creating a 3D scene and displaying it on an OLED screen using MicroPython.

This …

We've previously covered the basics of driving OLED I2C displays from MicroPython, including simple graphics commands and text. Here we look at displaying monochrome 1 bit-per-pixel images and animations using MicroPython on a Wemos D1.

Processing the images and correct choice of image-formats is important to get the most detail …

Dictionaries are key-value stores, meaning they store, and allow retrieval of data (or values) through a unique key. This is analogous with a real dictionary where you look up definitions (data) using a given key — the word. Unlike a language dictionary however, keys in Python dictionaries are not alphabetically sorted …

These mini monochrome OLED screens make great displays for projects — perfect for data readout, simple UIs or monochrome games.

Requirements
Wemos D1 v2.2+ or good imitations. amazon
0.91in OLED Screen 128x32 pixels, I2c interface. amazon
Breadboard Any size will do. amazon
Wires Loose ends, or jumper leads.

Setting …

This build started as something simple: a lucky cat which would turn on and off automatically in response to some event. Since lucky cats are associated with good fortune the idea was to make one do this every time I got paid. This was working pretty well but unfortunately, after …

Below is a quick reference guide to Wemos D1 pin mapping for GPIO, I2C and SPI when working from MicroPython.

Pin mapping

The visible pin numbers written on the Wemos D1 does not relate to the internal pin numbering. In MicroPython you need to use the internal pin numbers to …

Pulse sensors have become popular due to their use in health-monitors like the Fitbit. The sensors used are cheap, simple and pretty reliable at getting a reasonable indication of heart rate in daily use. They work by sensing the change in light absorption or reflection by blood as it pulses …

Pulse sensors are a common feature of fitness monitors, used to track your activity and cardiac fitness over time. These external monitors use the reflection and absorption of bright green/infra-red light to detect the pulse wave travelling down the artery — a technique called photoplethysmography (PPG). This same techique is …

2017

KropBot is a little multiplayer robot you can control over the internet. Co-operate with random internet strangers to drive around in circles and into walls.

If it is online, you can drive the KropBot yourself!

Requirements
Raspberry Pi Zero W amazon
Pi Zero Camera amazon
Pi Zero Camera Cable Watch …

The Scroll pHAT is a little 11x5 (55) white LED matrix pHAT which you can control easily from a Raspberry Pi. In this project we'll squeeze a tiny-yet-playable game of Tetris onto the Scroll pHAT.

Requirements
Raspberry Pi Zero / Zero W You don't need wireless for this project, but it …
2015

Partial least squares discriminant analysis (PLS-DA) is an adaptation of PLS regression methods to the problem of supervised clustering. It has seen extensive use in the analysis of multivariate datasets, such as that derived from NMR-based metabolomics.

In this method the groups within the samples are already known (e.g …

1D 1H NMR is a commonly applied to metabolomic studies, being well suited to untargeted analysis of complex biofluids. It has been successfully applied to the classification and diagnosis of a number of diseases including [ref].

There are a number of important steps that must be applied prior 1D …

Wooey is a simple web interface to run command line Python scripts. Think of it as an easy way to get your scripts up on the web for routine data analysis, file processing, or anything else.

The project was inspired by how simply and powerfully sandman could expose users to …

2014

Background Metabolomics is a systems approach to the analysis of cellular processes through small-molecule metabolite profiling. Standardisation of sample handling and acquisition approaches has contributed to reproducibility. However, the development of robust methods for the analysis of metabolomic data is a work-in-progress. The tools that do exist are often not …

This is quick start-up guide for new users of Pathomx. Following it should give you everything that you need to know to start using Pathomx right away. Once you've been through the basics you might like to see some of the demos to see what Pathomx is capable of.

Pathomx …

Pathomx is a workflow-based data analysis tool built on IPython. It began as a metabolomic-analysis toolkit, but has extended to support general data analysis workflows. It aims to be simple to use for non-experts while powerful enough for complex analysis tasks. Key to both of these goals is the ability …

This notebook demonstrates automatic phase correction algorithms implemented for nmrglue. Two standard algorithms are implemented:

  • ACME algorithm by Chen Li et al. Journal of Magnetic Resonance 158 (2002) 164-168

  • Naive peak minima minimisation

The outputs for the two algorithms are shown below. Automatic phase correction can be used through the …

This notebook uses a subset of the available processing features in NMRLab (+Metabolab) to process 1D NMR spectra. The output is saved as a CSV file that can be imported into pandas, PLS_Toolbox or any other package for subsequent analysis.

To use this workbook you will need an installation of …

This notebook contains snippets of code that are useful when working with MATLAB in IPython Notebooks.

Displaying images from MATLAB

Passing variables into cells using the %%matlab magic requires h5py which is tricky to install. If you only need to pass in simple variables (strings) you can instead pass it …

MetaboHunter is a Python module for accessing the MetaboHunter web service web service for automated assignment of 1D raw, bucketed or peak picked NMR spectra.

More information about the algorithm is available in the published paper:

Tulpan, D., Leger, S., Belliveau, L., Culf, A., Cuperlovic-Culf, M. (2011). MetaboHunter: semi-automatic identification …

MetaboHunter is a web service for automated assignment of 1D raw, bucketed or peak picked NMR spectra. Identification is performed in comparison to two publicly available databases (HMDB, MMCD) of NMR standard measurements. More information about the algorithm is available in the published paper:

Tulpan, D., Leger, S., Belliveau, L …

BioCyc is a Python interface to the BioCyc. Acting as a wrapper it queries the database and then presents the XML returned in a pythonic object-based interface. Support for IPython views is included offering nice summary tables of object attributes.

BioCyc are approaching the renewal period for their NIH grant …

This notebook is a quick demo of a BioCyc Web API I've released for Python. While incomplete the API offers access to most basic attributes for metabolites, proteins, reactions, pathways and organisms in the database. The Python interface comes with an disk-based caching mechanism under ~/.biocyc that greatly reduces the …

QtIPy: The data automator! a simple GUI-based run-automator for IPython notebooks. It allows you to attach triggers to files, folders or timers to automatically run notebooks.

Screenshot

About

IPython notebooks are great for interactively working through analysis problems, so why would you want to automatically run them? To get a record …

I've just released a simple API for managing matplotlib line and marker styles for plots. It's called mplstyler and you can get it from Github or PyPi. This code is based on the style manager in Pathomx, extracted for more general use.

python
:::python
from mplstyler import StylesManager
styles = StylesManager …

This short demo shows analysis of a publically available GEO dataset using Pathomx, with a workflow build using the new visual editor (available in the next release).

You can download the example dataset from here.

Pathomx is an open-source workflow-based scientific analysis application. Source code is available here with packaged …

2013

Short demo of an experimental analysis of metabolomic (NMR) data using Pathomx. Metabolomic test dataset produced from THP-1 cells grown under normal and hypoxic conditions. Spectra (2D 1H JRES) have been pre-processed and quantified using the BML-NMR service.

The video shows an example analysis from processed data through to metabolic …

Pathomx is a unique workflow-based analysis tool that provides complete analytical control while maximising usability.

Construct complex analysis workflows including multivariate, univariate and pathway-mining approaches from a simple drag-drop interface.

Configure tools and immediately see the result reflected downstream. Prototype scripts and share or export the result for others to …

A Python implementation of the Icoshift algorithm, a versatile tool for the rapid alignment of 1D NMR spectra

Icoshift is a Matlab-based algorithm for the alignment of NMR spectra developed by Francesco Savorani and Giorgio Tomasi. It performs correlation shifting of spectral intervals using an FFT engine that aligns …

I'd had success using py2app for building Mac binaries for distribution but wanted to give cx_Freeze a go since it's cross platform - allowing builds for Windows, Linux, and more. Unfortunately, attempting to build using cx_Freeze was resulting in errors:

python
libpyside-python2.7.1.1.dylib: No such file or directory …

As mentioned in the previous post, I recently migrated this site over to the very clever Pelican. Setting it up was relatively straightforward using a combination of the official docs, this post and linked github repo from Dominic Rodger. That said, there were a few things that I stumbled at …

2011

A short one liner to quickly serve any folder via a http server.

Start the server

cd to the directory you want to serve.

Python 2.7

At the shell prompt enter python -m SimpleHTTPServer

Python 3

At the shell prompt enter python -m http.server

Access the files from …

Established 1980