Batch process macro in Fiji fails to work - image-processing

I have a hyperstack which has 2 time frames and 13 z projection in each time frame. From the menu I choose Process, Batch, and then Macro. In the input I select the input folder and then determine the output folder in the output. Finally I use the code below to sum all the z projection:
run("Z Project...", "projection=[Max Intensity] all");
close();
Here is an screenshot:
After running process or Test the file I get in the output is the same as input without the z projection being summed.
Here is a sample tif file (13 MB). I tried to do this on different computers but the result is the same.

I'm not familiar with using batch process in this way, so I'm not sure I can address your issue directly, but, I can say that I know how to do this by recording/writing a macro directly. First though, have you tried using the "Save" button provided in the GUI you screenshotted? In that case, if it still doesn't work, you'd maybe want to do something like this in the macro editor instead:
openPath = getDirectory("Choose Source Directory");
savePath = getDirectory("Choose Save Location");
File.makeDirectory(savePath + "UNIQUE ID");
savePath = savePath + "UNIQUE ID" + File.separator;
files = getFileList(openPath);
setBatchMode(true);
for (timePoint = 0; timePoint < (files.length); timePoint++)
{
run("Z Project...", "projection=[Max Intensity] all");
saveAs("Tiff", savePath + "UNIQUE ID");
close();
}
setBatchMode(false);
I hope that helps some!

Related

DXL: Need to extract data from previous object baselines

Basically, I have to go through all baselines of an object until I get the author who modified "_ReqStatus" attribute and copy that value in "_Ownr" attribute. Everything is working fine for the current baseline, but I cannot get through the older baselines of the module. I have to mention that I run the script for 2000 objects each one having at least 20 baselines.
My code looks like this:
//scriptul recunoaste obiectele cu "ReqStatus modifica"
pragma runLim, 0
Module m = current
History h
HistoryType ht
Object o
string attributName
string attributNameBaseline
string authorName
string newOwner
Baseline lBaseLine
noError()
for o in entire m do {
**for lBaseLine in module(o) do{ //These 2 code lines were my try to load all baselines
Module lBaseMod = load(module(o), false) //but with no results**
for h in o do
{
string owner = ""
attributName=""
attributName = h.attrName
authorName=""
owner = o."_Owner"
if isDeleted(o) then continue
if(attributName=="_ReqStatus")
{
authorName=h.author
//print authorName
//print "\n"
if(null owner)
{
print identifier(o)
print "\n"
newOwner = authorName
print newOwner"\n"
o."_Ownr" = newOwner
//print newOwner
break
}
}
}
}
}
ErrMess = lastError()
Thanks
Tony Goodman provides a script "Smart History Viewer" at http://www.smartdxl.com/content/?p=418, Michael Sutherland has one at https://www.ibm.com/mysupport/s/forumsquestion?id=0D50z00006HIGSUCA5, also, if you do a search on https://www.ibm.com/mysupport/s/forumshome for e.g. "dxl history" you might find some more code examples which should help you with this topic.
Your problem is the variable o. It is set only in the loop for o in entire m, it always refers to the o in the current version of m, never to the corresponding Object in a baseline. When you open the Module lBaseMod, o is not automatically reassigned.
So, use a new variable of type Object, set it to the Object in the baseline corresponding to o and browse through this new Object's history, see the linked scripts for reference.
Also, you should rework the flow of your script. With your approach, you open all the Baselines of m for each Object. In your case this means 2000 * 20 load and close. It will be much faster (though not necessarily less memory consuming) to open all the baselines of m in an outer loop, probably using a Skip list to collect the necessary information.
Also note that when you test your script, "print" becomes very slow after some time. It will be faster if you remember all the values that you want to print e.g. in a Buffer and print it at the end of your script, or write the output to a file.

Print each process in OPL

I'm a college student in Taiwan and I'm doing a research about "how much wind turbines and solar photovoltaic panels should be installed to satisfy the require of minimum energy penetration rate in a semiconductor factory".
My professor hope I can display each variable in each period, but I don't know what code I should write.
Maybe there will be "execute" and "writeln" in my code? But there is nothing happened.
The following is my brief code:
{string} product = ...;
range time = 1..2;
{string} GreenPower = ...;
string NonGreenPower = ...οΌ›
dvar float InPut[product][time]; //In t period, amount of input of products
dvar float working[product][time]; //In t period, amount of working of products
dvar float OutPut[product][time]; //In t period, amount of output of products
So, I want to see the change in IntPut in each time, how to do it.
Thanks for your reading and tolerating my grammatical or spelling mistakes QQ
In order to print the solution to a console, you can use a post-processing block. A post-processing block is implemented by putting an execute block after the constraint specification (after the subject to block).
A post-processing block to print variables could look like this (untested code):
execute {
for (var p in product) {
for (var t in time) {
writeln(p + ", " + t + ": " + InPut[p][t] + ", " + working[p][t] + ", " + OutPut[p][t]);
}
}
}
Many of the examples shipped with CPLEX use post processing to display solutions to the console. You can look through them to learn what can be done in post processing and what are different ways to visualize solutions in the console.

RegEx for matching URLs with video IDs

I am trying to make an iOS shortcut that will makes me open all the websites videos links at once in new tabs so for that I need a RegEx for it.
Here is how the video links on this website look like:
https://m.worldstarhiphop.com/apple/video.php?v=wshhn5icmk9cKSyh9A17
https://m.worldstarhiphop.com/apple/video.php?v=wshhc8Ew271C2BZE0l31
I have this so far:
^(?!image$).*(worldstarhiphop.com/apple/video)
Because I don’t want the shortcut to open all images links but only video links.
I have added multiple capturing groups to this expression to be easy to modify/change and understand:
^((https?:\/\/.*)(worldstarhiphop.com)((\/apple\/video.php\?v=)|\/videos\/video.php\?v=)([A-Za-z0-9]{20}))
I did not close the right side using $, which you can do so, if you might want to.
The URLs you are wishing to match are in two mobile and web versions, which I have added both with various protocols, just in case. If it is unnecessary, you may remove it.
RegEx Descriptive Graph
The graph visualize how it works and you might want to test other expressions in this link:
Basic Performance Test
This JavaScript snippet returns runtime of a 1-million times for loop for performance.
const repeat = 1000000;
const start = Date.now();
for (var i = repeat; i >= 0; i--) {
const string = 'https://m.worldstarhiphop.com/apple/video.php?v=wshhc8Ew271C2BZE0l31';
const regex = /^((https?:\/\/.*)(worldstarhiphop.com)((\/apple\/video.php\?v=)|\/videos\/video.php\?v=)([A-Za-z0-9]{20}))/gm;
var match = string.replace(regex, "\nGroup #1: $1\nGroup #2: $2 \nGroup #3: $3 \nGroup #4: $4\nGroup #6: $6 \n");
}
const end = Date.now() - start;
console.log("YAAAY! \"" + match + "\" is a match πŸ’šπŸ’šπŸ’š ");
console.log(end / 1000 + " is the runtime of " + repeat + " times benchmark test. 😳 ");

Save vector to file during debug session (Xcode)

My application has crashed in an assert, and the debugger is attached. To be able to reproduce the crash I want to save a C++ vector with 397 struct{uint64_t, uint64_t} elements to file.
My first approach was to try to print the vector. I can print the vector to the console, but it seems like only the first 256 values are written. Is it possible to remove the 256 element restriction?
I've also searched for a way to save the vector to file from within the debugger, but I've not found any way. I've not even found a way to save a memory region, but I guess that must be possible...
Since you mentioned that you're stopped in the debugger in Xcode, I'll assume you're debugging with lldb. You can use the expression command to execute essentially arbitrary code when you're stopped in the debugger, for example:
expression for(int j = 0; j < 10; j++) { (void)NSLog(#"%d", j); }
Will execute a for loop and print the numbers 0 through 9. You should be able to use a similar technique to iterate over your vector and write it to a file. You can combine multiple expressions using a semicolon, just as if you were writing normal code (well, except for newlines). For example, this will write "Hello, world" to a temporary file at /tmp/vector.dat, not exactly what you want, but I think you'll get the idea:
expression FILE *fp = (FILE*)fopen("/tmp/vector.dat", "w"); (void)fprintf(fp, "Hello, world!\n"); (void)fclose(fp);

Matlab, Econometrics toolbox - Simulate ARIMA with deterministic time-varying variance

DISCLAIMER: This question is only for those who have access to the econometrics toolbox in Matlab.
The Situation: I would like to use Matlab to simulate N observations from an ARIMA(p, d, q) model using the econometrics toolbox. What's the difficulty? I would like the innovations to be simulated with deterministic, time-varying variance.
Question 1) Can I do this using the in-built matlab simulate function without altering it myself? As near as I can tell, this is not possible. From my reading of the docs, the innovations can either be specified to have a constant variance (ie same variance for each innovation), or be specified to be stochastically time-varying (eg a GARCH model), but they cannot be deterministically time-varying, where I, the user, choose their values (except in the trivial constant case).
Question 2) If the answer to question 1 is "No", then does anyone see any reason why I can't edit the simulate function from the econometrics toolbox as follows:
a) Alter the preamble such that the function won't throw an error if the Variance field in the input model is set to a numeric vector instead of a numeric scalar.
b) Alter line 310 of simulate from:
E(:,(maxPQ + 1:end)) = Z * sqrt(variance);
to
E(:,(maxPQ + 1:end)) = (ones(NumPath, 1) * sqrt(variance)) .* Z;
where NumPath is the number of paths to be simulated, and it can be assumed that I've included an error trap to ensure that the (input) deterministic variance path stored in variance is of the right length (ie equal to the number of observations to be simulated per path).
Any help would be most appreciated. Apologies if the question seems basic, I just haven't ever edited one of Mathwork's own functions before and didn't want to do something foolish.
UPDATE (2012-10-18): I'm confident that the code edit I've suggested above is valid, and I'm mostly confident that it won't break anything else. However it turns out that implementing the solution is not trivial due to file permissions. I'm currently talking with Mathworks about the best way to achieve my goal. I'll post the results here once I have them.
It's been a week and a half with no answer, so I think I'm probably okay to post my own answer at this point.
In response to my question 1), no, I have not found anyway to do this with the built-in matlab functions.
In response to my question 2), yes, what I have posted will work. However, it was a little more involved than I imagined due to matlab file permissions. Here is a step-by-step guide:
i) Somewhere in your matlab path, create the directory #arima_Custom.
ii) In the command window, type edit arima. Copy the text of this file into a new m file and save it in the directory #arima_Custom with the filename arima_Custom.m.
iii) Locate the econometrics toolbox on your machine. Once found, look for the directory #arima in the toolbox. This directory will probably be located (on a Linux machine) at something like $MATLAB_ROOT/toolbox/econ/econ/#arima (on my machine, $MATLAB_ROOT is at /usr/local/Matlab/R2012b). Copy the contents of #arima to #arima_Custom, except do NOT copy the file arima.m.
iv) Open arima_Custom for editing, ie edit arima_Custom. In this file change line 1 from:
classdef (Sealed) arima < internal.econ.LagIndexableTimeSeries
to
classdef (Sealed) arima_Custom < internal.econ.LagIndexableTimeSeries
Next, change line 406 from:
function OBJ = arima(varargin)
to
function OBJ = arima_Custom(varargin)
Now, change line 993 from:
if isa(OBJ.Variance, 'double') && (OBJ.Variance <= 0)
to
if isa(OBJ.Variance, 'double') && (sum(OBJ.Variance <= 0) > 0)
v) Open the simulate.m located in #arima_Custom for editing (we copied it there in step iii). It is probably best to open this file by navigating to it manually in the Current Folder window, to ensure the correct simulate.m is opened. In this file, alter line 310 from:
E(:,(maxPQ + 1:end)) = Z * sqrt(variance);
to
%Check that the input variance is of the right length (if it isn't scalar)
if isscalar(variance) == 0
if size(variance, 2) ~= 1
error('Deterministic variance must be a column vector');
end
if size(variance, 1) ~= numObs
error('Deterministic variance vector is incorrect length relative to number of observations');
end
else
variance = variance(ones(numObs, 1));
end
%Scale innovations using deterministic variance
E(:,(maxPQ + 1:end)) = sqrt(ones(numPaths, 1) * variance') .* Z;
And we're done!
You should now be able to simulate with deterministically time-varying variance using the arima_Custom class, for example (for an ARIMA(0,1,0)):
ARIMAModel = arima_Custom('D', 1, 'Variance', ScalarVariance, 'Constant', 0);
ARIMAModel.Variance = TimeVaryingVarianceVector;
[X, e, VarianceVector] = simulate(ARIMAModel, NumObs, 'numPaths', NumPaths);
Further, you should also still be able to use matlab's original arima class, since we didn't alter it.

Resources