From 163c0ff09b8235999fba7d491f17f544d9b792fa Mon Sep 17 00:00:00 2001 From: gac-x11ma Date: Wed, 30 Jun 2021 16:15:12 +0200 Subject: [PATCH] Shift calculation tests --- .../Co_L3_XAS_sv96p79_sandy.abs | Bin 0 -> 307 bytes config/AbsortionSpectrum/Co_L3_sandy.abs | Bin 0 -> 307 bytes config/AbsortionSpectrum/Co_L3_sandy_2.abs | Bin 0 -> 515 bytes config/AbsortionSpectrum/Pd_M3.abs | Bin 0 -> 203 bytes config/AbsortionSpectrum/Pd_M5.abs | Bin 0 -> 203 bytes .../S_L23_XAS_sv96p79_sandy.abs | Bin 0 -> 203 bytes .../Sn_M45_XAS_sv96p79_sandy.abs | Bin 0 -> 307 bytes config/AbsortionSpectrum/Sn_M45_sandy.abs | Bin 0 -> 307 bytes config/ROIs/FGT.roi | Bin 0 -> 266 bytes config/ROIs/SCRO.roi | Bin 0 -> 266 bytes config/devices.properties | 18 +- config/scicat.properties | 6 +- config/session_metadata.properties | 6 +- config/sessions.properties | 4 +- config/settings.properties | 23 +- config/variables.properties | 8 +- devices/Position.properties | 10 + devices/Time.properties | 10 + devices/exit_slit.properties | 18 + devices/exit_slit_motor.properties | 18 + devices/exit_slit_old.properties | 10 + devices/fe_slit_H_size.properties | 10 + devices/fe_slit_V_size.properties | 10 + devices/image.properties | 4 +- devices/image2.properties | 25 + devices/shift_0000.png.properties | 20 + devices/shift_0001.png.properties | 20 + plugins/Align_ComplexEdgeFiltering.java | 154 ++++ plugins/Align_ComputeShifts.java | 717 ++++++++++++++++ plugins/Align_TranslationFilter.java | 115 +++ plugins/Eiger.form | 33 +- plugins/Eiger.java | 70 +- plugins/ShiftsIO.java | 109 +++ script/Test_Autofocus_Armin.py | 36 +- script/Users/Armin/TestUserScript_Armin.py | 0 script/Users/Cinthia/2021_june_Energy.py | 174 ++++ script/Users/Cinthia/Fe_XMCD.py | 24 + script/Users/Cinthia/Fe_XMCD_hyst.py | 763 ++++++++++++++++++ script/Users/Cinthia/Fe_XMCD_hyst_1.py | 67 ++ .../Cinthia/Fe_XMCD_hyst_1sample_1voltage.py | 78 ++ script/Users/Cinthia/Fe_XMCD_hyst_cofield.py | 613 ++++++++++++++ script/Users/Cinthia/Test_alingment.py | 2 + script/Users/Cinthia/apply_voltage.py | 22 + script/Users/Cinthia/field_sweepID2.py | 119 +++ script/Users/Cinthia/hyst_ID2_Fe.py | 48 ++ .../Users/Cinthia/hyst_ID2_Fe_all_samples.py | 238 ++++++ script/Users/Cinthia/night.py | 2 + script/Users/Cinthia/troubleshooting.py | 3 + .../Sridhar/{ => 2017}/EnergyScanID1only.py | 0 .../Sridhar/{ => 2017}/EnergyScanID2only.py | 0 .../Users/Sridhar/{ => 2017}/field_sweep.py | 0 .../Sridhar/{ => 2017}/field_sweepID1.py | 0 .../Sridhar/{ => 2017}/field_sweepID2.py | 0 .../Sridhar/{ => 2017}/field_sweep_old.py | 0 .../Users/Sridhar/{ => 2017}/harmonic_ID1.xml | 0 .../Users/Sridhar/{ => 2017}/harmonic_ID2.xml | 0 script/Users/Sridhar/{ => 2017}/hyst_ID1.py | 0 script/Users/Sridhar/{ => 2017}/hyst_ID2.py | 0 .../Users/Sridhar/{ => 2017}/hyst_ID2_Co.py | 0 .../Users/Sridhar/{ => 2017}/hyst_ID2_Fe.py | 0 script/Users/Sridhar/{ => 2017}/test.py | 0 script/Users/Sridhar/{ => 2017}/test_field.py | 0 .../Users/Sridhar/{ => 2017}/test_fieldID1.py | 0 .../Users/Sridhar/{ => 2017}/test_fieldID2.py | 0 .../Users/Sridhar/{ => 2017}/xmcdID1&ID2.py | 0 script/Users/Sridhar/{ => 2017}/xmcdID1.py | 0 script/Users/Sridhar/{ => 2017}/xmcdID2.py | 0 script/Users/Sridhar/{ => 2017}/xmcdID2_Co.py | 0 script/Users/Sridhar/{ => 2017}/xmcdID2_Fe.py | 0 script/Users/Sridhar/{ => 2017}/xmcdID2_Ru.py | 0 script/Users/Sridhar/Test.py | 1 + script/Users/federico/2021_may_beamtime.py | 6 +- script/Users/federico/test.py | 24 + script/imaging/shifts.py | 642 +++++++++++++++ script/local.py | 18 +- script/old_scripts/EnergyScanID2only_juraj.py | 185 ----- script/templates/EnergyScan_v2.py | 9 +- script/test/ExitSlitCalib.py | 83 ++ script/test/LEEM_example_scans.py | 31 +- script/test/TestBasler.py | 33 + script/test/TestMscan.py | 23 + script/test/TestShifts.py | 90 +++ script/test/TestUserScript.py | 0 83 files changed, 4434 insertions(+), 318 deletions(-) create mode 100644 config/AbsortionSpectrum/Co_L3_XAS_sv96p79_sandy.abs create mode 100644 config/AbsortionSpectrum/Co_L3_sandy.abs create mode 100644 config/AbsortionSpectrum/Co_L3_sandy_2.abs create mode 100644 config/AbsortionSpectrum/Pd_M3.abs create mode 100644 config/AbsortionSpectrum/Pd_M5.abs create mode 100644 config/AbsortionSpectrum/S_L23_XAS_sv96p79_sandy.abs create mode 100644 config/AbsortionSpectrum/Sn_M45_XAS_sv96p79_sandy.abs create mode 100644 config/AbsortionSpectrum/Sn_M45_sandy.abs create mode 100644 config/ROIs/FGT.roi create mode 100644 config/ROIs/SCRO.roi create mode 100644 devices/Position.properties create mode 100644 devices/Time.properties create mode 100644 devices/exit_slit.properties create mode 100644 devices/exit_slit_motor.properties create mode 100644 devices/exit_slit_old.properties create mode 100644 devices/fe_slit_H_size.properties create mode 100644 devices/fe_slit_V_size.properties create mode 100755 devices/image2.properties create mode 100644 devices/shift_0000.png.properties create mode 100644 devices/shift_0001.png.properties create mode 100644 plugins/Align_ComplexEdgeFiltering.java create mode 100644 plugins/Align_ComputeShifts.java create mode 100644 plugins/Align_TranslationFilter.java create mode 100644 plugins/ShiftsIO.java mode change 100644 => 100755 script/Users/Armin/TestUserScript_Armin.py create mode 100755 script/Users/Cinthia/2021_june_Energy.py create mode 100644 script/Users/Cinthia/Fe_XMCD.py create mode 100644 script/Users/Cinthia/Fe_XMCD_hyst.py create mode 100644 script/Users/Cinthia/Fe_XMCD_hyst_1.py create mode 100644 script/Users/Cinthia/Fe_XMCD_hyst_1sample_1voltage.py create mode 100644 script/Users/Cinthia/Fe_XMCD_hyst_cofield.py create mode 100644 script/Users/Cinthia/Test_alingment.py create mode 100644 script/Users/Cinthia/apply_voltage.py create mode 100755 script/Users/Cinthia/field_sweepID2.py create mode 100755 script/Users/Cinthia/hyst_ID2_Fe.py create mode 100644 script/Users/Cinthia/hyst_ID2_Fe_all_samples.py create mode 100644 script/Users/Cinthia/night.py create mode 100644 script/Users/Cinthia/troubleshooting.py rename script/Users/Sridhar/{ => 2017}/EnergyScanID1only.py (100%) rename script/Users/Sridhar/{ => 2017}/EnergyScanID2only.py (100%) rename script/Users/Sridhar/{ => 2017}/field_sweep.py (100%) rename script/Users/Sridhar/{ => 2017}/field_sweepID1.py (100%) rename script/Users/Sridhar/{ => 2017}/field_sweepID2.py (100%) rename script/Users/Sridhar/{ => 2017}/field_sweep_old.py (100%) rename script/Users/Sridhar/{ => 2017}/harmonic_ID1.xml (100%) rename script/Users/Sridhar/{ => 2017}/harmonic_ID2.xml (100%) rename script/Users/Sridhar/{ => 2017}/hyst_ID1.py (100%) rename script/Users/Sridhar/{ => 2017}/hyst_ID2.py (100%) rename script/Users/Sridhar/{ => 2017}/hyst_ID2_Co.py (100%) rename script/Users/Sridhar/{ => 2017}/hyst_ID2_Fe.py (100%) rename script/Users/Sridhar/{ => 2017}/test.py (100%) rename script/Users/Sridhar/{ => 2017}/test_field.py (100%) rename script/Users/Sridhar/{ => 2017}/test_fieldID1.py (100%) rename script/Users/Sridhar/{ => 2017}/test_fieldID2.py (100%) rename script/Users/Sridhar/{ => 2017}/xmcdID1&ID2.py (100%) rename script/Users/Sridhar/{ => 2017}/xmcdID1.py (100%) rename script/Users/Sridhar/{ => 2017}/xmcdID2.py (100%) rename script/Users/Sridhar/{ => 2017}/xmcdID2_Co.py (100%) rename script/Users/Sridhar/{ => 2017}/xmcdID2_Fe.py (100%) rename script/Users/Sridhar/{ => 2017}/xmcdID2_Ru.py (100%) create mode 100644 script/Users/Sridhar/Test.py mode change 100644 => 100755 script/Users/federico/2021_may_beamtime.py create mode 100755 script/Users/federico/test.py create mode 100644 script/imaging/shifts.py delete mode 100755 script/old_scripts/EnergyScanID2only_juraj.py create mode 100644 script/test/ExitSlitCalib.py create mode 100644 script/test/TestBasler.py create mode 100644 script/test/TestMscan.py create mode 100644 script/test/TestShifts.py mode change 100644 => 100755 script/test/TestUserScript.py diff --git a/config/AbsortionSpectrum/Co_L3_XAS_sv96p79_sandy.abs b/config/AbsortionSpectrum/Co_L3_XAS_sv96p79_sandy.abs new file mode 100644 index 0000000000000000000000000000000000000000..168eee27692ba39f5acb7fed25130d73a2e1ef0e GIT binary patch literal 307 zcmZ4UmVvdjh(S2oCo8cmQ75_o3=E7wbt2JN z6iV#>9sDHw_9>V`=F&ojI-mvy2Ik@-1_6Y@F8QTNIjIes4|!>3|7KxgV02+%ElbQP zO|3vt=2x1Vlv>obW~warln32lQyscqfDJ4Lnat|Yt%1a|e*oq%AlZsVl|v6i6~qMl U3pn(ksB-9809FRo^8lg;094IRTL1t6 literal 0 HcmV?d00001 diff --git a/config/AbsortionSpectrum/Co_L3_sandy.abs b/config/AbsortionSpectrum/Co_L3_sandy.abs new file mode 100644 index 0000000000000000000000000000000000000000..7b1c3175b0e26f48821b385db196ab86477af26a GIT binary patch literal 307 zcmZ4UmVvdjh(S2oCo8cmQ75_o3=E7wbt2JN z6iV#>9sDHw_9>V`=F&ojI-mvy2Ik@-1_6Y@F8QTNIjIes4|!>3|7KxgV02+%ElbQP zO|3vt=2x1Vlv>obW~warln32lQyto0fDJ4Lnat|Yp@GD+e*oq%AlZsVl|#oLWIY#f Q=|NWI(76Cv&jW}a0Jj-XKL7v# literal 0 HcmV?d00001 diff --git a/config/AbsortionSpectrum/Co_L3_sandy_2.abs b/config/AbsortionSpectrum/Co_L3_sandy_2.abs new file mode 100644 index 0000000000000000000000000000000000000000..4c0755b5f3bf0837b1230275cd0f40cb379c0c3a GIT binary patch literal 515 zcmZ4UmVvdjh(S2oCo8cmQ75_o3=E7wbt2JN z6iV#>9sDHw_9>V`_R>OzI-mvy2Ik@-1_6Y@F8QTNIjIes4|!>3|7KxgV02+%ElbQP zO|3vt=2x1Vlv>obW~warln32lQyto0fDJ4Lnat|Yp@GD+e*oq%AlZsVl|zREvYrdL z^dPHp=m7bffdOKx{mz*nFbmTjWK|9w2axsPv5_o3=E7wbt2JN z6iV#>9sDHw_9=wILWVk^1_lP^;vxnCguyQPrAaxd4Vw>nX=eXsVPar(VPGvw%qdN+ sKvCvbnwykb)V5}-EccWL-C$E4N)~_(EC!j(>QL%{#Irv+69i@f0PE;LAOHXW literal 0 HcmV?d00001 diff --git a/config/AbsortionSpectrum/Pd_M5.abs b/config/AbsortionSpectrum/Pd_M5.abs new file mode 100644 index 0000000000000000000000000000000000000000..b18faa9574fab08e37293b102776f1426cee4ab1 GIT binary patch literal 203 zcmZ4UmVvdjh(S2oCo8cmQ75_o3=E7wbt2JN z6iV#>9sDHw_9=wILWVk^1_lP^;vxnCguyQPrAaxd4Vw>nX=eXsVPar(VPGvw%qdN+ rKvCvbnwykb)V5}-EccWL-C$E48XUj|7K2P?b!bvR;@O{^2?DbK-(5es literal 0 HcmV?d00001 diff --git a/config/AbsortionSpectrum/S_L23_XAS_sv96p79_sandy.abs b/config/AbsortionSpectrum/S_L23_XAS_sv96p79_sandy.abs new file mode 100644 index 0000000000000000000000000000000000000000..f25817e3add03a5a4af167d52759ceaac458f098 GIT binary patch literal 203 zcmZ4UmVvdjh(S2oCo8cmQ75_o3=E7wbt2JN z6iV#>9sDHw_9=wILWVk^1_lP^;vxnCguyQPrAaxd4Vw>nX=eXsVPar(VPGvw%qdN+ rKvCvbnwykb)V5}-EccWL-C$E4@(zFvEC!j(>QJx%iD!QS%wYfk>JU8z literal 0 HcmV?d00001 diff --git a/config/AbsortionSpectrum/Sn_M45_XAS_sv96p79_sandy.abs b/config/AbsortionSpectrum/Sn_M45_XAS_sv96p79_sandy.abs new file mode 100644 index 0000000000000000000000000000000000000000..68dd04fe51e9a118cb85e6b463472e353d1d0f0f GIT binary patch literal 307 zcmZ4UmVvdjh(S2oCo8cmQ75_o3=E7wbt2JN z6iV#>9sDHw_9>V`=F&ojI-mvy2Ik@-1_6Y@F8QTNIjIes4|!>3|7KxgV02+%ElbQP zO|3vt=2x1Vlv>obW~warln32lQym(AfDJ4Lnat|Y5_o3=E7wbt2JN z6iV#>9sDHw_9>V`=F&ojI-mvy2Ik@-1_6Y@F8QTNIjIes4|!>3|7KxgV02+%ElbQP zO|3vt=2x1Vlv>obW~warln32lQypqSE?{6N2ARz2Q2POiXa4}qVL-AKiz5_o3=E7wbt2JN z6iV#>9sDHw_9>V`rqV)&I-mvy2G$Y=mLPvm!{Qvue=oHiAhp P+QL{2DR5RYoK+0~$xun$ literal 0 HcmV?d00001 diff --git a/config/ROIs/SCRO.roi b/config/ROIs/SCRO.roi new file mode 100644 index 0000000000000000000000000000000000000000..b16fd9d503adb7f8f048491201423322927a64f3 GIT binary patch literal 266 zcmZ4UmVvdjh(S2oCo8cmQ75_o3=E7wbt2JN z6iV#>9sDHw_9>V`rqV)&I-mvy2G$Y=mLPvm!{Ql6?&ME}}sK!Zl literal 0 HcmV?d00001 diff --git a/config/devices.properties b/config/devices.properties index 9a1a34a..ea923f4 100755 --- a/config/devices.properties +++ b/config/devices.properties @@ -1,3 +1,13 @@ +#fe_slit_V_ctr:offset=ch.psi.pshell.epics.ChannelDouble|||| +#fe_slit_V_ctr=ch.psi.pshell.epics.Positioner|X11MA-FE-SV:ctr caget X11MA-FE-SV:t2.D|||true +#fe_slit_H_ctr_offset=ch.psi.pshell.epics.ChannelDouble|||| +#fe_slit_H_ctr=ch.psi.pshell.epics.Positioner|X11MA-FE-SH:ctr X11MA-FE-SH:t2.D|||true +fe_slit_V_size_offs=ch.psi.pshell.epics.ChannelDouble|X11MA-FE-DSVER.A|||true +fe_slit_V_size=ch.psi.pshell.epics.Positioner|X11MA-FE-SV:size X11MA-FE-SV:t2.C|||true +fe_slit_H_size_offs=ch.psi.pshell.epics.ChannelDouble|X11MA-FE-DSHOR.A|||true +fe_slit_H_size=ch.psi.pshell.epics.Positioner|X11MA-FE-SH:size X11MA-FE-SH:t2.C|||true +exit_slit_offset=ch.psi.pshell.epics.ChannelDouble|X11MA-OP2-SL:EOff|||true +exit_slit=ch.psi.pshell.epics.Motor|X11MA-OP2-SL:TRY|||true machine_cur=ch.psi.pshell.epics.ChannelDouble|ARIDI-PCT:CURRENT|Read||true field=ch.psi.pshell.epics.ChannelDouble|X11MA-XMCD:Ireadout|Read||true pol_mode=ch.psi.pshell.epics.DiscretePositioner|X11MA-ID2:MODE|||true @@ -68,13 +78,15 @@ eiger_bit_depth=ch.psi.pshell.epics.ChannelInteger|X11MA-ES1-SD1:cam1:BitDepth|| eiger_mode=ch.psi.pshell.epics.ChannelInteger|X11MA-ES1-SD1:cam1:ImageMode|||true eiger_exposure=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1-SD1:cam1:AcquireTime 2|||true Ecrbk=ch.psi.pshell.epics.ChannelDouble|X11MA-PGM:CERBK|Read||true -CADC1=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC1|Read||true -CADC2=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC2|Read||true -CADC3=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC3|Read||true +#CADC1=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC1|Read||true +#CADC2=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC2|Read||true +#CADC3=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC3|Read||true #CADC4=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC4|Read||true #CADC5=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC5|Read||true #CADC6=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC6|Read||true #CADC7=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC7|Read||true girder_x=ch.psi.pshell.epics.Positioner|X11MA-HG:X_SET X11MA-HG:X1|||true +cam2=ch.psi.pshell.epics.AreaDetector|X11MA-ES1-CAM2|||true image=ch.psi.pshell.imaging.CameraSource|eiger|||true +image2=ch.psi.pshell.imaging.CameraSource|cam2|||true axis=ch.psi.pshell.imaging.MjpegSource|http://axis-x11ma.psi.ch/axis-cgi/mjpg/video.cgi?id=176 true||-200|false diff --git a/config/scicat.properties b/config/scicat.properties index d18b197..f98c227 100755 --- a/config/scicat.properties +++ b/config/scicat.properties @@ -1,11 +1,11 @@ -#Wed Apr 14 15:11:25 CEST 2021 +#Wed Jun 30 15:27:33 CEST 2021 environment=prod testParameters=-testenv -user slssim\:4DMGBarXmr -sourceFolder=/sls/X11MA/Data1/e19148 +sourceFolder=/sls/X11MA/Data1/e18900 prodParameters=\ -user slssim\:4DMGBarXmr devParameters=-devenv -user slssim\:slssim ownerGroup= type=raw parameters=-ingest -allowexistingsource -noninteractive -autoarchive creationLocation=/PSI/SLS/SIM -principalInvestigator=arik.beck@psi.ch +principalInvestigator= diff --git a/config/session_metadata.properties b/config/session_metadata.properties index 8e3ae0a..faa8946 100755 --- a/config/session_metadata.properties +++ b/config/session_metadata.properties @@ -1,5 +1,5 @@ -#Wed May 05 22:02:15 CEST 2021 +#Mon Jun 07 19:28:06 CEST 2021 keywords=List;[] -ownerEmail=String;adirajan@uni-mainz.de +ownerEmail=String;caretta@berkeley.edu contactEmail=String;armin.kleibert@psi.ch -owner=String;Adithya Rajan +owner=String;Lucas Caretta diff --git a/config/sessions.properties b/config/sessions.properties index 1f746d2..7944e2f 100755 --- a/config/sessions.properties +++ b/config/sessions.properties @@ -1,2 +1,2 @@ -#Tue May 11 10:49:31 CEST 2021 -SessionCounter=24 +#Wed Jun 30 09:46:41 CEST 2021 +SessionCounter=29 diff --git a/config/settings.properties b/config/settings.properties index 05c9710..6b8212a 100755 --- a/config/settings.properties +++ b/config/settings.properties @@ -1,19 +1,26 @@ -#Wed May 12 09:47:57 CEST 2021 -proposal=proposal +#Wed Jun 30 16:03:46 CEST 2021 +HARMONIC_ID_1=1 RSYNC_USER= -ENERGY=710 OUTLIERS_THRESHOLD=1000000000 -proposer=proposer NORM_FILE=/sls/X11MA/data/X11MA/Data1/2021/Yona250121/s250121 -AUTO_SWITCH_VALVE=true +AUTO_SWITCH_VALVE=false +DRY_RUN=false +POL_ID_2=Lin_Hor +OFFSET_ID_1=0.0 +ID=ID2 +OFFSET_ID_2=0.0 +proposal=proposal +ENERGY=400.0 +proposer=proposer +POL_ID_1=Circ_Plus RSYNC_HOST= sample=sample RSYNC_PATH= -DRY_RUN=false pgroup=pgroup -POL_ID_2=Lin_Hor +ALPHA_ID_2=30.0 +ALPHA_ID_1=0.0 RSYNC_DEL=true -ID=ID2 AVERAGING_DETECTOR=true FdaBrowser=false authors=author1|author2 +HARMONIC_ID_2=1 diff --git a/config/variables.properties b/config/variables.properties index 75237c4..dcdc367 100755 --- a/config/variables.properties +++ b/config/variables.properties @@ -1,4 +1,4 @@ -#Wed May 12 09:49:36 CEST 2021 -LastRunDate=210512 -FileSequentialNumber=7552 -DaySequentialNumber=18 +#Wed Jun 30 14:55:49 CEST 2021 +LastRunDate=210630 +FileSequentialNumber=8602 +DaySequentialNumber=44 diff --git a/devices/Position.properties b/devices/Position.properties new file mode 100644 index 0000000..3b2220f --- /dev/null +++ b/devices/Position.properties @@ -0,0 +1,10 @@ +#Mon May 31 14:01:51 CEST 2021 +minValue=NaN +unit=null +offset=0.0 +maxValue=NaN +rotation=false +precision=-1 +sign_bit=0 +scale=1.0 +resolution=NaN diff --git a/devices/Time.properties b/devices/Time.properties new file mode 100644 index 0000000..312d4db --- /dev/null +++ b/devices/Time.properties @@ -0,0 +1,10 @@ +#Mon Jun 07 15:00:54 CEST 2021 +minValue=NaN +unit=null +offset=0.0 +maxValue=NaN +rotation=false +precision=-1 +sign_bit=0 +scale=1.0 +resolution=NaN diff --git a/devices/exit_slit.properties b/devices/exit_slit.properties new file mode 100644 index 0000000..849e4e7 --- /dev/null +++ b/devices/exit_slit.properties @@ -0,0 +1,18 @@ +#Tue Jun 22 16:58:14 CEST 2021 +precision=5 +scale=1.0 +estbilizationDelay=0 +resolution=1.0 +minValue=-3000.0 +defaultSpeed=200.0 +sign_bit=0 +monitorByPosition=false +minSpeed=10.0 +offset=0.0 +maxValue=3000.0 +rotation=false +maxSpeed=200.0 +homingType=None +startRetries=1 +unit=micron +hasEnable=false diff --git a/devices/exit_slit_motor.properties b/devices/exit_slit_motor.properties new file mode 100644 index 0000000..82bd339 --- /dev/null +++ b/devices/exit_slit_motor.properties @@ -0,0 +1,18 @@ +#Mon Jun 07 15:56:05 CEST 2021 +offset=0.0 +maxValue=3000.0 +rotation=false +precision=5 +scale=1.0 +estbilizationDelay=0 +maxSpeed=NaN +resolution=1.0 +homingType=None +startRetries=1 +minValue=-3000.0 +unit=micron +defaultSpeed=200.0 +hasEnable=false +sign_bit=0 +monitorByPosition=false +minSpeed=10.0 diff --git a/devices/exit_slit_old.properties b/devices/exit_slit_old.properties new file mode 100644 index 0000000..a9c71be --- /dev/null +++ b/devices/exit_slit_old.properties @@ -0,0 +1,10 @@ +#Mon Jun 07 09:49:47 CEST 2021 +offset=0.0 +maxValue=NaN +rotation=false +precision=5 +scale=1.0 +resolution=1.0 +minValue=NaN +unit=micron +sign_bit=0 diff --git a/devices/fe_slit_H_size.properties b/devices/fe_slit_H_size.properties new file mode 100644 index 0000000..bf8c859 --- /dev/null +++ b/devices/fe_slit_H_size.properties @@ -0,0 +1,10 @@ +#Wed Jun 30 14:15:27 CEST 2021 +offset=0.0 +maxValue=200.0 +rotation=false +precision=3 +scale=1.0 +resolution=0.005 +minValue=-200.0 +unit=mm +sign_bit=0 diff --git a/devices/fe_slit_V_size.properties b/devices/fe_slit_V_size.properties new file mode 100644 index 0000000..daa1e33 --- /dev/null +++ b/devices/fe_slit_V_size.properties @@ -0,0 +1,10 @@ +#Wed Jun 30 10:57:08 CEST 2021 +offset=0.0 +maxValue=200.0 +rotation=false +precision=3 +scale=1.0 +resolution=0.005 +minValue=-200.0 +unit=mm +sign_bit=0 diff --git a/devices/image.properties b/devices/image.properties index a43b320..0c9be59 100755 --- a/devices/image.properties +++ b/devices/image.properties @@ -1,4 +1,4 @@ -#Tue May 11 10:36:23 CEST 2021 +#Wed Jun 30 12:51:54 CEST 2021 spatialCalOffsetY=NaN spatialCalOffsetX=NaN colormapLogarithmic=false @@ -6,7 +6,7 @@ scale=1.0 grayscale=false spatialCalScaleX=NaN spatialCalScaleY=NaN -colormapMax=1.0 +colormapMax=500.0 rescaleOffset=0.0 roiWidth=-1 colormap=Grayscale diff --git a/devices/image2.properties b/devices/image2.properties new file mode 100755 index 0000000..b3586de --- /dev/null +++ b/devices/image2.properties @@ -0,0 +1,25 @@ +#Thu May 27 14:51:41 CEST 2021 +spatialCalOffsetY=NaN +spatialCalOffsetX=NaN +colormapLogarithmic=false +scale=1.0 +grayscale=false +spatialCalScaleX=NaN +spatialCalScaleY=NaN +colormapMax=255.0 +rescaleOffset=0.0 +roiWidth=-1 +colormap=Grayscale +invert=false +colormapMin=0.0 +rotation=0.0 +rotationCrop=false +rescaleFactor=1.0 +spatialCalUnits=mm +flipVertically=false +roiHeight=-1 +flipHorizontally=false +colormapAutomatic=false +roiY=0 +roiX=0 +transpose=false diff --git a/devices/shift_0000.png.properties b/devices/shift_0000.png.properties new file mode 100644 index 0000000..9a376ae --- /dev/null +++ b/devices/shift_0000.png.properties @@ -0,0 +1,20 @@ +#Wed Jun 23 09:10:47 CEST 2021 +spatialCalOffsetY=NaN +invert=false +spatialCalOffsetX=NaN +rotation=0.0 +rotationCrop=false +scale=1.0 +rescaleFactor=1.0 +grayscale=false +spatialCalUnits=mm +flipVertically=false +roiHeight=-1 +spatialCalScaleX=NaN +spatialCalScaleY=NaN +flipHorizontally=false +roiY=0 +roiX=0 +rescaleOffset=0.0 +transpose=false +roiWidth=-1 diff --git a/devices/shift_0001.png.properties b/devices/shift_0001.png.properties new file mode 100644 index 0000000..4d1fe33 --- /dev/null +++ b/devices/shift_0001.png.properties @@ -0,0 +1,20 @@ +#Wed Jun 23 09:20:13 CEST 2021 +spatialCalOffsetY=NaN +invert=false +spatialCalOffsetX=NaN +rotation=0.0 +rotationCrop=false +scale=1.0 +rescaleFactor=1.0 +grayscale=false +spatialCalUnits=mm +flipVertically=false +roiHeight=-1 +spatialCalScaleX=NaN +spatialCalScaleY=NaN +flipHorizontally=false +roiY=0 +roiX=0 +rescaleOffset=0.0 +transpose=false +roiWidth=-1 diff --git a/plugins/Align_ComplexEdgeFiltering.java b/plugins/Align_ComplexEdgeFiltering.java new file mode 100644 index 0000000..73fb949 --- /dev/null +++ b/plugins/Align_ComplexEdgeFiltering.java @@ -0,0 +1,154 @@ +import ij.*; +import ij.ImagePlus; +import ij.ImageStack; +import ij.plugin.filter.PlugInFilter; +import ij.process.ImageProcessor; +import ij.plugin.filter.GaussianBlur; +import ij.gui.GenericDialog; + +/** + * This is a template for a plugin that requires one image to + * be opened, and takes it as parameter. + */ +public class Align_ComplexEdgeFiltering implements PlugInFilter { + protected ImagePlus imp; + private static double g_sigma = 3.0, g_resolution = 1e-4; //filter parameters + private static int filter_output; + //private static int filter_type = 0; + private GaussianBlur gb = new GaussianBlur(); + private int[] sobel_r = new int[] {1,0,-1, 2,0,-2, 1,0,-1}; + private int[] sobel_i = new int[] {1,2,1, 0,0,0, -1,-2,-1}; + + String arg; + final java.util.List output = new java.util.ArrayList(); + public java.util.List getOutput(){ + return output; + } + boolean show=true; + + /** + * This method gets called by ImageJ / Fiji to determine + * whether the current image is of an appropriate type. + * + * @param arg can be specified in plugins.config + * @param image is the currently opened image + */ + public int setup(String arg, ImagePlus image) { + this.imp = image; + this.arg = arg; + /* + * The current return value accepts all gray-scale + * images (if you access the pixels with ip.getf(x, y) + * anyway, that works quite well. + * + * It could also be DOES_ALL; you can add "| NO_CHANGES" + * to indicate that the current image will not be + * changed by this plugin. + * + * Beware of DOES_STACKS: this will call the run() + * method with all slices of the current image + * (channels, z-slices and frames, all). Most likely + * not what you want. + */ + return DOES_8G | DOES_16 | DOES_32 | NO_CHANGES;// | DOES_STACKS; + } + + /** + * This method is run when the current image was accepted. + * + * @param ip is the current slice (typically, plugins use + * the ImagePlus set above instead). + */ + public void run(ImageProcessor ip) { + if ((arg !=null) && (!arg.isBlank())){ + String[] tokens = arg.trim().split(","); + g_sigma = Double.valueOf(tokens[0].trim()); + filter_output = Boolean.valueOf(tokens[1].trim().toLowerCase()) ? 0 : 1; + try{ + show = Boolean.valueOf(tokens[2].trim().toLowerCase()); + } catch (Exception ex){ + show = false; + } + } else { + String[] filter_outputs = {"complex", "real"}; + GenericDialog gd = new GenericDialog("Complex Edge Filtering Options:"); + gd.addSlider("Gaussian blur radius", 0, 20.0, g_sigma); + gd.addChoice("Edge filter output:", filter_outputs, filter_outputs[0]); + //String[] edge_filters = {"Sobel"};//, "Frei&Chen"}; + //gd.addChoice("Task:", edge_filters, edge_filters[0]); + gd.showDialog(); // display the dialog; preview runs in the background now + if (gd.wasCanceled()) return; + g_sigma = gd.getNextNumber(); + filter_output = gd.getNextChoiceIndex(); + } + //filter_type = gd.getNextChoiceIndex(); + exec(); + } + + private void exec() { + // display the results + if (filter_output == 1) { + ImagePlus imp_r = imp.createImagePlus(); + ImageStack stack_r = new ImageStack(imp.getWidth(), imp.getHeight()); + + for (int i = 1; i <= imp.getImageStackSize(); i++) { + ImageProcessor ip_r = imp.getStack().getProcessor(i).duplicate().convertToFloat(); + // Gaussian blurring + gb.blurGaussian(ip_r, g_sigma, g_sigma, g_resolution); + // Sobel edge filtering + ip_r.filter(ImageProcessor.FIND_EDGES); + + stack_r.addSlice(imp.getStack().getSliceLabel(i), ip_r); + IJ.showProgress(i, imp.getImageStackSize()); + } + + //real + imp_r.setStack("EdgeReal_" + imp.getTitle(), stack_r); + imp_r.resetDisplayRange(); + if (show){ + imp_r.show(); + imp_r.updateAndDraw(); + } + output.add(imp_r); + + } else { + ImagePlus imp_r = imp.createImagePlus(); + ImageStack stack_r = new ImageStack(imp.getWidth(), imp.getHeight()); + + ImagePlus imp_i = imp.createImagePlus(); + ImageStack stack_i = new ImageStack(imp.getWidth(), imp.getHeight()); + + for (int i = 1; i <= imp.getImageStackSize(); i++) { + ImageProcessor ip_r = imp.getStack().getProcessor(i).duplicate().convertToFloat(); + // Gaussian blurring + gb.blurGaussian(ip_r, g_sigma, g_sigma, g_resolution); + ImageProcessor ip_i = ip_r.duplicate(); + // Sobel edge filtering + ip_r.convolve3x3(sobel_r); + ip_i.convolve3x3(sobel_i); + + stack_r.addSlice(imp.getStack().getSliceLabel(i), ip_r); + stack_i.addSlice(imp.getStack().getSliceLabel(i), ip_i); + IJ.showProgress(i, imp.getImageStackSize()); + } + + //real + imp_r.setStack("EdgeReal_" + imp.getTitle(), stack_r); + imp_r.resetDisplayRange(); + if (show){ + imp_r.show(); + imp_r.updateAndDraw(); + } + output.add(imp_r); + + //imag + imp_i.setStack("EdgeImag_" + imp.getTitle(), stack_i); + imp_i.resetDisplayRange(); + if (show){ + imp_i.show(); + imp_i.updateAndDraw(); + } + output.add(imp_i); + } + } +} \ No newline at end of file diff --git a/plugins/Align_ComputeShifts.java b/plugins/Align_ComputeShifts.java new file mode 100644 index 0000000..6013eca --- /dev/null +++ b/plugins/Align_ComputeShifts.java @@ -0,0 +1,717 @@ +import ij.*; +import ij.process.*; +import ij.gui.*; +import java.awt.*; +import ij.plugin.PlugIn; +import ij.WindowManager; +//import edu.emory.mathcs.jtransforms.fft.*; +//import edu.emory.mathcs.utils.*; +import org.jtransforms.fft.*; +import org.jtransforms.utils.*; +import flanagan.complex.*; +import flanagan.math.*; +import ij.plugin.frame.RoiManager; +import ij.gui.Roi; + + +public class Align_ComputeShifts implements PlugIn { + protected ImagePlus imp_r, imp_i; + protected int reference_slide; + protected Roi roi; + protected int usfac; + protected boolean debug = true; + double[][] shifts; + boolean allShifts; + + static boolean isPowerOf2(int n) { + if (n == 0) + return false; + + while (n != 1) { + if (n % 2 != 0) + return false; + n = n / 2; + } + return true; + } + + + public void setup(int upscaleFactor, boolean allShifts, ImagePlus imp_r, ImagePlus imp_i, + int reference_slide, Roi roi) { + if (imp_r==null){ + throw new RuntimeException("Real part image must exist!"); + } + + if (roi==null){ + roi = new Roi(0,0,imp_r.getWidth(), imp_r.getHeight()); + } + Rectangle box = roi.getBounds(); + //if (!ConcurrencyUtils.isPowerOf2(box.height) || !ConcurrencyUtils.isPowerOf2(box.width)) { + if (!isPowerOf2(box.height) || !isPowerOf2(box.width)) { + throw new RuntimeException("The selected ROI height and with must be a power of 2"); + } + + this.usfac = upscaleFactor; + this.allShifts = allShifts; + this.imp_r = imp_r; + this.imp_i = imp_i; + this.reference_slide=reference_slide; + this.roi = roi; + + } + + public void run(String arg) { + if (allShifts) { + calculateAllShiftsRun(); + + } else { + calculateShiftsRun(); + } + return; + } + + private void calculateShiftsRun() { + // perform the FFT of each slice + + IJ.showStatus("1/2 Perform FFT of each slice"); + ComplexMatrix[] ffts = computeFFT(); + + // calculate shifts + IJ.showStatus("2/2 Calculate shifts between slices"); + shifts = calculateShifts(ffts); + + /* + // save shifts + ShiftsIO sio = new ShiftsIO(); + sio.save(shifts, "directshifts"); + */ + } + + public double[][] getShifts(){ + return shifts; + } + + private void calculateAllShiftsRun() { + // perform the FFT of each slice + IJ.showStatus("1/2 Perform FFT of each slice"); + ComplexMatrix[] ffts = computeFFT(); + + // calculate shifts + IJ.showStatus("2/2 Calculate shifts between slices"); + shifts = calculateAllShifts(ffts); + + /* + // save shifts + ShiftsIO sio = new ShiftsIO(); + sio.save(shifts, "allshifts"); + */ + } + + // perform the FFT of each slice + private ComplexMatrix[] computeFFT() { + + int slices = imp_r.getStackSize(); + + ComplexMatrix[] ffts = new ComplexMatrix[slices]; + for (int i=1; i <= slices; i++) { + if (imp_i == null) { + ImageProcessor ip = imp_r.getStack().getProcessor(i); + ip.setRoi(roi); + ImageProcessor curr = ip.crop().convertToFloat(); + double[][] data = ImageProcessor_to_FFTArray2D(curr); + ffts[i-1] = fft2(data); + } else { + ImageProcessor ip1, ip2; + ip1 = imp_r.getStack().getProcessor(i); + ip1.setRoi(roi); + ImageProcessor curr_r = ip1.crop().convertToFloat(); + ip2 = imp_i.getStack().getProcessor(i); + ip2.setRoi(roi); + ImageProcessor curr_i = ip2.crop().convertToFloat(); + double[][] data = ImageProcessor_to_FFTComplexArray2D(curr_r, curr_i); + ffts[i-1] = cfft2(data); + } + IJ.showProgress(i, slices); + } + + return ffts; + } + + //calculate the shifts between ffts + private double[][] calculateShifts(ComplexMatrix[] ffts) { + + double[][] shifts = new double[ffts.length][6]; + for (int i = 0; i < ffts.length; i++) { + shifts[i][0] = reference_slide; shifts[i][1] = i+1; + double[] temp = DFTRegistration(ffts[reference_slide - 1], ffts[i]); + shifts[i][2] = temp[2]; shifts[i][3] = temp[3]; + shifts[i][4] = temp[0]; shifts[i][5] = temp[1]; + IJ.showProgress(i + 1, ffts.length); + } + return shifts; // [ref, drifted, dr, dc, error, diffphase] + + } + + //calculate all the shifts between ffts + private double[][] calculateAllShifts(ComplexMatrix[] ffts) { + + double[][] shifts = new double[ffts.length*(ffts.length-1)/2][6]; + int id = 0; + for (int i = 0; i < ffts.length-1; i++) { + for (int j = i+1; j < ffts.length; j++) { + shifts[id][0] = i+1; shifts[id][1] = j+1; + double[] temp = DFTRegistration(ffts[i], ffts[j]); + shifts[id][2] = temp[2]; shifts[id][3] = temp[3]; + shifts[id][4] = temp[0]; shifts[id][5] = temp[1]; + id = id + 1; + IJ.showProgress(id + 1, ffts.length*(ffts.length-1)/2); + } + } + + return shifts; // [ref,drifted,dr,dc,error, diffphase] + } + + // compute 2D fft from an image + private ComplexMatrix fft2(double[][] data) { + + int h = data.length; + int w = data[0].length; + DoubleFFT_2D fft = new DoubleFFT_2D(h, w); + + fft.realForward(data); + ComplexMatrix m = FFTArray2D_to_ComplexMatrix(data, h, w); + + return m; + } + + // compute complex 2D fft from an image + private ComplexMatrix cfft2(double[][] data) { + + int h = data.length; + int w = data[0].length; + DoubleFFT_2D fft = new DoubleFFT_2D(h, w/2); + + fft.complexForward(data); + ComplexMatrix m = FFTComplexArray2D_to_ComplexMatrix(data, h, w/2); + + return m; + } + + // compute inverse 2D fft from a complex matrix + private double[][] ifft2(ComplexMatrix m) { + int w = m.getNcol(); + int h = m.getNrow(); + + DoubleFFT_2D fft = new DoubleFFT_2D(h, w); + + double[][] data = ComplexMatrix_to_FFTArray2D(m); + fft.realInverse(data, true); + + return data; + } + + // compute complex inverse 2D fft from a complex matrix + private ComplexMatrix cifft2(ComplexMatrix m) { + int w = m.getNcol(); + int h = m.getNrow(); + + DoubleFFT_2D fft = new DoubleFFT_2D(h, w); + + double[][] data = new double[h][2*w]; + for (int j=0; j m) { + peak[1] = peak[1] - mlarge; + } + if (peak[2] > n) { + peak[2] = peak[2] - nlarge; + } + + //% If upsampling > 2, then refine estimate with matrix multiply DFT + if (this.usfac > 2) { + // %%% DFT computation %%% + // % Initial shift estimate in upsampled grid + double row_shift = Math.round(peak[1]/2.0*this.usfac)/this.usfac; + double col_shift = Math.round(peak[2]/2.0*this.usfac)/this.usfac; + int dftshift = (int)Math.floor(Math.ceil(this.usfac*1.5)/2); // Center of output array at dftshift+1 + // % Matrix multiply DFT around the current shift estimate + ComplexMatrix in = ElementProduct(drifted, ref.conjugate()); + ComplexMatrix nCC = dftups(in, (int)Math.ceil(this.usfac*1.5), (int)Math.ceil(this.usfac*1.5), + dftshift-row_shift*this.usfac, dftshift-col_shift*this.usfac); + nCC = nCC.times(1.0/(m*n*this.usfac*this.usfac)).conjugate(); + // % Locate maximum and map back to original pixel grid + double[] npeak = cFindPeak(nCC); //max_r, max_i, r, c + + ComplexMatrix mrg00 = dftups(ElementProduct(ref, ref.conjugate()),1,1,0,0); + double rg00 = mrg00.getElementReference(0, 0).abs()/(m*n*this.usfac*this.usfac); + ComplexMatrix mrf00 = dftups(ElementProduct(drifted, drifted.conjugate()),1,1,0,0); + double rf00 = mrf00.getElementReference(0, 0).abs()/(m*n*this.usfac*this.usfac); + + npeak[1] = npeak[1] - dftshift; + npeak[2] = npeak[2] - dftshift; + output[0] = Math.sqrt(Math.abs(1.0 - npeak[0]*npeak[0]/(rg00*rf00))); //error + output[1] = Math.atan2(npeak[4], npeak[3]); //diffphase + output[2] = row_shift + npeak[1]/this.usfac; //delta row + output[3] = col_shift + npeak[2]/this.usfac; //delta col + + } else { + // % If upsampling = 2, no additional pixel shift refinement + double rg00 = SumSquareAbs(ref)/(mlarge*nlarge); + double rf00 = SumSquareAbs(drifted)/(mlarge*nlarge); + + output[0] = Math.sqrt(Math.abs(1.0 - peak[0]*peak[0]/(rg00*rf00))); //error + output[1] = Math.atan2(peak[4], peak[3]); //diffphase + output[2] = peak[1]/2.0; //delta row + output[3] = peak[2]/2.0; //delta col + } + + return output; + } + + private double SumSquareAbs(ComplexMatrix m) { + double sum = 0.0; + + for (int j = 0; j < m.getNrow(); j ++){ + for (int i = 0; i < m.getNcol(); i++) { + sum += m.getElementReference(j, i).squareAbs(); + } + } + + return sum; + } + + private double[] cFindPeak(ComplexMatrix m) { + double max = 0.0; + double realmax = 0.0; + double imagmax = 0.0; + int cmax = 0, rmax = 0; + + for (int j = 0; j < m.getNrow(); j ++){ + for (int i = 0; i < m.getNcol(); i++) { + if (m.getElementReference(j, i).abs() > max) { + max = m.getElementReference(j, i).abs(); + realmax = m.getElementReference(j, i).getReal(); + imagmax = m.getElementReference(j, i).getImag(); + rmax = j; + cmax = i; + } + } + } + + double[] res = new double[5]; + res[0] = Math.sqrt(realmax*realmax+imagmax*imagmax); res[1] = rmax; res[2] = cmax; + res[3] = realmax; res[4] = imagmax; + return res; + } + + private ComplexMatrix fftshift(ComplexMatrix in) { + int nc = in.getNcol(); + int nr = in.getNrow(); + + ComplexMatrix out = new ComplexMatrix (nr, nc); + + int midi = (int)Math.floor(nc/2.0); + int offi = (int)Math.ceil(nc/2.0); + int midj = (int)Math.floor(nr/2.0); + int offj = (int)Math.ceil(nr/2.0); + + for (int j = 0; j < nr; j ++){ + for (int i = 0; i < nc; i++) { + if (j < midj) { + if (i < midi) { + out.setElement(j, i, in.getElementReference(j+offj, i+offi)); + } else { + out.setElement(j, i, in.getElementReference(j+offj, i-midi)); + } + } else { + if (i < midi) { + out.setElement(j, i, in.getElementReference(j-midj, i+offi)); + } else { + out.setElement(j, i, in.getElementReference(j-midj, i-midi)); + } + } + } + } + + return out; + } + + private ComplexMatrix ifftshift(ComplexMatrix in) { + int nc = in.getNcol(); + int nr = in.getNrow(); + + ComplexMatrix out = new ComplexMatrix (nr, nc); + + int midi = (int)Math.ceil(nc/2.0); + int offi = (int)Math.floor(nc/2.0); + int midj = (int)Math.ceil(nr/2.0); + int offj = (int)Math.floor(nr/2.0); + + for (int j = 0; j < nr; j ++){ + for (int i = 0; i < nc; i++) { + if (j < midj) { + if (i < midi) { + out.setElement(j, i, in.getElementReference(j+offj, i+offi)); + } else { + out.setElement(j, i, in.getElementReference(j+offj, i-midi)); + } + } else { + if (i < midi) { + out.setElement(j, i, in.getElementReference(j-midj, i+offi)); + } else { + out.setElement(j, i, in.getElementReference(j-midj, i-midi)); + } + } + } + } + + return out; + } + + private Matrix ifftshift(Matrix in) { + int nc = in.getNcol(); + int nr = in.getNrow(); + + Matrix out = new Matrix (nr, nc); + + int midi = (int)Math.ceil(nc/2.0); + int offi = (int)Math.floor(nc/2.0); + int midj = (int)Math.ceil(nr/2.0); + int offj = (int)Math.floor(nr/2.0); + + for (int j = 0; j < nr; j ++){ + for (int i = 0; i < nc; i++) { + if (j < midj) { + if (i < midi) { + out.setElement(j, i, in.getElement(j+offj, i+offi)); + } else { + out.setElement(j, i, in.getElement(j+offj, i-midi)); + } + } else { + if (i < midi) { + out.setElement(j, i, in.getElement(j-midj, i+offi)); + } else { + out.setElement(j, i, in.getElement(j-midj, i-midi)); + } + } + } + } + + return out; + } + + public Matrix times(Matrix amat, Matrix bmat){ + + if(amat.getNumberOfColumns()!=bmat.getNumberOfRows())throw new IllegalArgumentException("Nonconformable matrices"); + + Matrix cmat = new Matrix(amat.getNumberOfRows(), bmat.getNumberOfColumns()); + double [][] aarray = amat.getArrayReference(); + double [][] barray = bmat.getArrayReference(); + double [][] carray = cmat.getArrayReference(); + double sum = 0.0D; + + for(int i=0; i 0 && i > 0 && i < w/2) { + m.setElement(j,i, new Complex(data[j][2*i], data[j][2*i+1])); + m.setElement(h-j, w-i, new Complex(data[j][2*i], -data[j][2*i+1])); + } + if (j == 0 && i > 0 && i < w/2) { + m.setElement(0, i, new Complex(data[0][2*i], data[0][2*i+1])); + m.setElement(0, w-i, new Complex(data[0][2*i], -data[0][2*i+1])); + } + if (i == 0 && j > 0 && j < h/2) { + m.setElement(j,0, new Complex(data[j][0], data[j][1])); + m.setElement(h-j, 0, new Complex(data[j][0], -data[j][1])); + m.setElement(j, w/2, new Complex(data[h-j][1], -data[h-j][0])); + m.setElement(h-j, w/2, new Complex(data[h-j][1], data[h-j][0])); + } + if (j == 0 && i == 0) { + m.setElement(0, 0, new Complex(data[0][0], 0)); + } + if (j == 0 && i == w/2) { + m.setElement(0, w/2, new Complex(data[0][1], 0)); + } + if (j == h/2 && i == 0) { + m.setElement(h/2, 0, new Complex(data[h/2][0], 0)); + } + if (j == h/2 && i == w/2) { + m.setElement(h/2, w/2, new Complex(data[h/2][1], 0)); + } + } + } + + return m; + } + + private ComplexMatrix FFTComplexArray2D_to_ComplexMatrix(double[][] data, int h, int w) { + + ComplexMatrix m = new ComplexMatrix(h,w); + + for (int j = 0; j < h; j++) { + for (int i = 0; i < w; i++) { + m.setElement(j,i, new Complex(data[j][2*i], data[j][2*i+1])); + } + } + + return m; + } + + private double[][] ComplexMatrix_to_FFTArray2D(ComplexMatrix m) { + int w = m.getNcol(); + int h = m.getNrow(); + double[][] data = new double[h][w]; + + for (int j = 0; j < h; j++) { + for (int i = 0; i <= w/2; i++) { + if (j > 0 && i > 0 && i < w/2) { + data[j][2*i] = m.getElementReference(j,i).getReal(); + data[j][2*i+1] = m.getElementReference(j,i).getImag(); + } + if (j == 0 && i > 0 && i < w/2) { + data[0][2*i] = m.getElementReference(0,i).getReal(); + data[0][2*i+1] = m.getElementReference(0,i).getImag(); + } + if (i == 0 && j > 0 && j < h/2) { + data[j][0] = m.getElementReference(j,0).getReal(); + data[j][1] = m.getElementReference(j,0).getImag(); + data[h-j][1] = m.getElementReference(j,w/2).getReal(); + data[h-j][0] = m.getElementReference(h-j,w/2).getImag(); + } + if (j == 0 && i == 0) { + data[0][0] = m.getElementReference(0,0).getReal(); + } + if (j == 0 && i == w/2) { + data[0][1] = m.getElementReference(0,w/2).getReal(); + } + if (j == h/2 && i == 0) { + data[h/2][0] = m.getElementReference(h/2,0).getReal(); + } + if (j == h/2 && i == w/2) { + data[h/2][1] = m.getElementReference(h/2,w/2).getReal(); + } + } + } + + return data; + } + + // convert a Complex Matrix into an 2d real part array data[0][][] + // and 2d imaginary part data[1][][] + private double[][][] ComplexMatrix_to_RealArray2D(ComplexMatrix m) { + int w = m.getNcol(); + int h = m.getNrow(); + double[][][] data = new double[2][h][w]; + + for (int j = 0; j < h; j++) { + for (int i = 0; i < w; i++) { + data[0][j][i] = m.getElementReference(j,i).getReal(); + data[1][j][i] = m.getElementReference(j,i).getImag(); + } + } + + return data; + } +} \ No newline at end of file diff --git a/plugins/Align_TranslationFilter.java b/plugins/Align_TranslationFilter.java new file mode 100644 index 0000000..416c0cb --- /dev/null +++ b/plugins/Align_TranslationFilter.java @@ -0,0 +1,115 @@ +import ij.plugin.filter.ExtendedPlugInFilter; +import ij.plugin.filter.PlugInFilterRunner; +import ij.plugin.filter.GaussianBlur; +import ij.*; +import ij.process.*; + +import ij.io.OpenDialog; +import ij.io.SaveDialog; +import java.util.ArrayList; +import java.io.IOException; +import java.io.File; +import jmatio.types.*; +import jmatio.io.*; +import ij.gui.GenericDialog; +import ij.IJ; +import ij.Prefs; + +public class Align_TranslationFilter implements ExtendedPlugInFilter { + private double[][] shifts; + private final int flags = (DOES_ALL-DOES_RGB)|DOES_STACKS|NO_CHANGES|FINAL_PROCESSING; + private ImagePlus imp; + private ImagePlus registred; + private ImageStack translated; + private PlugInFilterRunner pifr; + private int nbslices = 0; + private int processed = 0; + + public void setShifts(double[][] shifts){ + this.shifts = shifts; + } + + public double[][] getShifts(){ + return shifts; + } + + public ImagePlus getOutput(){ + return registred; + } + + public void setImp(ImagePlus imp){ + this.imp = imp; + } + + /** + * This method is called by ImageJ for initialization. + * @param arg Unused here. For plugins in a .jar file this argument string can + * be specified in the plugins.config file of the .jar archive. + * @param imp The ImagePlus containing the image (or stack) to process. + * @return The method returns flags (i.e., a bit mask) specifying the + * capabilities (supported formats, etc.) and needs of the filter. + * See PlugInFilter.java and ExtendedPlugInFilter in the ImageJ + * sources for details. + */ + public int setup(String arg, ImagePlus imp) { + System.out.println("Setup " + arg); + if ("final".equals(arg)) { + registred.setStack("REG_" + this.imp.getTitle(), translated); + return DONE; + } else { + if (imp==null ){ + this.imp = imp; + } + return flags; + } + } + + /** Called by ImageJ after setup. */ + public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { + pifr = pfr; + + //ShiftsIO sio = new ShiftsIO(); + //shifts = sio.load(null, "directshifts"); + //if (shifts == null) return DONE; + + //IJ.register(this.getClass()); // protect static class variables (filter parameters) from garbage collection + //return IJ.setupDialog(imp, flags); // ask whether to process all slices of stack (if a stack) + return flags; + } + + /** Process a FloatProcessor (with the CONVERT_TO_FLOAT flag, ImageJ does the conversion to float). + * Called by ImageJ for each stack slice (when processing a full stack); for RGB also called once for each color. */ + public void run(ImageProcessor ip) { + // translate from shifts + if (Thread.currentThread().isInterrupted()) return; + + int thisone = pifr.getSliceNumber(); + + ImageProcessor nip = ip.duplicate().convertToFloat(); + nip.setInterpolationMethod(ImageProcessor.BICUBIC); + if (shifts.length != nbslices) { + nip.translate(shifts[1][3], shifts[1][2]); // translate all the frame by the + // same shifts + } else { + nip.translate(shifts[thisone-1][3], shifts[thisone-1][2]); + } + + String lbl = imp.getStack().getSliceLabel(thisone); + if (lbl != null) { + translated.addSlice(lbl, nip, thisone - 1); + } else { + translated.addSlice("" + thisone, nip, thisone - 1); + } + translated.deleteSlice(thisone + 1); + + processed++; + IJ.showProgress(processed, nbslices); + } + + /** Called by ImageJ to set the number of calls to run(ip) corresponding to 100% of the progress bar */ + public void setNPasses(int nPasses) { + nbslices = nPasses; + registred = imp.createImagePlus(); + translated = new ImageStack(imp.getWidth(), imp.getHeight(), nbslices); + } +} \ No newline at end of file diff --git a/plugins/Eiger.form b/plugins/Eiger.form index d6e73ac..7e23739 100755 --- a/plugins/Eiger.form +++ b/plugins/Eiger.form @@ -32,8 +32,6 @@ - - @@ -61,11 +59,9 @@ - - - + @@ -98,7 +94,6 @@ - @@ -109,7 +104,6 @@ - @@ -164,11 +158,10 @@ - - - - - + + + + @@ -180,14 +173,6 @@ - - - - - - - - @@ -241,14 +226,6 @@ - - - - - - - - diff --git a/plugins/Eiger.java b/plugins/Eiger.java index f0964dc..64331ff 100755 --- a/plugins/Eiger.java +++ b/plugins/Eiger.java @@ -92,7 +92,6 @@ public class Eiger extends Panel { renderer = new ch.psi.pshell.imaging.Renderer(); jLabel1 = new javax.swing.JLabel(); comboDepth = new javax.swing.JComboBox<>(); - buttonStartDetector = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); comboMode = new javax.swing.JComboBox<>(); jLabel3 = new javax.swing.JLabel(); @@ -100,7 +99,6 @@ public class Eiger extends Panel { deviceValuePanel1 = new ch.psi.pshell.swing.DeviceValuePanel(); deviceValuePanel2 = new ch.psi.pshell.swing.DeviceValuePanel(); deviceValuePanel3 = new ch.psi.pshell.swing.DeviceValuePanel(); - buttonStopDetector = new javax.swing.JButton(); deviceValuePanel4 = new ch.psi.pshell.swing.DeviceValuePanel(); buttonShowDetectorPanel = new javax.swing.JButton(); checkMeasurements = new javax.swing.JCheckBox(); @@ -120,7 +118,7 @@ public class Eiger extends Panel { jLabel1.setText("Bit Depth:"); - comboDepth.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "4", "8", "16", "32" })); + comboDepth.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "8", "16", "32" })); comboDepth.setEnabled(false); comboDepth.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -128,13 +126,6 @@ public class Eiger extends Panel { } }); - buttonStartDetector.setText("Start EIGER"); - buttonStartDetector.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStartDetectorActionPerformed(evt); - } - }); - jLabel2.setText("Mode:"); comboMode.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Single", "Continuous" })); @@ -161,13 +152,6 @@ public class Eiger extends Panel { deviceValuePanel3.setDeviceName("eiger_exposure_rbv"); - buttonStopDetector.setText("Stop EIGER"); - buttonStopDetector.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStopDetectorActionPerformed(evt); - } - }); - deviceValuePanel4.setDeviceName("eiger_status"); buttonShowDetectorPanel.setText("Control Panel"); @@ -258,9 +242,7 @@ public class Eiger extends Panel { .addGap(224, 224, 224) .addComponent(buttonDone, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonCloseVG10, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonStopDetector, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(buttonCloseVG10, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(spinnerExposure, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -282,10 +264,8 @@ public class Eiger extends Panel { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonAquire, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonOpenVG10, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonStartDetector))) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(buttonOpenVG10, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap(118, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -301,7 +281,7 @@ public class Eiger extends Panel { .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) ); - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonStartDetector, buttonStopDetector, comboDepth, comboMode, deviceValuePanel1, deviceValuePanel2, deviceValuePanel3, spinnerExposure}); + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {comboDepth, comboMode, deviceValuePanel1, deviceValuePanel2, deviceValuePanel3, spinnerExposure}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -313,8 +293,7 @@ public class Eiger extends Panel { .addComponent(deviceValuePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonAquire, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonOpenVG10, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonStartDetector))) + .addComponent(buttonOpenVG10, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER, false) .addComponent(jLabel1) @@ -322,8 +301,7 @@ public class Eiger extends Panel { .addComponent(deviceValuePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonDone, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonCloseVG10, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(buttonStopDetector))) + .addComponent(buttonCloseVG10, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel3) @@ -353,7 +331,7 @@ public class Eiger extends Panel { .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)))) ); - layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {buttonStartDetector, buttonStopDetector, comboDepth, comboMode, deviceValuePanel1, deviceValuePanel2, deviceValuePanel3, deviceValuePanel4, spinnerExposure}); + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboDepth, comboMode, deviceValuePanel1, deviceValuePanel2, deviceValuePanel3, deviceValuePanel4, spinnerExposure}); }// //GEN-END:initComponents @@ -365,8 +343,6 @@ public class Eiger extends Panel { buttonDoneActionPerformed(null); eiger.waitState(State.Ready, 10000); //Timeout of 10s } - //((ch.psi.pshell.device.Camera) getDevice("eiger")).stop(); - //TimeUnit.SECONDS.sleep(1); if (comboDepth.getSelectedIndex()!=comboDepth.getItemCount()) { Integer value = Integer.valueOf((String)comboDepth.getSelectedItem()); bitDepth.write(value); @@ -377,19 +353,6 @@ public class Eiger extends Panel { } }//GEN-LAST:event_comboDepthActionPerformed - private void buttonStartDetectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartDetectorActionPerformed - try { - evalAsync("start_eiger_ioc()").handle((ret,ex)->{ - if (ex!=null){ - showException((Exception)ex); - } - return ret; - }); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonStartDetectorActionPerformed - private void comboModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboModeActionPerformed try{ if (!updatingControls){ @@ -398,8 +361,6 @@ public class Eiger extends Panel { buttonDoneActionPerformed(null); eiger.waitState(State.Ready, 10000); //Timeout of 10s } - //((ch.psi.pshell.device.Camera) getDevice("eiger")).stop(); - //TimeUnit.SECONDS.sleep(1); Integer value = comboMode.getSelectedIndex(); if (value==1){ value++; @@ -428,19 +389,6 @@ public class Eiger extends Panel { } }//GEN-LAST:event_spinnerExposureStateChanged - private void buttonStopDetectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopDetectorActionPerformed - try { - evalAsync("stop_eiger_ioc()").handle((ret,ex)->{ - if (ex!=null){ - showException((Exception)ex); - } - return ret; - }); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonStopDetectorActionPerformed - private void buttonShowDetectorPanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowDetectorPanelActionPerformed try { showDevicePanel("eiger"); @@ -553,8 +501,6 @@ public class Eiger extends Panel { private javax.swing.JButton buttonDone; private javax.swing.JButton buttonOpenVG10; private javax.swing.JButton buttonShowDetectorPanel; - private javax.swing.JButton buttonStartDetector; - private javax.swing.JButton buttonStopDetector; private javax.swing.JCheckBox checkMeasurements; private javax.swing.JComboBox comboDepth; private javax.swing.JComboBox comboMode; diff --git a/plugins/ShiftsIO.java b/plugins/ShiftsIO.java new file mode 100644 index 0000000..9c3daff --- /dev/null +++ b/plugins/ShiftsIO.java @@ -0,0 +1,109 @@ +import ij.io.OpenDialog; +import ij.io.SaveDialog; +import java.util.ArrayList; +import java.io.IOException; +import java.io.File; +import jmatio.types.*; +import jmatio.io.*; +import ij.gui.GenericDialog; +import ij.IJ; +import ij.Prefs; + +public class ShiftsIO { + + public ShiftsIO () {} + + public double[][] load(String filename, String varname) { + if (filename==null){ + String analysis_dir = Prefs.get("peem.analysis_dir", ""); + OpenDialog od = new OpenDialog("Open_shifts .mat file:", analysis_dir, "shifts.mat"); + String dir = od.getDirectory(); + if (null == dir) return null; // dialog was canceled + if (!dir.endsWith(File.separator)) dir += File.separator; + filename = dir + od.getFileName(); + Prefs.set("peem.analysis_dir", dir); + } + return low_load(filename, varname); + } + + private double[][] low_load(String filename, String varname) { + MatFileReader mfr = null; + try { + mfr = new MatFileReader(filename); + } catch (IOException e) { + System.err.println("Caught IOException: " + + e.getMessage()); + } + + if (mfr != null) { + MLDouble array = (MLDouble)mfr.getMLArray(varname); + if (array != null){ + return array.getArray(); + } else { + return null; + } + } else { + return null; + } + } + + public void save(String filename, double[][] shifts, String varname) { + boolean update = false; + if (filename==null){ + String analysis_dir = Prefs.get("peem.analysis_dir", ""); + SaveDialog sd = new SaveDialog("Save_shifts .mat file:", analysis_dir, "shifts.mat", ".mat"); + String dir = sd.getDirectory(); + String fname = sd.getFileName(); + if (null == fname) return; // user canceled dialog + if (!dir.endsWith(File.separator)) dir += File.separator; + Prefs.set("peem.analysis_dir", dir); + + if ((new File(dir + fname)).exists()) { // if file exist, overwrite or update shifts ? + GenericDialog gd = new GenericDialog("Update"); + String[] options = {"overwrite","update"}; + gd.addChoice("Mode of operation with existing file. You want to: ", options, options[0]); + gd.showDialog(); + if (gd.wasCanceled()) return; + if (gd.getNextChoiceIndex() == 1) update = true; + } + filename = dir + fname; + } + double[][] final_shifts; + if (update) { + double[][] prev_shifts = low_load(filename, "directshifts"); + if (prev_shifts == null) { + IJ.error("Can't read the direct shifts in this file"); + return; + } + + if (prev_shifts.length == shifts.length) { + for (int j = 0; j < prev_shifts.length; j++) { + prev_shifts[j][3] += shifts[j][3]; + prev_shifts[j][4] += shifts[j][4]; + } + } else if (shifts.length == 2) {// 2 shifts, like between two slices of different + // sequences + for (int j = 0; j < prev_shifts.length; j++) { + prev_shifts[j][3] += shifts[1][3]; + prev_shifts[j][4] += shifts[1][4]; + } + } else { + IJ.error("Old and new shifts have incompatible length !"); + return; + } + final_shifts = prev_shifts; + } else { + final_shifts = shifts; + } + + MLDouble mlDouble = new MLDouble(varname, final_shifts); + ArrayList list = new ArrayList(); + list.add(mlDouble); + try { + new MatFileWriter(filename, list); + } catch (IOException e) { + System.err.println("Caught IOException: " + + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/script/Test_Autofocus_Armin.py b/script/Test_Autofocus_Armin.py index b0876ae..c31ae5f 100755 --- a/script/Test_Autofocus_Armin.py +++ b/script/Test_Autofocus_Armin.py @@ -5,7 +5,9 @@ STEP_STIG = 1.0 UPDATE_POSITION = True AVERAGE = 1 width, height = eiger.getImageSize() -ROI = Rectangle(width/3, height/3, width/3, height/3,) +#ROI = Rectangle(width/3, height/3, width/3, height/3,) +#ROI = Rectangle(0, 0, width, height,) +ROI = Rectangle(233,30,128,128) initial_state = objective.read(),obj_stig_a.read(),obj_stig_b.read() print "Initial state:" , initial_state @@ -15,13 +17,45 @@ def apply_pos(pos): obj_stig_a.write(pos[1]) obj_stig_b.write(pos[2]) +def show_roi(): + global ROI + pn=show_panel(image) + ov=Overlays.Rect(Pen(Color.BLUE), Point(ROI.x,ROI.y),Dimension(ROI.width,ROI.height)) + pn.clearOverlays() + pn.addOverlay(ov) +show_roi() + +MAX_SHIFT = 20 +former_data = image.data +def update_roi(): + global former_data, ROI + cur_data = image.data + calc_roi = Roi(ROI.x,ROI.y,ROI.width, ROI.height) + try: + xoff, yoff, error, diffphase = calculate_shift(former_data,cur_data, calc_roi) + print "Calculated shift: ", xoff, yoff, error, diffphase + if (0 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="Hyst_M5_30_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + +#Sample M5 -30 + + + + +#XMCD + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI11:SETVOLTAGE',25) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',20) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',5) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',0) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-5) +time.sleep(1) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-20) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-25) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-30) + + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) +for i in range(2): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-30_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-30_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-30_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-30_Cp') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME="Hyst_M5_-30_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="Hyst_M5_-30_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + + + +#Sample M5 -50V + + + + +open_vg13() +time.sleep(1) + +#XMCD +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI11:SETVOLTAGE',-35) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-40) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-45) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-50) +time.sleep(10) + + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) +for i in range(2): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-50_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-50_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-50_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-50_Cp') + + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME="Hyst_M5_-50_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="Hyst_M5_-50_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + +#Sample M5 50V + + + +open_vg13() +time.sleep(1) + +#XMCD +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI11:SETVOLTAGE',-45) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-40) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-35) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-30) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-25) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-20) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-5) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',0) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',5) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',20) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',25) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',30) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',35) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',40) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',45) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',50) +time.sleep(10) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) +for i in range(2): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_50_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_50_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_50_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_50_Cp') + + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME="Hyst_M5_50_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="Hyst_M5_50_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + +#Sample M5 70V + + + +open_vg13() +time.sleep(1) + +#XMCD +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI11:SETVOLTAGE',55) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',65) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',70) +time.sleep(10) + + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(2): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_70_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_70_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_70_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_70_Cp') + + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME="Hyst_M5_70_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="Hyst_M5_70_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + +#Sample M5 -70V + + + +open_vg13() +time.sleep(1) + +#XMCD +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI11:SETVOLTAGE',65) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',60) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',55) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',50) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',45) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',40) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',35) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',30) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',25) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',20) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',5) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',0) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-5) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-20) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-25) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-30) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-35) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-40) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-45) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-50) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-55) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-60) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-65) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-70) +time.sleep(10) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(2): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-70_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-70_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-70_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-70_Cp') + + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME="Hyst_M5_-70_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="Hyst_M5_-70_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + +#Sample M5 -100V + + + +open_vg13() +time.sleep(1) + +#XMCD +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI11:SETVOLTAGE',-75) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-80) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-85) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-90) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-95) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-100) +time.sleep(10) +''' +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-100_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-100_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-100_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-100_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-100_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-100_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-100_Cp') + + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME="Hyst_M5_-100_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="Hyst_M5_-100_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + +#M5 100V + + + +open_vg13() +time.sleep(1) + +#XMCD +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI11:SETVOLTAGE',-95) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-90) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-85) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-80) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-75) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-70) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-65) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-60) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-55) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-50) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-45) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-40) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-35) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-30) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-25) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-20) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',-5) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',0) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',5) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',20) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',25) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',30) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',35) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',40) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',45) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',50) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',55) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',60) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',65) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',70) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',75) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',80) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',85) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',95) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',100) +time.sleep(10) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) +for i in range(2): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_100_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_100_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_100_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_100_Cp') + + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME="Hyst_M5_100_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="Hyst_M5_100_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + +caput('X11MA-KEI11:SETVOLTAGE',95) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',90) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',85) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',80) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',75) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',70) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',65) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',60) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',55) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',50) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',45) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',40) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',35) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',30) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',25) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',20) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',5) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',0) + +caput('X11MA-KEI11:VOLTOUT','OFF') + +close_vg13() + + + + + + + diff --git a/script/Users/Cinthia/Fe_XMCD_hyst_1.py b/script/Users/Cinthia/Fe_XMCD_hyst_1.py new file mode 100644 index 0000000..14fabba --- /dev/null +++ b/script/Users/Cinthia/Fe_XMCD_hyst_1.py @@ -0,0 +1,67 @@ +#otf(start, end, time, delay = 0.0, mode = None, offset = None, alpha = None, name = None, folder = 'TEST') + +#Sample M5 +TRY.write(2.0) +TRZ.write(24.5) + +open_vg13() +time.sleep(1) + +#XMCD + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +sample_name='M5_100_-20' + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(2): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + +close_vg13() + + + + + + + diff --git a/script/Users/Cinthia/Fe_XMCD_hyst_1sample_1voltage.py b/script/Users/Cinthia/Fe_XMCD_hyst_1sample_1voltage.py new file mode 100644 index 0000000..b85f176 --- /dev/null +++ b/script/Users/Cinthia/Fe_XMCD_hyst_1sample_1voltage.py @@ -0,0 +1,78 @@ +#otf(start, end, time, delay = 0.0, mode = None, offset = None, alpha = None, name = None, folder = 'TEST') + +#Sample M5 +TRY.write(2.0) +TRZ.write(24.5) + +open_vg13() +time.sleep(1) + +#XMCD + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +''' +caput('X11MA-KEI11:VOLTOUT','ON') + +#caput('X11MA-KEI11:VOLTOUT',1) +caput('X11MA-KEI11:SETVOLTAGE',5) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',10) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',15) +time.sleep(1) +caput('X11MA-KEI11:SETVOLTAGE',20) +''' + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 8) +caput('X11MA-KEI12:RANGE', 9) +for i in range(2): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-20_0_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-20_0_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_M5_-20_0_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_M5_-20_0_Cp') + +#HYST +''' +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME="Hyst_M5_-20_0_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="Hyst_M5_-20_0_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') +''' +close_vg13() + + + + + + + diff --git a/script/Users/Cinthia/Fe_XMCD_hyst_cofield.py b/script/Users/Cinthia/Fe_XMCD_hyst_cofield.py new file mode 100644 index 0000000..47da868 --- /dev/null +++ b/script/Users/Cinthia/Fe_XMCD_hyst_cofield.py @@ -0,0 +1,613 @@ +#otf(start, end, time, delay = 0.0, mode = None, offset = None, alpha = None, name = None, folder = 'TEST') + +#Sample M6 150 + +TRY.write(2.0) +TRZ.write(30.0) + +open_vg13() +time.sleep(1) +''' +#XMCD +sample_name='M6_150' + +v_start =0 +v_end = 150 +#run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + +#XMCD +sample_name='M6_150_-20' + +v_start =150 +v_end = -20 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 8) +caput('X11MA-KEI12:RANGE', 9) + +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 8) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + + + +#XMCD +#sample_name='M6_-150' + +v_start =-20 +v_end = -150 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + +sample_name='M6_-150' + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + +#XMCD +#sample_name='M6_-150_55' + +v_start =-150 +v_end = 55 + + +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + +sample_name='M6_-150_55' + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + +#XMCD +#sample_name='M6_150_0' + +v_start =55 +v_end = 150 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') +v_start =150 +v_end = 0 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + +sample_name='M6_150_0' +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 8) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + +#XMCD +#sample_name='M6_-150_0' + +v_start =0 +v_end = -150 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') +v_start =-150 +v_end = 0 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + +sample_name='M6_-150_0' +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 8) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + +#XMCD +#sample_name='M6_150' + +v_start =0 +v_end = 150 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') +''' +sample_name='M6_150' +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 8) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + +#XMCD +sample_name='M6_150_-20' + +v_start =150 +v_end = -20 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 8) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + +#XMCD +#sample_name='M6_-150' + +v_start =-20 +v_end = -150 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + +sample_name='M6_-150' +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + + + +#XMCD +sample_name='M6_-150_55' + +v_start =-150 +v_end = 55 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(15) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) +for i in range(1): + time.sleep(1) + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC +', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cp') + otf2(start=695, end=740, time=3, delay=10, mode='CIRC -', alpha = 0.0, offset=-1.2, name='Fe_'+sample_name + '_Cm') + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + +v_start =55 +v_end = 0 +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/apply_voltage.py') + + +caput('X11MA-KEI11:VOLTOUT','OFF') + +close_vg13() + + + + + + + diff --git a/script/Users/Cinthia/Test_alingment.py b/script/Users/Cinthia/Test_alingment.py new file mode 100644 index 0000000..4063ef1 --- /dev/null +++ b/script/Users/Cinthia/Test_alingment.py @@ -0,0 +1,2 @@ +#otf2(start=703, end=715, time=0.2, delay=5, mode='LINEAR', alpha = 0.0, offset=-1.2, name='test') +otf2(start=450, end=475, time=3.0, delay=5, mode='CIRC -', alpha = 0.0, offset=-1.2, name='test') \ No newline at end of file diff --git a/script/Users/Cinthia/apply_voltage.py b/script/Users/Cinthia/apply_voltage.py new file mode 100644 index 0000000..cdecbbb --- /dev/null +++ b/script/Users/Cinthia/apply_voltage.py @@ -0,0 +1,22 @@ +v_start= -20 +v_end = 0 + +step_size=5 +n=(v_start - v_end)/step_size + +for i in range (int(abs(n))+1): + if v_start > v_end: + v=v_start - i*step_size + #print "reverse" + print ("Apply", v," volts") + caput('X11MA-KEI11:SETVOLTAGE',v) + sleep(0.1) + else: + v= i*step_size+v_start + print "forward" + print ("Apply", v," volts") + caput('X11MA-KEI11:SETVOLTAGE',v) + sleep(0.1) +sleep(20) + + diff --git a/script/Users/Cinthia/field_sweepID2.py b/script/Users/Cinthia/field_sweepID2.py new file mode 100755 index 0000000..c3ffef1 --- /dev/null +++ b/script/Users/Cinthia/field_sweepID2.py @@ -0,0 +1,119 @@ +#Parameters + +sample_name='M4_120' +''' +FILENAME='Hyst_'+ sample_name + '_E2_Cm' +B1 = 1.0 # starting mag. field in Amps +B2 = -1.0 # final mag. field in Amps +BSTEP = 0.5 # step size mag. field in Amps. in Amps (1mT ~0.25A) +ENERGIES = (707.4) #list of energies in eV +MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) +OFFSET2 = -1.2 #ID2 offset +FIELD_PRECISION = 0.04 # +ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed +FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed +ACC_TIME = 0.1 # time in 100ms +''' + + +# List of scans. Each scan is defined as: (start,stop, step) +# to make a whole loop two scans are needed: [(B1, B2, BSTEP),(B2,B1,-BSTEP)] +# to make half of a loop one scan is needed: [(B1, B2, BSTEP),] <- don't forget to put comma before ] +RANGES = [(B1, B2, -BSTEP),(B2,B1,BSTEP)] +set_exec_pars(open=False, tag=FILENAME) + +#open_vg13() + +#Pre-actions +# Here polarization and offsets are set + +caput ("X11PHS-E:OPT","PGM+ID2") +print "ID mode set to PGM+ID2" +#caput(OTF_OFF1,-50) #detune ID1 +caput('X11MA-ID2:ENERGY-OFFS', OFFSET2) +print "ID offset set to ", OFFSET2 +cawait('X11MA-ID2:DONE',1) +print "Offset setting done" + + +if MODE is 1 or 2: + caput('X11MA-ID2:MODE',MODE) + #print "Polarization mode set" +else: + raise Exception("Invalid polarization type: " + MODE) + +cawait('X11MA-ID2:DONE',1) +print "ID mode setting done" + + + + +# setting number of samples to be averaged, which depends on the accumulation time +avg = ACC_TIME * 10 +caput("X11MA-ES1-10ADC:AVG",avg) + +# Generating a list of mag. fields (setpoints) needed for the loop +setpoints = [] +for r in RANGES: + setpoints = setpoints + frange(r[0], r[1], r[2], True) + +# plot properties +set_preference(Preference.ENABLED_PLOTS, ['field', 'tey_norm']) +set_preference(Preference.PLOT_TYPES, {'tey_norm':1}) + +#scan = ManualScan(['field', 'Energy'], ['TEY', 'I0', 'polarization', 'temperature', 'RingCurrent', 'tey_norm'] , [min(setpoints), min(ENERGIES)], [max(setpoints), max(ENERGIES)], [len(setpoints)-1, len(ENERGIES)-1]) +scan = ManualScan(['field', 'Energy'], ['I0', 'TEY', 'TFY', 'polarization', 'temperature', 'RingCurrent', 'tey_norm','tfy_norm'] , [min(setpoints), min(ENERGIES)], [max(setpoints), max(ENERGIES)], [len(setpoints)-1, len(ENERGIES)-1]) +scan.start() + +# Main loop +for B in setpoints: + print "Setting field = ", B + caput("X11MA-XMCD:I-SETraw",B) + time.sleep( FIELD_CHANGE_SLEEP ) # Settling time + + #readback1 = caget("X11MA-XMCD:Ireadout") + readback1 = field.read() + + while abs(readback1-B) > FIELD_PRECISION: + #readback1 = caget("X11MA-XMCD:Ireadout") + readback1 = field.read() + time.sleep(0.1) + + for E in ENERGIES: + print "Setting energy = ", E + #caput('X11PHS-E:GO.A', E) + energy.write(E) + time.sleep (0.1) + print "Energy set" + cawait('X11PHS:alldone', 1) + print "done" + + readback2 = energy.read() + if abs(readback2 - E) > 0.1 : # TODO: Check accuracy + raise Exception('Energy could not be set to the value ' + str(E)) + sleep( ENERGY_CHANGE_SLEEP ) # Settling time + + detector1 = keithley_1a.read() #Keithley1 + detector2 = keithley_2a.read() #Keithley2 + detector3 = keithley_3a.read() #Keithley3 + detector4 = caget('X11MA-ID2:MODE') #polarization in ID2 + #detector5 = caget("X11MA-ID2:ALPHA-READ") # polAngle in ID2 + detector6 = caget('X11MA-ES3-LSCI:TEMP_RBV') #temperature.get() + detector7 = caget("ARIDI-PCT:CURRENT") + #detector8 = signal_field_analog_x.read() # fieldAnalogX.get() + + tey_norm = detector2/detector1 + tfy_norm = detector3/detector1 + + #converting polarization strings to integer numbers: C+ -> 1 and C- -> 2 + if detector4 == 'CIRC +': detector4 = 1 + elif detector4 == 'CIRC -': detector4 = 2 + else: detector4 = 0 + #print "step 7" + #scan.append ([B, E], [readback1, readback2], [detector1, detector2, detector4, detector6, detector7, tey_norm]) + scan.append ([B, E], [readback1, readback2], [detector1, detector2, detector3, detector4, detector6, detector7, tey_norm, tfy_norm]) + +scan.end() +caput("X11MA-ES1-10ADC:AVG",1) + +#close_vg13() diff --git a/script/Users/Cinthia/hyst_ID2_Fe.py b/script/Users/Cinthia/hyst_ID2_Fe.py new file mode 100755 index 0000000..6a48096 --- /dev/null +++ b/script/Users/Cinthia/hyst_ID2_Fe.py @@ -0,0 +1,48 @@ + +open_vg13() + + +sample_name='M4_120' + + +#HYST + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) + +for i in range(1): + FILENAME='Hyst_'+ sample_name + '_Cm' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME='Hyst_'+ sample_name + '_Cp' + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + +close_vg13() + + + + + + + diff --git a/script/Users/Cinthia/hyst_ID2_Fe_all_samples.py b/script/Users/Cinthia/hyst_ID2_Fe_all_samples.py new file mode 100644 index 0000000..72f9261 --- /dev/null +++ b/script/Users/Cinthia/hyst_ID2_Fe_all_samples.py @@ -0,0 +1,238 @@ + +time.sleep(1) +open_vg13() +open_vg13() +''' + +#Sample M1 +TRY.write(-1.5) +TRZ.write(14) + +time.sleep(30) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.04 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.03 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.04 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.03 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + +#Sample M2 +TRY.write(-0.9) +TRZ.write(22.5) + + + +time.sleep(30) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.04 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.03 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="M2_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.04 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.03 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + #Sample M3 +TRY.write(-0.9) +TRZ.write(30) + +time.sleep(30) + +FILENAME="M3" + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 8) + +for i in range(1): + FILENAME="M3_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="M3_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') +''' + + #Sample M4 +TRY.write(1.0) +TRZ.write(18) + + + +time.sleep(30) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) + +for i in range(1): + FILENAME="M4_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="M4_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + #Sample M5 +TRY.write(2.0) +TRZ.write(24.5) + +time.sleep(30) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) + + +for i in range(1): + FILENAME="M5_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="M5_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + #Sample M6 +TRY.write(2.0) +TRZ.write(30) + +time.sleep(30) + +caput('X11MA-KEI10:RANGE', 7) +caput('X11MA-KEI11:RANGE', 7) +caput('X11MA-KEI12:RANGE', 9) + + +for i in range(1): + FILENAME="M6_Cm" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 2 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + + FILENAME="M6_Cp" + B1 = 2.0 # starting mag. field in Amps + B2 = -2.0 # final mag. field in Amps + BSTEP = 0.05 # step size mag. field in Amps. in Amps (1mT ~0.25A) + ENERGIES = (700,707.4) #list of energies in eV + MODE = 1 #polarization (CIRC+ -> 1 or CIRC- -> 2) + OFFSET2 = -1.2 #ID2 offset + FIELD_PRECISION = 0.04 # + ENERGY_CHANGE_SLEEP = 0.5 # put the Enerrgy settling time if needed + FIELD_CHANGE_SLEEP = 0.5 # put the Field settling time if needed + ACC_TIME = 0.1 #I think this number x 10 is in seconds + run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/field_sweepID2.py') + +close_vg13() \ No newline at end of file diff --git a/script/Users/Cinthia/night.py b/script/Users/Cinthia/night.py new file mode 100644 index 0000000..95c7f26 --- /dev/null +++ b/script/Users/Cinthia/night.py @@ -0,0 +1,2 @@ +#run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/2021_june_Energy.py')#there was a timeout in the second script, but this one was complete, so I re start from the second one +run('/sls/X11MA/data/X11MA/pshell/home/script/Users/Cinthia/hyst_ID2_Fe_all_samples.py') diff --git a/script/Users/Cinthia/troubleshooting.py b/script/Users/Cinthia/troubleshooting.py new file mode 100644 index 0000000..4ba4064 --- /dev/null +++ b/script/Users/Cinthia/troubleshooting.py @@ -0,0 +1,3 @@ +#energy.write(710) +#time.sleep (2) +cawait('X11PHS:alldone', 0, timeout=5) \ No newline at end of file diff --git a/script/Users/Sridhar/EnergyScanID1only.py b/script/Users/Sridhar/2017/EnergyScanID1only.py similarity index 100% rename from script/Users/Sridhar/EnergyScanID1only.py rename to script/Users/Sridhar/2017/EnergyScanID1only.py diff --git a/script/Users/Sridhar/EnergyScanID2only.py b/script/Users/Sridhar/2017/EnergyScanID2only.py similarity index 100% rename from script/Users/Sridhar/EnergyScanID2only.py rename to script/Users/Sridhar/2017/EnergyScanID2only.py diff --git a/script/Users/Sridhar/field_sweep.py b/script/Users/Sridhar/2017/field_sweep.py similarity index 100% rename from script/Users/Sridhar/field_sweep.py rename to script/Users/Sridhar/2017/field_sweep.py diff --git a/script/Users/Sridhar/field_sweepID1.py b/script/Users/Sridhar/2017/field_sweepID1.py similarity index 100% rename from script/Users/Sridhar/field_sweepID1.py rename to script/Users/Sridhar/2017/field_sweepID1.py diff --git a/script/Users/Sridhar/field_sweepID2.py b/script/Users/Sridhar/2017/field_sweepID2.py similarity index 100% rename from script/Users/Sridhar/field_sweepID2.py rename to script/Users/Sridhar/2017/field_sweepID2.py diff --git a/script/Users/Sridhar/field_sweep_old.py b/script/Users/Sridhar/2017/field_sweep_old.py similarity index 100% rename from script/Users/Sridhar/field_sweep_old.py rename to script/Users/Sridhar/2017/field_sweep_old.py diff --git a/script/Users/Sridhar/harmonic_ID1.xml b/script/Users/Sridhar/2017/harmonic_ID1.xml similarity index 100% rename from script/Users/Sridhar/harmonic_ID1.xml rename to script/Users/Sridhar/2017/harmonic_ID1.xml diff --git a/script/Users/Sridhar/harmonic_ID2.xml b/script/Users/Sridhar/2017/harmonic_ID2.xml similarity index 100% rename from script/Users/Sridhar/harmonic_ID2.xml rename to script/Users/Sridhar/2017/harmonic_ID2.xml diff --git a/script/Users/Sridhar/hyst_ID1.py b/script/Users/Sridhar/2017/hyst_ID1.py similarity index 100% rename from script/Users/Sridhar/hyst_ID1.py rename to script/Users/Sridhar/2017/hyst_ID1.py diff --git a/script/Users/Sridhar/hyst_ID2.py b/script/Users/Sridhar/2017/hyst_ID2.py similarity index 100% rename from script/Users/Sridhar/hyst_ID2.py rename to script/Users/Sridhar/2017/hyst_ID2.py diff --git a/script/Users/Sridhar/hyst_ID2_Co.py b/script/Users/Sridhar/2017/hyst_ID2_Co.py similarity index 100% rename from script/Users/Sridhar/hyst_ID2_Co.py rename to script/Users/Sridhar/2017/hyst_ID2_Co.py diff --git a/script/Users/Sridhar/hyst_ID2_Fe.py b/script/Users/Sridhar/2017/hyst_ID2_Fe.py similarity index 100% rename from script/Users/Sridhar/hyst_ID2_Fe.py rename to script/Users/Sridhar/2017/hyst_ID2_Fe.py diff --git a/script/Users/Sridhar/test.py b/script/Users/Sridhar/2017/test.py similarity index 100% rename from script/Users/Sridhar/test.py rename to script/Users/Sridhar/2017/test.py diff --git a/script/Users/Sridhar/test_field.py b/script/Users/Sridhar/2017/test_field.py similarity index 100% rename from script/Users/Sridhar/test_field.py rename to script/Users/Sridhar/2017/test_field.py diff --git a/script/Users/Sridhar/test_fieldID1.py b/script/Users/Sridhar/2017/test_fieldID1.py similarity index 100% rename from script/Users/Sridhar/test_fieldID1.py rename to script/Users/Sridhar/2017/test_fieldID1.py diff --git a/script/Users/Sridhar/test_fieldID2.py b/script/Users/Sridhar/2017/test_fieldID2.py similarity index 100% rename from script/Users/Sridhar/test_fieldID2.py rename to script/Users/Sridhar/2017/test_fieldID2.py diff --git a/script/Users/Sridhar/xmcdID1&ID2.py b/script/Users/Sridhar/2017/xmcdID1&ID2.py similarity index 100% rename from script/Users/Sridhar/xmcdID1&ID2.py rename to script/Users/Sridhar/2017/xmcdID1&ID2.py diff --git a/script/Users/Sridhar/xmcdID1.py b/script/Users/Sridhar/2017/xmcdID1.py similarity index 100% rename from script/Users/Sridhar/xmcdID1.py rename to script/Users/Sridhar/2017/xmcdID1.py diff --git a/script/Users/Sridhar/xmcdID2.py b/script/Users/Sridhar/2017/xmcdID2.py similarity index 100% rename from script/Users/Sridhar/xmcdID2.py rename to script/Users/Sridhar/2017/xmcdID2.py diff --git a/script/Users/Sridhar/xmcdID2_Co.py b/script/Users/Sridhar/2017/xmcdID2_Co.py similarity index 100% rename from script/Users/Sridhar/xmcdID2_Co.py rename to script/Users/Sridhar/2017/xmcdID2_Co.py diff --git a/script/Users/Sridhar/xmcdID2_Fe.py b/script/Users/Sridhar/2017/xmcdID2_Fe.py similarity index 100% rename from script/Users/Sridhar/xmcdID2_Fe.py rename to script/Users/Sridhar/2017/xmcdID2_Fe.py diff --git a/script/Users/Sridhar/xmcdID2_Ru.py b/script/Users/Sridhar/2017/xmcdID2_Ru.py similarity index 100% rename from script/Users/Sridhar/xmcdID2_Ru.py rename to script/Users/Sridhar/2017/xmcdID2_Ru.py diff --git a/script/Users/Sridhar/Test.py b/script/Users/Sridhar/Test.py new file mode 100644 index 0000000..3c4b854 --- /dev/null +++ b/script/Users/Sridhar/Test.py @@ -0,0 +1 @@ +otf2(start=703, end=715, time=0.2, delay=5, mode='LINEAR', alpha = 0.0, offset=-1.2, name='test') \ No newline at end of file diff --git a/script/Users/federico/2021_may_beamtime.py b/script/Users/federico/2021_may_beamtime.py old mode 100644 new mode 100755 index 352a867..c34bb49 --- a/script/Users/federico/2021_may_beamtime.py +++ b/script/Users/federico/2021_may_beamtime.py @@ -1,11 +1,7 @@ #otf(start, end, time, delay = 0.0, mode = None, offset = None, alpha = None, name = None, folder = 'TEST') -#Sample Na -set_exec_pars(path="/sls/X11MA/data/X11MA/Data1/XAS/210512/LMO/") -nr_loops=2 - -TRY.write(21.0) +TRY.write() TRZ.write(8.2) time.sleep(30) diff --git a/script/Users/federico/test.py b/script/Users/federico/test.py new file mode 100755 index 0000000..05071ab --- /dev/null +++ b/script/Users/federico/test.py @@ -0,0 +1,24 @@ +#otf(start, end, time, delay = 0.0, mode = None, offset = None, alpha = None, name = None, folder = 'TEST') + + +#Sample Na +set_exec_pars(path="/sls/X11MA/data/X11MA/Data1/XAS/2021/2021_05/") +nr_loops=1 + +time.sleep(10) + +open_vg13() +time.sleep(1) + +caput('X11MA-ES3-MAG1:V', 2) +time.sleep(5) +caput('X11MA-ES3-MAG1:V', 1) +time.sleep(2) + + +time.sleep(1) +caput('X11MA-KEI10:RANGE', 6) +caput('X11MA-KEI11:RANGE', 8) +caput('X11MA-KEI12:RANGE', 10) +otf2(start=520, end=570, time=2.5, delay=10, mode='LINEAR', alpha = 90.0, offset=0.0, name='test1052_', folder='/sls/X11MA/data/X11MA/Data1/XAS/2021/2021_05/') + diff --git a/script/imaging/shifts.py b/script/imaging/shifts.py new file mode 100644 index 0000000..8e8cb09 --- /dev/null +++ b/script/imaging/shifts.py @@ -0,0 +1,642 @@ +from ijutils import * +import java.lang.reflect +import flanagan.complex.ComplexMatrix as ComplexMatrix +import flanagan.math.Matrix as Matrix +import flanagan.complex.Complex as Complex +import org.jtransforms.fft.DoubleFFT_2D as DoubleFFT_2D +import math +from startup import ScriptUtils +import ij.plugin.filter.PlugInFilterRunner as PlugInFilterRunner +import ij.plugin.filter.ExtendedPlugInFilter as ExtendedPlugInFilter +import ij.plugin.filter.ExtendedPlugInFilter as ExtendedPlugInFilter +import java.lang.Thread as Thread + + +def new_array(type, *dimensions): + return java.lang.reflect.Array.newInstance(ScriptUtils.getPrimitiveType(type), *dimensions) + +def load_stack(title, file_list, show=False): + ip_list = [] + for f in file_list: + ip_list.append(open_image(expand_path(f))) + stack = create_stack(ip_list, title=title) + if show: + stack.show() + return stack + +def load_test_stack(title="Test", show=False, size=9): + file_list = [] + for index in range(40, 40+size): + file_list.append("{images}/TestObjAligner/i210517_0" + str(index) + "#001.tif") + return load_stack(title, file_list, show) + +def load_corr_stack(title="Corr", show=False): + file_list = [] + for index in range(40, 49): + file_list.append("{images}/TestObjAligner_corr/i210517_0" + str(index) + "#001.tif") + return load_stack(title, file_list, show) + +def complex_edge_filtering(imp, complex=True, g_sigma=3.0, g_resolution=1e-4, show=False, java_code=False): + if java_code: + get_context().getPluginManager().loadInitializePlugin("Align_ComplexEdgeFiltering.java") + complex_edge_filter = get_context().getClassByName("Align_ComplexEdgeFiltering").newInstance() + complex_edge_filter.setup(str(g_sigma)+","+str(complex)+","+str(show), imp) #Gaussian blur radius, Complex (True) or Real (False), show dialog = False + complex_edge_filter.run(imp.getProcessor()) + return complex_edge_filter.output + + gb = GaussianBlur() + sobel_r = [1, 0, -1, 2, 0, -2, 1, 0, -1] + sobel_i = [1, 2, 1, 0, 0, 0, -1, -2, -1] + + imp_r = imp.createImagePlus() + stack_r = ImageStack(imp.getWidth(), imp.getHeight()) + + if (complex): + imp_i = imp.createImagePlus() + stack_i = ImageStack(imp.getWidth(), imp.getHeight()) + for i in range(1, imp.getImageStackSize() + 1): + ip_r = imp.getStack().getProcessor(i).duplicate().convertToFloat() + # Gaussian blurring + gb.blurGaussian(ip_r, g_sigma, g_sigma, g_resolution) + ip_i = ip_r.duplicate() + # Sobel edge filtering + ip_r.convolve3x3(sobel_r) + ip_i.convolve3x3(sobel_i) + + stack_r.addSlice(imp.getStack().getSliceLabel(i), ip_r) + stack_i.addSlice(imp.getStack().getSliceLabel(i), ip_i) + IJ.showProgress(i, imp.getImageStackSize()) + + # imag + imp_i.setStack("EdgeImag_" + imp.getTitle(), stack_i); + imp_i.resetDisplayRange() + if show: + imp_i.show() + imp_i.updateAndDraw() + else: + imp_i = None + for i in range(1, imp.getImageStackSize() + 1): + ip_r = imp.getStack().getProcessor(i).duplicate().convertToFloat() + # Gaussian blurring + gb.blurGaussian(ip_r, g_sigma, g_sigma, g_resolution) + # Sobel edge filtering + ip_r.filter(ImageProcessor.FIND_EDGES) + stack_r.addSlice(imp.getStack().getSliceLabel(i), ip_r) + IJ.showProgress(i, imp.getImageStackSize()) + + # real + imp_r.setStack("EdgeReal_" + imp.getTitle(), stack_r) + imp_r.resetDisplayRange() + if show: + imp_r.show() + imp_r.updateAndDraw() + return [imp_r, imp_i] + +class TranslationFilter(ExtendedPlugInFilter): + def __init__(self): + self.shifts=None + self.flags = (self.DOES_ALL-self.DOES_RGB)|self.DOES_STACKS|self.NO_CHANGES|self.FINAL_PROCESSING + self.imp=None + self.output = None + self.translated = None + self.pifr = None + self.nbslices = 0 + self.processed = 0 + + def setup(self, arg, imp): + if "final"==arg: + self.output.setStack("REG_" + self.imp.getTitle(), self.translated) + return self.DONE + else: + if self.imp is None: + self.imp = imp; + return self.flags; + + def showDialog(self,imp, command, pfr): + self.pifr = pfr + return flags + + # Called by ImageJ to set the number of calls to run(ip) corresponding to 100% of the progress bar + def setNPasses(self, nPasses): + self.nbslices = nPasses; + self.output = self.imp.createImagePlus(); + self.translated = ImageStack(self.imp.getWidth(), self.imp.getHeight(), self.nbslices) + + #Process a FloatProcessor (with the CONVERT_TO_FLOAT flag, ImageJ does the conversion to float). + # Called by ImageJ for each stack slice (when processing a full stack); for RGB also called once for each color. */ + def run(self, ip): + if Thread.currentThread().isInterrupted(): + return + thisone = self.pifr.getSliceNumber() + + nip = ip.duplicate().convertToFloat() + nip.setInterpolationMethod(ImageProcessor.BICUBIC) + if len(self.shifts) != self.nbslices: + xoff, yoff = self.shifts[1][3], self.shifts[1][2] # translate all the frame by the same shifts + else: + xoff, yoff = self.shifts[thisone-1][3], self.shifts[thisone-1][2] + nip.translate(xoff, yoff) + + lbl = self.imp.getStack().getSliceLabel(thisone) + if lbl != None: + self.translated.addSlice(lbl, nip, thisone - 1) + else: + self.translated.addSlice(str(thisone), nip, thisone - 1) + + self.translated.deleteSlice(thisone + 1) + + self.processed+=1 + IJ.showProgress(self.processed, self.nbslices); + +def translate(stack, shifts, show=False, java_code=False): + WindowManager.setTempCurrentImage(stack) + if java_code: + get_context().getPluginManager().loadInitializePlugin("Align_TranslationFilter.java") + translation_filter = get_context().getClassByName("Align_TranslationFilter").newInstance() + translation_filter.imp = imp + translation_filter.shifts = shifts + pfr = PlugInFilterRunner(translation_filter, "", "" ) + ret = translation_filter.output + else: + translation_filter = TranslationFilter() + translation_filter.shifts = shifts + translation_filter.imp = stack + pfr = PlugInFilterRunner(translation_filter, "", "" ) + ret = translation_filter.output + if show: + ret.show() + ret.updateAndDraw() + return ret + + +def load_shifts(filename): + get_context().getPluginManager().loadInitializePlugin("ShiftsIO.java") + sio = get_context().getClassByName("ShiftsIO").newInstance() + return sio.load(expand_path(filename), "directshifts") + +def save_shifts(filename, shifts): + get_context().getPluginManager().loadInitializePlugin("ShiftsIO.java") + sio = get_context().getClassByName("ShiftsIO").newInstance() + sio.save(expand_path(filename), shifts, "directshifts") + + +def ip_to_fft_array_2d(ip): + pixels = ip.getPixels() + w = ip.getWidth() + h = ip.getHeight() + data = new_array('d', h, w) # new double[h][w] + for j in range(h): # (int j = 0; j < h; j++) + for i in range(w): # for (int i = 0; i < w; i++) + data[j][i] = pixels[j * w + i] + return data + + +def ip_to_fft_complex_array_2d(ip_r, ip_i): + pixels_r = ip_r.getPixels() + pixels_i = ip_i.getPixels() + w = ip_r.getWidth() + h = ip_r.getHeight() + data = new_array('d', h, 2 * w) # new double[h][2*w]; + for j in range(h): # (int j = 0; j < h; j++) + for i in range(w): # for (int i = 0; i < w; i++) + data[j][2 * i] = pixels_r[j * w + i] + data[j][2 * i + 1] = pixels_i[j * w + i]; + return data + +def fft_array_2d_to_complex_matrix(data, h, w): + m = ComplexMatrix(h,w) + for j in range(h): #for (int j = 0; j < h; j++) { + for i in range(w/2): # for (int i = 0; i <= w/2; i++) { + if (j > 0) and (i > 0) and (i < w/2): + m.setElement(j, i, Complex(data[j][2*i], data[j][2*i+1])) + m.setElement(h-j, w-i, Complex(data[j][2*i], -data[j][2*i+1])) + if (j == 0) and (i > 0) and (i < w/2): + m.setElement(0, i, Complex(data[0][2*i], data[0][2*i+1])) + m.setElement(0, w-i, Complex(data[0][2*i], -data[0][2*i+1])) + if (i == 0) and (j > 0) and (j < h/2): + m.setElement(j,0, Complex(data[j][0], data[j][1])) + m.setElement(h-j, 0, Complex(data[j][0], -data[j][1])) + m.setElement(j, w/2, Complex(data[h-j][1], -data[h-j][0])) + m.setElement(h-j, w/2, Complex(data[h-j][1], data[h-j][0])) + if (j == 0) and (i == 0): + m.setElement(0, 0, Complex(data[0][0], 0)); + if (j == 0) and (i == w/2): + m.setElement(0, w/2, Complex(data[0][1], 0)); + if (j == h/2) and (i == 0): + m.setElement(h/2, 0, Complex(data[h/2][0], 0)); + if (j == h/2) and (i == w/2): + m.setElement(h/2, w/2, Complex(data[h/2][1], 0)); + return m + + +def fft_complex_array_2d_to_complex_matrix(data, h, w): + m = ComplexMatrix(h,w); + for j in range(h): #for (int j = 0; j < h; j++) { + for i in range(w): # for (int i = 0; i < w; i++) { + m.setElement(j,i, Complex(data[j][2*i], data[j][2*i+1])) + return m + +def complex_matrix_to_fft_array_2d(m): + w = m.getNcol() + h = m.getNrow() + data = new_array('d', h,w) #new double[h][w]; + for j in range(h): #for (int j = 0; j < h; j++) { + for i in range(w): #for (int i = 0; i <= w/2; i++) { + if (j > 0) and (i > 0) and (i < w/2): + data[j][2*i] = m.getElementReference(j,i).getReal() + data[j][2*i+1] = m.getElementReference(j,i).getImag() + if (j == 0) and (i > 0) and (i < w/2): + data[0][2*i] = m.getElementReference(0,i).getReal() + data[0][2*i+1] = m.getEementReference(0,i).getImag() + if (i == 0) and (j > 0) and (j < h/2): + data[j][0] = m.getElementReference(j,0).getReal() + data[j][1] = m.getElementReference(j,0).getImag() + data[h-j][1] = m.getElementReference(j,w/2).getReal() + data[h-j][0] = m.getElementReference(h-j,w/2).getImag() + if (j == 0) and (i == 0): + data[0][0] = m.getElementReference(0,0).getReal() + if (j == 0) and (i == w/2): + data[0][1] = m.getElementReference(0,w/2).getReal() + if (j == h/2) and (i == 0): + data[h/2][0] = m.getElementReference(h/2,0).getReal() + if (j == h/2) and ( i == w/2): + data[h/2][1] = m.getElementReference(h/2,w/2).getReal() + return data + + +# convert a Complex Matrix into an 2d real part array data[0][][] and 2d imaginary part data[1][][] +def complex_matrix_to_real_array_2d(m): + w = m.getNcol() + h = m.getNrow() + data = new_array('d', 2,h,w) #new double[2][h][w]; + for j in range(h): #for (int j = 0; j < h; j++) { + for i in range(w): #for (int i = 0; i < w; i++) { + data[0][j][i] = m.getElementReference(j,i).getReal() + data[1][j][i] = m.getElementReference(j,i).getImag() + return data; + + +def compute_fft(imp_r, imp_i, roi): + slices = imp_r.getStackSize() + ffts = java.lang.reflect.Array.newInstance(ComplexMatrix, slices) # new ComplexMatrix[slices] + for i in range(1, slices + 1): + if imp_i is None: + ip = imp_r.getStack().getProcessor(i) + ip.setRoi(roi) + curr = ip.crop().convertToFloat(); + data = ip_to_fft_array_2d(curr) + ffts[i - 1] = fft2(data) + else: + ip1 = imp_r.getStack().getProcessor(i) + ip1.setRoi(roi) + curr_r = ip1.crop().convertToFloat() + ip2 = imp_i.getStack().getProcessor(i) + ip2.setRoi(roi) + curr_i = ip2.crop().convertToFloat() + data = ip_to_fft_complex_array_2d(curr_r, curr_i) + ffts[i - 1] = cfft2(data) + IJ.showProgress(i, slices) + return ffts + + +def element_product(a, b): + nr = a.getNrow() + nc = a.getNcol() + res = ComplexMatrix(nr, nc) + for j in range(nr): # (int j = 0; j < nr; j++) { + for i in range(nc): # (int i = 0; i < nc; i++) { + res.setElement(j, i, a.getElementReference(j, i).times(b.getElementReference(j, i))) + return res; + + +def fft_shift(complex_matrix): + nc = complex_matrix.getNcol() + nr = complex_matrix.getNrow() + out = ComplexMatrix(nr, nc) + midi = int(math.floor(nc / 2.0)) + offi = int(math.ceil(nc / 2.0)) + midj = int(math.floor(nr / 2.0)) + offj = int(math.ceil(nr / 2.0)) + for j in range(nr): # for (int j = 0; j < nr; j ++){ + for i in range(nc): # for (int i = 0; i < nc; i++) { + if j < midj: + if i < midi: + out.setElement(j, i, complex_matrix.getElementReference(j + offj, i + offi)) + else: + out.setElement(j, i, complex_matrix.getElementReference(j + offj, i - midi)) + else: + if i < midi: + out.setElement(j, i, complex_matrix.getElementReference(j - midj, i + offi)) + else: + out.setElement(j, i, complex_matrix.getElementReference(j - midj, i - midi)) + return out + + +def ifft_shift(complex_matrix): + nc = complex_matrix.getNcol() + nr = complex_matrix.getNrow() + out = ComplexMatrix(nr, nc) + midi = int(math.ceil(nc / 2.0)) + offi = int(math.floor(nc / 2.0)) + midj = int(math.ceil(nr / 2.0)) + offj = int(math.floor(nr / 2.0)) + + for j in range(nr): # (int j = 0; j < nr; j ++){ + for i in range(nc): # for (int i = 0; i < nc; i++) { + if j < midj: + if i < midi: + out.setElement(j, i, complex_matrix.getElementReference(j + offj, i + offi)) + else: + out.setElement(j, i, complex_matrix.getElementReference(j + offj, i - midi)) + else: + if i < midi: + out.setElement(j, i, complex_matrix.getElementReference(j - midj, i + offi)) + else: + out.setElement(j, i, complex_matrix.getElementReference(j - midj, i - midi)) + return out; + + +def ifft_shift_real(matrix): + nc = matrix.getNcol() + nr = matrix.getNrow() + out = Matrix (nr, nc) + + midi = int(math.ceil(nc/2.0)) + offi = int(math.floor(nc/2.0)) + midj = int(math.ceil(nr/2.0)) + offj = int(math.floor(nr/2.0)) + + for j in range(nr): # for (int j = 0; j < nr; j ++){ + for i in range(nc): #for (int i = 0; i < nc; i++) { + if j < midj: + if i < midi: + out.setElement(j, i, matrix.getElement(j+offj, i+offi)) + else: + out.setElement(j, i, matrix.getElement(j+offj, i-midi)) + else: + if i < midi: + out.setElement(j, i, matrix.getElement(j-midj, i+offi)) + else: + out.setElement(j, i, matrix.getElement(j-midj, i-midi)) + return out + + + +# compute 2D fft from an image +def fft2(data): + h =len(data) + w = len(data[0]) + fft = DoubleFFT_2D(h, w) + fft.realForward(data) + return fft_array_2d_to_complex_matrix(data, h, w) + +# compute complex 2D fft from an image +def cfft2(data): + h = len(data) + w = len(data[0]) + fft = DoubleFFT_2D(h, w/2) + fft.complexForward(data) + return fft_complex_array_2d_to_complex_matrix(data, h, w/2) +# compute inverse 2D fft from a complex matrix +def ifft2(m): + w = m.getNcol() + h = m.getNrow() + fft = DoubleFFT_2D(h, w) + data = complex_matrix_to_fft_array_2d(m) + fft.realInverse(data, True) + return data + +# compute complex inverse 2D fft from a complex matrix +def cifft2(m): + w = m.getNcol() + h = m.getNrow() + fft = DoubleFFT_2D(h, w) + data = new_array('d', h, 2 * w) # new double[h][2*w]; + for j in range(h): # for (int j=0; j max: + max = m.getElementReference(j, i).abs() + realmax = m.getElementReference(j, i).getReal() + imagmax = m.getElementReference(j, i).getImag() + rmax = j + cmax = i + res = new_array("d", 5) + res[0] = math.sqrt(realmax * realmax + imagmax * imagmax) + res[1] = rmax + res[2] = cmax + res[3] = realmax + res[4] = imagmax + return res; + + +def sum_square_abs(m): + s = 0.0 + for j in range(m.getNrow()): # (int j = 0; j < m.getNrow(); j ++): + for i in range(m.getNcol()): # for (int i = 0; i < m.getNcol(); i++): + s += m.getElementReference(j, i).squareAbs(); + return s; + + +def dftups(complex_matrix, nor, noc, roff, coff, usfac): + # function out=dftups(in,nor,noc,usfac,roff,coff); + # Upsampled DFT by matrix multiplies, can compute an upsampled DFT in justa small region. + # usfac Upsampling factor (default usfac = 1) + # [nor,noc] Number of pixels in the output upsampled DFT, in + # units of upsampled pixels (default = size(in)) + # roff, coff Row and column offsets, allow to shift the output array to + # a region of interest on the DFT (default = 0) + # Recieves DC in upper left corner, image center must be in (1,1) + # Loic Le Guyader - Jun 11, 2011 Java version for ImageJ plugin + # Manuel Guizar - Dec 13, 2007 + # Modified from dftus, by J.R. Fienup 7/31/06 + + # This code is intended to provide the same result as if the following + # operations were performed + # - Embed the array "in" in an array that is usfac times larger in each + # dimension. ifftshift to bring the center of the image to (1,1). + # - Take the FFT of the larger array + # - Extract an [nor, noc] region of the result. Starting with the + # [roff+1 coff+1] element. + + # It achieves this result by computing the DFT in the output array without + # the need to zeropad. Much faster and memory efficient than the + # zero-padded FFT approach if [nor noc] are much smaller than [nr*usfac nc*usfac] + + nr = complex_matrix.getNrow() + nc = complex_matrix.getNcol() + # Compute kernels and obtain DFT by matrix products + amplitude = -2.0 * math.pi / (nc * usfac) + nor,noc=int(nor),int(noc) + u = Matrix(nc, 1) + for i in range(nc): # (int i = 0; i < nc; i++) { + u.setElement(i, 0, i - math.floor(nc / 2.0)) + u = ifft_shift_real(u) + + v = Matrix(1, noc) + for i in range(noc): # for (int i = 0; i < noc; i++) { + v.setElement(0, i, i - coff) + + phase = u.times(v) + kernc = ComplexMatrix(nc, noc) + for j in range(nc): # for (int j = 0; j < nc; j++) { + for i in range(noc): # for (int i = 0; i < noc; i++) { + t = Complex() + t.polar(1.0, amplitude * phase.getElement(j, i)); + kernc.setElement(j, i, t) + + # ComplexMatrixPrint(kernc) + amplitude = -2.0 * math.pi / (nr * usfac) + + w = Matrix(nor, 1) + for i in range(nor): # for (int i = 0; i < nor; i++) { + w.setElement(i, 0, i - roff) + + x = Matrix(1, nr) + for i in range(nr): # for (int i = 0; i < nr; i++) { + x.setElement(0, i, i - math.floor(nr / 2.0)) + x = ifft_shift_real(x) + + nphase = w.times(x); + kernr = ComplexMatrix(nor, nr) + for j in range(nor): # for (int j = 0; j < nor; j++) { + for i in range(nr): # for (int i = 0; i < nr; i++) { + t = Complex(); + t.polar(1.0, amplitude * nphase.getElement(j, i)) + kernr.setElement(j, i, t) + # ComplexMatrixPrint(kernr); + return kernr.times(complex_matrix.times(kernc)) + +def dft_registration(ref, drifted, usfac): + m = ref.getNrow() + n = ref.getNcol() + output = new_array('d', 4) # new double[4] + + # First upsample by a factor of 2 to obtain initial estimate + # Embed Fourier data in a 2x larger array + mlarge = m * 2 + nlarge = n * 2 + large = ComplexMatrix(mlarge, nlarge) + c = fft_shift(element_product(ref, drifted.conjugate())) + + for j in range(m): # (int j = 0; j < m; j++): + for i in range(n): # (int i = 0; i < n; i++): + large.setElement(int(j + m - math.floor(m / 2.0)), int(i + n - math.floor(n / 2.0)), c.getElementReference(j, i)) + + # Compute crosscorrelation and locate the peak + CC = cifft2(ifft_shift(large)); + peak = c_find_peak(CC); # max, r, c, max_r, max_c + # Obtain shift in original pixel grid from the position of the + # crosscorrelation peak + if peak[1] > m: + peak[1] = peak[1] - mlarge; + if peak[2] > n: + peak[2] = peak[2] - nlarge; + # If upsampling > 2, then refine estimate with matrix multiply DFT + if usfac > 2: + # DFT computation + # Initial shift estimate in upsampled grid + row_shift = round(peak[1] / 2.0 * usfac) / usfac + col_shift = round(peak[2] / 2.0 * usfac) / usfac + dftshift = math.floor(math.ceil(usfac * 1.5) / 2) # Center of output array at dftshift+1 + # Matrix multiply DFT around the current shift estimate + cm = element_product(drifted, ref.conjugate()) + nCC = dftups(cm, math.ceil(usfac * 1.5), math.ceil(usfac * 1.5), \ + dftshift - row_shift * usfac, dftshift - col_shift * usfac, usfac) + nCC = nCC.times(1.0 / (m * n * usfac * usfac)).conjugate() + # Locate maximum and map back to original pixel grid + npeak = c_find_peak(nCC) # max_r, max_i, r, c + mrg00 = dftups(element_product(ref, ref.conjugate()), 1, 1, 0, 0, usfac) + rg00 = mrg00.getElementReference(0, 0).abs() / (m * n * usfac * usfac) + mrf00 = dftups(element_product(drifted, drifted.conjugate()), 1, 1, 0, 0, usfac) + rf00 = mrf00.getElementReference(0, 0).abs() / (m * n * usfac * usfac) + npeak[1] = npeak[1] - dftshift + npeak[2] = npeak[2] - dftshift + output[0] = math.sqrt(abs(1.0 - npeak[0] * npeak[0] / (rg00 * rf00))) # error + output[1] = math.atan2(npeak[4], npeak[3]) # diffphase + output[2] = row_shift + npeak[1] / usfac # delta row + output[3] = col_shift + npeak[2] / usfac # delta col + else: + # If upsampling = 2, no additional pixel shift refinement + rg00 = sum_square_abs(ref) / (mlarge * nlarge) + rf00 = sum_square_abs(drifted) / (mlarge * nlarge) + output[0] = math.sqrt(abs(1.0 - peak[0] * peak[0] / (rg00 * rf00))) # error + output[1] = math.atan2(peak[4], peak[3]) # diffphase + output[2] = peak[1] / 2.0 # delta row + output[3] = peak[2] / 2.0 # delta col + return output + + +def calculate_shifts(imp_r, imp_i, roi, upscale_factor=100, reference_slide=1, java_code=False): + if roi is None or roi.bounds.minX <0 or roi.bounds.minY<0 or roi.bounds.maxX>=imp_r.width or roi.bounds.maxY>=imp_r.height: + raise Exception("Invalid roi: " + str(roi)) + if java_code: + get_context().getPluginManager().loadInitializePlugin("Align_ComputeShifts.java") + compute_shifts_filter = get_context().getClassByName("Align_ComputeShifts").newInstance() + compute_shifts_filter.setup(upscale_factor, False, imp_r, imp_i, 1, roi) + compute_shifts_filter.run(None) + return compute_shifts_filter.shifts + + IJ.showStatus("1/2 Perform FFT of each slice") + ffts = compute_fft(imp_r, imp_i, roi) + + # calculate shifts + IJ.showStatus("2/2 Calculate shifts between slices") + + shifts = new_array('d', len(ffts), 6) # new double[ffts.length][6]; + for i in range(len(ffts)): # (int i = 0; i < ffts.length; i++): + shifts[i][0] = reference_slide + shifts[i][1] = i + 1 + temp = dft_registration(ffts[reference_slide - 1], ffts[i], upscale_factor) + shifts[i][2] = temp[2] + shifts[i][3] = temp[3] + shifts[i][4] = temp[0] + shifts[i][5] = temp[1] + IJ.showProgress(i + 1, len(ffts))\ + return shifts # [ref, drifted, dr, dc, error, diffphase] + +def to_ip(obj): + if is_string(obj): + try: + obj = open_image(obj) + except: + obj = load_image(obj) + else: + if type(obj) == Data: + obj = obj.toBufferedImage(False) + if type(obj) == BufferedImage: + obj = load_image(obj) + return obj + +#TODO: Check maximum error and phase diff values +def calculate_shift(ref,img, roi, g_sigma=3.0, upscale_factor=100, max_error=2.0, max_diffphase=0.1): + ref = to_ip(ref) + img = to_ip(img) + stack = create_stack([ref,img]) + ipr, ipi = complex_edge_filtering(stack, g_sigma=g_sigma, show=False) + shifts = calculate_shifts(ipr, ipi, roi, upscale_factor=upscale_factor, java_code=True) + xoff, yoff = shifts[1][3], shifts[1][2] + error, diffphase = shifts[1][4], shifts[1][5] + if math.isnan(error) or abs(error)> max_error: + raise Exception("Bad image registration error: " + str(error)) + if math.isnan(diffphase) or abs(diffphase)> max_diffphase: + raise Exception("Bad image registration phase difference: " + str(diffphase)) + return xoff, yoff, error, diffphase + diff --git a/script/local.py b/script/local.py index 461cebf..345cf47 100755 --- a/script/local.py +++ b/script/local.py @@ -8,6 +8,7 @@ from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_lis from mathutils import fit_polynomial,fit_gaussian, fit_harmonic, calculate_peaks from mathutils import PolynomialFunction, Gaussian, HarmonicOscillator from collections import OrderedDict +run ("imaging/shifts") ProviderCSV.setDefaultItemSeparator(", ") get_context().dataManager.createLogs=False @@ -48,6 +49,14 @@ TIME_DELAY_COMPLETE = "X11MA-ES2-scan1.SMSG" TBT_MAG = "X11MA-LSCI632:MFIELD" " """ + + +#Device initialization +keithley_1a.setForcedRead(False) +keithley_2a.setForcedRead(False) +keithley_3a.setForcedRead(False) + + def get_next_fid(folder, prefix): try: import glob @@ -240,10 +249,8 @@ def otf(start, end, time, delay = 0.0, mode = None, offset = None, alpha = None, def otf2(start, end, time, delay = 0.0, mode = None, offset = None, alpha = None, name = None, folder = 'TEST'): """ """ - if name is None: - name = get_exec_pars().name #folder = get_context().setup.expandPath("{year}_{month}/{date}"); - run("templates/EnergyScan_v2", {"E1":start, "E2":end, "TIME":time, "DELAY":float(delay), "MODE":mode, "OFFSET":(offset), "FOLDER":folder, "FILE":name, "ALPHA":float(alpha) if alpha is not None else None}) + run("templates/EnergyScan_v2", {"E1":start, "E2":end, "TIME":time, "DELAY":float(delay), "MODE":mode, "OFFSET":(offset), "FOLDER":folder, "FILE":name, "TAG":name, "ALPHA":float(alpha) if alpha is not None else None}) def two_pol(switching="Tune_Detune", sequence="A", measurements=1, exposure=1.0, average=1, name = None): @@ -738,7 +745,10 @@ def fit(ydata, xdata = None, limit_to_range=False): if limit_to_range: print "Max -> " + str(max_x) p.addMarker(max_x, None, "Max="+str(round(max_x,2)), Color.MAGENTA.darker()) - return (None , max_x, None) + return (None , max_x, None) + else: + print "Fit error" + return (None, None, None) (norm, mean, sigma) = gaussians[0] print " mean:" + str(mean) fitted_gaussian_function = Gaussian(norm, mean, sigma) diff --git a/script/old_scripts/EnergyScanID2only_juraj.py b/script/old_scripts/EnergyScanID2only_juraj.py deleted file mode 100755 index f00ef9a..0000000 --- a/script/old_scripts/EnergyScanID2only_juraj.py +++ /dev/null @@ -1,185 +0,0 @@ -import os -import traceback -import thread - -############################################################################### -# Plotting -############################################################################### - -task = None -running = False - - -def _startPlot(type): - global running - print "Starting plot: type " + str(type) - running = True - p = plot(None,name="Energy")[0] - s = p.getSeries(0) - cur = 0 - time.sleep(3.0) - while running: - try: - if otf_start.read() == 0: - break - e = energy.read() - if (abs(e-cur)) > 0.1: - v = abs((keithley_2a.read() / ((keithley_1a if (type==1) else keithley_3a).read() ))) - s.appendData(e,v) - cur = e - time.sleep(0.2) - except: - pass - print "Done Plotting" - -def startPlot(type = 1): - global task - task = fork((_startPlot,(type,)),) - -def stopPlot(): - global task, running - running = False - ret = join(task) - -############################################################################### -# Parameters -############################################################################### - - -E1 = 634 -E2 = 660 -TIME = 4.0 #min -DELAY = 1.0 #s -#PREFIX = 'Data' -RUNTYPE = "+/-" -ROUNDS = 1 -OFFSETp = -1.9 -OFFSETm = -1.9 -PLOT_TYPE = 1 - -caput ("X11PHS-E:OPT","PGM+ID2") - -print "\nStarting energy scan - Parameters: ", -print E1,E2,TIME,DELAY,RUNTYPE - -file_prefix = time.strftime("%y%m%d") -#input_path = "/sls/X11MA/data/X11MA/fechner_beamtime/"+file_prefix+"/" -input_path = "/sls/X11MA/data/X11MA/pshell/home/data/2017_12/juraj/" -output_path = input_path #+file_prefix+"/" #"/sls/X/pshell/home/data/2017_12/juraj11MA/Data1/public/e10989/"+file_prefix+"/" -pol_str = None -mag_str = None -fid = get_next_fid(input_path, "o" + file_prefix) -number_of_scans = 1 - - -wait_channel(OTF_DONE, 1, type = 'i') - - -############################################################################### -#Prepare scan for PGM+ID2 -############################################################################### - -caput ("X11PHS-E:OPT","PGM+ID2") -#caput(OTF_OFF1,-40) #detune ID2 -#wait_channel(OTF_DONE, 1, type = 'i')/sls/X11MA/datmokuser/ - -if RUNTYPE in ["+/-", "+", "-"]: - if RUNTYPE == "+": - caput(OTF_MODE2,1) # circ+ in ID2 - caput(OTF_OFF2,OFFSETp) - number_of_scans = ROUNDS - elif RUNTYPE == "-": - caput(OTF_MODE2,2) # circ- in ID2 - caput(OTF_OFF2,OFFSETm) - number_of_scans = ROUNDS - elif RUNTYPE == "+/-": - caput(OTF_MODE2,1) # circ+ in ID2 - caput(OTF_OFF2,OFFSETp) - number_of_scans = 2 * ROUNDS - wait_channel(OTF_DONE, 1, type = 'i') - -elif RUNTYPE in ["LH/LV", "LH", "LV"]: - print "Wrong polarization selected!" - - -else: - raise Exception("Invalid run type: " + RUNTYPE) - -#open_vg10() -#time.sleep(0.5) -#open_vg11() -#time.sleep(0.5) -#open_vg12() -#time.sleep(0.5) -open_vg13() - -############################################################################### -#Main scan loop -############################################################################### - -for scan_no in range(number_of_scans): - suffix = ("%03d" % fid) - input_file = input_path + "o" + file_prefix + "_" + suffix + ".dat" - - caput(OTF_E1, E1) - caput(OTF_E2, E2) - caput(OTF_TIME, TIME) - caput(OTF_FTS,file_prefix) - caput(OTF_FID,fid) - time.sleep(2.0) - caput(OTF_ESET, E1) - wait_channel(OTF_DONE, 1, type = 'i') - time.sleep(DELAY) - time.sleep(2.0) - - startPlot(PLOT_TYPE) - otf_start.write(1) #Start the OTF scan - time.sleep(3.0) - print "Running scan " + str(scan_no+1) + " out of " + str(number_of_scans) - try: - #wait_channel(OTF_START, 'STOP', timeout = int(TIME*60), type = 's') - otf_start.waitValue(0, (15 + int(TIME*60)) *1000) - except: - print "******** OTF STOP TIMEOUT **********" - otf_start.write(0) - finally: - stopPlot() - - time.sleep(5.0) - #TODO: wait for file instead of sleep - #Convert file - output_file = output_path + "os" + file_prefix + "_" + suffix + ".dat" - - - - if RUNTYPE in ["+/-"]: - pol_str = caget(OTF_MODE2) - if pol_str == "CIRC +": - caput(OTF_MODE2,2) # circ- in ID2 - caput(OTF_OFF2,OFFSETm) - elif pol_str == "CIRC -": - caput(OTF_MODE2,1) # circ+ in ID2 - caput(OTF_OFF2,OFFSETp) - else: print "Check pol. change" - wait_channel(OTF_DONE, 1, type = 'i') - else: - print "running in one polarization mode, no switching" - pol_str = caget(OTF_MODE2) - - print("Converting data file: " + output_file); - mag_str = caget(MAG) - #convert_file(input_file, output_file, mag_str, pol_str) - convert_file(input_file, output_file, mag_str, pol_str) # tey and tfy saved - not normalized - plot_file(output_file, file_prefix+"_" + suffix) #"Scan " + str(scan_no+1)) - print "Finished scan " + str(scan_no+1) + " out of " + str(number_of_scans) - - time.sleep(3.0) - fid = fid + 1 - -caput(OTF_ESET, E1) -#close_vg13() - -print "Finished Energy scan" - -print("Success") - diff --git a/script/templates/EnergyScan_v2.py b/script/templates/EnergyScan_v2.py index fae0167..63c6710 100755 --- a/script/templates/EnergyScan_v2.py +++ b/script/templates/EnergyScan_v2.py @@ -9,6 +9,7 @@ OFFSET = 0.0 FOLDER = 'XAS/2020/11/SL-IN/' FILE = 'test' ALPHA=0.0 +TAG=None """ print "\nStart energy scan..." @@ -19,7 +20,11 @@ else: print E1,"eV ->",E2,"eV,",TIME,"min duration,",DELAY,"sec delay,",str(MODE) folder = os.path.expanduser("~/Data1/") + FOLDER + "/"; -set_exec_pars(name= FILE) + +if TAG is not None: + TAG = ("%03d" % (get_exec_pars().index,)) + "_" + TAG +#set_exec_pars(name= FILE) + #Pre-actions #if NO_BEAM_CHECK == False: @@ -84,7 +89,7 @@ try: print "Scanning...", try: - mscan(Ecrbk, sensors, -1, None, range="auto", domain_axis="Ecrbk", enabled_plots = ["NORMtey", "NORMdiode", CADC1,CADC3, CADC2], ) + mscan(Ecrbk, sensors, -1, None, range="auto", domain_axis="Ecrbk", enabled_plots = ["NORMtey", "NORMdiode", CADC1,CADC3, CADC2], tag=TAG) finally: ret[0].cancel(True) print "Finished Energy scan." diff --git a/script/test/ExitSlitCalib.py b/script/test/ExitSlitCalib.py new file mode 100644 index 0000000..2f5b5f2 --- /dev/null +++ b/script/test/ExitSlitCalib.py @@ -0,0 +1,83 @@ +################################################################################################### +# Function fitting and peak search with mathutils.py +################################################################################################### + +from mathutils import fit_polynomial +from mathutils import PolynomialFunction + +# Input parameters +Slit = exit_slit +Slit_offset = exit_slit_offset + +start = 30.0 +end = -20.0 +step_size = 1.0 +settling_time= 1.0 #Slits need 1s to accept next command +final_pos = 20.0 + +#setting parameters +caput('X11MA-KEI10:RANGE', 6) # 6 --> 200 nA +Slit.move(start) +#Slit. + +if(Slit==exit_slit): + speed = Slit.getSpeed() + min_speed=Slit.getMinSpeed() + Slit.setSpeed(min_speed) + +time.sleep(1) + +# Execute the scan +result=cscan(Slit, keithley_1a, start, end, float(step_size)) + +readable_ = result[keithley_1a] +positions_ = result[Slit] +print positions_ +readable=[] +positions=[] + +# execute the fit +fit_threshold=readable_[0]*0.05 + +#filter the positions with analog values above the threshold +for i in range(8,len(positions_),1): + if(readable_[i]>fit_threshold): + readable.append(readable_[i]) + positions.append(positions_[i]) + + + +pars_polynomial = (a0, a1) = fit_polynomial(readable, positions,1) +fitted_polynomial_function = PolynomialFunction(pars_polynomial) +print pars_polynomial + + +resolution = step_size/100 +fit_polinomial = [] + +# from the fit function calculate the values at the positions +for x in frange(end,start,resolution, True): + fit_polinomial.append(fitted_polynomial_function.value(x)) +x = frange(end, start+resolution, resolution) + +# crate plots +plots = plot([readable_, fit_polinomial] , ["data", "polinomial"], xdata = [positions_,x], title="Data") +p = plot(None,name="Data 1")[0] +p.addSeries(LinePlotSeries("Data2")) +p.getSeries(0).setData(positions_, readable_) +p.getSeries(1).setData(x, fit_polinomial) + +#calculate the position where the line crosses zero +k=-pars_polynomial[0]/pars_polynomial[1] +print k + +#change the offset +offset=Slit_offset.read() +Slit_offset.write(offset+k) + +#resetting parameters +caput('X11MA-KEI10:RANGE', 0) # 0--> AUTO +if(Slit == exit_slit): + Slit.setSpeed(speed) +Slit.write(final_pos) + diff --git a/script/test/LEEM_example_scans.py b/script/test/LEEM_example_scans.py index 7aacd22..977b018 100755 --- a/script/test/LEEM_example_scans.py +++ b/script/test/LEEM_example_scans.py @@ -1,19 +1,38 @@ #ascan ([manip_x,manip_y],machine_cur, [-950,900], [-960,910], [5.0,5.0], latency=1.0,zigzag=True, save=False) -RANGE_V = [-2000, 2000] -RANGE_H = [-2000, 2000] -STEP_V = 500.0 -STEP_H = 500.0 +RANGE_V = [-500, 500] +RANGE_H = [-500, 500] +STEP_V = 100.0 +STEP_H = 100.0 SETTLING_TIME = 1.0 + +class LeemRoiIntensity (ImageMeasurement): + def __init__(self, x,y,w,h): + ImageMeasurement.__init__(self, image2, "roi"+ str([x,y,w,h])) + self.x, self.y, self.w, self.h, = x,y,w,h + def calc(self, data): + return data.getRoi(Rectangle(self.x, self.y, self.w, self.h)).integrate(False) + + +microscope.move_timeout=240000 + #We start at 0,0 absolute position tilt_vertical.initialize() tilt_horizontal.initialize() +roi_intensity = LeemRoiIntensity(550,420, 150, 150) +set_device_alias(image2.intensity, "CameraIntensity") +set_device_alias(roi_intensity, "ROI_Intensity") +sensors = [machine_cur, image2.intensity, roi_intensity] + +def before_read(pos,scan): + image2.update() + try: - ascan ( [tilt_horizontal, tilt_vertical], machine_cur, \ + ascan ( [tilt_horizontal, tilt_vertical], sensors, \ [RANGE_H[0], RANGE_V[0]], [RANGE_H[1], RANGE_V[1]], [float(STEP_H), float(STEP_V)], \ - latency=SETTLING_TIME,zigzag=True, save=True) + latency=SETTLING_TIME,zigzag=True, save=True, before_read=before_read) finally: tilt_vertical.write(0) diff --git a/script/test/TestBasler.py b/script/test/TestBasler.py new file mode 100644 index 0000000..55f7e1f --- /dev/null +++ b/script/test/TestBasler.py @@ -0,0 +1,33 @@ +class BaslerRoiIntensity (ImageMeasurement): + def __init__(self, x,y,w,h): + ImageMeasurement.__init__(self, image2, "roi"+ str([x,y,w,h])) + self.x, self.y, self.w, self.h, = x,y,w,h + def calc(self, data): + return data.getRoi(Rectangle(self.x, self.y, self.w, self.h)).integrate(False) + +class Profile(ReadableArray): + def read(self): + return image2.data.integrateHorizontally(False) + def getSize(self): + return image2.data.getWidth() + +def before_read(pos, scan): + cam2.start(); + image2.waitNext(3000) + +EXPOSITION = [0.001, 0.002, 0.005, 0.01 , 0.025, 0.05, 0.1, 0.25, 0.5, 1.0] +def before_pass(pass_id, scan): + #exposure = (0.005) * (pass_ids) + exposure = EXPOSITION[pass_id-1] + while cam2.exposure != exposure: + cam2.setExposure(exposure) + time.sleep(0.5) + print "Exposure = ", exposure + +set_device_alias(image2.intensity, "Intensity") +p=Profile() +set_device_alias(p, "Profile_1d") +sensors = [image2.intensity, Profile(),p,BaslerRoiIntensity(10,10,20,20)] +tscan(sensors, 10, 1.0, passes = 10, \ + before_read=before_read, before_pass=before_pass, \ + save=False, line_plots=[p]) \ No newline at end of file diff --git a/script/test/TestMscan.py b/script/test/TestMscan.py new file mode 100644 index 0000000..85745f4 --- /dev/null +++ b/script/test/TestMscan.py @@ -0,0 +1,23 @@ +import ch.psi.pshell.scan.ScanAbortedException as ScanAbortedException + + +start = 1 +end = 5 +fe_slit_V_size.move(float(start)) + + +fe_slit_V_size.moveAsync(float(end)) + +readback=fe_slit_V_size.getReadback() +#Execute the scan: sample undefined number of samples until a condition is met, with auto range +scan_completed=False +def after_read(record, scan): + global scan_completed + if abs(readback.take()-end) < 0.1: + print "Stopping" + scan_completed=True + scan.abort() +try: + r5 = mscan(readback, keithley_1a, -1, after_read=after_read, range="auto") +except ScanAbortedException as ex: + if not scan_completed: raise diff --git a/script/test/TestShifts.py b/script/test/TestShifts.py new file mode 100644 index 0000000..8a93504 --- /dev/null +++ b/script/test/TestShifts.py @@ -0,0 +1,90 @@ +from ijutils import Roi +#from sim import * +import traceback +run ("imaging/shifts") +""" +roi=Roi(256,0,128,128) +stack = load_test_stack(show=False, size=9) +ipr, ipi = complex_edge_filtering(stack, show=False) +shifts = calculate_shifts(ipr, ipi, roi, java_code=True) +#shifts= load_shifts("{images}/TestObjAligner/shifts.mat") +#stack = load_test_stack(show=True) +r=translate(stack, shifts, show=True) + +ref = "{images}/TestObjAligner/i210517_040#001.tif" +img = "{images}/TestObjAligner/i210517_041#001.tif" +#ref = stack.getStack().getProcessor(1) +#img = stack.getStack().getProcessor(2) +#roi=Roi(0,0,32, 32) +#ref=image2.data.getRoi(Rectangle(Point(0,0),image.data.getSize(False))) +#time.sleep(0.2) +#img =image.data +""" + + +def eval_shift(roi, obj=None, stiga=None, stigb=None, wait=3.0): + ref = image.data + if obj is not None: + objective.write(obj) + if stiga is not None: + obj_stig_a.write(stiga) + if stigb is not None: + obj_stig_b.write(stigb) + time.sleep(wait) + image.waitNext(10000) + img = image.data + xoff, yoff, error, diffphase = calculate_shift(ref,img, roi) + print "xoff: ", xoff + print "yoff: ", yoff + print "error: ", error + print "diffphase: ", diffphase +""" +roi=Roi(300,240,64,64) +eval_shift(roi, obj=1493.5) +eval_shift(roi, obj=1494.8) +""" + + +def eval_shift_obj(roi, obj1, obj2, wait=3.0): + cur = objective.read() + if abs(obj1-cur) > 0.001: + objective.write(obj1) + time.sleep(wait) + image.waitNext(10000) + ref = image.data + objective.write(obj2) + time.sleep(wait) + image.waitNext(10000) + img = image.data + xoff, yoff, error, diffphase = calculate_shift(ref,img, roi) + print "Ref obj: ", obj1, " img obj: ", obj2 + print "xoff: ", xoff + print "yoff: ", yoff + print "error: ", error + print "diffphase: ", diffphase + + +def get_roi_overlay(): + pn=show_panel(image) + for ov in pn.overlays: + if type(ov) is Overlays.Rect: + return ov + return None + +def get_roi(): + #return Roi(300,240,64,64) + roi_ov=get_roi_overlay(); + return Roi(roi_ov.position.x, roi_ov.position.y, roi_ov.width, roi_ov.height) + +def set_roi_size(size): + pn=show_panel(image) + roi = get_roi_overlay() + if roi is None: + raise Exception("No ROI defined") + roi.width = size + roi.height = size + pn.refresh() + +#set_roi_size(128) +eval_shift_obj(get_roi(), 1494.8, 1493.5) +eval_shift_obj(get_roi(), 1493.5, 1494.8) diff --git a/script/test/TestUserScript.py b/script/test/TestUserScript.py old mode 100644 new mode 100755