Jython works line by line, not via script

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
brianvh
Posts: 10
Joined: Mon Oct 08, 2018 12:14 pm

Jython works line by line, not via script

Post by brianvh »

For some time I've been happily running a script by cron job, but then it stopped working. The funny thing is that the script stopped working both on my laptop and on the server I use. I checked the script but running it line by line: no problems. But when I run it as a script, nothing happens. No error messages, but no output either. It's supposed to download GOES data, but it quietly does nothing.

Since it happened both to server and laptop I suspect this is related to an update, but I'm not sure when the script stopped working and I only vaguely remember perhaps doing a mcidas V update on the laptop about a year ago.

My system manager suggested that the path to java is no longer correct, but it's in /usr/bin/java which is of course in my path.

Any other suggestions on what may have happened?

thanks.
User avatar
bobc
Posts: 987
Joined: Mon Nov 15, 2010 5:57 pm

Re: Jython works line by line, not via script

Post by bobc »

Hello,

A few questions and things to try:
  1. What version of McIDAS-V are you running? You can find this out in a foreground session by going to "Help > About McIDAS-V" in the Main Display window. It's been a few years since the last release of McIDAS-V (version 1.8), though we are planning to release version 1.9 in the coming months.
  2. Could you please send us your script?
  3. In a foreground session, can you run the entire script at once through the Jython Shell (Tools > Formulas > Jython Shell from the Main Display window)?
  4. In a foreground session, select Edit > User Preferences from the Main Display window. From the User Preferences window, navigate to the Advanced tab and set Log Level to "TRACE". Exit the foreground session and try running the script again from the background. Assuming the script fails, go to your /Users/username/McIDAS-V directory and see if anything was written to mcidasv.log. There are many cases where no error output goes to the Terminal window, but it goes to mcidasv.log. For example, this can happen if you don't point correctly to the script or if there are any invalid characters in the script.
Thanks,
Bob Carp
McIDAS User Services
User avatar
brianvh
Posts: 10
Joined: Mon Oct 08, 2018 12:14 pm

Re: Jython works line by line, not via script

Post by brianvh »

Thanks for the detailed response.

I'm running version 1.7.1, I suppose I could update to at least 1.8 and see if that fixes it.

I only know how to run the script using runMcV; the jython shell appears to only accept code one line at a time. I tried pasting the whole file (minus multiline comments) but nothing seems to be happening. Some guidance on how to run an entire script in the jython shell would help.

The script is below (converted to script from a function so input is via reading a file):

--------------------------------------------

# G16_download(datafolder,year,month,day,starthr,endhr,startmin,endmin)
"""
function or script to download goes16 data using mcidas-V
(to convert to function uncomment the first line, then move triple quotes below 'endmin')
note that all data must be within the last 24 hours
All are except datafolder are expected to be integers
datafolder must end with '/'

run by 'runMcV -script goes16_download.py', but use full paths for runMcV, etc
/applications/McIDAS-V-System/

data is input by goes16_datetime.txt; look at read for format
"""

datafolder='/users/brianvanthull2/documents/grants/prathap/indoor/goes/'

# read date,time information from file
# if time = 0, most recent file is retrieved
f = open(datafolder+'goes16_datetime.txt','r')
dateline = f.readline()
f.close()
datearray = dateline.split(',')
year = (datearray[0]).strip()
month = (datearray[1]).strip()
day = (datearray[2]).strip()
starthr = (datearray[3]).strip()
endhr = (datearray[4]).strip()
startmin = (datearray[5]).strip()
endmin = (datearray[6]).strip()

# create date and time strings, assuming all inputs are integers
datestr = str(year)+'-'+str(month)+'-'+str(day)
starttime = str(starthr)+':'+str(startmin)+':00'
endtime = str(endhr)+':'+str(endmin)+':00'

print('start, end times:',starttime,endtime)
# make Python dictionary of parameters
# datestr must be within one day of present
# short range of times to capture one image ('timestr1','timestr2')
g16Parms = dict(
server = 'lead.unidata.ucar.edu',
dataset = 'NPGOESR',
descriptor = 'CODCN',
day = datestr,
time = (starttime,endtime),
unit = 'BRIT',
size = 'ALL'
)

# loadADDEImage call
# g16Data = loadGrid(**g16Parms)
g16Data = loadADDEImage(**g16Parms)

# Export the data returned from loadADDEImage in the currently active display panel
exportGridToNetcdf(g16Data,datafolder+'G16_download.nc')

----------------------------------------

The goes_datetime.txt file is simple: "2022, 08, 31, 12, 12, 00, 03"
User avatar
bobc
Posts: 987
Joined: Mon Nov 15, 2010 5:57 pm

Re: Jython works line by line, not via script

Post by bobc »

Hello,

Your script is running fine on my Windows 10 machine. To get the Jython Shell to multi-line input mode you can either use Ctrl+/ or click the blue arrow button (circled in red in the image below):

Jython Shell
Jython Shell
shell.png (5.1 KiB) Viewed 1331 times

Let me know if you're able to run the script in the Shell and if there are any errors you can't work around. I'm assuming this is just from how your script was pasted in your response, but you want to make sure you have proper indentation when setting up your dictionary. For example:

Code: Select all

g16Parms = dict(
    server = 'lead.unidata.ucar.edu',
    dataset = 'NPGOESR',
    descriptor = 'CODCN',
    day = datestr,
    time = (starttime,endtime),
    unit = 'BRIT',
    size = 'ALL'
    )
Thanks,
Bob
User avatar
brianvh
Posts: 10
Joined: Mon Oct 08, 2018 12:14 pm

Re: Jython works line by line, not via script

Post by brianvh »

It ran fine via the jython shell, downloading my GOES file. I erased the old mcidasv.log and ran it again, no messages. I was somewhat amazed, so went back and ran the script using runMcV and am back to getting no GOES file. I do get a bunch of screen messages, the dump is

(base) bvh-3:code brianvanthull2$ /applications/McIDAS-V-System/runMcV -script goes116_download.py
Reading system configuration...
sys mem: 8192
mcv flags: -Dvisad.java3d.noerasebackground=true -Dvisad.java3d.textureNpot=false -Dvisad.java3d.imageByRef=true -Dvisad.java3d.geometryByRef=true -Didv.3d=true -DtextureWidthMax=4096 -forceaqua -userpath "/Users/brianvanthull2/Documents/McIDAS-V" -bundle "0;"
"/applications/McIDAS-V-System/.install4j/jre.bundle/Contents/Home/jre/bin/java" -Xmx6553M -Djava.ext.dirs="/applications/McIDAS-V-System/.install4j/jre.bundle/Contents/Home/jre/lib/ext" -Djava.library.path="/applications/McIDAS-V-System/.install4j/jre.bundle/Contents/Home/jre/lib/ext" -Dloglevel="TRACE" -Dlogback.configurationFile="/Users/brianvanthull2/Documents/McIDAS-V/logback.xml" -Dmcv.userpath="/Users/brianvanthull2/Documents/McIDAS-V" -Dmcv.logpath="/Users/brianvanthull2/Documents/McIDAS-V/mcidasv.log" -Dfile.encoding=UTF-8 -Dpython.security.respectJavaAccessibility=false -Xdock:name=McIDAS-V -Xdock:icon=mcidasv.icns -classpath ".:./mcv_userguide.jar:./mcidasv.jar" -da edu.wisc.ssec.mcidasv.McIDASV -Dvisad.java3d.noerasebackground=true -Dvisad.java3d.textureNpot=false -Dvisad.java3d.imageByRef=true -Dvisad.java3d.geometryByRef=true -Didv.3d=true -DtextureWidthMax=4096 -forceaqua -userpath "/Users/brianvanthull2/Documents/McIDAS-V" -bundle "0;" -script goes116_download.py

And I end up with no downloaded file.
User avatar
bobc
Posts: 987
Joined: Mon Nov 15, 2010 5:57 pm

Re: Jython works line by line, not via script

Post by bobc »

Hello,

That looks like the standard output I would expect to see when running a background script. It essentially returns all of your settings from the advanced preferences. A couple things:
  1. Can you specify the full path to your script in your runMcV command? for example:

    Code: Select all

    runMcV -script /Users/brianvanthull2/goes116_download.py
    or wherever the script lives on your machine.
  2. Take a look in your /Users/brianvanthull2/McIDAS-V directory and open the mcidasv.log file. This file will likely give you more information as to what is going wrong. Do you see this log file when running a background script?
Thanks,
Bob
User avatar
brianvh
Posts: 10
Joined: Mon Oct 08, 2018 12:14 pm

Re: Jython works line by line, not via script

Post by brianvh »

I just wanted to report that updating to the most recent version of McIDAS-V fixed the problem. Thanks for all the responses! (Sorry it took me so long to finally get around to the upgrade.)
Post Reply