Skip to content

Commit

Permalink
Remove fortran
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwright committed Nov 14, 2017
1 parent 5ee9c83 commit 9406329
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 56 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 18 additions & 17 deletions ImageD11/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@


import numpy as np
from ImageD11 import closest, grain, transform, fImageD11, indexing
from . import unitcell
from ImageD11 import grain, transform, cImageD11, indexing, unitcell
import scipy.optimize
import math, time, sys, logging

Expand Down Expand Up @@ -76,16 +75,16 @@ def updatecolfile(self):
self.cf.addcolumn(xl,"xl")
self.cf.addcolumn(yl,"yl")
self.cf.addcolumn(zl,"zl")
self.peaks_xyz = np.array((self.cf.xl,self.cf.yl,self.cf.zl))
self.peaks_xyzT = np.array(zip(self.cf.xl,self.cf.yl,self.cf.zl))
om = self.cf.omega
sign = self.transformpars.get("omegasign")
osign = self.transformpars.get("omegasign")
tth, eta = transform.compute_tth_eta_from_xyz(
self.peaks_xyz, om*sign,
self.peaks_xyzT.T, om*osign,
**self.transformpars.parameters)
self.cf.addcolumn( tth, "tth", )
self.cf.addcolumn( eta, "eta", )
gx, gy, gz = transform.compute_g_vectors(
tth, eta, om*sign,
tth, eta, om*osign,
wvln = self.transformpars.get("wavelength"),
wedge = self.transformpars.get("wedge"),
chi = self.transformpars.get("chi") )
Expand Down Expand Up @@ -207,10 +206,11 @@ def pairs(self, hkl1, hkl2, cos_tol = 0.02, hkl_tol = 0.1):
ub = np.dot( U, self.unitcell.B)
ubi = np.linalg.inv( ub )
ubio = ubi.copy()
npks = closest.score(ubi,gvf,hkl_tol)
npks = cImageD11.score(ubi,gvf,hkl_tol)
pairs.append( (ind1[i], ind2[k], U, ubi ) )
print(npks, end=' ')
ubi, trans = self.refine( ubi, [0.,0.,0.], tol=hkl_tol )

ubi, trans = self.refine( ubi, np.zeros(3,np.float), tol=hkl_tol )
inds, hkls = self.assign( ubi, trans, hkl_tol )
ubi, trans = self.refine( ubi, trans, inds = inds, hkls= hkls, tol=hkl_tol )
print(npks, ubi)
Expand All @@ -223,16 +223,16 @@ def pairs(self, hkl1, hkl2, cos_tol = 0.02, hkl_tol = 0.1):


def assign(self, ubi, translation, tol):
gv = np.zeros(self.peaks_xyz.shape, order='F')
fImageD11.compute_gv( self.peaks_xyz,
gv = np.zeros(self.peaks_xyzT.shape, np.float )
cImageD11.compute_gv( self.peaks_xyzT,
self.cf.omega,
self.transformpars.get('omegasign'),
self.transformpars.get('wavelength'),
self.transformpars.get('wedge'),
self.transformpars.get('chi'),
translation,
gv)
hkl = np.dot( ubi, gv )
hkl = np.dot( ubi, gv.T )
hkli = np.floor( hkl + 0.5 )
e = (hkl - hkli)
e = (e*e).sum(axis=0)
Expand All @@ -244,15 +244,15 @@ def assign(self, ubi, translation, tol):
def gof( self, p, *args ):
self.NC += 1
try:
hkls, inds, peaks_xyz, gobs, omega = args
hkls, inds, peaks_xyzT, gobs, omega = args
except:
print(args, len(args))
raise
p.shape = 4,3
ub = p[:3]
t = p[3]
gcalc = np.dot( ub, hkls )
fImageD11.compute_gv( peaks_xyz,
cImageD11.compute_gv( peaks_xyzT,
omega,
self.transformpars.get('omegasign'),
self.transformpars.get('wavelength'),
Expand All @@ -264,7 +264,7 @@ def gof( self, p, *args ):
#print gcalc
#print (gobs-gcalc).ravel()
#1/0
e = (gcalc - gobs).ravel()
e = (gcalc - gobs.T).ravel()
p.shape = 12,
# print p-0.1,(e*e).sum()
return e#(e*e).sum()
Expand All @@ -285,8 +285,8 @@ def refine(self, ubi, translation=(0,0,0) ,
ub = np.linalg.inv( ubi )
x0 = np.array( list( ub.ravel() ) + list(translation ) )
fun = self.gof
args = (hkls, inds, self.peaks_xyz[:,inds],
np.zeros( hkls.shape, order='F'),
args = (hkls, inds, self.peaks_xyzT[inds],
np.zeros(self.peaks_xyzT[inds].shape ),
self.cf.omega[inds])
def Dfun( x0, *args ):
epsilon = np.ones(12)*1e-6
Expand Down Expand Up @@ -319,7 +319,8 @@ def deriv( xk, f, epsilon, *args):
c = columnfile( sys.argv[2] )
i = indexer( p, c )
if sys.argv[3][:3] == "fit":
# \test\simul_1000_grains>python ..\..\ImageD11\indexer.py Al1000\Al1000.par Al1000\Al1000.flt allgrid.map allgridfitscipy.map
# 0 1 2 3 4 5
# \test\simul_1000_grains>python ..\..\ImageD11\indexer.py Al1000\Al1000.par Al1000\Al1000.flt fit allgrid.map allgridfitscipy.map
gl = ImageD11.grain.read_grain_file( sys.argv[4] )
inds = np.arange( len(gl), dtype=np.int )
allhkls = np.array( (c.h, c.k, c.l) )
Expand Down
37 changes: 37 additions & 0 deletions data/F21.spline
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
SPATIAL DISTORTION SPLINE INTERPOLATION COEFFICIENTS

VALID REGION
0.0000000E+00 0.0000000E+00 0.2048000E+04 0.2048000E+04

GRID SPACING, X-PIXEL SIZE, Y-PIXEL SIZE
0.5000000E+03 0.4720000E+02 0.4720000E+02

X-DISTORTION
10 10
0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.7076429E+03
0.1577964E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04
0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.4027673E+03
0.1057752E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04
0.2398826E+02 0.2048422E+02 0.1429872E+02 0.3077442E+01-0.3623524E+01
-0.4007609E+01 0.1816188E+02 0.1579749E+02 0.1047060E+02-0.3814745E+01
-0.5290683E+01-0.4835961E+01 0.6533235E+01 0.4544265E+01-0.5887027E+00
-0.9715304E+01-0.9387800E+01-0.5001641E+01-0.1752037E+01-0.9268028E+00
0.2058256E+01 0.1049031E+02 0.7798081E+01 0.3080360E+01-0.1708627E+01
-0.4155122E+00 0.3320914E+01 0.1731841E+02 0.1939375E+02 0.1356520E+02
-0.2937748E+01-0.8179513E+00 0.4551235E+01 0.1833449E+02 0.2361189E+02
0.1761619E+02

Y-DISTORTION
10 10
0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.5029477E+03
0.1069972E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04
0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.6536555E+03
0.1484966E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04
0.3010482E+02 0.1976658E+02 0.8254602E+00 0.5231365E+01 0.1935954E+02
0.2251361E+02 0.3251266E+02 0.2218231E+02 0.4134152E+00 0.3865374E+01
0.1589760E+02 0.2057192E+02 0.3430236E+02 0.2176262E+02-0.3316354E+01
0.3753351E+01 0.1288071E+02 0.1637811E+02 0.2962677E+02 0.1462596E+02
-0.9510106E+01 0.5420035E+01 0.1569161E+02 0.1677635E+02 0.2481695E+02
0.1436112E+02-0.8407432E+01 0.4173449E+01 0.1509188E+02 0.1850943E+02
0.1934954E+02 0.9587394E+01-0.7165972E+01 0.5524649E+01 0.1782644E+02
0.2133346E+02
120 changes: 120 additions & 0 deletions data/f4mnew.spline
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
SPATIAL DISTORTION SPLINE INTERPOLATION COEFFICIENTS

VALID REGION
0.0000000E+00 0.0000000E+00 0.2048000E+04 0.2048000E+04

GRID SPACING, X-PIXEL SIZE, Y-PIXEL SIZE
0.2500000E+04 0.5000000E+02 0.5000000E+02

X-DISTORTION
17 16
0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.2418913E+03
0.4475310E+03 0.6782789E+03 0.8075235E+03 0.1007055E+04 0.1239804E+04
0.1429597E+04 0.1594739E+04 0.1826166E+04 0.2048000E+04 0.2048000E+04
0.2048000E+04 0.2048000E+04
0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.2266119E+03
0.4592156E+03 0.7153538E+03 0.9272284E+03 0.1166317E+04 0.1445248E+04
0.1728452E+04 0.1854673E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04
0.2048000E+04
-0.5201186E+02-0.4632922E+02-0.3659042E+02-0.2617715E+02-0.2055044E+02
-0.1816569E+02-0.1833720E+02-0.2464587E+02-0.3270218E+02-0.4417843E+02
-0.5272483E+02-0.5698082E+02-0.4299451E+02-0.3769843E+02-0.2753066E+02
-0.1770070E+02-0.1238515E+02-0.1120339E+02-0.1141512E+02-0.1511483E+02
-0.2368953E+02-0.3363860E+02-0.4125049E+02-0.4511438E+02-0.2728195E+02
-0.2234236E+02-0.1447735E+02-0.7427963E+01-0.4427287E+01-0.3083623E+01
-0.2762622E+01-0.6096533E+01-0.1050874E+02-0.1929293E+02-0.2405182E+02
-0.2878974E+02-0.1200905E+02-0.9141261E+01-0.3368401E+01-0.4425942E+00
0.1807091E+01 0.1770488E+01 0.2227225E+01 0.1156541E+01-0.2079139E+01
-0.6696260E+01-0.1006073E+02-0.1370021E+02-0.4734754E+01-0.3412446E+01
-0.7691700E+00 0.1087414E+01 0.1827055E+01 0.1588120E+01 0.2572252E+01
0.1880351E+01 0.3652128E+00-0.2641584E+01-0.4990768E+01-0.6473622E+01
-0.6701069E+00-0.1797274E+00 0.1080743E+01 0.1440889E+01 0.1790087E+01
0.1519273E+01 0.1748704E+01 0.1592924E+01 0.9542685E+00-0.8752533E+00
-0.1724366E+01-0.3584190E+01 0.1562799E+01 0.1694366E+01 0.8224127E+00
0.5737285E+00-0.9952993E-01 0.4258121E+00 0.8908537E-01 0.4486451E+00
0.3816212E+00 0.2933783E+00-0.2795915E+00-0.7440553E+00 0.1990556E+01
0.4143248E+00-0.3716868E+00-0.2341895E+01-0.2584696E+01-0.2980217E+01
-0.2444303E+01-0.1977985E+01-0.1428718E+01-0.1145486E+01-0.7660698E+00
-0.4903854E+00 0.3452271E+01 0.1787123E+01-0.1411178E+01-0.3498115E+01
-0.4973338E+01-0.4888458E+01-0.4478839E+01-0.3327857E+01-0.1895608E+01
-0.4307023E+00 0.9922206E+00 0.1012953E+01 0.8061293E+01 0.4954515E+01
0.5688176E+00-0.4039334E+01-0.5451169E+01-0.6051292E+01-0.5060211E+01
-0.3338642E+01-0.6182896E+00 0.2139060E+01 0.3942676E+01 0.6273694E+01
0.1768721E+02 0.1334404E+02 0.6380904E+01-0.1227076E-01-0.3448512E+01
-0.4090919E+01-0.3259585E+01-0.3285005E+00 0.3720122E+01 0.9512928E+01
0.1307105E+02 0.1503928E+02 0.3122856E+02 0.2671659E+02 0.1786632E+02
0.8171778E+01 0.3098663E+01 0.1640701E+01 0.2565387E+01 0.7130813E+01
0.1327358E+02 0.2050599E+02 0.2441765E+02 0.2797728E+02 0.4177501E+02
0.3579494E+02 0.2419088E+02 0.1493757E+02 0.8873123E+01 0.6112015E+01
0.7850461E+01 0.1198786E+02 0.1914062E+02 0.2716549E+02 0.3198692E+02
0.3701125E+02

Y-DISTORTION
20 22
0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.2043579E+03
0.3492441E+03 0.4024646E+03 0.4540469E+03 0.5744396E+03 0.8545580E+03
0.9737934E+03 0.1095663E+04 0.1221194E+04 0.1338507E+04 0.1576779E+04
0.1800904E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04 0.2048000E+04
0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.1152642E+03
0.2249289E+03 0.3213147E+03 0.4248349E+03 0.5359870E+03 0.6550099E+03
0.7619839E+03 0.8868854E+03 0.1011955E+04 0.1056239E+04 0.1107808E+04
0.1260051E+04 0.1430448E+04 0.1722168E+04 0.2048000E+04 0.2048000E+04
0.2048000E+04 0.2048000E+04
-0.5945474E+02-0.5072061E+02-0.4284021E+02-0.3358655E+02-0.2633997E+02
-0.2081924E+02-0.1484850E+02-0.1070098E+02-0.7315581E+01-0.3600893E+01
-0.9924139E+00 0.1429608E+01 0.3731673E+01 0.7445563E+01 0.1385084E+02
0.2816854E+02 0.4715980E+02 0.6093507E+02-0.5318327E+02-0.4526072E+02
-0.3879781E+02-0.3040670E+02-0.2316829E+02-0.1795274E+02-0.1241689E+02
-0.9471337E+01-0.5613902E+01-0.3043698E+01-0.1468989E+01 0.1518077E+01
0.3322921E+01 0.6208187E+01 0.1254984E+02 0.2512542E+02 0.4234255E+02
0.5653271E+02-0.4038531E+02-0.3906926E+02-0.3224828E+02-0.2455687E+02
-0.1887620E+02-0.1397250E+02-0.1088123E+02-0.6301063E+01-0.4856787E+01
-0.1929207E+01-0.6956266E+00 0.1400922E+01 0.2523445E+01 0.5511462E+01
0.9715003E+01 0.1995859E+02 0.3683191E+02 0.4900761E+02-0.3529956E+02
-0.3285453E+02-0.2655235E+02-0.1992601E+02-0.1496329E+02-0.1081308E+02
-0.7530067E+01-0.5599672E+01-0.3249732E+01-0.1492528E+01-0.9779863E+00
0.1305801E+01 0.2459862E+01 0.3806675E+01 0.7637379E+01 0.1625609E+02
0.3025987E+02 0.4155986E+02-0.3213951E+02-0.2889303E+02-0.2363780E+02
-0.1683462E+02-0.1310348E+02-0.9614949E+01-0.6125175E+01-0.4647862E+01
-0.2922698E+01-0.1163170E+01-0.9138898E+00 0.1335463E+01 0.2011345E+01
0.4114643E+01 0.6775389E+01 0.1355921E+02 0.2683530E+02 0.3811830E+02
-0.2951514E+02-0.2672780E+02-0.2113238E+02-0.1538376E+02-0.1107524E+02
-0.7923703E+01-0.5763533E+01-0.3673053E+01-0.2572707E+01-0.6880887E+00
-0.6997524E+00 0.1147373E+01 0.2094500E+01 0.3047910E+01 0.5911966E+01
0.1194592E+02 0.2412055E+02 0.3468470E+02-0.2466121E+02-0.2182657E+02
-0.1710677E+02-0.1201129E+02-0.8130177E+01-0.6115394E+01-0.3579694E+01
-0.2557990E+01-0.1754875E+01-0.4529223E+00-0.7767681E+00 0.1389353E+01
0.1542376E+01 0.2304399E+01 0.4632015E+01 0.9071615E+01 0.1926565E+02
0.2810112E+02-0.2130017E+02-0.1975521E+02-0.1400348E+02-0.9899141E+01
-0.7303840E+01-0.4083793E+01-0.3375714E+01-0.1881242E+01-0.7786947E+00
0.6073860E-01-0.5983245E+00 0.1191399E+01 0.1235920E+01 0.2315969E+01
0.3093900E+01 0.7386682E+01 0.1552314E+02 0.2423882E+02-0.2132743E+02
-0.1709353E+02-0.1390471E+02-0.9101821E+01-0.5562990E+01-0.4256365E+01
-0.2119341E+01-0.1463529E+01-0.8794067E+00-0.7576630E-01-0.6598123E+00
0.1230344E+01 0.1339024E+01 0.1719924E+01 0.3032930E+01 0.6196914E+01
0.1405724E+02 0.2175341E+02-0.2038570E+02-0.1878391E+02-0.1369556E+02
-0.8841237E+01-0.6076307E+01-0.3769681E+01-0.2082396E+01-0.1321203E+01
-0.7231995E+00 0.8555128E-01-0.4580436E+00 0.9452130E+00 0.1009681E+01
0.1846175E+01 0.2513440E+01 0.5956625E+01 0.1330991E+02 0.2125992E+02
-0.2143649E+02-0.1900654E+02-0.1326153E+02-0.9230311E+01-0.6014440E+01
-0.3562411E+01-0.2444701E+01-0.1035424E+01-0.5656492E+00-0.2383011E+00
-0.4776030E+00 0.1204508E+01 0.1238095E+01 0.1449259E+01 0.2880404E+01
0.5820508E+01 0.1387772E+02 0.2117304E+02-0.2389377E+02-0.2055486E+02
-0.1615096E+02-0.9680655E+01-0.6663705E+01-0.4392826E+01-0.2335671E+01
-0.1197933E+01-0.6970004E+00-0.3020044E+00-0.7496802E+00 0.8270651E+00
0.1185197E+01 0.1759859E+01 0.2779980E+01 0.6642985E+01 0.1467102E+02
0.2311983E+02-0.2804659E+02-0.2549255E+02-0.1826835E+02-0.1346295E+02
-0.8540470E+01-0.5533566E+01-0.3172450E+01-0.1894693E+01-0.1104339E+01
-0.6525576E+00-0.4742335E+00 0.1246633E+01 0.1063987E+01 0.1649360E+01
0.3694115E+01 0.8224239E+01 0.1820715E+02 0.2653784E+02-0.3733800E+02
-0.3372348E+02-0.2738339E+02-0.1906237E+02-0.1349040E+02-0.9222338E+01
-0.6313040E+01-0.3651978E+01-0.3142033E+01-0.1165016E+01-0.1575816E+01
0.3240710E+00 0.1397794E+01 0.2695992E+01 0.5373291E+01 0.1199238E+02
0.2509657E+02 0.3601522E+02-0.4820952E+02-0.4368536E+02-0.3523262E+02
-0.2698876E+02-0.2027069E+02-0.1405958E+02-0.1005852E+02-0.7106818E+01
-0.3803500E+01-0.2744409E+01-0.1634626E+01 0.1271196E+01 0.1612557E+01
0.3114590E+01 0.7501362E+01 0.1742124E+02 0.3276107E+02 0.4355239E+02
-0.4987164E+02-0.4912157E+02-0.4101380E+02-0.3079878E+02-0.2328437E+02
-0.1795016E+02-0.1247761E+02-0.8115891E+01-0.6372280E+01-0.2623033E+01
-0.2048201E+01 0.5066016E+00 0.1814694E+01 0.4533741E+01 0.9318826E+01
0.2076617E+02 0.3722160E+02 0.5068682E+02
38 changes: 11 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@



# from distutils.core import setup, Extension
# from setuptools import setup, Extension
import setuptools
import sys
from numpy.distutils.core import setup, Extension

from numpy import get_include

nid = [get_include(),]
import sys

if sys.platform == "win32" and "--compiler=mingw32" not in sys.argv:
ecomparg = ["/openmp","-DF2PY_REPORT_ON_ARRAY_COPY"]
Expand All @@ -43,8 +39,9 @@
elibs = ["gomp","pthread"]


# Compiled extensions:
nid = [get_include(),]

# Compiled extension:
cImageD11extension = Extension( "cImageD11",
sources = [ "src/cImageD11.pyf",
"src/connectedpixels.c",
Expand All @@ -58,30 +55,21 @@
)



import sys

# New fortran code - you might regret this...
fi = Extension("fImageD11",
sources = ['fsrc/fImageD11.f90' ],
# This is always gcc/gfortran for now
extra_f90_compile_args=["-fopenmp -O2"],
libraries = elibs)

# Remove list of dependencies from setup file
# Removed list of dependencies from setup file
# Do a miniconda (or something) instead...
#if sys.platform == 'win32':
# needed = [
# 'six',
# 'numpy>=1.0.0',
# 'scipy',
# 'xfab>=0.0.2',
# 'pycifrw'
# 'fabio>=0.0.5',
# 'numpy>=1.0.0',
# 'matplotlib>=0.90.0',
# ...
# ]
#else: # Take care of yourself if you are on linux

needed = []
# 'xfab>=0.0.1',
# 'fabio>=0.0.4']

# See the distutils docs...
setup(name='ImageD11',
Expand All @@ -91,13 +79,13 @@
description='ImageD11',
license = "GPL",
ext_package = "ImageD11", # Puts extensions in the ImageD11 directory
ext_modules = [cImageD11extension,fi],
ext_modules = [cImageD11extension,],
install_requires = needed,
packages = ["ImageD11"],
package_dir = {"ImageD11":"ImageD11"},
url = "http://github.com/jonwright/ImageD11",
# download_url = ["http://sourceforge.net/project/showfiles.php?group_id=82044&package_id=147869"],
package_data = {"ImageD11" : ["doc/*.html"]},
package_data = {"ImageD11" : ["doc/*.html", "data/*" ]},
scripts = ["ImageD11/rsv_mapper.py",
"scripts/peaksearch.py",
"scripts/fitgrain.py",
Expand Down Expand Up @@ -130,8 +118,4 @@
"scripts/avg_par.py",
"scripts/powderimagetopeaks.py"])

print("For windows you would need:")
print('set LDFLAGS="-static-libgfortran -static-libgcc -static -lgomp -shared"')
print('also gfortran/gcc installed (--compiler=mingw32)')
print('also to patch f2py to let it run')

Loading

0 comments on commit 9406329

Please sign in to comment.