importing new jython tools when running in a jython shell

Post any questions, ideas, or topics related to Jython and Python scripting.
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

I did not realize I was pointing to the wrong jython version. I was able to use the jython libraries distributed with McIDAS-V by using the following on the command line

Code: Select all

java -mx3000m -Dj3d.debug=true -Dpython.home=/home/user/McIDAS-V/jython2.5.2 -Dpython.security.respectJavaAccessibility=false org.python.util.jython -i mcvinit.py


This must be what I used previously. In this form, I can use the file you provided without any changes.

I wanted to test listADDEImageTimes, so I added that to the list of methods imported from mcvadde.

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

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

Currently, I have added the entire file of mcvinit to the beginning of my background scripts. I have not found a way to run the file mcvinit than a script or import mcvinit. Is there a better way to do this? Is there a way to run the import module once and cache the import for latter processes?

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

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

With the upgrade to 1.6, what do I need to the import section of mcvinit (I already removed oldADDEImage from the list of mcvadde imports and added loadADDEImage)? Also, right now I insert the content of mcvinit at the beginning of multiple files which run different pieces user code. Is there a way to maintain one mcvinit file and point to that file before running my user code?

Traceback (most recent call last):
File "/home/joleenf/McIDAS-V-System/mcvinitTest.py", line 121, in <module>
myList=listADDEImageTimes(server=server, dataset=group, descriptor=desc, day=aDay, time=('00:00','10:00'), band=1, accounting=myAccounting)
File "/home/joleenf/McIDAS-V-System/mcidasv.jar/edu/wisc/ssec/mcidasv/resources/python/mcvadde.py", line 815, in listADDEImageTimes
File "/home/joleenf/McIDAS-V-System/mcidasv.jar/edu/wisc/ssec/mcidasv/resources/python/mcvadde.py", line 815, in listADDEImageTimes
NameError: global name 'ErrorCodeAreaUtils' is not defined


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

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Any ideas about how to fix this error?
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

Hi Joleen,

Sorry for the delayed reply (I was out on Friday and Monday). I'm still working on the error message itself, but you may be able to avoid copy/pasting the mcvinit code now that we're using Jython 2.7. You can try placing your mcvinit.py in '~/.local/lib/jython2.7/site-packages' (you may need to create the directories first) and then from your scripts simply do "import mcvinit".
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

I should've waited a few minutes! Can you try adding the following line to your mcvinit (I added it right before the "from edu.wisc.ssec.mcidasv.data.hydra import Statistics" line)?

Code: Select all

from edu.wisc.ssec.mcidasv.util import ErrorCodeAreaUtils
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

I still see the same error after adding the import statement.

Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

Hi Joleen,

I have things in a "works for me" state--hopefully it won't be limited to just me. At any rate, the command line was getting pretty cumbersome, so I added a shell script that can be used to launch things. If you'd like to avoid the additional script, you can always alter the last line of run_mcvinit.sh to something like:

Code: Select all

echo "java -Xmx3000 ..."


and then you should be able to run the output of that.

To get things working with the script, you'll want to "chmod +x run_mcvinit.sh" and then change run_mcvinit.sh's "MCV_DIR" and "MCV_INIT" variable are pointing to the correct locations. Similarly, make sure mcvinit.py's "_mcv_classpath_to_syspath" call is pointing to the same location as "MCV_DIR". Also, mcvinit.py has been updated, so be sure to use the copy in the attached zip file.

I apologize for how convoluted this process is becoming--I'll work on making this less tedious/fragile.

Jon
Attachments
mcvinit.zip
Launcher script and new mcvinit.py.
(2.63 KiB) Downloaded 307 times
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

Reviewing what we have done, questions will be in bold:

1.) I have taken the code from mcvinit.py, renamed it to usercustomize.py and placed it in my ~/.local/lib/jython2.7/site-packages directory.

2.) I have placed my code that I wish to run in cron in that directory (~/.local/lib/jython2.7/site-packages) as well. For now, I am calling it comparisonStats.py.

3.) At one point, we added "import usercustomize" to the beginning of that code, but have since removed it. So I am not sure that the comparisonStats.py code ever gets any information from usercustomize (mcvinit). Am I using usercustomize?

4.) At the end of the comparisonStats.py code, I have added a main() module, in this module. mcvadde is imported. I have changed the "import mcvadde" line to "from mcvadde import *" I did this so that I could use the mcvadde modules as I would call them in the jython shell (listADDEImageTimes() versus mcvadde.listADDEImageTimes()). Maybe I should just import the specific modules I need: from mcvadde import listADDEImageTimes, loadADDEImage.

if __name__ == '__main__':
from mcvadde import *
from reverse_enum import reverse_enum
from visad.python.JPythonMethods import *
import makeDateDir, splitSearch
print dir()
getImageSets()

exit()

Also, I can't find the sub() function, do you know where that is?

Thanks,
Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

Hi Joleen,

usercustomize.py:
~/.local/lib/jython2.7/site-packages/usercustomize.py should always be implicitly loaded by Jython (assuming the file exists). It does look like "runMcV -pyfile/-script file.py" (incorrectly) ignores usercustomize.py, but usercustomize.py should be getting loaded if you're not launching an actual McV session. I'll get the bug fixed ASAP.

sub:
sub(...) is defined in the IDV's griddiag.py:

https://github.com/Unidata/IDV/blob/mas ... py#L55-L62

It's just a wrapper around GridMath.subtract(...):

https://github.com/Unidata/IDV/blob/mas ... #L162-L177

GridMath.subtract() itself is just a wrapper around GridMath.doMath():

https://github.com/Unidata/IDV/blob/mas ... #L292-L351

imports:
So-called "wild card" imports do work fine, but their use is discouraged (see the last bullet in this link).

Apologies for the delayed reply.

Jon
Post Reply