Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An R package to download Mexico City air quality data

License

NotificationsYou must be signed in to change notification settings

diegovalle/aire.zmvm

Repository files navigation

Diego Valle-JonesFebruary 09, 2024

R build statusCoverage StatusCRAN_Status_Badge

Author:Diego Valle-Jones
License:BSD_3
Website:https://hoyodesmog.diegovalle.net/aire.zmvm/

What does it do?

Tools for downloading airquality data for the Mexico City metro area.This package can download real-time, daily maximum, minimum, or hourlyaverage data for each of the pollution measuring stations orgeographical zones in the Zona Metropolitana del Valle de México(greater Mexico City). It also includes the locations of all themeasuring stations and a function to perform inverse distance weightingmodified to work with wind direction.

Installation

You can always install the development version from GitHub:

if (!require(devtools)) {    install.packages("devtools")}devtools::install_github('diegovalle/aire.zmvm')

To install the most recent package version from CRAN type:

install.packages("aire.zmvm")library(aire.zmvm)

Note that the version on CRAN might not reflect the most recent changesmade to this package.

Core Functions

The package core functions:

  • get_station_data andget_station_month_data download pollution,wind and temperature data for each of the measuring stations in theoriginal units (ppb, µg/m³, etc).
  • get_station_imeca download pollution values for each station inIMECAs
  • get_zone_imeca download pollution data in IMECAs for each of the 5geographic zones of Mexico City
  • get_latest_imeca download the latest pollution hourly maximums foreach of the measuring stations.
  • idw360 inverse distance weighting modified to work with degrees,useful for wind data
FunctionDate rangeUnitsWind, Tmp, RHEarliest DatePollutantsIncludes All StationsCriterion
get_station_datayearsOriginalYes1986SO2, CO, NO2, O3, PM10, PM25, WSP, WDR, TMP, RHYeshourly, daily maximum, daily minimum
get_station_month_data1 monthOriginalYes2005‑01SO2, CO, NO2, O3, PM10, PM25, WSP, WDR, TMP, RHYeshourly, daily maximum, daily minimum
get_station_imeca1 dayIMECANo2009‑01‑01SO2, CO, NO2, O3, PM10Nohourly
get_zone_imeca1 or more daysIMECANo2008‑01‑01SO2, CO, NO2, O3, PM10Only zoneshourly, daily maximum
get_latest_imeca1 hourIMECANoLatest onlyMaximum value of SO2, CO, NO2, O3, PM10Nolatest hourly

Quick Example

library("aire.zmvm")library("dplyr")library("ggplot2")library("ggseas")o3<- get_station_data(criterion="MAXIMOS",# Can be one of MAXIMOS (daily maximum),# MINIMOS (daily minimum),# or HORARIOS (hourly average)pollutant="O3",# Can be one of "SO2", "CO", "NOX", "NO2", "NO", "O3",# "PM10", "PM25", "WSP", "WDR", "TMP", "RH"year=2009:2018)# A numeric vector, the earliest year allowed is 1986knitr::kable(head(o3))
datestation_codepollutantunitvalue
2009-01-01ACOO3ppb67
2009-01-02ACOO3ppb71
2009-01-03ACOO3ppb112
2009-01-04ACOO3ppb91
2009-01-05ACOO3ppb70
2009-01-06ACOO3ppb71
# Daily max among all base stationso3_max<-o3 %>%   group_by(date) %>%   summarise(max= ifelse(all(is.na(value)),NA,base::max(value,na.rm=TRUE))) %>%  na.omit()# ozone values at which a contingencia ambiental was declared# and the dates during which they were valid# source: http://www.aire.cdmx.gob.mx/descargas/ultima-hora/calidad-aire/pcaa/pcaa-modificaciones.pdfcontingencia<-data.frame(ppb= c(216,210,205,199,185,155,155),start= c(2009,2009.4973,2010.4973,2011.5795,2012.6052,2016.291,2016.4986),end= c(2009.4973,2010.4945,2011.4945,2012.6025,2016.2883,2016.4959,Inf))max_daily_df<- tsdf(ts(o3_max$max,start= c(2009,1),frequency=365.25))ggplot(max_daily_df,       aes(x=x,y=y))+   geom_line(colour="grey75",alpha=.5)+  stat_rollapplyr(width=30,align="right",color="#01C5D2")+#geom_vline(xintercept = 2015 + 183/365) +  geom_segment(data=contingencia,                aes(x=start,y=ppb,xend=end,yend=ppb),color="darkred",linetype=2)+  xlab("date")+  ylab("parts per billion")+  scale_x_continuous(breaks= c(2010,2012,2014,2016,2018))+  ggtitle("Maximum daily ozone concentration and 30 day rolling average",subtitle= paste0("Red lines indicate the values necessary to","activate a phase I smog alert.","\nData source: SEDEMA"))

About

An R package to download Mexico City air quality data

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp