how to load data locally from scrip, without using bundle

Cool displays
User avatar
glez_b
Posts: 87
Joined: Thu May 05, 2011 9:19 pm
Contact:

how to load data locally from scrip, without using bundle

Post by glez_b »

How I can load satellites data , without going through a bundle. My data is stored in a local directory (/ home / mcidasv / Data). how I can call this data from a script?

I'm working with a database of satellites very long. Sometimes I need to load up to 100 satellite imagery data. What is the best way to call or load this data?
Boris_MCS
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: how to load data locally from scrip, without using bundle

Post by joleenf »

Boris,

If will be difficult to achieve this without a bundle in the current version of McIDAS-V (version 1.01). However, if you wish, you can created a generic name for the datasourcename in the bundle, and then use a reference to replace that data from a script. If this is done in a loop, I believe you can achieve your desired result. Please see this post for the explanation of how to replace data in bundles:

viewtopic.php?f=31&t=443&hilit=loading+data+with+bundle

I have also posted information on how to write a script without a bundle, however, this will only work in version 1.02 and there is current development which should make the process clearer and more versatile.

As far as pointing to your local data, this may still be difficult in the current version, unless the data is from the same local dataset (same GROUP and DESCRIPTOR). If it is, you could try copying the location from the interactive session:

In the Field Selector right-click over the dataset that you wish to load through a script. Select Edit>Properties
Screen Shot 2012-03-09 at 6.43.33 AM.png


Then Click on the Details tab
Screen Shot 2012-03-14 at 10.26.22 AM.png


The location can be used "adde://localhost:8112/imagedata?..." If you are working within the same dataset, change the date, time, band information to access the desired data.

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: how to load data locally from scrip, without using bundle

Post by joleenf »

Hi Boris,

I just checked this script and this works in version 1.01 with local data

viewtopic.php?f=31&t=505&hilit=load

This will help you to achieve what you want to do without a bundle.

Joleen
User avatar
glez_b
Posts: 87
Joined: Thu May 05, 2011 9:19 pm
Contact:

Re: how to load data locally from scrip, without using bundle

Post by glez_b »

Thank you for your contribution. Some time ago I received a code to call data from a jython script. The following code calls the data, which are located in my local directory: "/ home / mcidasv / Documents / CLASS". The code is as follows:

def scm(directory):
import os;
fs = os.listdir(directory);
for name in fs:
print "Reading in:",name
scm("/home/mcidasv/Documentos/CLASS")


I run the script scm.py as follows: /home/mcidasv/McIDAS-V-System/runMcV -islfile /home/mcidasv/JYTHON/scm.py
i get the list of data contained in: /home/mcidasv/Documentos/CLASS
Reading in: goes12.2004.096.181515.BAND_06
Reading in: goes12.2004.096.221515.BAND_06
Reading in: goes12.2004.095.021514.BAND_06
Reading in: goes12.2004.095.221515.BAND_06
Reading in: goes12.2004.095.141514.BAND_06
Reading in: goes12.2004.094.231515.BAND_06
Reading in: goes12.2004.096.011515.BAND_06

One of my goals in my research on mesoscale convective systems is to identify those systems whose brightness temperature (TIR <-54 º C) and whose area of cloud shield (for TIR<-54 º C) is of 34000 km2.

To achieve this, add the following lines of code to my code above:
The full code:

def scm(directory):
import os;
fs = os.listdir(directory);
for name in fs:
print "Reading in:",name

scm("/home/mcidasv/Documentos/CLASS")

af = Files(directory+"/"+name);
ad = af.getFilesDirectory();
count = 0;
data = af.getFloatData();

# now look through the first band y count pixels
for i in xrange(ad.getLines()):
for j in xrange(ad.getElements()):
if (data[0][i][j] > 199.5 and (data[0][i][j] < 200.5
count = count + 1;
print "For file",name," count = ",count
Again I run the script scm.py as follows: /home/mcidasv/McIDAS-V-System/runMcV -islfile /home/mcidasv/JYTHON/scm.py and i get the next error:

File "<string>", line 16
for i in xrange(ad.getLines()):
^
IndentationError: unindent does not match any outer indentation level
Error running jython script:/home/mcidasv/JYTHON/scm.py
File "<string>", line 16
for i in xrange(ad.getLines()):
^
IndentationError: unindent does not match any outer indentation level

Actually I'm new to the jython language and I'm just learning. If anyone can help me with this script or any idea you suggest to improve it, I would greatly appreciate.
Attachments
scm.py
(590 Bytes) Downloaded 536 times
Boris_MCS
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: how to load data locally from scrip, without using bundle

Post by tomw »

Boris:

Jython syntax is like Python -- blocks must be indented a constant amount. For example:

Code: Select all

for i in xrange(20): 
    k = i + 1;
    print k;


The lines "k = i + 1" and "print k" must be indented the same number of spaces (the number does not matter as long as it is greater than the number of the enclosing block).

I recommend that you look at the on-line Jython User Guide, plus any basic Python documentation. There are also books available, referenced from the jython.org web site.

<http://wiki.python.org/jython/UserGuide>

tom
User avatar
glez_b
Posts: 87
Joined: Thu May 05, 2011 9:19 pm
Contact:

Re: how to load data locally from scrip, without using bundle

Post by glez_b »

Sorry, I posted wrong code. Really My error is this:

File "<string>", line 9
af = Files(directory+"/"+name);
^
SyntaxError: mismatched input '' expecting EOF
Error running jython script:/home/mcidasv/JYTHON/scm.py
File "<string>", line 9
af = Files(directory+"/"+name);
^

i would like you can guide me

Thanks
Boris_MCS
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: how to load data locally from scrip, without using bundle

Post by joleenf »

Boris,

This is not very clear to me. First, have you imported the AreaFile class so that you can use it?

Code: Select all

from edu.wisc.ssec.mcidas import AreaFile;


then the correct syntax is

af = AreaFile(directory+"/"+name);


If you had imported AreaFile in this way:

Code: Select all

from edu.wisc.ssec.mcidas import AreaFile as File;
,

then you could construct the command as you have in the post: af = File(directory+"/"+name);

Otherwise, check the value of the string

Code: Select all

myFiles = directory + "/" + name
print myFiles


To make sure it is the expected filename structure.

As a note, the code you are referencing actually came from this post: viewtopic.php?f=24&t=1026

Thanks,
Joleen
User avatar
glez_b
Posts: 87
Joined: Thu May 05, 2011 9:19 pm
Contact:

Re: how to load data locally from scrip, without using bundle

Post by glez_b »

Thanks for your comments. You'll think I'm a fool or not reviewed the manuals, but I assure you that I have made an effort to learn the language of jython. I copied the code you posted in viewtopic.php?f=24&t=1026 , and when I run the script now I get this error:


File "<string>", line 16
count = count + 1;
^
SyntaxError: no viable alternative at input 'count'
Error running jython script:/home/mcidasv/JYTHON/TIR.py
File "<string>", line 16
count = count + 1;
^
SyntaxError: no viable alternative at input 'count'
Boris_MCS
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: how to load data locally from scrip, without using bundle

Post by tomw »

Hi Boris...

Sorry, but when I looked at what you posted here, there were no indents in the code, and thus I thought to direct you to some reference reading as you indicated you were new to the Python language. I am glad that you have taken the time to learn the language.

Also, please note that when you post to this Forum, you can click on the little "Code" button above the editor window, and then put your code between the tags that are pasted into your text -- that way, we can get the indenting, etc., that is in your code.

Regarding the error message on the "count = count + 1;" line, in the code you sent in a previous post, you had written:

Code: Select all

for i in xrange(ad.getLines()):
for j in xrange(ad.getElements()):
if (data[0][i][j] > 199.5 and (data[0][i][j] < 200.5
count = count + 1;


Assuming that this is actually indented to something like this:

Code: Select all

for i in xrange(ad.getLines()):
    for j in xrange(ad.getElements()):
        if (data[0][i][j] > 199.5 and (data[0][i][j] < 200.5
            count = count + 1;


There are a couple of syntax errors in the "if" statement. It should read:

Code: Select all

        if (data[0][i][j]) > 199.5 and (data[0][i][j]) < 200.5:


I added two parentheses and the colon at the end.

Hope this helps.

tom
User avatar
glez_b
Posts: 87
Joined: Thu May 05, 2011 9:19 pm
Contact:

Re: how to load data locally from scrip, without using bundle

Post by glez_b »

Thanks, the script ran correctly. I have a doubt on the part of the if, values ??of 199.5 and 200.5 corresponding to temperature values ??or values ??of brigthness. When i run the scrip does not find any data whit the above values. All is 0

Reading in: goes12.2004.095.064513.BAND_06
For file goes12.2004.095.064513.BAND_06 count = 0
Reading in: goes12.2004.095.201515.BAND_06
For file goes12.2004.095.201515.BAND_06 count = 0
Reading in: goes12.2004.096.161517.BAND_06
For file goes12.2004.096.161517.BAND_06 count = 0
Reading in: goes12.2004.095.001515.BAND_06
For file goes12.2004.095.001515.BAND_06 count = 0
Reading in: goes12.2004.095.071514.BAND_06
For file goes12.2004.095.071514.BAND_06 count = 0

I guess this happens because the range of values ??assigned. I need to do is change the range,por example : temperatures infrarred < 219 K. Again I run the script i get the same value of count(0)
Boris_MCS
Post Reply