- Notifications
You must be signed in to change notification settings - Fork0
WAQI (World Air Quality Index) client for MATLAB
License
NotificationsYou must be signed in to change notification settings
kostrse/waqi-matlab
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
WAQI (World Air Quality Index) provides open API for reading air quality data from the stations registered on the project.
Request the WAQI API access token athttps://aqicn.org/api/.
token="<your token>";aqi=waqi.WAQI(token);% Get data for the given known citybangkok=aqi.city("bangkok");% Get data from the nearest station for given coordinatesseattle=aqi.nearest([47.62050,-122.34930]);
Plot received forecast data:
forecast=seattle.Forecast.pm25;figureplot(forecast.Time,forecast.Avg, Color="black", LineWidth=1.5, Color=[0,0.3,0.5])title("Air Quality Forecast")holdonplot(forecast.Time,forecast.Max, Color=[0.6,0.6,0.6])plot(forecast.Time,forecast.Min, Color=[0.3,0.3,0.3])legend(["Avg","Max","Min"], Location="northwest")holdoff
% Geographic boundarychiang_mai_area= [ geopoint(19.05580,98.53775) geopoint(18.41727,99.32121)];% Get list of stationsresult=aqi.stations(chiang_mai_area)
Result includes locations of returned stations, station information and current readings of AQI:
Display stations on the map:
station_names= [result.Station.Name];station_descriptions= arrayfun(@(a,t) sprintf("AQI: %.0f<br/>Measured: %s",a, string(t,"M/dd/yyyy hh:mm:ss XXX")),result.AQI,result.Timestamp);colors= cell2mat(arrayfun(@colorcode,result.AQI, UniformOutput=false));wmmarker(result.Location, FeatureName=station_names, Description=station_descriptions, Color=colors);% A helper function to color code values of AQIfunctioncolor= colorcode(aqi)ifaqi<=50% Good color= [0,153/255,102/255];elseifaqi<=100% Moderate color= [1,222/255,51/255];elseifaqi<=150% Unhealthy for Sensitive Groups color= [1,153/255,51/255];elseifaqi<=200% Unhealthy color= [204/255,0,51/255];elseifaqi<=300% Very Unhealthy color= [102/255,0,153/255];else% Hazardous color= [126/255,0,35/255];endend
% Find station with the worst AQI[~,i]= max(result.AQI);worst_station=result.Station([i(1)]);% Get air quality data for given stationmeasurements=aqi.station(worst_station)
About
WAQI (World Air Quality Index) client for MATLAB