How to carry out multiple SI acquisition automatically? - dm-script

I would like to write a Gatan DigitalMicrograph script to acquire multiple EELS spectrum images continuously. If there is a command to obtain Spectrum Image (SI) data, and store the three-dimensional image to an array, I will achieve my plan. However, I could not find appropriate commands for SI imaging mode from reference manual. What command should I use in this case? Do you have a helpful knowledge for my purpose? It will be appreciated if you share some wisdom.

A short demo-script of how to use the SIAcquisition commands for multiple iterations of SI acquisition and "renaming" the acquired data sets.
// Assumptions:
// - GMS 2.3 used
// - Valid survey image and ROI already assigned
// - SI array size already defined
// - Signals and other SI settings made
number SIx, SIy
SIGetFieldValue( "2D Array, X samples", SIx )
SIGetFieldValue( "2D Array, Y samples", SIy )
Result("\n SI size:"+ SIx + "x" + SIy )
// Start SI
number nSI = 3
for (number i=0; i<nSI; i++ )
{
SIInvokeButton( "Start/Stop", 1 )
while(SIIsAcquisitionActive()) yield()
sleep(0.5) // Small delay needed to allow DM finish SI acquisition clean-up
// Find (and rename) SI DataSets
number nImgDoc = CountImageDocuments()
string findStr = "Spectrum Image"
for (number d=0; d<nImgDoc; d++ )
{
string docName = GetImageDocument(d).ImageDocumentGetName()
if ( find(docName,findStr) == (len(docName)-len(findStr)) )
{
GetImageDocument(d).ImageDocumentSetName( docName + "#"+(d+1) )
}
}
}
OKDialog( "Done" )

If you have the spectrum-imaging plugin installed, then the F1 help file will have a section on STEM SI scripting commands here...
However, the commands described there will allow the acquisition of one SI after the other. Each will start anew with the same overhead you get when repeatedly starting SI acquisition via the UI.
I've got the impression you want to get a "faster" repeated SI.
Unfortunately, no commands exist which could easily give you that.
However, you might be able to create a "work-arround" solution by the following idea (untested):
Set up a STEM SI with multiple-frames (Each frame pass will be summed into the same container)
Use the "SI HookUP Scripts" on a per-pixel basis (Pixel end) to catch the "last" acquired SI point (before the new frame starts). Use this to copy the existing data into a new container and set the orignal back to zero.
Alternative:
You might also be able to use the "Correction start" HookUp script point, if you set spatial drift-correction to perform at end of frame...
The above will only work with software-synchronized SI's. For hardware-synchronized, it becomes more tricky, but you might be able to do something similar with a "ImageUpdate" event-listener.

Related

BAPI_GOODSMVT_CREATE with multiple material numbers and same PP order?

As I know of, When you're using BAPI_GOODSMVT_CREATE at the same time(by loop or just coincidence), Using same material number puts you an error about locked object (Material XXXX is locked by USER YYYY).
But, as i know of, using BAPI_GOODSMVT_CREATE at the same time, but different material number WITH same production order makes no error.
Issue
Recently I found an error about M3/897 (Plant Data of Material XXXX is locked by user XXXX) when I'm doing BAPI_GOODSMVT_CREATE when I'm trying GI for Production order, by parallel processing, which are putting different Material number to same production order.
Question
So, I'm asking about constraint of BAPI_GOODSMVT_CREATE.
So far I know is -
A. You can't issue GI for Production Order(Mvt 261) at the same time, when you're putting same material number for different production order.
B. (I'm not sure about this) You can't issue GI for Production Order(Mvt 261) at the same time, when you're putting different material number for same production order.
Is both is right, or just A is right? Any help from experienced ABAPer or MM consultant would be appreciated!
To post GI in a loop you need to make commit after each run, and unlock the object explicitly, otherwise you will get the PP lock.
Try like this:
LOOP AT lt_orders ASSIGNING <fs>.
...
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = ls_header
goodsmvt_code = ls_code
IMPORTING
goodsmvt_headret = ls_headret
materialdocument = ls_retmtd
TABLES
goodsmvt_item = lt_item
return = lt_return.
IF line_exists( lt_return[ type = 'E' ] ).
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
COMMIT WORK AND WAIT.
CALL FUNCTION 'DEQUEUE_ALL'.
ENDIF.
ENDLOOP.
Always use BAPI_TRANSACTION_COMMIT with WAIT parameter or COMMIT WORK with the same after each BAPI call.
Also there can be tricky issues with the GR and implicit GI movements, see the note 369518 about this.
You can check the presence of existing lock at runtime using this FM - "ENQUE_READ2".
data: RAW_ENQ like LOCKSEDX_ENQ_TAB,
SUBRC type SY-SUBRC,
NUMBER type I.
clear : RAW_ENQ[], SUBRC, NUMBER.
add 1 to COUNTER.
call function 'ENQUE_READ2'
importing
SUBRC = SUBRC
NUMBER = NUMBER
tables
ENQ = RAW_ENQ.
But if you have to prevent a failure of GOODS mvt. in general you have instead to implement some reprocessing logic to store errors.
The steps would be : Catch errors --> store bapi information or header doc number --> retry later

Trying to build a PC (counter) for the nand2tetris , but I'm having some trouble with the logic

The project aims to build a program counter.
The description are as follows:
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/03/a/PC.hdl
/**
* A 16-bit counter with load and reset control bits.
* if (reset[t] == 1) out[t+1] = 0
* else if (load[t] == 1) out[t+1] = in[t]
* else if (inc[t] == 1) out[t+1] = out[t] + 1 (integer addition)
* else out[t+1] = out[t]
*/
I figured out all the possibilities as follows
All possible output
Then here I go:
CHIP PC
{
IN in[16],load,inc,reset;
OUT out[16];
PARTS:
// Put your code here:
Register(in=in, load=true, out=thein);
Register(in=in, load=false, out=theout);
Inc16(in=theout, out=forinc);
Register(in=forinc, load=true, out=theinc);
Mux8Way16(a=theout, b=false, c=theinc, d=false, e=thein, f=false, g=thein, h=false, sel[2]=load, sel[1]=inc, sel[0]=reset, out=out);
}
I tried many times but all failed when the clock load to time 1+ or something like this.
Since the register defined here is out(t+1) = out(t)
what is the output of time ?+.I found it really annoying.
Any suggestions will be appreciated.
Some observations:
You're storing the output in a register, which is good. However, note that the register output is also one of your inputs -- it is out[t].
You don't need a big Mux8Way16. There are 4 possible different outputs, so you can either use multiple Mux16s in a cascade or (extra credit) a single Mux4Way16 with some extra logic to compute the two selection bits.
I usually found that the simplest way to do things was first compute all the possible outputs (in this case, 0, input, register+1 or register) and then have the logic to decide which one of those actually gets output.
Good luck. You are very close.

ImageJ batch processing - opening a series of images containing a specific name and doing stuff on them

I have 25K tif files (please don't ask why) that I want to organize into stacks on image J. Basically for each region of interest (ROI), there are 50 images which breaks down into 25 z-planes for two channels. I want everything in a single stack. And I'd like to batch process the whole folder without opening 50 images 500 times at a time. I've attached a picture of what the file names look like:
Folder organization
r01c01f01p01-ch1.tif - the first 10 characters are unique ID to each ROI, then plane number (p01) then channel - ch1 or ch2, then file extension
Here's what I have so far (which I cobbled together based on other macros so this may not make sense...).This is using the ImageJ macros language.
//Processing loop to process each file in the folder.
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
if (endsWith(list[i], ".tif")) { // skip the subfolder (I create a subfolder earlier in the macros)
print("-- Processing file: " + list[i] + " --");
open(dir+list[i]);
imageTitle= getTitle();
newTitle = substring(imageTitle, 0, lengthOf(imageTitle)-10); // r01c01f01p, cutting off plane number and then the rest to just get the ROI ID
//This is where I'm stuck:
// find all files containing newTitle and open them (which would be 50 at a time), then run the following macros on them
run("Images to Stack", "name=Ch1 title=[] use");
run("Duplicate...", "title=Ch2 duplicate");
selectWindow("Ch1");
run("Slice Remover", "first=1 last=50 increment=2");
selectWindow("Ch2");
run("Slice Remover", "first=2 last=50 increment=2");
run("Merge Channels...", "c1=Ch1 c2=Ch2 create");
saveAs("tiff", dirNew + newTitle + "_Stack.tif");
//Close(All)?
}
}
print("-- Done --");
showStatus("Finished.");
setBatchMode(false); // Exit batch mode
run("Collect Garbage");
Thank you!
You could do something like:
for (plane=1; plane<51; plane++) {
open(newTitle+plane+"-ch1.tif");
open(newTitle+place+"-ch2.tif");
}
Which would take care of the opening. I would be inclined to have a loop prior to this which would collate the number of unique "newTitle"'s, as your current setup would end up doing something like opening the first item, assembling the combined TIF, and then repeat the process 25K times if I understand it correctly.
Given that you know the number of unique "r01c01f01p" values, in principle you could do a set of stacked loops akin to:
newTitleArray = newArray();
for (r=1; r<50; r++) {
titleBit = "r0" + toString(r);
for (c=1; c<501; c++) {
titleBit = titleBit + "f0"...
Alternatively, you could set up a loop where you check for unique "r01c01f01p" values and add them to an array. In any case, you'd replace the for "list" loop with the for "newTitleArray" loop, and then continue onto the opener I listed above, instead of your existing one.
If I am understanding correctly, it seems like you might do well to stack by channel first, then merge the two. I am not 100% sure, but I think you could potentially use a macro I have already created to do that. It was originally meant to batch process terabytes of 5D data, so it should be very comfortable handling your volume of images. It is not exactly what you are looking for, but should be super easy to modify (I went a little overboard with the commenting in the code), and I think the only thing it does that you might rather it not is produce max projects from the inputs. I'll throw a link here and look for your reply. If it's of interest, let me know and we can work to make it suit your needs together :-) Otherwise, if you could provide a little more detail about where you're getting stuck and/or where I may have misunderstood, I will do my very best to help!
https://github.com/evanjkiely/FIJIMacros

How to make a reverse foreach search in velocity script?

Marketo has a limit of 10 most recent opportunities that are searchable, and unfortunately we have a good number of users with more than 10 opportunities.
It appears the foreach loop starts at the least recently updated opportunity, and works its way up the list to the most recently update opportunity. The issue here is that when they have more than 10, the script can't access those opportunities that are the most recently updated. We could get around this by reversing the order the script searches the opportunity list (by reversing the foreach).
This is is the setup we have now (the script looks for a set of conditions within an opportunity, if it doesn't find them it looks for a different set, and so on).
#set($stip_guid = ${StipList.get(0).stip_opp_guid})
#foreach($opportunity in $OpportunityList)
#if($opportunity.o_opportunity_guid == $stip_guid && $opportunity.o_clear_to_close_date)
Display Unique Copy A
#break
#elseif($opportunity.o_opportunity_guid == $stip_guid && $opportunity.o_sent_to_underwriting)
Display Unique Copy B
#break
#elseif($opportunity.o_opportunity_guid == $stip_guid && $opportunity.o_processing_received)
Display Unique Copy C
#break
#else
Default Copy
#break#end#end
Marketo doesn't seem to be providing a tool which would reverse a collection.
But why not look on indices rather than on objects themselves?
#set($max = $opportunityList.size() - 1)
#foreach($i in [ $max .. 0 ])
#set($opportunity = $opportunityList[$i])
...
#end

Understanding PsychoPy codes for trialHandler and responses

I am new to coding, and would like help in understanding the script used by the PsychoPy program.
To be more specific, I would like to understand the codes that are in line 6 to 15. I am aware that this is used to manage the multiple trials, but I am hoping someone can help me clarify those bits? I also noted that removing the codes from line 6-8 doesn't change the experiment, but removing the codes from line 10-15 essentially stop the experiment from running.
trialsAll = data.TrialHandler(trialList=data.importConditions('trialType.xlsx'), nReps=10, method='random', name='trialsAll', dataTypes='corr')
thisExp = data.ExperimentHandler(name='Ours')
thisExp.addLoop(trialsAll) #adds a loop to the experiment
thisTrial = trialsAll.trialList[0]
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '= thisTrial.' + paramName)
# Loop through trials
for thisTrial in trialsAll:
currentLoop=trialsAll
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '=thisTrial.' + paramName)
My second question would be about getting responses. Is there a reason that thisResp is equalled to None?
#get response
thisResp=None
while thisResp==None:
allKeys=event.waitKeys()
Thanks a lot for any help. I appreciate it.
Regards,
Cash
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '= thisTrial.' + paramName)
This code allows the use of abbreviations. For example, say your conditions file has a field called 'angle', you can refer to this directly rather than via the keys of that trial's dictionary (e.g. thisTrial['angle'] ) or using dot notation ( thisTrial.angle ). i.e., in this example:
angle = thisTrial.angle
for thisTrial in trialsAll:
is fundamental to running a psychoPy trial loop. It will cycle though each trial that is contained in the TrialHandler object that is created to manage trials, connected to a given conditions file.
#get response
thisResp=None
while thisResp==None:
allKeys=event.waitKeys()
The line 'while thisResp==None:' requires that the variable 'thisResp' actually exists if we are going to be able to check its value. So in the immediately preceding line, it is created and given an initial null value so that the next line will run OK. Note that at this stage, it is just an arbitrary variable, which doesn't have any actual connection to the subject's response. That will presumably occur later in the code, when it gets assigned a value other than None.