Skip to content

Commit 53a3134

Browse files
committed
Merge branch 'master' of https://github.com/ODM2/ODM2PythonAPI into setup
Getting rid of the set up branch. Fingers crossed.
2 parents 908da54 + f2e9acc commit 53a3134

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+172
-89
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
*.py[cod]
2-
2+
*~
33

44
# C extensions
5-
*.ipynb
65
*.so
76

87
# Packages
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
__author__ = 'stephanie'
22
import sys
33
import os
4-
from api.ODMconnection import dbconnection
4+
from odm2api.ODMconnection import dbconnection
55
import pprint
6-
from api.ODM1_1_1.services import SeriesService
6+
from odm2api.ODM1_1_1.services import SeriesService
77

88
this_file = os.path.realpath(__file__)
99
directory = os.path.dirname(this_file)
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
# print directory
1414
# sys.path.insert(0, directory)
1515

16-
from api.ODMconnection import dbconnection
17-
from api.ODM2.services.readService import *
16+
from odm2api.ODMconnection import dbconnection
17+
from odm2api.ODM2.services.readService import *
1818
# Create a connection to the ODM2 database
1919
# ----------------------------------------
2020

2121

2222
#connect to database
2323
#createconnection (dbtype, servername, dbname, username, password)
2424
#session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')
25-
session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/DBs/ODM2.sqlite', 2.0)
25+
#session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)
26+
session_factory = dbconnection.createConnection('sqlite', '/Users/denversmith/Downloads/ODM2.sqlite', 2.0)
2627
# session_factory= dbconnection.createConnection('mssql')
2728

2829

@@ -68,26 +69,25 @@
6869
print "Unable to demo getSamplingFeaturesByType", e
6970

7071

71-
7272
# Now get the SamplingFeature object for a SamplingFeature code
7373
try:
7474
sf = read.getSamplingFeatureByCode('USU-LBR-Mendon')
75+
print sf
7576
print "\n-------- Information about an individual SamplingFeature ---------"
76-
print (
77-
"The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n" +
78-
"SamplingFeatureCode: " + sf.SamplingFeatureCode + "\n" +
79-
"SamplingFeatureName: " + sf.SamplingFeatureName + "\n" +
80-
"SamplingFeatureDescription: " + sf.SamplingFeatureDescription + "\n" +
81-
"SamplingFeatureGeotypeCV: " + sf.SamplingFeatureGeotypeCV + "\n" +
82-
"SamplingFeatureGeometry: " + sf.FeatureGeometry + "\n" +
83-
"Elevation_m: " + str(sf.Elevation_m))
77+
print "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n"
78+
print "SamplingFeatureCode: " + sf.SamplingFeatureCode
79+
print "SamplingFeatureName: " + sf.SamplingFeatureName
80+
print "SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription
81+
print "SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV
82+
print "SamplingFeatureGeometry: %s" % sf.FeatureGeometry
83+
print "Elevation_m: %s" % str(sf.Elevation_m)
8484
except Exception as e:
8585
print "Unable to demo getSamplingFeatureByCode: ", e
8686

8787
#add sampling feature
8888
print "\n------------ Create Sampling Feature --------- \n",
8989
try:
90-
from api.ODM2.models import SamplingFeatures
90+
from odm2api.ODM2.models import SamplingFeatures
9191
newsf = SamplingFeatures()
9292
session = session_factory.getSession()
9393
newsf.FeatureGeometry = "POINT(-111.946 41.718)"
@@ -127,27 +127,27 @@
127127
# Now get a particular Result using a ResultID
128128
print "\n------- Example of Retrieving Attributes of a Time Series Result -------"
129129
try:
130-
tsResult = read.getTimeSeriesResultByResultId(19)
130+
tsResult = read.getTimeSeriesResultByResultId(1)
131131
print (
132132
"The following are some of the attributes for the TimeSeriesResult retrieved using getTimeSeriesResultByResultID(): \n" +
133-
"ResultTypeCV: " + tsResult.ResultTypeCV + "\n" +
133+
"ResultTypeCV: " + tsResult.ResultObj.ResultTypeCV + "\n" +
134134
# Get the ProcessingLevel from the TimeSeriesResult's ProcessingLevel object
135-
"ProcessingLevel: " + tsResult.ProcessingLevelObj.Definition + "\n" +
136-
"SampledMedium: " + tsResult.SampledMediumCV + "\n" +
135+
"ProcessingLevel: " + tsResult.ResultObj.ProcessingLevelObj.Definition + "\n" +
136+
"SampledMedium: " + tsResult.ResultObj.SampledMediumCV + "\n" +
137137
# Get the variable information from the TimeSeriesResult's Variable object
138-
"Variable: " + tsResult.VariableObj.VariableCode + ": " + tsResult.VariableObj.VariableNameCV + "\n"
138+
"Variable: " + tsResult.ResultObj.VariableObj.VariableCode + ": " + tsResult.ResultObj.VariableObj.VariableNameCV + "\n"
139139
"AggregationStatistic: " + tsResult.AggregationStatisticCV + "\n" +
140140
"Elevation_m: " + str(sf.Elevation_m) + "\n" +
141141
# Get the site information by drilling down
142-
"SamplingFeature: " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
143-
tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
142+
"SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
143+
tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
144144
except Exception as e:
145145
print "Unable to demo Example of retrieving Attributes of a time Series Result: ", e
146146

147147
# Get the values for a particular TimeSeriesResult
148148
print "\n-------- Example of Retrieving Time Series Result Values ---------"
149149

150-
tsValues = read.getTimeSeriesResultValuesByResultId(19) # Return type is a pandas dataframe
150+
tsValues = read.getTimeSeriesResultValuesByResultId(1) # Return type is a pandas dataframe
151151

152152
# Print a few Time Series Values to the console
153153
# tsValues.set_index('ValueDateTime', inplace=True)
@@ -162,9 +162,9 @@
162162
fig = plt.figure()
163163
ax = fig.add_subplot(111)
164164
tsValues.plot(x='ValueDateTime', y='DataValue', kind='line',
165-
title=tsResult.VariableObj.VariableNameCV + " at " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName,
165+
title=tsResult.ResultObj.VariableObj.VariableNameCV + " at " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName,
166166
ax=ax)
167-
ax.set_ylabel(tsResult.VariableObj.VariableNameCV + " (" + tsResult.UnitObj.UnitsAbbreviation + ")")
167+
ax.set_ylabel(tsResult.ResultObj.VariableObj.VariableNameCV + " (" + tsResult.ResultObj.UnitsObj.UnitsAbbreviation + ")")
168168
ax.set_xlabel("Date/Time")
169169
ax.xaxis.set_minor_locator(dates.MonthLocator())
170170
ax.xaxis.set_minor_formatter(dates.DateFormatter('%b'))

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include README.md
2+
include *.txt
3+

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,26 @@ A Python-based application programmer's interface for the Observations Data Mode
66
### Credits
77

88
This work was supported by National Science Foundation Grants [EAR-1224638](http://www.nsf.gov/awardsearch/showAward?AWD_ID=1224638) and [ACI-1339834](http://www.nsf.gov/awardsearch/showAward?AWD_ID=1339834). Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
9+
10+
### Installation
11+
12+
Currently the easiest and most reliable way to install the ODM2 Python API (`odm2api`) is using the [Conda package management system](http://conda.pydata.org/docs/) via either [Anaconda](https://www.continuum.io/downloads) or [Miniconda](http://conda.pydata.org/miniconda.html). To create a new `odm2api` environment, first download the conda environment file [condaenvironment_1.yml](https://raw.githubusercontent.com/ODM2/ODM2PythonAPI/master/condaenvironment_1.yml). Then, on a terminal shell:
13+
14+
1. Add conda to the PATH; on MacOSX and Linux, it's something like `export PATH=$HOME/miniconda/bin:$PATH`, but the exact path may vary.
15+
2. Go to the directory where `condaenvironment_1.yml` was downloaded.
16+
3. Create a new conda environment. This command will create an environment called 'odm2api_env1':
17+
18+
```bash
19+
conda env create -f condaenvironment_1.yml
20+
```
21+
4. Activate the new environment:
22+
23+
```bash
24+
activate odm2api_env1 # On Windows
25+
source activate odm2api_env1 # On MacOSX or Linux
26+
```
27+
5. Install the `odm2api` package into the environment:
28+
29+
```bash
30+
pip install --process-dependency-links git+https://github.com/ODM2/ODM2PythonAPI.git
31+
```

__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

condaenvironment_1.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: odm2api_env1
2+
channels:
3+
- ioos
4+
dependencies:
5+
- python=2.7
6+
- pip
7+
- ipython-notebook
8+
- scipy
9+
- pandas
10+
- seaborn
11+
- sqlalchemy
12+
- psycopg2
13+
- pymysql
14+
- pyodbc
15+
- shapely

0 commit comments

Comments
 (0)