Skip to content

Commit b1cc22b

Browse files
author
Stephanie Reeder
committed
Merge pull request #39 from ODM2/addinheritance
Addinheritance
2 parents e636f7b + 8179e10 commit b1cc22b

File tree

6 files changed

+1039
-1199
lines changed

6 files changed

+1039
-1199
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ log
4242
.idea
4343

4444
.DS_Store
45+
.ipynb_checkpoints

Examples/Sample.py

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
__author__ = 'stephanie'
2-
import sys
3-
import os
2+
43

54

65
import matplotlib.pyplot as plt
76
from matplotlib import dates
87

98

10-
#this will be removed when we can installthe api
11-
# this_file = os.path.realpath(__file__)
12-
# directory = os.path.dirname(os.path.dirname(this_file))
13-
# print directory
14-
# sys.path.insert(0, directory)
159

1610
from odm2api.ODMconnection import dbconnection
1711
from odm2api.ODM2.services.readService import *
12+
from odm2api.ODM2.services import CreateODM2
1813
# Create a connection to the ODM2 database
1914
# ----------------------------------------
2015

2116

2217
#connect to database
23-
#createconnection (dbtype, servername, dbname, username, password)
24-
#session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')
25-
#session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)
26-
# session_factory= dbconnection.createConnection('mssql', "(local)", "LBRODM2", "ODM", "odm")
27-
session_factory= dbconnection.createConnection('mssql', "arroyoodm2", "LBRODM2", "ODM", "odm")
18+
# createconnection (dbtype, servername, dbname, username, password)
19+
# session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)#sqlite
20+
# session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')#mysql
21+
# session_factory= dbconnection.createConnection('mssql', "(local)", "LBRODM2", "ODM", "odm")#win MSSQL
22+
session_factory= dbconnection.createConnection('mssql', "arroyoodm2", "", "ODM", "odm")#mac/linux MSSQL
2823

2924

3025

3126
#_session = session_factory.getSession()
32-
3327
read = ReadODM2(session_factory)
28+
create =CreateODM2(session_factory)
3429

3530

3631

@@ -64,41 +59,37 @@
6459
numSites = len(siteFeatures)
6560

6661
for x in siteFeatures:
67-
print x.SamplingFeatureCode + ": " + x.SamplingFeatureName
62+
print x.SamplingFeatureCode + ": " + str(x.SamplingFeatureName) + ", " + x.SamplingFeatureTypeCV
6863
except Exception as e:
6964
print "Unable to demo getSamplingFeaturesByType", e
7065

7166

7267
# Now get the SamplingFeature object for a SamplingFeature code
7368
try:
74-
sf = read.getSamplingFeatures(code='USU-LBR-Mendon')
69+
sf = read.getSamplingFeatures(code='USU-LBR-Mendon')[0]
7570
print sf
7671
print "\n-------- Information about an individual SamplingFeature ---------"
77-
print "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n"
72+
print "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeature(code = x): \n"
7873
print "SamplingFeatureCode: " + sf.SamplingFeatureCode
7974
print "SamplingFeatureName: " + sf.SamplingFeatureName
8075
print "SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription
8176
print "SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV
82-
print "SamplingFeatureGeometry: %s" % sf.FeatureGeometry
77+
print "SamplingFeatureGeometry: %s" % sf.FeatureGeometryWKT
8378
print "Elevation_m: %s" % str(sf.Elevation_m)
8479
except Exception as e:
8580
print "Unable to demo getSamplingFeatureByCode: ", e
8681

8782
#add sampling feature
8883
print "\n------------ Create Sampling Feature --------- \n",
8984
try:
90-
from odm2api.ODM2.models import SamplingFeatures
91-
newsf = SamplingFeatures()
85+
# from odm2api.ODM2.models import SamplingFeatures
9286
session = session_factory.getSession()
93-
newsf.FeatureGeometry = "POINT(-111.946 41.718)"
94-
newsf.Elevation_m=100
95-
newsf.ElevationDatumCV=sf.ElevationDatumCV
96-
newsf.SamplingFeatureCode= "TestSF"
97-
newsf.SamplingFeatureDescription = "this is a test to add Feature Geomotry"
98-
newsf.SamplingFeatureGeotypeCV= "Point"
99-
newsf.SamplingFeatureTypeCV=sf.SamplingFeatureTypeCV
100-
newsf.SamplingFeatureUUID= sf.SamplingFeatureUUID+"2"
101-
session.add(newsf)
87+
newsf = Sites(FeatureGeometryWKT = "POINT(-111.946 41.718)", Elevation_m=100, ElevationDatumCV=sf.ElevationDatumCV,
88+
SamplingFeatureCode= "TestSF",SamplingFeatureDescription = "this is a test to add Feature Geomotry",
89+
SamplingFeatureGeotypeCV= "Point", SamplingFeatureTypeCV=sf.SamplingFeatureTypeCV,SamplingFeatureUUID= sf.SamplingFeatureUUID+"2",
90+
SiteTypeCV="cave", Latitude= "100", Longitude= "-100", SpatialReferenceID= 0)
91+
92+
create.createSamplingFeature(newsf)
10293
#session.commit()
10394
print "new sampling feature added to database", newsf
10495

@@ -127,51 +118,42 @@
127118
# Now get a particular Result using a ResultID
128119
print "\n------- Example of Retrieving Attributes of a Time Series Result -------"
129120
try:
130-
tsResult = read.getTimeSeriesResultByResultId(1)
121+
tsResult = read.getResults(id = 1)[0]
131122
print (
132123
"The following are some of the attributes for the TimeSeriesResult retrieved using getTimeSeriesResultByResultID(): \n" +
133-
"ResultTypeCV: " + tsResult.ResultObj.ResultTypeCV + "\n" +
124+
"ResultTypeCV: " + tsResult.ResultTypeCV + "\n" +
134125
# Get the ProcessingLevel from the TimeSeriesResult's ProcessingLevel object
135-
"ProcessingLevel: " + tsResult.ResultObj.ProcessingLevelObj.Definition + "\n" +
136-
"SampledMedium: " + tsResult.ResultObj.SampledMediumCV + "\n" +
126+
"ProcessingLevel: " + tsResult.ProcessingLevelObj.Definition + "\n" +
127+
"SampledMedium: " + tsResult.SampledMediumCV + "\n" +
137128
# Get the variable information from the TimeSeriesResult's Variable object
138-
"Variable: " + tsResult.ResultObj.VariableObj.VariableCode + ": " + tsResult.ResultObj.VariableObj.VariableNameCV + "\n"
129+
"Variable: " + tsResult.VariableObj.VariableCode + ": " + tsResult.VariableObj.VariableNameCV + "\n"
139130
"AggregationStatistic: " + tsResult.AggregationStatisticCV + "\n" +
140131
"Elevation_m: " + str(sf.Elevation_m) + "\n" +
141132
# Get the site information by drilling down
142-
"SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
143-
tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
133+
"SamplingFeature: " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
134+
tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
144135
except Exception as e:
145136
print "Unable to demo Example of retrieving Attributes of a time Series Result: ", e
146137

147138
# Get the values for a particular TimeSeriesResult
148139
print "\n-------- Example of Retrieving Time Series Result Values ---------"
149140

150-
tsValues = read.getTimeSeriesResultValuesByResultId(1) # Return type is a pandas dataframe
151-
tsValues = read.getResultValues(type = 'timeseries', id = 1)
141+
tsValues = read.getResultValues(resultid = 1) # Return type is a pandas datafram
152142

153143
# Print a few Time Series Values to the console
154144
# tsValues.set_index('ValueDateTime', inplace=True)
155145
try:
146+
print "tsValues "
156147
print tsValues.head()
157148
except Exception as e:
158149
print e
159150

160151
# Plot the time series
161152

162153
try:
163-
fig = plt.figure()
164-
ax = fig.add_subplot(111)
165-
tsValues.plot(x='ValueDateTime', y='DataValue', kind='line',
166-
title=tsResult.ResultObj.VariableObj.VariableNameCV + " at " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName,
167-
ax=ax)
168-
ax.set_ylabel(tsResult.ResultObj.VariableObj.VariableNameCV + " (" + tsResult.ResultObj.UnitsObj.UnitsAbbreviation + ")")
169-
ax.set_xlabel("Date/Time")
170-
ax.xaxis.set_minor_locator(dates.MonthLocator())
171-
ax.xaxis.set_minor_formatter(dates.DateFormatter('%b'))
172-
ax.xaxis.set_major_locator(dates.YearLocator())
173-
ax.xaxis.set_major_formatter(dates.DateFormatter('\n%Y'))
174-
ax.grid(True)
154+
plt.figure()
155+
ax=tsValues.plot(x='ValueDateTime', y='DataValue')
156+
175157
plt.show()
176158
except Exception as e:
177159
print "Unable to demo plotting of tsValues: ", e

0 commit comments

Comments
 (0)