What you’ll use 90% of the time

Reading Data

The soundDENA module has an attribute for each type of file it can access—for example, soundDENA.nvspl, soundDENA.srcid, and soundDENA.metrics. These are all instances of the class Accessor. (For the full list of supported files, see Filetype Accessors.) There are several ways to use the Accessor class, but the most common are:

soundDENA.<filetype>(sites)

Returns an iterator over the data for each site. The iterator yields a tuple of (data, unit, site, year), where data is usually a pandas DataFrame or Panel. See full documentation.

In [1]: props = jets = 0

In [2]: denaliSites = ["DENAKAHP2010", "DENAWEBU2009", "DENAUKAH2011"]

In [3]: for srcid, unit, site, year in soundDENA.srcid(denaliSites):
   ...:     jets += len( srcid[ srcid.srcID == 1.1 ] )
   ...:     props += len( srcid[ srcid.srcID == 1.2 ] )
   ...: 

# Ratio of props to jets near the Denali massif:
In [4]: props / jets
Out[4]: 9.393617021276595
soundDENA.<filetype>.all(sites)

Returns data from all the sites concatenated into a single object, typically a pandas DataFrame or Panel. See full documentation.

In [5]: denaliSites = ["DENAKAHP2010", "DENAWEBU2009", "DENAUKAH2011"]

In [6]: srcids = soundDENA.srcid.all(denaliSites)

In [7]: jets = len( srcids[ srcids.srcID == 1.1 ] )

In [8]: props = len( srcids[ srcids.srcID == 1.2 ] )

# Ratio of props to jets near the Denali massif:
In [9]: props / jets
Out[9]: 9.393617021276595
soundDENA.<filetype>.paths(sites)

Returns an iterator over the paths to the data files for each site. See full documentation.

In [10]: denaliSites = ["DENAKAHP2010", "DENAWEBU2009", "DENAUKAH2011"]

In [11]: for path, unit, site, year in soundDENA.srcid.paths(denaliSites):
   ....:     print(site, year, path)
   ....: 
KAHP 2010 E:\AKRO Soundscape Data\2010 DENAKAHP Kahiltna Pass\02 ANALYSIS\SPL Analysis\SRCID_DENAKAHP.txt
WEBU 2009 E:\AKRO Soundscape Data\2009 DENAWEBU West Buttress\02 ANALYSIS\SPL Analysis\SRCID_DENAWEBU.txt
UKAH 2011 E:\AKRO Soundscape Data\2011 DENAUKAH Upper Kahiltna Glacier\02 ANALYSIS\SPL Analysis\SRCID_DENAUKAH.txt

In all cases, the parameter sites is an iterable of siteIDs. It could be as simple as ["DENAFANG2013", "DENACARB2013", "DENAPAIN2014"], but it can also be a pandas DataFrame or Series whose index is the siteIDs you want. So most commonly, you’ll use a subselection from the metadata DataFrame, like soundDENA.metadata.query("unit == 'DENA' and type == 'grid'").

Note

Why not always use .all()? Though it’s sometimes less convenient, iterating site-by-site greatly reduces memory useage, as you only need to keep around data for a single site at a time.

Performing some operation on a site-by-site basis (like a median or count) is also a very common task. In any case where you only need values from one site at a time, using the iterator is often syntactically easier than dealing with the MultiIndex returned by .all().

Selecting Sites

Using a list of siteID strings gets tedious—usually, you want data from sites that meet some criteria, like season, elevation, year, or park. This sort of metadata is found in the Complete Metadata and Derived Data workbooks, so when you import soundDENA, it loads both into a single pandas DataFrame, accessible as soundDENA.metadata. You can then sub-select sites using criteria such as unit, winter_site, elevation, etc. soundDENA.metadata‘s row indicies are siteIDs, so you can use it as a site specifier for an Accessor.

In [12]: import soundDENA

In [13]: soundDENA.metadata
Out[13]: 
               unit      ...      atmospressure
DENA7MIL2001   DENA      ...                NaN
DENADUNK2001   DENA      ...                NaN
DENASAVR2001   DENA      ...                NaN
DENATEKP2001   DENA      ...                NaN
...             ...      ...                ...
DENACATH12012  DENA      ...       88118.220506
DENADUNK12012  DENA      ...       89569.738106
DENAUWBT12012  DENA      ...       87551.618591
DENALMCR2013   DENA      ...       98673.247357

[161 rows x 159 columns]

In [14]: soundDENA.metadata.columns
Out[14]: 
Index(['unit', 'title', 'site', 'year', 'winter_site', 'BCMP_zone', 'lat',
       'long', 'elevation', 'noise floor', 
       ...
       'day_l50', 'mean_l50_impact_day', 'mean_l50_impact_all',
       'precip30yrannual', 'precip30yrsummer', 'precip30yrwinter',
       'temp30yrannual', 'temp30yrsummer', 'temp30yrwinter', 'atmospressure'],
      dtype='object', length=159)

In [15]: soundDENA.metadata.index
Out[15]: 
Index(['DENA7MIL2001', 'DENADUNK2001', 'DENASAVR2001', 'DENATEKP2001',
       'DENATOKL2001', 'DENATOKO2001', 'DENAWOND2001', 'DENABASE2002',
       'DENAPICA2002', 'DENARUTH2002', 
       ...
       'KATMPFMI2015', 'KATMSWLA2015', 'KATMVTTS2015', 'WRSTBLMT2015',
       'WRSTTALA2015', 'DENATOKO12010', 'DENACATH12012', 'DENADUNK12012',
       'DENAUWBT12012', 'DENALMCR2013'],
      dtype='object', length=161)

Putting It Together

By using a subselection of soundDENA.metadata as the site specifier for an Accessor, you can read the type of data you want from just certain sites that meet a criterion:

Todo

More explanation

In [16]: highDena = soundDENA.metadata.query("unit == 'DENA' and elevation > 2000 and not winter_site")

In [17]: highDena
Out[17]: 
              unit      ...      atmospressure
DENABASE2002  DENA      ...                NaN
DENAKAHP2007  DENA      ...       69396.094544
DENAUTRA2009  DENA      ...       74332.326884
DENAWEBU2009  DENA      ...                NaN
...            ...      ...                ...
DENAUKAH2011  DENA      ...                NaN
DENAUPEL2013  DENA      ...       78619.651929
DENASKGL2015  DENA      ...                NaN
DENAUPST2015  DENA      ...                NaN

[10 rows x 159 columns]

In [18]: soundDENA.srcid.all(highDena)
Out[18]: 
                                  Hz_L    ...       userName
siteID                                    ...               
DENABASE2002 2002-05-15 09:43:20  12.5    ...      DBetchkal
             2002-05-15 09:47:54  12.5    ...      DBetchkal
             2002-05-15 10:00:00  12.5    ...      DBetchkal
             2002-05-15 10:04:26  40.0    ...      DBetchkal
...                                ...    ...            ...
DENAWEBU2010 2010-06-22 15:00:02  12.5    ...      DBETCHKAL
             2010-06-22 15:13:15  12.5    ...      DBETCHKAL
             2010-06-22 16:37:16  12.5    ...      DBETCHKAL
             2010-06-22 17:12:38  12.5    ...      DBETCHKAL

[3076 rows x 10 columns]