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), wheredatais 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