Mercurial > repos > rv43 > tomo
comparison msnc_tools.py @ 3:f9c52762c32c draft
"planemo upload for repository https://github.com/rolfverberg/galaxytools commit 7dce44d576e4149f31bdc2ee4dce0bb6962badb6"
author | rv43 |
---|---|
date | Tue, 05 Apr 2022 18:23:54 +0000 |
parents | e4778148df6b |
children | baf9f5eef128 |
comparison
equal
deleted
inserted
replaced
2:b8977c98800b | 3:f9c52762c32c |
---|---|
295 illegal_value('title', title, 'clearFig') | 295 illegal_value('title', title, 'clearFig') |
296 return | 296 return |
297 plt.close(fig=re.sub(r"\s+", '_', title)) | 297 plt.close(fig=re.sub(r"\s+", '_', title)) |
298 | 298 |
299 def quickImshow(a, title=None, path=None, name=None, save_fig=False, save_only=False, | 299 def quickImshow(a, title=None, path=None, name=None, save_fig=False, save_only=False, |
300 clear=True, **kwargs): | 300 clear=True, extent=None, show_grid=False, grid_color='w', grid_linewidth=1, **kwargs): |
301 if title is not None and not isinstance(title, str): | 301 if title is not None and not isinstance(title, str): |
302 illegal_value('title', title, 'quickImshow') | 302 illegal_value('title', title, 'quickImshow') |
303 return | 303 return |
304 if path is not None and not isinstance(path, str): | 304 if path is not None and not isinstance(path, str): |
305 illegal_value('path', path, 'quickImshow') | 305 illegal_value('path', path, 'quickImshow') |
325 else: | 325 else: |
326 if path is None: | 326 if path is None: |
327 path = name | 327 path = name |
328 else: | 328 else: |
329 path = f'{path}/{name}' | 329 path = f'{path}/{name}' |
330 if extent is None: | |
331 extent = (0, a.shape[1], a.shape[0], 0) | |
330 if clear: | 332 if clear: |
331 plt.close(fig=title) | 333 plt.close(fig=title) |
332 if save_only: | 334 if save_only: |
333 plt.figure(title) | 335 plt.figure(title) |
334 plt.imshow(a, **kwargs) | 336 plt.imshow(a, extent=extent, **kwargs) |
337 if show_grid: | |
338 ax = plt.gca() | |
339 ax.grid(color=grid_color, linewidth=grid_linewidth) | |
335 plt.savefig(path) | 340 plt.savefig(path) |
336 plt.close(fig=title) | 341 plt.close(fig=title) |
337 #plt.imsave(f'{title}.png', a, **kwargs) | 342 #plt.imsave(f'{title}.png', a, **kwargs) |
338 else: | 343 else: |
339 plt.ion() | 344 plt.ion() |
340 plt.figure(title) | 345 plt.figure(title) |
341 plt.imshow(a, **kwargs) | 346 plt.imshow(a, extent=extent, **kwargs) |
347 if show_grid: | |
348 ax = plt.gca() | |
349 ax.grid(color=grid_color, linewidth=grid_linewidth) | |
342 if save_fig: | 350 if save_fig: |
343 plt.savefig(path) | 351 plt.savefig(path) |
344 plt.pause(1) | 352 plt.pause(1) |
345 | 353 |
346 def quickPlot(*args, title=None, path=None, name=None, save_fig=False, save_only=False, | 354 def quickPlot(*args, title=None, path=None, name=None, save_fig=False, save_only=False, |
347 clear=True, **kwargs): | 355 clear=True, show_grid=False, **kwargs): |
348 if title is not None and not isinstance(title, str): | 356 if title is not None and not isinstance(title, str): |
349 illegal_value('title', title, 'quickPlot') | 357 illegal_value('title', title, 'quickPlot') |
350 return | 358 return |
351 if path is not None and not isinstance(path, str): | 359 if path is not None and not isinstance(path, str): |
352 illegal_value('path', path, 'quickPlot') | 360 illegal_value('path', path, 'quickPlot') |
381 if depth_tuple(args) > 1: | 389 if depth_tuple(args) > 1: |
382 for y in args: | 390 for y in args: |
383 plt.plot(*y, **kwargs) | 391 plt.plot(*y, **kwargs) |
384 else: | 392 else: |
385 plt.plot(*args, **kwargs) | 393 plt.plot(*args, **kwargs) |
394 if show_grid: | |
395 ax = plt.gca() | |
396 ax.grid(color='k')#, linewidth=1) | |
386 plt.savefig(path) | 397 plt.savefig(path) |
387 plt.close(fig=title) | 398 plt.close(fig=title) |
388 else: | 399 else: |
389 plt.ion() | 400 plt.ion() |
390 plt.figure(title) | 401 plt.figure(title) |
391 if depth_tuple(args) > 1: | 402 if depth_tuple(args) > 1: |
392 for y in args: | 403 for y in args: |
393 plt.plot(*y, **kwargs) | 404 plt.plot(*y, **kwargs) |
394 else: | 405 else: |
395 plt.plot(*args, **kwargs) | 406 plt.plot(*args, **kwargs) |
407 if show_grid: | |
408 ax = plt.gca() | |
409 ax.grid(color='k')#, linewidth=1) | |
396 if save_fig: | 410 if save_fig: |
397 plt.savefig(path) | 411 plt.savefig(path) |
398 plt.pause(1) | 412 plt.pause(1) |
399 | 413 |
400 def selectArrayBounds(a, x_low=None, x_upp=None, num_x_min=None, | 414 def selectArrayBounds(a, x_low=None, x_upp=None, num_x_min=None, |
534 else: | 548 else: |
535 if not is_int(upp, low+num_min, a.shape[axis]): | 549 if not is_int(upp, low+num_min, a.shape[axis]): |
536 illegal_value('upp', upp, 'selectImageBounds') | 550 illegal_value('upp', upp, 'selectImageBounds') |
537 return None | 551 return None |
538 bounds = [low, upp] | 552 bounds = [low, upp] |
539 a_tmp = a | 553 a_tmp = np.copy(a) |
554 a_tmp_max = a.max() | |
540 if axis: | 555 if axis: |
541 a_tmp[:,bounds[0]] = a.max() | 556 a_tmp[:,bounds[0]] = a_tmp_max |
542 a_tmp[:,bounds[1]] = a.max() | 557 a_tmp[:,bounds[1]-1] = a_tmp_max |
543 else: | 558 else: |
544 a_tmp[bounds[0],:] = a.max() | 559 a_tmp[bounds[0],:] = a_tmp_max |
545 a_tmp[bounds[1],:] = a.max() | 560 a_tmp[bounds[1]-1,:] = a_tmp_max |
546 print(f'lower bound = {low} (inclusive)\nupper bound = {upp} (exclusive)') | 561 print(f'lower bound = {low} (inclusive)\nupper bound = {upp} (exclusive)') |
547 quickImshow(a_tmp, title=title) | 562 quickImshow(a_tmp, title=title) |
563 del a_tmp | |
548 if pyip.inputYesNo('Accept these bounds ([y]/n)?: ', blank=True) == 'no': | 564 if pyip.inputYesNo('Accept these bounds ([y]/n)?: ', blank=True) == 'no': |
549 bounds = selectImageBounds(a, axis, low=low_save, upp=upp_save, num_min=num_min_save, | 565 bounds = selectImageBounds(a, axis, low=low_save, upp=upp_save, num_min=num_min_save, |
550 title=title) | 566 title=title) |
551 return bounds | 567 return bounds |
552 | 568 |