Skip to content

Commit 9bbeb6e

Browse files
committed
remove depricated scipy.misc
1 parent b090ffd commit 9bbeb6e

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

GSASII/exports/G2export_image.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
'''
44
from __future__ import division, print_function
55
import os.path
6-
import scipy.misc
6+
try:
7+
import matplotlib.pyplot as plt
8+
except ImportError:
9+
plt = None
710
from .. import GSASIIfiles as G2fil
811

912
class ExportImagePNG(G2fil.ExportBaseclass):
@@ -18,7 +21,10 @@ def __init__(self,G2frame):
1821
extension='.png',
1922
longFormatName = 'Export image in PNG format'
2023
)
21-
self.exporttype = ['image']
24+
if plt is None:
25+
self.exporttype = []
26+
else:
27+
self.exporttype = ['image']
2228
#self.multiple = True
2329
def Exporter(self,event=None):
2430
'''Export an image
@@ -29,13 +35,12 @@ def Exporter(self,event=None):
2935
self.loadTree()
3036
if self.ExportSelect(): return # select one image; ask for a file name
3137
# process the selected image(s) (at present only one image)
32-
for i in sorted(self.histnam):
38+
for i in sorted(self.histnam):
3339
filename = os.path.join(
3440
self.dirname,
3541
os.path.splitext(self.filename)[0] + self.extension
3642
)
3743
imgFile = self.Histograms[i].get('Data',(None,None))
3844
Image = G2fil.GetImageData(self.G2frame,imgFile,imageOnly=True)
39-
scipy.misc.imsave(filename,Image)
45+
plt.imsave(filename,Image)
4046
print('Image '+imgFile+' written to file '+filename)
41-

GSASII/imports/G2img_CheMin.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,37 @@
44

55
from __future__ import division, print_function
66
from .. import GSASIIobj as G2obj
7+
try:
8+
import imageio
9+
except ImportError:
10+
imageio = None
711
class png_ReaderClass(G2obj.ImportImage):
812
'''Reads standard PNG images; parameters are set to those of the
913
Mars Rover (CheMin) diffractometer.
1014
'''
1115
def __init__(self):
16+
if imageio is None:
17+
self.UseReader = False
18+
msg = 'CheMin Reader skipped because imageio library is not installed'
19+
if GSASIIpath.condaTest():
20+
msg += ' To fix this use command:\n\tconda install imageio'
21+
G2fil.ImportErrorMsg(msg,{'CheMin image importer':['imageio']})
1222
super(self.__class__,self).__init__( # fancy way to self-reference
1323
extensionlist=('.png',),
1424
strictExtension=True,
15-
formatName = 'PNG image',
25+
formatName = 'CheMin PNG image',
1626
longFormatName = 'PNG image from CheMin'
1727
)
1828

1929
def ContentsValidator(self, filename):
2030
'''no test at this time
2131
'''
2232
return True
23-
33+
2434
def Reader(self,filename, ParentFrame=None, **unused):
2535
'''Reads using standard scipy PNG reader
2636
'''
27-
import scipy.misc
28-
self.Image = scipy.misc.imread(filename,flatten=True)
37+
self.Image = imageio.imread(filename,flatten=True)
2938
self.Npix = self.Image.size
3039
if self.Npix == 0:
3140
return False

GSASII/imports/G2img_pixirad_1ID_16bit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def ContentsValidator(self, filename):
4848
return True
4949

5050
def Reader(self,filename, ParentFrame=None, **unused):
51-
'''Read the TIF file using :func:`GetTifData`. If that fails,
52-
use :func:`scipy.misc.imread` and give the user a chance to
53-
edit the likely wrong default image parameters.
51+
'''Read the TIF file using :func:`GetTifData`.
5452
'''
5553
self.Comments,self.Data,self.Npix,self.Image = GetTifData(filename)
5654
if self.Npix == 0:

0 commit comments

Comments
 (0)