mapping-noise-overland-apple-watch.ipynb
This notebook expects environmental noise tracking data from an Apple Watch as an additional data source in addition to GPS data from Overland. It then maps out where in your environment you encounter noise.
I saw that the latest Apple Watch hardware/software passively keeps track of environmental noise you encounter. I thought it would be interesting to see where around the city (in my case in Paris) I encounter environmental noise.
This notebook makes use of two data sources:
The Overland connection for Open Humans. It passively tracks your GPS data and stores the data in Open Humans.
The environmental noise data as collected by your Apple Watch. Right now there is no easy way to perform this extraction of data through Open Humans. Instead you will have to manually export the data from your phone, process it locally on your computer and then upload a correctly formatted file. Otherwise this notebook will not be able to run.
A description of how to get your environmental noise data from your Apple Watch can be found further down in this notebook. This notebook itself is written in R
to perform the analysis ^ visualization of the data.
For a start let's load our required packages. This can take a bit of time, as two packages need to be installed.
With this out of the way, we can in a first step load our Overland data from Open Humans. As the GPS records are can grow pretty large, each Year-Month
will get it's own file. You can select 3 months of data by editing the year-month
data in the bit below, to make sure to grab the data you are interested in. In my case I'm getting the data from October to December 2019.
Now we can start downloading the data. In the end this data will be stored in the variable loc
We have columns for our latitude & longitude, along with data on if/how we moved around and the speed. For further analyses we might be interested in a number of things:
That way we can plot our maps in a way that tells us when we were at a given space, helping us to better understand the noise measured at that time. The cell below performs this processing:
Now comes one of the most tricky parts of using this notebook: For the visualization to properly work you need to define the boundaries of the map, by giving the correct boundary_
values below. Those are the latitude & longitude values which will define how big/small the map piece is we will see.
There is no easy way at this point to find 'good' boundaries and it will take some fiddeling around with those numbers to get the map you are actually interested in. The values provided by default give a good view of central Paris, but you are likely interested in a different place.
The cell above will download the map according to your boundaries. Run the cell below to see the map and evaluate whether it matches the area you are interested in. Otherwise adjust the boundaries above, run the cell above again and then plot again to see if you're having the right area. Rinse & repeat until you are happy with the map itself.
Okay, you are happy with the map. Now it's time to load the Noise data that you got from your Apple Watch. To export the data from your iPhone you have to open the Health app and then click on your user profile image, from there you will get an option to export the data. A more detailed instruction on where to find it can be found here.
Creating this export will take a while, depending on how much data is in your phone. In my case it took between 5-10 minutes. Once this file is created you get a regular iOS sharing option. beware: the export you create will be a Zip file that will potentially be big! My own Zip archive with all health data was 117 MB (and blew up to over 2 GB after the unzipping)!
The best way forward with this data is to Airdrop it to a Mac, if you have one handy. Once that is done you should open your terminal and process the data inside the export:
unzip export.zip
cd apple_health_export
cat export.xml|grep dBASPL|grep -v Headphone|grep Record |sed "s/.*startDate=\"//"|sed "s/\" endDate=\"/,/"|sed "s/\" value=\"/,/"|sed "s/\"\/>//" > environmental_noise.csv
This will unzip the whole Apple Health archive, go into the folder this creates and then process the large XML dump with all data.
It finds all data points for environmental noise and stores those records as a simple CSV file with 3 columns:
Upload this data to your own notebook server and then you can run the code below to read it:
In addition loading the data, this also identifies the halfway date/time point of each data point (individual recordings can have a total length of around 30 minutes. By calculating the halfway point we just pretend that the dB value was recorded in the middle of it.
Now we can look at our noise data:
We're close to doing our first map. The only thing we need to do is to join the data. We do this by matching each GPS entry we recorded to the noise recording that was done most closely to the recording of that GPS data point. As the Noise data is most likely much more coarse grained than the GPS data, we will end up assigning the same noise level recording to many GPS points, but that's the best we can do.
For a start let's look at the noise levels in rough categories across town. To this end we bin the individual dB values into different groups
For each of those categories we create one map, showing where most of those recordings where done: