GithubHelp home page GithubHelp logo

winnerlbm / air Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cambecc/air

0.0 1.0 0.0 1.83 MB

a project to visualize Tokyo wind and air pollutants

Home Page: air.nullschool.net

License: Other

JavaScript 99.59% CSS 0.41%

air's Introduction

air

"air" is a project to visualize live air quality data provided by the Tokyo Metropolitan Government. The main components of the project are:

  • a scraper to extract air data from www.kankyo.metro.tokyo.jp
  • a postgres database to store the data
  • an express.js server to serve this data and other static files to the client
  • a client app that interpolates the data and renders an animated wind map

An instance of "air" is available at http://air.nullschool.net. It is currently hosted by Amazon Web Services and fronted by CloudFlare.

"air" is a personal project I've used to learn javascript, node.js, when.js, postgres, D3 and browser programming. Some of the design decisions were made simply to try something new (e.g., postgres). Undoubtedly, other decisions were made from a lack of experience. Feedback welcome!

building and launching

Clone the project and install libraries from npm:

npm install

NOTE: you will need libpq to build pg. The libpq library was installed automatically by postgres on Mac OS X but required separate installation on AWS.

Install postgres and create a database, something like:

CREATE DATABASE air
  WITH OWNER = postgres
       ENCODING = 'UTF8'
       TABLESPACE = pg_default
       LC_COLLATE = 'en_US.UTF-8'
       LC_CTYPE = 'en_US.UTF-8'
       CONNECTION LIMIT = -1;

Launch the server:

node server.js <port> <postgres-connection-string> <air-data-url>

Example:

node server.js 8080 postgres://postgres:12345@localhost:5432/air <air-data-url>

Finally, point the browser at the server:

http://localhost:8080

implementation notes

Building this project required solutions to some interesting problems. Here are a few:

  • Live air data is available as Shift_JIS encoded HTML. Node.js does not natively support Shift_JIS, so the iconv library is used to perform the conversion to UTF-8.
  • Geographic data of Tokyo was sourced directly from the Ministry of Land, Infrastructure, Transport and Tourism, as an 80MB XML file. This data was transformed to a 300KB TopoJSON file, small enough for browsers to download and render as SVG with D3.
  • Roughly 50 sampling stations provide hourly wind and pollutant data. Inverse Distance Weighting interpolation is used to construct a wind vector field that covers all of Tokyo. IDW produces strange artifacts and is considered obsolete, but it is very simple and was easy to extend to perform vector interpolation.
  • The browser interpolates each point (x, y) using the n-closest sampling stations. To determine the n-closest neighbors, the client constructs a k-d tree, which greatly improves the performance.
  • Pollutant visualization overlays use Thin Plate Spline interpolation. TPS is definitely the wrong method to use for natural phenomenon such as air pollutants, but it produces a smoother surface than IDW.
  • The SVG map of Tokyo is overlaid with an HTML5 Canvas, where the animation is drawn. The animation renderer needs to know where the borders of Tokyo are rendered by the SVG engine, but this pixel-for-pixel information is difficult to obtain directly from the SVG elements. To workaround this problem, Tokyo's polygons are re-rendered to a detached Canvas element, and the Canvas' pixels operate as a mask to distinguish points that lie inside the map to those outside. The field mask occupies the red color channel, and the display mask is encoded in the green color channel.
  • I used when.js in the browser because it was a fun experiment.

inspiration

The awesome wind map at hint.fm provided the main inspiration for this project. And the very nice D3 tutorial Let's Make a Map showed how easy it was to get started.

air's People

Contributors

cambecc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.