Skip to content

Commit

Permalink
Develop (#63)
Browse files Browse the repository at this point in the history
* Reorganize import and lists

* Update to break on Travis

* Create help text string from helpTextPython39

* Reorganize test
Update to replace \r in travis specific string

* Update all cmd help tests

* Add print statement for temporary debugging

* Update help texts

* Update test to (hopefully) remove error for windows 10 + pyhton3.9

* Catch typo

* Add print for debut...

* Update help string

* Restrict matplotlib to version <3.4
Add python 3.9 to classifiers

* Update version

* Suggested comparison changes from pyinstaller

* Move check of date to above monitor load

* Add two theta variable

* Update normalization routine to take monitor into account
Add support for non-constant monitor across Van

* Add additional background parameter for normalizaiton plot

* Update version
  • Loading branch information
Jakob-Lass committed May 20, 2021
1 parent 199caa8 commit 1dad312
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 49 deletions.
12 changes: 7 additions & 5 deletions MJOLNIR/Data/DataFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ def __init__(self,fileLocation=None):
self.Norm=np.array(f.get('entry/data/normalization'))
self.MonitorMode = np.array(f.get('entry/control/mode'))[0].decode()
self.MonitorPreset=np.array(f.get('entry/control/preset'))
self.startTime = np.array(f.get('entry/start_time'))[0]
if self.type == 'hdf':
self.Monitor = np.array(f.get('entry/control/data'))
if not self.MonitorMode == 't' and len(self.Monitor)>1: # If not counting on time and more than one point saved
if self.Monitor.flatten()[0]!=self.MonitorPreset: # For all data in 2018 with wrong monitor saved
if self.Monitor.flatten()[0]!=self.MonitorPreset and self.startTime[:4]=='2018': # For all data in 2018 with wrong monitor saved
self.Monitor = np.ones_like(self.Monitor)*self.MonitorPreset ### TODO: Make Mark save the correct monitor!!
else:
self.Monitor=np.array(f.get('entry/data/monitor'))
self.Time = np.array(f.get('entry/control/time'))
self.startTime = np.array(f.get('entry/start_time'))[0]
self.endTime = np.array(f.get('entry/end_time'))[0]
self.experimentIdentifier = np.array(f.get('entry/experiment_identifier'))[0]
self.comment = np.array(f.get('entry/comment'))[0]
Expand Down Expand Up @@ -165,7 +165,9 @@ def __init__(self,fileLocation=None):
calibrations.append([EfTable,A4,bound])
self.instrumentCalibrations = np.array(calibrations,dtype=object)
self.loadBinning(self.binning)


self.twotheta = self.A4-self.A4Off

self.temperature = np.array(sample.get('temperature'))
self.magneticField = np.array(sample.get('magnetic_field'))
self.electricField = np.array(sample.get('electric_field'))
Expand Down Expand Up @@ -1787,11 +1789,11 @@ def extractData(files):
scanParamUnit.append(datafile.scanUnits)

Monitor.append(datafile.Monitor)
if np.array(datafile.A3Off).shape is ():
if np.array(datafile.A3Off).shape == ():
datafile.A3Off = 0.0
a3.append(datafile.A3-datafile.A3Off)
a3Off.append(datafile.A3Off)
if np.array(datafile.A4Off).shape is ():
if np.array(datafile.A4Off).shape == ():
datafile.A4Off = [0.0]
a4.append(datafile.A4-datafile.A4Off)
a4Off.append(datafile.A4Off)
Expand Down
2 changes: 1 addition & 1 deletion MJOLNIR/Data/RLUAxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def calculateTicks(ticks,angle,round=True):
ax.basey = basey

def set_axis(ax,v1,v2,*args):
if not args is ():
if args != ():
points = np.concatenate([[v1,v2],[x for x in args]],axis=0)
else:
points = np.array([v1,v2])
Expand Down
77 changes: 40 additions & 37 deletions MJOLNIR/Geometry/Instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ def generateCalibration(self,Vanadiumdatafile,A4datafile=False,savelocation='cal
if ignoreTubes is None:
ignoreTubes = []

with hdf.File(Vanadiumdatafile,'r') as VanFile:
with hdf.File(Vanadiumdatafile,'r') as VanFile: # Open normalziation file
if not A4datafile == False: # pragma: no cover
A4File = hdf.File(A4datafile,'r')
A4FileInstrument = getInstrument(A4File)
A4FileInstrumentType = A4FileInstrument.name.split('/')[-1]


VanFileInstrument = getInstrument(VanFile)
VanFileInstrument = getInstrument(VanFile) # Get the HDF object of the instrument (CAMEA)


VanFileInstrumentType = VanFileInstrument.name.split('/')[-1]
Expand All @@ -390,8 +390,19 @@ def generateCalibration(self,Vanadiumdatafile,A4datafile=False,savelocation='cal
if savelocation[-1]!='/':
savelocation+='/'

Data = np.array(VanFileInstrument.get('detector/counts')).transpose(2,0,1).astype(float)
monitor = np.mean(np.array(VanFile.get('entry/control/data'))) # Extract monitor count
monitor = np.array(VanFile.get('entry/control/data')) # Extract monitor count
# Divide data with corresponding monitor by reshaping it correctly
Data = np.array(VanFileInstrument.get('detector/counts')).transpose(2,0,1).astype(float)/monitor[np.newaxis,:,np.newaxis]
if sampleMass != None: # A sample mass has been proivided

sampleMolarMass = _tools.calculateMolarMass(sample,formulaUnitsPerUnitCell)

# TODO: Check placement of sampleDebyeWallerFactor!
vanadiumFactor = sampleDebyeWallerFactor*sampleMolarMass/(sampleMass*sampleIncoherent)
Data*=vanadiumFactor # Multiply vanadium factor to perform absolut normalization 22-02-2021 JL
else:
vanadiumFactor = 1.0


if False: #Mask pixels where spurion is present
Data[:,:,:100]=0
Expand Down Expand Up @@ -435,7 +446,7 @@ def generateCalibration(self,Vanadiumdatafile,A4datafile=False,savelocation='cal
plt.scatter(np.arange(pixels),np.sum(Data[:][i],axis=0),s=5)
plt.ylim(0,np.max(np.sum(Data[i],axis=0))*1.1)
plt.xlabel('Pixel')
plt.ylabel('Intensity [arg]')
plt.ylabel('Intensity [arb]')
plt.title('Vanadium normalization detector '+str(i))
plt.tight_layout()
plt.savefig(savelocation+'Raw/detector'+str(i)+'.png',format='png', dpi=150)
Expand Down Expand Up @@ -479,7 +490,7 @@ def generateCalibration(self,Vanadiumdatafile,A4datafile=False,savelocation='cal
plt.plot([peakPos[i+13*k,j],peakPos[i+13*k,j]],[0,np.max(ESummedData[i+13*k])*1.1])
plt.plot(x,y,'k')
plt.xlabel('Pixel')
plt.ylabel('Intensity [arg]')
plt.ylabel('Intensity [arb]')
plt.title('Detector {}'.format(i+13*k))
plt.ylim(0,np.max(ESummedData[i+13*k])*1.1)

Expand Down Expand Up @@ -537,22 +548,14 @@ def generateCalibration(self,Vanadiumdatafile,A4datafile=False,savelocation='cal
if plot: # pragma: no cover
plt.ylim(0,np.max(ESummedData[i])*1.1)
plt.xlabel('Pixel')
plt.ylabel('Intensity [arg]')
plt.ylabel('Intensity [arb]')
plt.savefig(savelocation+'/Raw/Active_'+str(i)+'.png',format='png', dpi=150)

Eguess = np.zeros_like(peakPos,dtype=int)
for i in range(Eguess.shape[0]):
for j in range(analysers):
Eguess[i,j]=np.argmax(Data[i,:,int(pixelpos[i,j])])

if sampleMass != None: # A sample mass has been proivided

sampleMolarMass = _tools.calculateMolarMass(sample,formulaUnitsPerUnitCell)

# TODO: Check placement of sampleDebyeWallerFactor!
vanadiumFactor = sampleDebyeWallerFactor*sampleMolarMass/(sampleMass*sampleIncoherent*monitor)
else:
vanadiumFactor = 1.0

fitParameters = []
activePixelRanges = []
Expand Down Expand Up @@ -611,8 +614,8 @@ def generateCalibration(self,Vanadiumdatafile,A4datafile=False,savelocation='cal
for k in range(detpixels):
binPixelData = Data[i,:,pixelAreas[k]:pixelAreas[k+1]].sum(axis=1)
ECenter = Ei[np.argmax(binPixelData)]
ECutLow = ECenter-0.4
ECutHigh= ECenter+0.4
ECutLow = ECenter-3.0
ECutHigh= ECenter+3.0
TopId = np.argmin(np.abs(Ei-ECutHigh))
BotId = np.argmin(np.abs(ECutLow-Ei))
if TopId<BotId:
Expand All @@ -622,9 +625,9 @@ def generateCalibration(self,Vanadiumdatafile,A4datafile=False,savelocation='cal
binPixelData = binPixelData[BotId:TopId]
EiLocal = Ei[BotId:TopId]
Bg = np.min(binPixelData[[0,-1]])
guess = np.array([np.max(binPixelData), ECenter,0.005,Bg],dtype=float)
guess = np.array([np.max(binPixelData), ECenter,0.08],dtype=float)
try:
res = scipy.optimize.curve_fit(Gaussian,EiLocal,binPixelData.astype(float),p0=guess)
res = scipy.optimize.curve_fit(lambda x,A,mu,sigma:Gaussian(x,A,mu,sigma,0.0),EiLocal,binPixelData.astype(float),p0=guess)

except: # pragma: no cover
if not os.path.exists(savelocation+'/{}_pixels'.format(detpixels)):
Expand All @@ -633,16 +636,16 @@ def generateCalibration(self,Vanadiumdatafile,A4datafile=False,savelocation='cal
plt.ioff
plt.figure()
plt.scatter(EiLocal,binPixelData)
plt.plot(Ei,Gaussian(Ei,*guess))
plt.plot(Ei,Gaussian(Ei,*guess,0.0))

plt.savefig(savelocation+'/{}_pixels/Detector{}_{}.png'.format(detpixels,i,k),format='png',dpi=150)
plt.close()

fittedParameters[i,j,k]=res[0]
fittedParameters[i,j,k]=np.concatenate([res[0],[0.0]])
fittedParameters[i,j,k,0] *= np.sqrt(2*np.pi)*fittedParameters[i,j,k,2] #np.sum(binPixelData) # Use integrated intensity as amplitude 29-07-2020 JL
fittedParameters[i,j,k,0] *= vanadiumFactor # Multiply vanadium factor to perform absolut normalization 22-02-2021 JL
if plot: # pragma: no cover
plt.plot(EiX,GaussianNormalized(EiX,*fittedParameters[i,j,k]),color='black')
plt.plot(EiX,Gaussian(EiX,*fittedParameters[i,j,k])/(np.sqrt(2*np.pi)*fittedParameters[i,j,k,2]),color='black')
plt.scatter(EiLocal,binPixelData,color=colors[:,k])
activePixelAnalyser.append(np.linspace(-width/2.0,width/2.0,detpixels+1,dtype=int)+center+1)
activePixelDetector.append(activePixelAnalyser)
Expand Down Expand Up @@ -1326,7 +1329,7 @@ def converterToQxQy(A3,A4,Ei,Ef):
Qx,Qy = (QV*q.reshape(-1,1))[:,:2].T
return (Qx,Qy)

def converterToA3A4(Qx,Qy, Ei,Ef,A3Off=0.0):
def converterToA3A4(Qx,Qy, Ei,Ef,A3Off=0.0,A4Sign=-1):
Qx = np.asarray(Qx)
Qy = np.asarray(Qy)

Expand Down Expand Up @@ -1354,12 +1357,12 @@ def converterToA3A4(Qx,Qy, Ei,Ef,A3Off=0.0):

A4 = ss*TasUBlib.arccosd(cos2t)
theta = TasUBlib.calcTheta(ki, kf, A4)
A3 = -om + -ss*theta + A3Off
return A3,-A4
A3 = -om + np.sign(A4Sign)*ss*theta + A3Off
return A3,np.sign(A4Sign)*A4


t = simpleDataSet(s)
fig = plt.figure(figsize=(26,13))
fig = plt.figure(figsize=(16,11))
Ax = [RLUAxes.createRLUAxes(t,figure=fig,ids=(3,3,i+1)) for i in range(9)]

MJOLNIRDir = os.path.dirname(_tools.__file__)
Expand All @@ -1381,8 +1384,8 @@ def converterToA3A4(Qx,Qy, Ei,Ef,A3Off=0.0):
startColor = np.array([0.83921569, 0.15294118, 0.15686275, 0.5])
diff = (endColor-startColor)/7.0

def format_axes_func(self,x,y,Ei,Ef,A3Off=s.theta):
A3,A4 = converterToA3A4(x,y,Ei,Ef,-A3Off)
def format_axes_func(self,x,y,Ei,Ef,A3Off=s.theta,A4Sign=-1.0):
A3,A4 = converterToA3A4(x,y,Ei,Ef,-A3Off,A4Sign=A4Sign)
return ax.sample.format_coord(x,y)+', A3 = {:.2f} deg, A4 = {:.2f} deg, Ef = {:.2f}'.format(A3,A4,Ef)

for i,(ax,Ef,A4) in enumerate(zip(Ax,EfInstrument.reshape(104,8).T,A4Instrument.reshape(104,8).T)):
Expand Down Expand Up @@ -1410,14 +1413,14 @@ def format_axes_func(self,x,y,Ei,Ef,A3Off=s.theta):
Ax[-1].set_title('All Planes')

fig.tight_layout()
Ax[0].format_coord = lambda x,y: format_axes_func(Ax[0],x,y,Ei,np.nanmean(EfInstrument,axis=0)[0],-s.theta)
Ax[1].format_coord = lambda x,y: format_axes_func(Ax[1],x,y,Ei,np.nanmean(EfInstrument,axis=0)[1],-s.theta)
Ax[2].format_coord = lambda x,y: format_axes_func(Ax[2],x,y,Ei,np.nanmean(EfInstrument,axis=0)[2],-s.theta)
Ax[3].format_coord = lambda x,y: format_axes_func(Ax[3],x,y,Ei,np.nanmean(EfInstrument,axis=0)[3],-s.theta)
Ax[4].format_coord = lambda x,y: format_axes_func(Ax[4],x,y,Ei,np.nanmean(EfInstrument,axis=0)[4],-s.theta)
Ax[5].format_coord = lambda x,y: format_axes_func(Ax[5],x,y,Ei,np.nanmean(EfInstrument,axis=0)[5],-s.theta)
Ax[6].format_coord = lambda x,y: format_axes_func(Ax[6],x,y,Ei,np.nanmean(EfInstrument,axis=0)[6],-s.theta)
Ax[7].format_coord = lambda x,y: format_axes_func(Ax[7],x,y,Ei,np.nanmean(EfInstrument,axis=0)[7],-s.theta)
Ax[0].format_coord = lambda x,y: format_axes_func(Ax[0],x,y,Ei,np.nanmean(EfInstrument,axis=0)[0],-s.theta,A4Sign=A4Positions[0])
Ax[1].format_coord = lambda x,y: format_axes_func(Ax[1],x,y,Ei,np.nanmean(EfInstrument,axis=0)[1],-s.theta,A4Sign=A4Positions[0])
Ax[2].format_coord = lambda x,y: format_axes_func(Ax[2],x,y,Ei,np.nanmean(EfInstrument,axis=0)[2],-s.theta,A4Sign=A4Positions[0])
Ax[3].format_coord = lambda x,y: format_axes_func(Ax[3],x,y,Ei,np.nanmean(EfInstrument,axis=0)[3],-s.theta,A4Sign=A4Positions[0])
Ax[4].format_coord = lambda x,y: format_axes_func(Ax[4],x,y,Ei,np.nanmean(EfInstrument,axis=0)[4],-s.theta,A4Sign=A4Positions[0])
Ax[5].format_coord = lambda x,y: format_axes_func(Ax[5],x,y,Ei,np.nanmean(EfInstrument,axis=0)[5],-s.theta,A4Sign=A4Positions[0])
Ax[6].format_coord = lambda x,y: format_axes_func(Ax[6],x,y,Ei,np.nanmean(EfInstrument,axis=0)[6],-s.theta,A4Sign=A4Positions[0])
Ax[7].format_coord = lambda x,y: format_axes_func(Ax[7],x,y,Ei,np.nanmean(EfInstrument,axis=0)[7],-s.theta,A4Sign=A4Positions[0])
fig.tight_layout()

return Ax
2 changes: 1 addition & 1 deletion MJOLNIR/Marray.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __len__(self):
if self.multidimensional:
return len(self._data)
else:
if not self._data.shape is ():
if self._data.shape != ():
return len(self._data)
else:
return 0
Expand Down
2 changes: 1 addition & 1 deletion MJOLNIR/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys,os
sys.path.append('.')

__version__ = '1.1.18'
__version__ = '1.1.19'
__author__ = 'Jakob Lass'

__multiFLEXXNormalization__ = os.path.join(os.path.dirname(__file__),'CalibrationMultiFLEXX.csv')
Expand Down
Binary file modified docs/Tutorials/Advanced/ConstantEnergy3D.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Advanced/FittedQEPlot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Advanced/RawQEPlot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Advanced/ViewerAnimationEPlane.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Advanced/ViewerAnimationEPlane.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Advanced/plotCutQELineMnF2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Advanced/plotCutQELineMnF21D.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Quick/ConstantEnergy3DPolar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Quick/ConstantEnergy3DXY.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Quick/EnergyPlaneViewer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Quick/HPlaneViewer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Quick/OrthogonalPlaneViewer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Quick/masking_10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Quick/masking_40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Quick/masking_QELine.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Tutorials/Quick/plotCutQELineMnF2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
author = u'Jakob Lass'

# The short X.Y version
version = u'1.1.18'
version = u'1.1.19'
# The full version, including alpha/beta/rc tags
release = u'1.1.18'
release = u'1.1.19'



Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

setup(
name='MJOLNIR',

version='1.1.18',
version='1.1.19',
description=('Neutron Scattering software suite.'),
long_description=long_description,
author='Jakob Lass',
Expand Down

0 comments on commit 1dad312

Please sign in to comment.