help with a script

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

help with a script

George Patterson
Dear all,
These are pretty amateur issues and but you can probably save me a several more hours of searching the mailing list and/or google searches.
I have written a script to collect multiple channels and multiple z positions for each channel. It will collect 10-20 images in one channel before switching to the next to collect 10-20 images.    In an earlier inquiry to the mailing list I was informed that the Multi-D Acq was unable to do this and a script was needed.  Saumya Saurabh and Nico Sturrman were kind enough to send scripts which I've been able to modify to meet my needs.  The script I've produced works well and my thanks to both.
I'm trying to make it a little easier for users to input the channels and their subsequent settings.  My plan was to make it such that users only needed to input the channels they wished to use in this part:

BlueChannel="";
GreenChannel="FITC";
RedChannel="Rhodamine";
FarRedChannel="";

For instance, here I want to use only the "FITC" and "Rhodamine" channels.
I've made a shortened version which produces the same problem.  Or at least where I think the problem lies.  It is copied below.

When I run the script, the error is "Line 41: general error : channels .length" and highlights this line:
gui.openAcquisition(acqName, rootDirName, nrSteps, channels.length, numSlices, true, true);

It seems the channel information cannot be read inside this if loop.  

if(GreenChannel!="" && RedChannel!="" ){
String[] channels = {GreenChannel,RedChannel};
Color[] colors = {Color.GREEN,Color.RED};    
int[] exposures = {GreenChannelExposure,RedChannelExposure};    
}

When I remove the if loop and have the channel information outside the loop, the script runs fine and produces the proper message.
 

1.  I know this is a pretty ugly way to do this, but it's simple approach for a novice like me.  Is this possible and where is my mistake?

2. I have a separate question.  I've found that the script seems to remember variables from one run to the next.  For instance, if I run the script first with the channel information outside the if loop, then modify the script to put the information inside the if loop, the script runs fine.  I have to restart Micromanager to reproduce the error with the channel information inside the if loop.  
Is this normal?  What's going on here?  Is there a command I should include to clear this?

I've using the demo configuration in Micromanger 1.46 and have tried last night's build which gives the same error.
I running a Mac Pro with OS X 10.6.7.

Thanks,
George



//**************************************Begin script*********************************
// clear all previous acquisitions
gui.closeAllAcquisitions();
gui.clearMessageWindow();

import java.lang.System;

// file locations
acqName = "test-acq-col";
rootDirName = "/Users/pattersg/George_Main_Folder/Microscope_stuff/Test_script/";

BlueChannel="";
GreenChannel="FITC";
RedChannel="Rhodamine";
FarRedChannel="";
                                                                                                               
                                                                                               
BlueChannelExposure=100;
GreenChannelExposure=100;
RedChannelExposure=100;
FarRedChannelExposure=100;



if(GreenChannel!="" && RedChannel!="" ){
String[] channels = {GreenChannel,RedChannel};
Color[] colors = {Color.GREEN,Color.RED};    
int[] exposures = {GreenChannelExposure,RedChannelExposure};    
}



channelGroup = "Channel";


numSlices = 1;
nrSteps=1;
intervalMs = 0;


gui.openAcquisition(acqName, rootDirName, nrSteps, channels.length, numSlices, true, true);

gui.message(acqName+"   "+ rootDirName+"   "+ nrSteps+"   "+channels.length+"   "+ numSlices);



------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general

smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: help with a script

Nico Stuurman-4
Hi George,

On Nov 9, 2011, at 6:18 AM, George Patterson wrote:

> I have written a script to collect multiple channels and multiple z positions for each channel. It will collect 10-20 images in one channel before switching to the next to collect 10-20 images.    I'm trying to make it a little easier for users to input the channels and their subsequent settings.  My plan was to make it such that users only needed to input the channels they wished to use in this part:
>
> When I run the script, the error is "Line 41: general error : channels .length" and highlights this line:
> gui.openAcquisition(acqName, rootDirName, nrSteps, channels.length, numSlices, true, true);
>
> It seems the channel information cannot be read inside this if loop.  

This is most likely a question of scope.  The variable "String[] channels" is declared within the if block, and is therefore not known outside of that block.  Move the declaration ("String[] channels") before the if block and things should start working.

However, you will need to write many of these if blocks to catch all different possibilities.  What may be easier in the end is to let your users set up channels, colors and exposure times in the Micro-Manager Multi-Dimensional Acquisition window.  You can then get all relevant variables out with the following code


channelGroup = acq.getChannelGroup();
chSpec = acq.getChannels();
String[] channels = new String[chSpec.size()];
Color[] colors = new Color[chSpec.size()];
double[] exposure = new double[chSpec.size()];

int i = 0;
for (ch : chSpec) {
      channels[i] = ch.config_;
      colors[i] = ch.color_;
      exposure[i++] = ch.exposure_;
}


Best,

Nico



------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: help with a script

George Patterson
Mike,
Thanks for giving the script a go and the info on lexical scoping as well.
I don't just hit random keys when I'm working on these scripts, but my approach isn't too far from it.
Obviously, I need to work on the basics.
Best, George


Nico,
I did write a whole bunch of those blocks to catch all of the possibilities for 4 channels.  Pretty ham-handed, but I figured it would serve the purpose.  I like your way much better.  I wasn't even aware that was a possibility.  You'd think for as much as I stared at the Multi-Dimensional Engine API Reference, I'd have picked up on it.
Thanks for the quick response and especially for the code.
Best,
George

On Nov 10, 2011, at 12:00 AM, Nico Stuurman wrote:

> Hi George,
>
> On Nov 9, 2011, at 6:18 AM, George Patterson wrote:
>
>> I have written a script to collect multiple channels and multiple z positions for each channel. It will collect 10-20 images in one channel before switching to the next to collect 10-20 images.    I'm trying to make it a little easier for users to input the channels and their subsequent settings.  My plan was to make it such that users only needed to input the channels they wished to use in this part:
>>
>> When I run the script, the error is "Line 41: general error : channels .length" and highlights this line:
>> gui.openAcquisition(acqName, rootDirName, nrSteps, channels.length, numSlices, true, true);
>>
>> It seems the channel information cannot be read inside this if loop.  
>
> This is most likely a question of scope.  The variable "String[] channels" is declared within the if block, and is therefore not known outside of that block.  Move the declaration ("String[] channels") before the if block and things should start working.
>
> However, you will need to write many of these if blocks to catch all different possibilities.  What may be easier in the end is to let your users set up channels, colors and exposure times in the Micro-Manager Multi-Dimensional Acquisition window.  You can then get all relevant variables out with the following code
>
>
> channelGroup = acq.getChannelGroup();
> chSpec = acq.getChannels();
> String[] channels = new String[chSpec.size()];
> Color[] colors = new Color[chSpec.size()];
> double[] exposure = new double[chSpec.size()];
>
> int i = 0;
> for (ch : chSpec) {
>      channels[i] = ch.config_;
>      colors[i] = ch.color_;
>      exposure[i++] = ch.exposure_;
> }
>
>
> Best,
>
> Nico
>
>
>
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save $700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> micro-manager-general mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/micro-manager-general
George H. Patterson
Building 13 3E33
13 South Drive
Biophotonics Section
National Institute of Biomedical Imaging and Bioengineering
National Institutes of Health
Bethesda, MD 20892
Office: 301-443-0241
Fax: 301-496-6608
[hidden email]


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general

smime.p7s (5K) Download Attachment
Loading...