Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add an option to remove warnings #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/openalea/mtg/interface/mtg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
This module provides multiscale tree concepts to form MTG interface.
"""

class MultiscaleTreeConcept(object):
class MultiscaleTreeConcept():
"""
Multiscale Tree Graph definition.
"""
Expand Down
37 changes: 22 additions & 15 deletions src/openalea/mtg/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,17 @@ def get_properties(name,vid=None, time=False):
args[k] = klass(v)
except:
if vid is not None:
if k =='_line':
continue
print('Args ', v, 'of vertex ', vid, 'of type ', k, 'is not of type ', str(klass))
else:
print('Args ', v, 'of type ', k, 'is not of type ', str(klass))
return args

def add_dynamic_properties(mtg, vid, args):
print("Existing properties at ", vid, " ", mtg.get_vertex_property(vid))
print("New property: ", args)
if mtg.verbose:
log("Existing properties at ", vid, " ", mtg.get_vertex_property(vid))
log("New property: ", args)

# a property can be a list but not a timeserie.
# Create a real timeserie object...
Expand Down Expand Up @@ -167,7 +170,7 @@ def add_dynamic_properties(mtg, vid, args):
implicit_scale = bool(symbol_at_scale)

if debug:
print(list(symbol_at_scale.keys()))
log(list(symbol_at_scale.keys()))

mtg = mtg if mtg else MTG()

Expand Down Expand Up @@ -234,7 +237,7 @@ def add_dynamic_properties(mtg, vid, args):
scale = mtg.scale(vid)
elif tag == '*':
args = get_properties(name, vid=vid, time=True)
print(vid, '*(', args, ')')
log(vid, '*(', args, ')')
# CPL Manage Dynamic_MTG
add_dynamic_properties(mtg, vid, args)
else:
Expand All @@ -252,7 +255,7 @@ def add_dynamic_properties(mtg, vid, args):
try:
new_scale = symbol_at_scale[symbol_class]
except:
print('NODE ',node, bool(tag=='*'))
print('NODE ',symbol_class, node, tag, bool(tag=='*'))
if tag == '/' and new_scale <= scale:
new_scale -= 1
pending_edge = '/'
Expand Down Expand Up @@ -457,7 +460,7 @@ def transform(turtle, mesh):
current_vertex = vid
pending_edge = ''

log('','Cas 1.1', scale,
log('','Case 1.1', scale,
'mtg.scale(vid)', mtg.scale(vid),
'generated vertex', vid)

Expand All @@ -467,7 +470,7 @@ def transform(turtle, mesh):
current_vertex = mtg.add_child(current_vertex,
edge_type=edge_type,
label=name)
log('', 'Cas 1.2', scale,
log('', 'Case 1.2', scale,
'mtg.scale(vid)', mtg.scale(vid),
'generated vertex', current_vertex)
assert mtg.scale(current_vertex) == module_scale
Expand All @@ -481,7 +484,7 @@ def transform(turtle, mesh):
assert vid == current_vertex
vid = mtg.add_component(vid)
current_vertex = vid
log('', '', 'Cas 2.1', scale, 'generate new component', current_vertex)
log('', '', 'Case 2.1', scale, 'generate new component', current_vertex)
scale += 1
if module_scale == scale:
assert mtg.scale(current_vertex) == module_scale
Expand Down Expand Up @@ -893,7 +896,7 @@ class Reader(object):
The code contains topology relations and properties.
"""

def __init__(self, string, has_line_as_param=True, mtg=None, has_date=False):
def __init__(self, string, has_line_as_param=True, mtg=None, has_date=False, verbose=True):
self.mtg = mtg

# First implementation.
Expand All @@ -912,14 +915,17 @@ def __init__(self, string, has_line_as_param=True, mtg=None, has_date=False):
self._no_line = 0
self.warnings = []
self.has_line_as_param = has_line_as_param
self.verbose = verbose

def parse(self):
"""
""" Read the header and parse the code.
"""
self.header()
self.code()

self.errors()
if self.verbose:
self.errors()

return self.mtg

def header(self):
Expand Down Expand Up @@ -1120,6 +1126,7 @@ def errors(self):
print(warning)
else:
print(id, " ", warning)

############################################################################
### Parsing of the MTG code
### That's the real stuff...
Expand Down Expand Up @@ -1270,7 +1277,7 @@ def build_mtg(self):
self.mtg = multiscale_edit(self._new_code, self._symbols, self._features, self.has_date, mtg=self.mtg)
#self.mtg = multiscale_edit(self._new_code, {}, self._features)

def read_mtg(s, mtg=None, has_date=False):
def read_mtg(s, mtg=None, has_date=False, verbose=True):
""" Create an MTG from its string representation in the MTG format.

:Parameter:
Expand All @@ -1290,11 +1297,11 @@ def read_mtg(s, mtg=None, has_date=False):
.. seealso:: :func:`read_mtg_file`.

"""
reader = Reader(s, mtg=mtg, has_date=has_date)
reader = Reader(s, mtg=mtg, has_date=has_date, verbose=verbose)
g = reader.parse()
return g

def read_mtg_file(fn, mtg=None, has_date=False):
def read_mtg_file(fn, mtg=None, has_date=False, verbose=True):
""" Create an MTG from a filename.

:Usage:
Expand All @@ -1306,7 +1313,7 @@ def read_mtg_file(fn, mtg=None, has_date=False):
f = open(fn)
txt = f.read()
f.close()
return read_mtg(txt, mtg=mtg, has_date=has_date)
return read_mtg(txt, mtg=mtg, has_date=has_date, verbose=verbose)


def mtg_display(g, vtx_id, tab=' ', edge_type=None, label=None):
Expand Down
16 changes: 11 additions & 5 deletions src/openalea/mtg/mtg.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MTG(PropertyTree):

'''

def __init__(self, filename='', has_date=False):
def __init__(self, filename='', has_date=False, verbose=False):
''' Create a new MTG object.

:Usage:
Expand All @@ -78,6 +78,8 @@ def __init__(self, filename='', has_date=False):

super(MTG, self).__init__()

self.verbose = verbose

# Map a vid to its scale
self._scale = {0:0}

Expand All @@ -93,7 +95,9 @@ def __init__(self, filename='', has_date=False):

if filename:
from .io import read_mtg_file
self = read_mtg_file(filename, mtg=self, has_date=has_date)
self = read_mtg_file(filename, mtg=self, has_date=has_date, verbose=verbose)



def __getitem__(self, vtx_id):
"""A simple getitem to extract relevant information on a vertex.
Expand Down Expand Up @@ -2389,7 +2393,8 @@ def _compute_missing_edges(mtg, scale, edge_type_property=None):
for vid in roots:
components = mtg._components.get(vid)
if components is None:
print('ERROR: Missing component for vertex %d'%vid)
if mtg.verbose:
print('ERROR: Missing component for vertex %d'%vid)
continue
#assert len(components) == 1
cid = components[0]
Expand All @@ -2398,7 +2403,8 @@ def _compute_missing_edges(mtg, scale, edge_type_property=None):
parent_id = mtg.complex(mtg.parent(cid))
if parent_id is None:
#roots.append(vid)
print('ERROR: Missing parent for vertex %d'%cid)
if mtg.verbose:
print('ERROR: Missing parent for vertex %d'%cid)
continue
if edge_type_property:
edge_type = edge_type_property.get(cid)
Expand Down Expand Up @@ -2753,7 +2759,7 @@ def new_f(self, *args, **kwds):
new_f.__doc__ = mtg_f.__doc__
return new_f

class _ProxyNode(object):
class _ProxyNode():
def __init__(self, g, vid):
self.__dict__['_g'] = g
self.__dict__['_vid'] = vid
Expand Down
4 changes: 2 additions & 2 deletions src/openalea/mtg/plantframe/dresser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import os
from openalea.plantgl.scenegraph import AmapSymbol

class DressingData(object):
class DressingData():
""" Data and default geometric parameters.

The dressing data are the default data that are used to define
Expand Down Expand Up @@ -205,7 +205,7 @@ def dressing_data(file):

###############################################################
## Define the parser which is just a dict from keyword to a function
class Reader(object):
class Reader():
def __init__(self, dresser):
self.dresser = dresser

Expand Down
6 changes: 3 additions & 3 deletions src/openalea/mtg/plantframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@



class Frame(object):
class Frame():
""" Frame representing geometric variables of each topologic elements.

A frame is used to have a common representation of the geometric information
Expand Down Expand Up @@ -137,15 +137,15 @@ def get_top_radius(self):
top_radius = property(get_top_radius, set_top_radius, 'top_radius of the Frame')


class AxialFrames(object):
class AxialFrames():
''' Solve continuity constraints on an axis, i.e. a set of frames.

'''
pass



class PlantFrame(object):
class PlantFrame():
''' Engine to compute the geometry of a plant based on
its topological description and parameters.
'''
Expand Down
2 changes: 1 addition & 1 deletion src/openalea/mtg/plantframe/plantframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
error = True
epsilon = 1e-5

class PlantFrame(object):
class PlantFrame():
''' Engine to compute the geometry of a plant based on
its topological description and parameters.
'''
Expand Down
4 changes: 2 additions & 2 deletions src/openalea/mtg/rewriting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#### Module declaration #######

class Module(object):
class Module():
def __init__(self, name, scale, **parameters):
self.name = name
self.scale = scale
Expand Down Expand Up @@ -299,7 +299,7 @@ def interpretation(f):

eForward, eBackward = 1,0

class MTGLsystem(object):
class MTGLsystem():
rules = dict()

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion src/openalea/mtg/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def traverse_tree(tree, vtx_id, visitor):
yield visitor.post_order(vtx_id)


class Visitor(object):
class Visitor():
''' Used during a tree traversal. '''

def pre_order(self, vtx_id):
Expand Down
2 changes: 1 addition & 1 deletion src/openalea/mtg/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class InvalidVertex (GraphError, KeyError) :
exception raised when a wrong vertex id is provided
"""

class Tree(object):
class Tree():
'''
Implementation of a rooted :class:`Tree`,
with methods to add and remove vertex.
Expand Down
2 changes: 1 addition & 1 deletion src/openalea/mtg/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
minor = 2
"""(int) Version minor component."""

post = 0
post = 1
"""(int) Version post or bugfix component."""

__version__ = ".".join([str(s) for s in (major, minor, post)])
Expand Down
Loading