|
7 | 7 | "metadata": {},
|
8 | 8 | "outputs": [],
|
9 | 9 | "source": [
|
| 10 | + "import os\n", |
10 | 11 | "from pathlib import Path\n",
|
11 |
| - "import pandas as pd\n", |
12 | 12 | "from datetime import datetime\n",
|
13 | 13 | "\n",
|
| 14 | + "import pandas as pd\n", |
| 15 | + "\n", |
| 16 | + "from openalea.mtg import MTG\n", |
14 | 17 | "from openalea.mtg.io import write_mtg\n",
|
15 |
| - "from openalea.deploy.shared_data import shared_data\n", |
16 | 18 | "from oawidgets.plantgl import PlantGL\n",
|
17 | 19 | "\n",
|
18 | 20 | "import openalea.strawberry\n",
|
19 |
| - "from openalea.strawberry.import_mtgfile import import_mtgfile,import_mtg_from_csv, union,strawberry_reader_csv\n", |
| 21 | + "from openalea.strawberry.data import data_directory\n", |
| 22 | + "from openalea.strawberry.import_mtgfile import import_mtgfile,import_mtg_from_csv, union, strawberry_reader_csv\n", |
20 | 23 | "from openalea.strawberry import analysis\n",
|
21 | 24 | "from openalea.strawberry import visu2d, visu3d\n",
|
22 | 25 | "from openalea.plantgl.all import Viewer"
|
|
41 | 44 | "metadata": {},
|
42 | 45 | "outputs": [],
|
43 | 46 | "source": [
|
44 |
| - "shared_data(openalea.strawberry) / \"breeding_value\"" |
| 47 | + "path_data = data_directory / \"breeding_value\"\n", |
| 48 | + "files=list(path_data.glob(\"*xlsx\"))\n", |
| 49 | + "print(files)" |
45 | 50 | ]
|
46 | 51 | },
|
47 | 52 | {
|
|
54 | 59 | "mtgs=import_mtg_from_csv(files=files, first_property=\"experimental_names\",symbol_at_scale=dict(P=1,T=2, F=3, f=3, b=3, HT=3, bt=3, ht=3,s=3))"
|
55 | 60 | ]
|
56 | 61 | },
|
| 62 | + { |
| 63 | + "cell_type": "code", |
| 64 | + "execution_count": null, |
| 65 | + "id": "10cedf67", |
| 66 | + "metadata": {}, |
| 67 | + "outputs": [], |
| 68 | + "source": [ |
| 69 | + "list(mtgs)" |
| 70 | + ] |
| 71 | + }, |
57 | 72 | {
|
58 | 73 | "cell_type": "code",
|
59 | 74 | "execution_count": null,
|
|
112 | 127 | "data=path_data / filename\n",
|
113 | 128 | "f = open(str(data), 'w',encoding='UTF8')\n",
|
114 | 129 | "f.write(mtg_lines)\n",
|
115 |
| - "f.close()" |
| 130 | + "f.close()\n" |
116 | 131 | ]
|
117 | 132 | },
|
118 | 133 | {
|
|
122 | 137 | "metadata": {},
|
123 | 138 | "outputs": [],
|
124 | 139 | "source": [
|
125 |
| - "t= import_mtgfile(filename=\"Belle_et_Bonne\")" |
126 |
| - ] |
127 |
| - }, |
128 |
| - { |
129 |
| - "cell_type": "code", |
130 |
| - "execution_count": null, |
131 |
| - "id": "65a6098c-15e3-4544-8ba0-ffcef2d64a6b", |
132 |
| - "metadata": {}, |
133 |
| - "outputs": [], |
134 |
| - "source": [ |
135 |
| - "import_mtgfile?" |
| 140 | + "\n", |
| 141 | + "t= MTG(data)\n", |
| 142 | + "t.display()" |
136 | 143 | ]
|
137 | 144 | },
|
138 | 145 | {
|
|
145 | 152 | },
|
146 | 153 | {
|
147 | 154 | "cell_type": "code",
|
148 |
| - "execution_count": 1, |
| 155 | + "execution_count": null, |
149 | 156 | "id": "f8cca6f3-bf39-476f-95a8-c90decd57fc4",
|
150 | 157 | "metadata": {},
|
151 | 158 | "outputs": [],
|
|
167 | 174 | },
|
168 | 175 | {
|
169 | 176 | "cell_type": "code",
|
170 |
| - "execution_count": 2, |
| 177 | + "execution_count": null, |
171 | 178 | "id": "ae301e8f",
|
172 | 179 | "metadata": {},
|
173 | 180 | "outputs": [],
|
174 | 181 | "source": [
|
175 | 182 | "def path_data(directory_name=None, filename=None):\n",
|
176 | 183 | " if directory_name is None:\n",
|
177 |
| - " pathdir = shared_data(openalea.strawberry)\n", |
| 184 | + " pathdir = Path(data_directory)\n", |
178 | 185 | " else:\n",
|
179 |
| - " pathdir= shared_data(openalea.strawberry) / directory_name\n", |
| 186 | + " pathdir= Path(data_directory) / directory_name\n", |
| 187 | + " if (not pathdir.exists()) and (Path(directory_name).exists()):\n", |
| 188 | + " pathdir = Path(directory_name)\n", |
| 189 | + " \n", |
180 | 190 | " \n",
|
181 |
| - " if filename is None:\n", |
182 |
| - " pathdir = pathdir\n", |
183 |
| - " else:\n", |
184 |
| - " pathdir = pathdir / filename +\".xlsx\"\n", |
| 191 | + " if filename:\n", |
| 192 | + " pathdir = pathdir / (filename +\".xlsx\")\n", |
185 | 193 | " \n",
|
186 | 194 | " return pathdir\n",
|
187 | 195 | "\n",
|
|
204 | 212 | " \n",
|
205 | 213 | " path_file=path_data(directory_name=directory_name, filename=filename)\n",
|
206 | 214 | " \n",
|
207 |
| - " if path_file.endswith(\".xlsx\"):\n", |
| 215 | + " if path_file.name.endswith(\".xlsx\"):\n", |
208 | 216 | " g=strawberry_reader_csv(file=path_file,first_property=\"experimental_name\",symbole_at_scale=symbole_at_scale)\n",
|
209 | 217 | " g= union(g)\n",
|
210 | 218 | " else: \n",
|
211 |
| - " files=list(path_file.glob(\"*xlsx\"))\n", |
| 219 | + " files=list(path_file.glob(\"*.xlsx\"))\n", |
212 | 220 | " #assert (files== None, \"directory no contain .xlsx file\")\n",
|
213 | 221 | " g= import_mtg_from_csv(files=files,first_property=\"experimental_name\",symbol_at_scale=symbole_at_scale)\n",
|
214 | 222 | " g=union(g)\n",
|
215 | 223 | " \n",
|
216 |
| - " for k in g.property('Sample_date').keys():\n", |
217 |
| - " g.property('Sample_date')[k]=datetime.strftime(g.property('Sample_date')[k], '%d/%m/%Y')\n", |
218 |
| - " g.property('Architecture_date')[k]=datetime.strftime(g.property('Architecture_date')[k], '%d/%m/%Y')\n", |
| 224 | + " sample_dates = g.property('Sample_date')\n", |
| 225 | + " archi_dates = g.property('Architecture_date')\n", |
| 226 | + " for k in sample_dates:\n", |
| 227 | + " sample_dates[k]=datetime.strftime(sample_dates[k], '%d/%m/%Y')\n", |
| 228 | + " archi_dates[k]=datetime.strftime(archi_dates[k], '%d/%m/%Y')\n", |
219 | 229 | " \n",
|
220 | 230 | " # convert total_flowers name in FLWRNUMBER (properties requiered in the source code)\n",
|
221 | 231 | " g.properties()[\"FLWRNUMBER\"]=g.properties()[\"total_flowers\"]\n",
|
222 | 232 | " del g.properties()[\"total_flowers\"]\n",
|
223 | 233 | " \n",
|
224 | 234 | " max_order= max(g.property(\"order\").values())+1\n",
|
225 | 235 | " mtg_lines = write_mtg(g, properties,class_at_scale=symbole_at_scale,nb_tab=max_order)\n",
|
226 |
| - " name = path_file.replace('.xlsx','.mtg')\n", |
| 236 | + " name = path_file.name.replace('.xlsx','.mtg')\n", |
227 | 237 | " \n",
|
228 | 238 | " f = open(str(name), 'w',encoding='UTF8')\n",
|
229 | 239 | " f.write(mtg_lines)\n",
|
|
238 | 248 | "### For a single .xlsx file"
|
239 | 249 | ]
|
240 | 250 | },
|
| 251 | + { |
| 252 | + "cell_type": "code", |
| 253 | + "execution_count": null, |
| 254 | + "id": "781e9db9", |
| 255 | + "metadata": {}, |
| 256 | + "outputs": [], |
| 257 | + "source": [] |
| 258 | + }, |
241 | 259 | {
|
242 | 260 | "cell_type": "code",
|
243 | 261 | "execution_count": null,
|
|
261 | 279 | },
|
262 | 280 | {
|
263 | 281 | "cell_type": "code",
|
264 |
| - "execution_count": 3, |
| 282 | + "execution_count": null, |
265 | 283 | "id": "fa2a156e-3d99-47f4-8829-b1d8377288bf",
|
266 | 284 | "metadata": {},
|
267 |
| - "outputs": [ |
268 |
| - { |
269 |
| - "name": "stderr", |
270 |
| - "output_type": "stream", |
271 |
| - "text": [ |
272 |
| - "c:\\users\\mlabadie\\documents\\github\\strawberry\\src\\openalea\\strawberry\\import_mtgfile.py:222: Warning: Redeclaration of module 'F'.\n", |
273 |
| - " l.declare(module)\n", |
274 |
| - "c:\\users\\mlabadie\\documents\\github\\strawberry\\src\\openalea\\strawberry\\import_mtgfile.py:222: Warning: Redeclaration of module 'f'.\n", |
275 |
| - " l.declare(module)\n" |
276 |
| - ] |
277 |
| - } |
278 |
| - ], |
| 285 | + "outputs": [], |
279 | 286 | "source": [
|
280 | 287 | "directory_name= \"breeding_value\" # name of your directory containing .xlsx file\n",
|
281 | 288 | "\n",
|
282 |
| - "path=shared_data(openalea.strawberry).glob(directory_name+'\\*.xlsx')\n", |
283 |
| - "names=[filename.split(\"\\\\\")[-1].split(\".\")[0] for filename in path]\n", |
| 289 | + "path = (data_directory/directory_name).glob('*.xlsx')\n", |
| 290 | + "names=[filename.split(os.sep)[-1].split(\".\")[0] for filename in path]\n", |
284 | 291 | "for name in names:\n",
|
285 | 292 | " write_excel_to_mtg(directory_name=directory_name,filename=name)"
|
286 | 293 | ]
|
|
292 | 299 | "metadata": {},
|
293 | 300 | "outputs": [],
|
294 | 301 | "source": []
|
295 |
| - }, |
296 |
| - { |
297 |
| - "cell_type": "code", |
298 |
| - "execution_count": null, |
299 |
| - "id": "b99ee175-73a6-40cc-8e79-aad048d88ad6", |
300 |
| - "metadata": {}, |
301 |
| - "outputs": [], |
302 |
| - "source": [] |
303 | 302 | }
|
304 | 303 | ],
|
305 | 304 | "metadata": {
|
|
318 | 317 | "name": "python",
|
319 | 318 | "nbconvert_exporter": "python",
|
320 | 319 | "pygments_lexer": "ipython3",
|
321 |
| - "version": "3.9.12" |
| 320 | + "version": "3.12.1" |
322 | 321 | }
|
323 | 322 | },
|
324 | 323 | "nbformat": 4,
|
|
0 commit comments