Skip to content

Commit

Permalink
scripts documentations
Browse files Browse the repository at this point in the history
  • Loading branch information
pesekon2 committed Aug 15, 2017
1 parent 2eb9469 commit 03acaed
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 12 deletions.
21 changes: 20 additions & 1 deletion r.in.sos/r.in.sos.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
#% key: event_time
#% type: string
#% label: Timestamp of first/timestamp of last requested observation
#% description: Exmaple: 2015-06-01T00:00:00+0200/2015-06-03T00:00:00+0200
#% description: Example: 2015-06-01T00:00:00+0200/2015-06-03T00:00:00+0200
#% required: no
#% guisection: Request
#%end
Expand Down Expand Up @@ -208,6 +208,11 @@ def main():

def get_description(service):
# DUPLICATED: Also in v.in.sos
"""
Return informations about the requested service if given necessary flags
:param service: Service which we are requesting informations about
"""

if flags['o'] is True:
if flags['g'] is False:
print('SOS offerings:')
Expand Down Expand Up @@ -243,6 +248,15 @@ def get_description(service):

def handle_not_given_options(service, offering=None):
# DUPLICATED: Also in v.in.sos
"""
If there are not given some options, use the full scale
:param service: Service which we are requesting parameters for
:param offering: A collection of sensors used to conveniently group them up
:return procedure: Who provide the observations (mostly the sensor)
:return observed_properties: The phenomena that are observed
:return event_time: Timestamp of first,last requested observation
"""

if options['procedure'] == '':
procedure = None
else:
Expand All @@ -266,6 +280,11 @@ def handle_not_given_options(service, offering=None):


def create_maps(parsed_obs, offering):
"""
Create raster maps representing offerings, observed props and procedures
:param parsed_obs: Observations for a given offering in geoJSON format
:param offering: A collection of sensors used to conveniently group them up
"""

for key, observation in parsed_obs.iteritems():
data = json.loads(observation)
Expand Down
24 changes: 22 additions & 2 deletions t.rast.in.sos/t.rast.in.sos.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
#% key: event_time
#% type: string
#% label: Timestamp of first/timestamp of last requested observation
#% description: Exmaple: 2015-06-01T00:00:00+0200/2015-06-03T00:00:00+0200
#% description: Example: 2015-06-01T00:00:00+0200/2015-06-03T00:00:00+0200
#% required: no
#% guisection: Request
#%end
Expand Down Expand Up @@ -161,7 +161,7 @@ def main():

run_command('r.in.sos', flags=fl, **options)
if any(value is True and key in [
'o', 'v', 'p', 't'] for key, value in flags.iteritems()):
'o', 'v', 'p', 't'] for key, value in flags.iteritems()):
return 0

service = SensorObservationService(options['url'],
Expand All @@ -187,6 +187,12 @@ def main():


def get_maps(mapName):
"""
Get the list of maps created during r.in.sos
:param mapName: Prefix of raster maps names (name without timestamp)
:return tmpFile: Temporary file containing the intermediate raster maps
"""

tmpFile = grass.tempfile()
run_command('g.list', type='raster',
pattern='{}_*'.format(mapName),
Expand All @@ -196,6 +202,11 @@ def get_maps(mapName):


def create_temporal(mapsListFile, mapName):
"""
Create strds from given raster maps where every raster map is timestamped
:param mapsListFile: Temporary file containing names of raster maps
:param mapName: Name for the output strds
"""

run_command('t.create',
output=mapName,
Expand All @@ -220,6 +231,15 @@ def create_temporal(mapsListFile, mapName):

def handle_not_given_options(service, offering=None):
# DUPLICATED: Also in v.in.sos
"""
If there are not given some options, use the full scale
:param service: Service which we are requesting parameters for
:param offering: A collection of sensors used to conveniently group them up
:return procedure: Who provide the observations (mostly the sensor)
:return observed_properties: The phenomena that are observed
:return event_time: Timestamp of first,last requested observation
"""

if options['procedure'] == '':
procedure = None
else:
Expand Down
34 changes: 29 additions & 5 deletions t.vect.in.sos/t.vect.in.sos.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
#% key: event_time
#% type: string
#% label: Timestamp of first/timestamp of last requested observation
#% description: Exmaple: 2015-06-01T00:00:00+0200/2015-06-03T00:00:00+0200
#% description: Example: 2015-06-01T00:00:00+0200/2015-06-03T00:00:00+0200
#% required: no
#% guisection: Request
#%end
Expand Down Expand Up @@ -211,6 +211,11 @@ def main():

def get_description(service):
# DUPLICATED: Also in v.in.sos
"""
Return informations about the requested service if given necessary flags
:param service: Service which we are requesting informations about
"""

if flags['o'] is True:
if flags['g'] is False:
print('SOS offerings:')
Expand All @@ -236,7 +241,7 @@ def get_description(service):
print('Begin timestamp, end timestamp of '
'{} offering:'.format(options['offering']))
print('{},{}'.format(service[offering].begin_position,
service[offering].end_position))
service[offering].end_position))
else:
print('start_time={}'.format(service[offering].begin_position))
print('end_time={}'.format(service[offering].end_position))
Expand All @@ -246,6 +251,15 @@ def get_description(service):

def handle_not_given_options(service, offering=None):
# DUPLICATED: Also in v.in.sos
"""
If there are not given some options, use the full scale
:param service: Service which we are requesting parameters for
:param offering: A collection of sensors used to conveniently group them up
:return procedure: Who provide the observations (mostly the sensor)
:return observed_properties: The phenomena that are observed
:return event_time: Timestamp of first,last requested observation
"""

if options['procedure'] == '':
procedure = None
else:
Expand All @@ -269,6 +283,11 @@ def handle_not_given_options(service, offering=None):


def create_maps(parsed_obs, offering):
"""
Create vector map representing offerings and observed properties
:param parsed_obs: Observations for a given offering in geoJSON format
:param offering: A collection of sensors used to conveniently group them up
"""

for key, observation in parsed_obs.iteritems():

Expand Down Expand Up @@ -326,8 +345,8 @@ def create_maps(parsed_obs, offering):
else:
if timestamp not in layersTimestamps:
new.open(mode='rw', layer=i, tab_name=tableName,
tab_cols=cols, link_name=tableName,
overwrite=True)
tab_cols=cols, link_name=tableName,
overwrite=True)

i += 1
layersTimestamps.append(timestamp)
Expand All @@ -341,7 +360,6 @@ def create_maps(parsed_obs, offering):
new.close(build=False)
run_command('v.build', map=mapName, quiet=True)


if len(cols) > 2000:
grass.warning(
'Recommended number of columns is less than 2000, you have '
Expand All @@ -353,6 +371,12 @@ def create_maps(parsed_obs, offering):


def create_temporal(vectorMap, layersCount, layersTimestamps):
"""
Create stvds from given vector map where one layer represents one timestamp
:param vectorMap: Vector map used as the original for registration
:param layersCount: Count of layers (timestamps) of a vector map
:param layersTimestamps: List of timestamps used in the origina; vector map
"""

run_command('g.message',
message='Registering maps in the space time dataset...')
Expand Down
29 changes: 25 additions & 4 deletions v.in.sos/v.in.sos.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@
#%option
#% key: procedure
#% type: string
#% description: Who provide the observations
#% description: Who provide the observations (mostly the sensor)
#% required: no
#% guisection: Request
#%end
#%option
#% key: event_time
#% type: string
#% label: Timestamp of first/timestamp of last requested observation
#% description: Exmaple: 2015-06-01T00:00:00+0200/2015-06-03T00:00:00+0200
#% description: Example: 2015-06-01T00:00:00+0200/2015-06-03T00:00:00+0200
#% required: no
#% guisection: Request
#%end
Expand Down Expand Up @@ -208,6 +208,11 @@ def main():


def get_description(service):
"""
Return informations about the requested service if given necessary flags
:param service: Service which we are requesting informations about
"""

if flags['o'] is True:
if flags['g'] is False:
print('SOS offerings:')
Expand All @@ -233,7 +238,7 @@ def get_description(service):
print('Begin timestamp, end timestamp of '
'{} offering:'.format(options['offering']))
print('{},{}'.format(service[offering].begin_position,
service[offering].end_position))
service[offering].end_position))
else:
print('start_time={}'.format(service[offering].begin_position))
print('end_time={}'.format(service[offering].end_position))
Expand All @@ -242,6 +247,14 @@ def get_description(service):


def handle_not_given_options(service, offering=None):
"""
If there are not given some options, use the full scale
:param service: Service which we are requesting parameters for
:param offering: A collection of sensors used to conveniently group them up
:return procedure: Who provide the observations (mostly the sensor)
:return observed_properties: The phenomena that are observed
:return event_time: Timestamp of first,last requested observation
"""
if options['procedure'] == '':
procedure = None
else:
Expand All @@ -265,6 +278,14 @@ def handle_not_given_options(service, offering=None):


def create_maps(parsed_obs, offering, layer, new):
"""
Add layers representing offerings and observed properties to the vector map
:param parsed_obs: Observations for a given offering in geoJSON format
:param offering: A collection of sensors used to conveniently group them up
:param layer: Count of yet existing layers in vector map
:param new: Given vector map which should be updated with new layers
"""

i = layer + 1

for key, observation in parsed_obs.iteritems():
Expand Down Expand Up @@ -313,7 +334,7 @@ def create_maps(parsed_obs, offering, layer, new):
new.table.conn.commit()
new.close()

i = i+1
i += 1


if __name__ == "__main__":
Expand Down

0 comments on commit 03acaed

Please sign in to comment.