Skip to content

Commit 44eea67

Browse files
committed
Fix issue #96
1 parent 4c24897 commit 44eea67

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

example/tutorials/1.import_and_read_MTG.ipynb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
{
2727
"cell_type": "code",
28-
"execution_count": 1,
28+
"execution_count": 4,
2929
"metadata": {},
3030
"outputs": [],
3131
"source": [
@@ -44,7 +44,7 @@
4444
},
4545
{
4646
"cell_type": "code",
47-
"execution_count": 2,
47+
"execution_count": 5,
4848
"metadata": {},
4949
"outputs": [],
5050
"source": [
@@ -60,7 +60,7 @@
6060
},
6161
{
6262
"cell_type": "code",
63-
"execution_count": 3,
63+
"execution_count": 6,
6464
"metadata": {},
6565
"outputs": [],
6666
"source": [
@@ -88,19 +88,24 @@
8888
},
8989
{
9090
"cell_type": "code",
91-
"execution_count": 4,
91+
"execution_count": 8,
9292
"metadata": {},
9393
"outputs": [
9494
{
95-
"name": "stdout",
96-
"output_type": "stream",
97-
"text": [
98-
"MTG : nb_vertices=158, nb_scales=4\n"
95+
"ename": "KeyError",
96+
"evalue": "'Breading_value'",
97+
"output_type": "error",
98+
"traceback": [
99+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
100+
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
101+
"Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m g \u001b[38;5;241m=\u001b[39m \u001b[43mimport_mtgfile\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilename\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mBreading_value\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(g)\n",
102+
"File \u001b[0;32m~/devlp/git/strawberry/src/openalea/strawberry/import_mtgfile.py:41\u001b[0m, in \u001b[0;36mimport_mtgfile\u001b[0;34m(filename)\u001b[0m\n\u001b[1;32m 39\u001b[0m mtgfile \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mdict\u001b[39m((k,f) \u001b[38;5;28;01mfor\u001b[39;00m k,f \u001b[38;5;129;01min\u001b[39;00m mtg_path\u001b[38;5;241m.\u001b[39mitems() \u001b[38;5;28;01mif\u001b[39;00m k \u001b[38;5;129;01min\u001b[39;00m filenames)\n\u001b[1;32m 40\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(filenames) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m---> 41\u001b[0m g \u001b[38;5;241m=\u001b[39m MTG(\u001b[43mmtgfile\u001b[49m\u001b[43m[\u001b[49m\u001b[43mfilenames\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m)\n\u001b[1;32m 42\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m g\n\u001b[1;32m 43\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
103+
"\u001b[0;31mKeyError\u001b[0m: 'Breading_value'"
99104
]
100105
}
101106
],
102107
"source": [
103-
"g = import_mtgfile(filename= [\"Breadding_value\"])\n",
108+
"g = import_mtgfile(filename= [\"Breading_value\"])\n",
104109
"print(g)\n"
105110
]
106111
},
@@ -242,7 +247,7 @@
242247
],
243248
"metadata": {
244249
"kernelspec": {
245-
"display_name": "Python 3",
250+
"display_name": "Python 3 (ipykernel)",
246251
"language": "python",
247252
"name": "python3"
248253
},
@@ -256,7 +261,7 @@
256261
"name": "python",
257262
"nbconvert_exporter": "python",
258263
"pygments_lexer": "ipython3",
259-
"version": "3.8.10"
264+
"version": "3.9.16"
260265
},
261266
"widgets": {
262267
"application/vnd.jupyter.widget-state+json": {

src/openalea/strawberry/import_mtgfile.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,22 @@ def topology(df, first_property):
100100
string=[]
101101

102102
for row in row_index:
103+
empty = True
103104
for column in column_index:
104105
if array[row,column]!=-1:
106+
empty = False
105107
break
108+
if empty:
109+
print("Error : Empty lines are forbidden")
110+
continue
106111
if column == column_start:
107112
string.append(array[row,column])
108113
elif column < column_start:
109-
string.extend([']',array[row,column]])
114+
if column_start-column >1:
115+
print('ERROR : ',column_start-column, ' LINE: ',row+2)
116+
print(array[row-1,:])
117+
nb = column_start-column
118+
string.extend([']'*nb,array[row,column]])
110119
else:
111120
string.extend(['[',array[row,column]])
112121

@@ -138,7 +147,9 @@ def test_string_convertion(string):
138147
if test_string_convertion(string)==0:
139148
return string
140149
else:
141-
print("Error in convertion dataframe to string")
150+
print("Error in convertion dataframe to string:")
151+
print(string)
152+
return string
142153

143154

144155
def add_properties(g, df, first_property):
@@ -188,9 +199,10 @@ def add_axis_scale(g):
188199
p_cpx = g.complex(pid)
189200

190201
g.add_child(p_cpx, cpx, label="A", edge_type="+")
191-
192-
g.reindex()
193-
return g
202+
203+
new_g = g.reindex(copy=True)
204+
205+
return new_g
194206

195207
def strawberry_reader_csv(file, first_property='experimental_name',symbole_at_scale = dict(P=1,T=2, F=3, f=3, b=3, HT=3, bt=3, ht=3,s=3)):
196208
''' Main function to import MTG from csv file
@@ -212,6 +224,7 @@ def strawberry_reader_csv(file, first_property='experimental_name',symbole_at_sc
212224
mtgs = list()
213225

214226
for sheet in sheets:
227+
print(f"{sheet}")
215228
df = read_file(file=file, sheet_name=sheet)
216229

217230
string= topology(df,first_property=first_property)
@@ -228,7 +241,15 @@ def strawberry_reader_csv(file, first_property='experimental_name',symbole_at_sc
228241

229242
g= add_properties(g, df,first_property=first_property)
230243
g.property("Stade")
231-
g= add_axis_scale(g)
244+
try:
245+
g= add_axis_scale(g)
246+
except Exception as e:
247+
print("#"*80)
248+
print(f"{sheet} in ERROR")
249+
print(g)
250+
g.display()
251+
raise(e)
252+
232253
g.properties()["order"] = algo.orders(g)
233254
mtgs.append(g)
234255

0 commit comments

Comments
 (0)