Commit 10db500e authored by Miller, Stephen D's avatar Miller, Stephen D
Browse files

Initial make_mantid_cal.pro check-in

parents
;define program control flags - 0 for off and 1 for on (true)
doshow=0
dowrite=1
difclistfile = '/SNS/NOM/shared/difclist.dat'
difclist = read_ascii(difclistfile) ;provides difc as an ascii list
NPTS=n_elements(difclist.field1)
print,'NPTS: ',NPTS
difclistfile50 = '/SNS/NOM/shared/difclist50.dat'
difclist50 = read_ascii(difclistfile50)
difc = difclist.field1
cs=3
if doshow eq 1 then begin
window,0
Device, decomposed=0, retain=2
!p.background = 255
!p.multi=[0,1,5]
loadct,39
plot,difc,color=0,charsize=cs,title='DIFC Restored',xstyle=1
endif
;restore file with offsets
;basedir = '/SNS/NOM/IPTS-12941/shared/autoNOM/'
;basedir = '/SNS/NOM/IPTS-12941'
basedir = '/SNS/NOM/IPTS-13191'
;aqdepfile= '/shared/autoNOM/aqdep41531.dat'
aqdepfile= '/shared/autoNOM/aqdep47702.dat'
runnum='47702'
restore,basedir+aqdepfile,restored_objects=obj,/verbose ;restores AQDEP41531 and difa
;caldir:/SNS/NOM/IPTS-12941/shared/autoNOM/
calnomfile='nomad_47702.calfile'
caldir='/SNS/NOM/IPTS-13191/shared/autoNOM/'
calnom=read_ascii(caldir+calnomfile,data_start=1)
print,"Number of elements in calnom array: ",n_elements(calnom.field1(2,*))
;nomad_47702.calfile Example data
;# number UDET offset select group
; 0 3072 -0.0213900 0 1
; 1 3073 -0.0212027 0 1
; 2 3074 -0.0210154 0 1
; 3 3075 -0.0208279 0 1
; 4 3076 -0.0206403 0 1
; 5 3077 -0.0204527 0 1
; 6 3078 -0.0202651 0 1
; 7 3079 -0.0200773 0 1
; 8 3080 -0.0198894 1 1
; 9 3081 -0.0197015 1 1
; 10 3082 -0.0195135 1 1
;calnom is compressed in size
number=fltarr(NPTS)
number[calnom.field1(1,*)] = calnom.field1(0,*)
UDET=fltarr(NPTS)
UDET[calnom.field1(1,*)] = calnom.field1(1,*)
offset=fltarr(NPTS)
offset[calnom.field1(1,*)] = calnom.field1(2,*)
indx_offset=where(offset GT 1 OR offset LT -1,Nindx_offset)
if Nindx_offset GT 0 then offset[indx_offset] = 0
if doshow eq 1 then plot,offset < 0.2,color=0,charsize=cs,title='Offsets Restored and Expanded',xstyle=1
;;clip offset to max and min values
;tmax=0.1
;indx=where(offset GE tmax,Nt)
;if Nt GT 0 then offset[indx]=tmax
;tmin=-0.1
;indx=where(offset LE tmin,Nt)
;if Nt GT 0 then offset[indx]=tmin
select=fltarr(NPTS)
select[calnom.field1(1,*)]=calnom.field1(3,*)
group=fltarr(NPTS)
group[calnom.field1(1,*)]=calnom.field1(4,*)
;group numbers range between 1 and 6
;some group values are 7 - these need to be changed to 5
;IDL wants to index between 0 and 5, handle with subtract one of group
indx=where(group eq 7,Ngroup)
if Ngroup gt 0 then group[indx]=5
if doshow eq 1 then plot,group,color=0,charsize=cs,title='Group Restored and Expanded',xstyle=1
if doshow eq 1 then plot,udet,color=0,charsize=cs,title='UDET Restored and Expanded',xstyle=1
if doshow eq 1 then plot,select,color=0,charsize=cs,title='Select Restored and Expanded',xstyle=1
;plot difa[*,0-2]
if doshow eq 1 then begin
window,2
Device, decomposed=0, retain=2
!p.background = 255
!p.multi=[0,1,3]
loadct,39
xaxis=findgen(6)
pcs=2.1
plot,xaxis,difa[*,0],color=0,charsize=cs,title='DIFA[*,0]',psym=4,symsize=pcs
oplot,xaxis,difa[*,0],color=100
plot,xaxis,difa[*,1],color=0,charsize=cs,title='DIFA[*,1]',psym=4,symsize=pcs
oplot,xaxis,difa[*,1],color=200
plot,xaxis,difa[*,2],color=0,charsize=cs,title='DIFA[*,2]',psym=4,symsize=pcs
oplot,xaxis,difa[*,2],color=300
endif
;calculate TZERO, DIFC, and DIFA
;note difa stored as array[6,3]
TZERO_DAS=difc*difa[group-1,0]/(1+offset)
DIFC_DAS=difc*difa[group-1,1]/(1+offset)
DIFA_DAS=difc*difa[group-1,2]/(1+offset)
;deciding that 'select' should not be gated onto these variables
TZERO_DAS_SELECT=difc*difa[group-1,0]/(1+offset);*select
DIFC_DAS_SELECT=difc*difa[group-1,1]/(1+offset);*select
DIFA_DAS_SELECT=difc*difa[group-1,2]/(1+offset);*select
;next two lines show how to generate mantid indicies using morebin
;spawn, 'morebin -t int32 /SNS/NOM/2010_2_1B_CAL/calibrations/NOM_TS_2010_12_01.dat > nom_2010_12_01.txt'
;nom_2010_12_01 = read_ascii('nom_2010_12_01.txt')
;nom_2010_12_01 is used here to provide DAS to Mantid indicies
;the last two elements in nom_2010_12_01.field1 are NaNs - strip these out
Nchk=n_elements(nom_2010_12_01.field1)
indx=where(Finite(nom_2010_12_01.field1) EQ 0,Nnans)
print,'Number of NaNs: ',Nnans
number_mantid = number[nom_2010_12_01.field1[0:Nchk-Nnans-1]]
udet_mantid=udet[nom_2010_12_01.field1[0:Nchk-Nnans-1]]
offset_mantid=offset[nom_2010_12_01.field1[0:Nchk-Nnans-1]]
select_mantid=select[nom_2010_12_01.field1[0:Nchk-Nnans-1]]
group_mantid=group[nom_2010_12_01.field1[0:Nchk-Nnans-1]]
det_id=nom_2010_12_01.field1[0:Nchk-Nnans-1]
;New info: select should not be factored in for producing TZERO_MANTID, DIFA_MANTID, and DIFC_MANTID
TZERO_MANTID=TZERO_DAS_SELECT[nom_2010_12_01.field1[0:Nchk-Nnans-1]]
DIFC_MANTID=DIFC_DAS_SELECT[nom_2010_12_01.field1[0:Nchk-Nnans-1]]
DIFA_MANTID=DIFA_DAS_SELECT[nom_2010_12_01.field1[0:Nchk-Nnans-1]]
if doshow eq 1 then begin
window,1
Device, decomposed=0, retain=2
!p.background = 255
!p.multi=[0,1,3]
loadct,39
plot,TZERO_DAS ,color=0,charsize=cs,title='TZERO DAS',xstyle=1,yrange=[-350,200],ystyle=1
plot,DIFC_DAS ,color=0,charsize=cs,title='DIFC DAS',xstyle=1,yrange=[-100,13000],ystyle=1
plot,DIFA_DAS ,color=0,charsize=cs,title='DIFA DAS',xstyle=1,yrange=[-10,2],ystyle=1
window,3
Device, decomposed=0, retain=2
!p.background = 255
!p.multi=[0,1,3]
loadct,39
plot,TZERO_DAS_SELECT ,color=0,charsize=cs,title='TZERO DAS_SELECT',xstyle=1,yrange=[-350,200],ystyle=1
plot,DIFC_DAS_SELECT,color=0,charsize=cs,title='DIFC DAS_SELECT',xstyle=1,yrange=[-100,13000],ystyle=1
plot,DIFA_DAS_SELECT,color=0,charsize=cs,title='DIFA DAS_SELECT',xstyle=1,yrange=[-10,2],ystyle=1
window,4
Device, decomposed=0, retain=2
!p.background = 255
!p.multi=[0,1,3]
loadct,39
plot,TZERO_MANTID ,color=0,charsize=cs,title='TZERO MANTID SELECT',xstyle=1,yrange=[-350,200],ystyle=1
plot,DIFC_MANTID ,color=0,charsize=cs,title='DIFC MANTID SELECT',xstyle=1,yrange=[-100,13000],ystyle=1
plot,DIFA_MANTID ,color=0,charsize=cs,title='DIFA MANTID SELECT',xstyle=1,yrange=[-10,2],ystyle=1
endif
if dowrite eq 1 then begin
;# number UDET offset select group
;define data location
basedir = '/SNS/NOM/IPTS-/shared/autoNOM/'
runnum='47702'
;set ndw file name
h5file='nomad_cal_example_6.hdf'
h5fid=h5f_create(h5file)
fname='h5 cal data'
gid=h5g_create(h5fid,'calibration')
;write instrument
gid2=h5g_create(gid,'instrument')
nomad=['nomad']
type_id=h5t_idl_create(nomad)
space_id=h5s_create_simple(size(nomad,/dimensions))
id=h5d_create(gid2,'name',type_id,space_id)
h5d_write,id,nomad
h5d_close,id
h5s_close,space_id
h5t_close,type_id
h5g_close,gid2
;write difc
type_id=h5t_idl_create(difc_mantid)
space_id=h5s_create_simple(size(difc_mantid,/dimensions))
id=h5d_create(gid,'difc',type_id,space_id)
h5d_write,id,difc_mantid
h5d_close,id
h5s_close,space_id
h5t_close,type_id
;write difa
type_id=h5t_idl_create(difa_mantid)
space_id=h5s_create_simple(size(difa_mantid,/dimensions))
id=h5d_create(gid,'difa',type_id,space_id)
h5d_write,id,difa_mantid
h5d_close,id
h5s_close,space_id
h5t_close,type_id
;write TZERO Mantid
type_id=h5t_idl_create(tzero_mantid)
space_id=h5s_create_simple(size(tzero_mantid,/dimensions))
id=h5d_create(gid,'tzero',type_id,space_id)
h5d_write,id,tzero_mantid
h5d_close,id
h5s_close,space_id
h5t_close,type_id
;write mantid detector IDs
type_id=h5t_idl_create(long(det_id))
space_id=h5s_create_simple(size(long(det_id),/dimensions))
id=h5d_create(gid,'detid',type_id,space_id)
h5d_write,id,det_id
h5d_close,id
h5s_close,space_id
h5t_close,type_id
;write DAS IDs - this approach derived from expanded data which leaves gaps in the UDET numbers
;type_id=h5t_idl_create(long(udet))
;space_id=h5s_create_simple(size(long(udet),/dimensions))
;id=h5d_create(gid,'dasid',type_id,space_id)
;h5d_write,id,udet
;h5d_close,id
;h5s_close,space_id
;h5t_close,type_id
;write DAS IDs - derive DAS IDs from the data
dasid=lindgen(NPTS)
type_id=h5t_idl_create(dasid)
space_id=h5s_create_simple(size(long(dasid),/dimensions))
id=h5d_create(gid,'dasid',type_id,space_id)
h5d_write,id,dasid
h5d_close,id
h5s_close,space_id
h5t_close,type_id
;write group
type_id=h5t_idl_create(long(group_mantid))
space_id=h5s_create_simple(size(long(group_mantid),/dimensions))
id=h5d_create(gid,'group',type_id,space_id)
h5d_write,id,group_mantid
h5d_close,id
h5s_close,space_id
h5t_close,type_id
;write "use" (formerly select)
type_id=h5t_idl_create(long(select_mantid))
space_id=h5s_create_simple(size(long(select_mantid),/dimensions))
id=h5d_create(gid,'use',type_id,space_id)
h5d_write,id,select_mantid
h5d_close,id
h5s_close,space_id
h5t_close,type_id
;write offset
type_id=h5t_idl_create(offset_mantid)
space_id=h5s_create_simple(size(offset_mantid,/dimensions))
id=h5d_create(gid,'offset',type_id,space_id)
h5d_write,id,offset_mantid
h5d_close,id
h5s_close,space_id
h5t_close,type_id
h5g_close,gid
h5f_close,h5fid
endif
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment