Skip to content

epa_util

check_cmaq_units(df, param='O3', aqs_param='OZONE')

Short summary.

Parameters:

Name Type Description Default
df type

Description of parameter df.

required
param type

Description of parameter param (the default is 'O3').

'O3'
aqs_param type

Description of parameter aqs_param (the default is 'OZONE').

'OZONE'

Returns:

Type Description
type

Description of returned object.

Source code in monetio/obs/epa_util.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def check_cmaq_units(df, param="O3", aqs_param="OZONE"):
    """Short summary.

    Parameters
    ----------
    df : type
        Description of parameter `df`.
    param : type
        Description of parameter `param` (the default is 'O3').
    aqs_param : type
        Description of parameter `aqs_param` (the default is 'OZONE').

    Returns
    -------
    type
        Description of returned object.

    """
    aunit = df[df.variable == aqs_param].Units.unique()[0]

    if aunit == "UG/M3":
        fac = 1.0
    elif aunit == "PPB":
        fac = 1000.0
    elif aunit == "ppbC":
        fac = 1000.0
        if aqs_param == "ISOPRENE":
            fac *= 5.0
        elif aqs_param == "BENZENE":
            fac *= 6.0
        elif aqs_param == "TOLUENE":
            fac *= 7.0
        elif aqs_param == "O-XYLENE":
            fac *= 8.0
    else:
        fac = 1.0
    return fac

convert_epa_unit(df, obscolumn='SO2', unit='UG/M3')

converts ppb to ug/m3 for SO2 in aqs and airnow datasets See 40 CFR Part 50.5, Appendix A-1 to part 50, appendix A=2 to Part 50. to convert from ppb to ug/m3 multiply by 2.6178.

Also will convert from ug/m3 to ppb.

Parameters:

Name Type Description Default
df pandas dataframe

self.df attribute from aqs or airnow class.

required
obscolumn string

name of column with SO2 data in it.

'SO2'
unit string

either 'UG/M3' or 'PPB' (not case sensitive) will convert data to this unit.

'UG/M3'
inplace boolean

if TRUE then changes self.df attribute

required

Returns:

Name Type Description
df pandas dataframe

returns dataframe identical to original but with data converted to new unit.

Source code in monetio/obs/epa_util.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def convert_epa_unit(df, obscolumn="SO2", unit="UG/M3"):
    """
    converts ppb to ug/m3 for SO2 in aqs and airnow datasets
    See 40 CFR Part 50.5, Appendix A-1 to part 50, appendix A=2 to Part 50.
    to convert from ppb to ug/m3 multiply by 2.6178.

    Also will convert from ug/m3 to ppb.

    Parameters
    ----------
    df : pandas dataframe
         self.df attribute from aqs or airnow class.
    obscolumn : string
        name of column with SO2 data in it.
    unit : string
        either 'UG/M3' or 'PPB' (not case sensitive)
        will convert data to this unit.
    inplace : boolean
        if TRUE then changes self.df attribute

    Returns
    -------
    df : pandas dataframe
        returns dataframe identical to original but with data converted to new
        unit.
    """
    factor = 2.6178
    ppb = "ppb"
    ugm3 = "ug/m3"
    if unit.lower() == ugm3:
        df = df[df["units"] == ppb]  # find columns with units of 'ppb'
        df["units"] = unit.upper()
        df[obscolumn] = df[obscolumn] * factor
    elif unit.lower() == ppb:
        df = df[df["units"] == ugm3]  # find columns with units of 'ppb'
        df[obscolumn] = df[obscolumn] / factor
    return df

ensure_values_indomain(df, lon, lat)

Short summary.

Parameters:

Name Type Description Default
df type

Description of parameter df.

required
lon type

Description of parameter lon.

required
lat type

Description of parameter lat.

required

Returns:

Type Description
type

Description of returned object.

Source code in monetio/obs/epa_util.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def ensure_values_indomain(df, lon, lat):
    """Short summary.

    Parameters
    ----------
    df : type
        Description of parameter `df`.
    lon : type
        Description of parameter `lon`.
    lat : type
        Description of parameter `lat`.

    Returns
    -------
    type
        Description of returned object.

    """
    con = (
        (df.Latitude.values > lat.min())
        & (df.Latitude.values < lat.max())
        & (df.Longitude.values > lon.min())
        & (df.Longitude.values < lon.max())
    )

    df = df[con].copy()
    return df

get_epa_location_df(df, param, site='', city='', region='', epa_region='', state='')

Short summary.

Parameters:

Name Type Description Default
df type

Description of parameter df.

required
param type

Description of parameter param.

required
site type

Description of parameter site (the default is '').

''
city type

Description of parameter city (the default is '').

''
region type

Description of parameter region (the default is '').

''
epa_region type

Description of parameter epa_region (the default is '').

''
state type

Description of parameter state (the default is '').

''

Returns:

Type Description
type

Description of returned object.

Source code in monetio/obs/epa_util.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def get_epa_location_df(df, param, site="", city="", region="", epa_region="", state=""):
    """Short summary.

    Parameters
    ----------
    df : type
        Description of parameter `df`.
    param : type
        Description of parameter `param`.
    site : type
        Description of parameter `site` (the default is '').
    city : type
        Description of parameter `city` (the default is '').
    region : type
        Description of parameter `region` (the default is '').
    epa_region : type
        Description of parameter `epa_region` (the default is '').
    state : type
        Description of parameter `state` (the default is '').

    Returns
    -------
    type
        Description of returned object.

    """
    new = df.groupby("variable").get_group(param)
    if site != "":
        if site in new.siteid.unique():
            df2 = new.loc[new.siteid == site]
            title = df2.siteid.unique().astype("str")[0].zfill(9)
    elif city != "":
        names = df.msa_name.dropna().unique()
        for i in names:
            if i.upper().find(city.upper()) != -1:
                name = i
                print(name)
        df2 = new[new["msa_name"] == name].copy().drop_duplicates()
        title = name
    elif state != "":
        df2 = new[new["state_name"].str.upper() == state.upper()].copy().drop_duplicates()
        title = "STATE: " + state.upper()
    elif region != "":
        df2 = new[new["Region"].str.upper() == region.upper()].copy().drop_duplicates()
        title = "REGION: " + region.upper()
    elif epa_region != "":
        df2 = new[new["EPA_region"].str.upper() == epa_region.upper()].copy().drop_duplicates()
        title = "EPA_REGION: " + epa_region.upper()
    else:
        df2 = new
        title = "Domain"
    return df2, title

get_region(df)

Short summary.

Parameters:

Name Type Description Default
df type

Description of parameter df.

required

Returns:

Type Description
type

Description of returned object.

Source code in monetio/obs/epa_util.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
def get_region(df):
    """Short summary.

    Parameters
    ----------
    df : type
        Description of parameter `df`.

    Returns
    -------
    type
        Description of returned object.

    """
    from numpy import array, concatenate
    from pandas import DataFrame, merge

    se = array(["AL", "FL", "GA", "MS", "NC", "SC", "TN", "VA", "WV"])
    ne = array(["CT", "DE", "DC", "ME", "MD", "MA", "NH", "NJ", "NY", "PA", "RI", "VT"])
    nc = array(["IL", "IN", "IA", "KY", "MI", "MN", "MO", "OH", "WI"])
    sc = array(["AR", "LA", "OK", "TX"])
    r = array(["AZ", "CO", "ID", "KS", "MT", "NE", "NV", "NM", "ND", "SD", "UT", "WY"])
    p = array(["CA", "OR", "WA"])
    ner = array(["Northeast" for i in ne])
    ser = array(["Southeast" for i in se])
    ncr = array(["North_Central" for i in nc])
    scr = array(["South_Central" for i in sc])
    rr = array(["Rockies" for i in r])
    pr = array(["Pacific" for i in p])
    states = concatenate([se, ne, nc, sc, r, p])
    region = concatenate([ser, ner, ncr, scr, rr, pr])
    dd = DataFrame({"state_name": states, "region": region})
    return merge(df, dd, how="left", on="state_name")