HydrologicEngineeringCenter / Vortex

data processing utilities
MIT License
25 stars 7 forks source link

geo not recognized #92

Open ranleu opened 1 year ago

ranleu commented 1 year ago

I am trying to automate importing of *.nc files. I've taken the script and batch samples here and modified them to work with Jython-Standalone and to work with the vortex installation included in HEC-HMS as follows:

SET "VORTEX_HOME=C:\Program Files\HEC\HEC-HMS\4.10"
SET "PATH=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal;%PATH%"
SET "PROJ_LIB=%VORTEX_HOME%\bin\gdal\projlib"
SET "GDAL_DATA=%VORTEX_HOME%\bin\gdal\gdal-data"
SET "CLASSPATH=%VORTEX_HOME%\lib\*"

"%VORTEX_HOME%\jre\bin\java.exe" -jar C:\Users\...\jython-standalone-2.7.3.jar C:\Users\...\GRID_Importer\met_data_import.py

and the script met_data_import.py

import sys
sys.path.insert(0, 'C:/Program Files/HEC/HEC-HMS/4.10/lib/vortex-0.10.30.jar')
print sys.path

from mil.army.usace.hec.vortex.io import BatchImporter
from mil.army.usace.hec.vortex.geo import WktFactory
....
....
....

The first import on BatchImporter works just fine. The problem is that ...geo... is not being recognized and I get a vanilla error message as follows:

 File "C:\Users\...\GRID_Importer\met_data_import.py", line 16, in <module>
    from mil.army.usace.hec.vortex.geo import WktFactory
ImportError: No module named geo

I have also tried importing other classes e.g. BatchSanitzer and it also works. Any ideas on what might be the problem?

tombrauer commented 1 year ago

Nice, I recently reworked my scripts to use java.exe with jython-standalone because of Java 17. Waiting to see if that is a major inconvenience for folks...

I set up a script that imports both BatchImporter and WktFactory and I wasn't able to reproduce. :(

from mil.army.usace.hec.vortex.io import BatchImporter
from mil.army.usace.hec.vortex.geo import WktFactory

One workaround would be to avoid using WktFactory. For the targetWkt arg you can specify the WKT representation of the projection. WKT strings can be a bit arduous to work with so I would specify an EPSG code if you have one, e.g. targetEpsg: 5070.

I'd like to get to root cause if possible to know if this is going to be an issue for other scripters. Did your script work previously with a Java 11 version of the vortex jar and jython.exe?

ranleu commented 1 year ago

Thanks for your reply.

Do you mean I can simply modify my script to:

....
geo_options = {
    'pathToShp': clip_shp,
    'targetCellSize': '2000',
    'targetWkt': targetEpsg: 5070,
    'resamplingMethod': 'Bilinear'
}
...

By the way I do intend to have my data in SHG.

Now if by: Did your script work previously with a Java 11 version of the vortex jar and jython.exe?

you mean the standalone Vortex, no I have not. Actually the whole reason why I am trying this approach is because I have no administrative rights on my system and it is a pain for me to go through the burocracy to install, modify, etc things in the system.

Now I just tryed using another excisting java installation, in this case "C:\Program Files\Microsoft\jdk-17.0.7.7-hotspot\bin\java.exe" and still the same issue. In any case I also want to get to the bottom of this. What would be your suspect of choice? a. The Jython-Standalone? b. Using the HEC-HMS Vortex installation? c. Any PATH issues?

One more thing. This is the very first time I put my hands on Jython and java for that matter, so please bare with me a little.

tombrauer commented 1 year ago

No worries, you are doing well to get this far on your own.

It would be:

geo_options = {
    'pathToShp': clip_shp,
    'targetCellSize': '2000',
    'targetEpsg': '5070',
    'resamplingMethod': 'Bilinear'
}

5070 is the EPSG code for SHG.

tombrauer commented 1 year ago

The vortex standalone distribution does not require admin to install. I created a C:/Programs directory on my machine. From there I downloaded the vortex distribution and unzipped in that directory. I use 7-zip to unzip rather than the windows unzip option. I'm not sure if this is possible within your IT setup.

ranleu commented 1 year ago

Nope, still not working. I've installed the Vortex standalone (v. 0.11.3) the same as you, using 7-zip, and tested my batch & script on it and I get the same error ImportError: No module named geo no matter what Java installation I use.

I have also tested the workaround with 'targetEpsg': '5070' and with all possible Javas and Vortex's in my system it goes a bit further but then I get the following error:

Traceback (most recent call last):
  File "C:\Users\....\GRID_Importer\met_data_import_v2.py", line 53, in <module>
    myImport.process()
        at mil.army.usace.hec.vortex.io.DataReader.getVariables(DataReader.java:92)
        at mil.army.usace.hec.vortex.io.BatchImporter.lambda$getDataReaders$0(BatchImporter.java:113)
        at java.base/java.lang.Iterable.forEach(Unknown Source)
        at mil.army.usace.hec.vortex.io.BatchImporter.lambda$getDataReaders$1(BatchImporter.java:112)
        at java.base/java.lang.Iterable.forEach(Unknown Source)
        at mil.army.usace.hec.vortex.io.BatchImporter.getDataReaders(BatchImporter.java:110)
        at mil.army.usace.hec.vortex.io.ConcurrentBatchImporter.process(ConcurrentBatchImporter.java:20)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: ucar/unidata/geoloc/Projection

for reference, line 53 of my script is:

myImport.process()

This feels to me as some misspelling issue. Could that be?

I will try on another computer where I have full admin rights to see if there might be some issue with local system. However if you have any other tip, I would be gratefull because at the end I need for this to run under my current system.

tombrauer commented 1 year ago

This is the env config that I used successfully:

set "VORTEX_HOME=C:\Programs\vortex-0.11.2"
set "PATH=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal;%PATH%"
set "GDAL_DATA=%VORTEX_HOME%\bin\gdal\gdal-data"
set "PROJ_LIB=%VORTEX_HOME%\bin\gdal\projlib"
set "CLASSPATH=C:\Programs\jython-standalone-2.7.2.jar;%VORTEX_HOME%\lib\*"
%VORTEX_HOME%\jre\bin\java.exe -Xmx2g -Djava.library.path=%VORTEX_HOME%\bin;%VORTEX_HOME%\bin\gdal org.python.util.jython met_data_import.py