Skip to content

Commit a95be82

Browse files
committed
fix missed np.Inf (#180); expand import error in scripting (#165); misc cleanups
1 parent 75ce746 commit a95be82

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

GSASII/GSASIIfiles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import os
1414
import sys
1515
import glob
16-
import inspect
16+
#import inspect
1717
import re
1818

1919
import numpy as np
@@ -23,7 +23,7 @@
2323
from . import GSASIIstrIO as G2stIO
2424
from . import GSASIImapvars as G2mv
2525
from . import GSASIImath as G2mth
26-
from . import GSASIIlattice as G2lat
26+
#from . import GSASIIlattice as G2lat
2727

2828
#if not sys.platform.startswith('win'):
2929
# try:

GSASII/GSASIImath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5447,7 +5447,7 @@ def anneal(func, x0, args=(), schedule='fast',
54475447
else:
54485448
x0 = random.uniform(size=len(x0))*(upper-lower) + lower
54495449
best_state.x = None
5450-
best_state.cost = numpy.Inf
5450+
best_state.cost = numpy.inf
54515451

54525452
last_state.x = asarray(x0).copy()
54535453
fval = func(x0,*args)

GSASII/GSASIIscriptable.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
from . import GSASIImath as G2mth
5555

5656
# Delay imports loading to not slow down small scripts that don't need them
57-
Readers = {'Pwdr':[], 'Phase':[], 'Image':[]}
57+
Readers = {'Pwdr': [], 'Phase': [], 'Image': [], 'importErrpkgs': []}
5858
'''Readers by reader type'''
5959
exportersByExtension = {}
6060
'''Specifies the list of extensions that are supported for Powder data export'''
@@ -166,10 +166,14 @@ def LoadG2fil():
166166
'''
167167
if len(Readers['Pwdr']) > 0: return
168168
# initialize imports
169+
before = list(G2fil.condaRequestList.keys())
169170
Readers['Pwdr'] = G2fil.LoadImportRoutines("pwd", "Powder_Data")
170171
Readers['Phase'] = G2fil.LoadImportRoutines("phase", "Phase")
171172
Readers['Image'] = G2fil.LoadImportRoutines("img", "Image")
172173
Readers['HKLF'] = G2fil.LoadImportRoutines('sfact','Struct_Factor')
174+
# save list of importers that could not be loaded
175+
Readers['importErrpkgs'] = [i for i in G2fil.condaRequestList.keys()
176+
if i not in before]
173177

174178
# initialize exports
175179
for obj in G2fil.LoadExportRoutines(None):
@@ -435,14 +439,31 @@ def import_generic(filename, readerlist, fmthint=None, bank=None,
435439
filename = downloadFile(filename,download_loc)
436440
# Translated from OnImportGeneric method in GSASII.py
437441
primaryReaders, secondaryReaders = [], []
442+
hintcount = 0
438443
for reader in readerlist:
439444
if fmthint is not None and fmthint not in reader.formatName: continue
445+
hintcount += 1
440446
flag = reader.ExtensionValidator(filename)
441447
if flag is None:
442448
secondaryReaders.append(reader)
443449
elif flag:
444450
primaryReaders.append(reader)
445451
if not secondaryReaders and not primaryReaders:
452+
print('Available importers:')
453+
for reader in readerlist:
454+
print(f'\t{reader.longFormatName}')
455+
# common reason for read error -- package needed?
456+
l = []
457+
for i in Readers['importErrpkgs']:
458+
for j in G2fil.condaRequestList[i]:
459+
if j not in l: l.append(j)
460+
if Readers['importErrpkgs']:
461+
print('The following importer(s) are not available:\n'+
462+
f'\t{", ".join(Readers["importErrpkgs"])}')
463+
print('because the following optional Python package(s) are not installed:\n'+
464+
f'\t{", ".join(l)}\n')
465+
if fmthint is not None and hintcount == 0:
466+
print(f'No readers matched hint {fmthint!r}\n')
446467
raise G2ImportException(f"Could not read file: {filename}")
447468

448469
with open(filename, 'r'):

GSASII/imports/G2phase_CIF.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ def __init__(self):
4242
def ContentsValidator(self, filename):
4343
fp = open(filename,'r')
4444
ok = self.CIFValidator(fp)
45-
print('validator: ',ok)
45+
#print('validator: ',ok)
4646
fp.close()
4747
return ok
4848

4949
def Reader(self,filename, ParentFrame=None, usedRanIdList=[], **unused):
50-
if cif is None: # can happen in scripting
50+
if cif is None: # unexpected, but worth a specific error message
5151
print('Attempting to read a CIF without PyCifRW installed')
5252
raise Exception('Attempting to read a CIF without PyCifRW installed')
5353
isodistort_warnings = '' # errors that would prevent an isodistort analysis

0 commit comments

Comments
 (0)