gyanz/pydsstools

Installation From Source and Import Error

Closed this issue · 3 comments

Installation From Source issues presented in #23 and #27 may be related to hecdatetime.h. The error I was getting is related to grid.a not found. Traced it down to header hecdatetime.h renamed to HecDateTime.h. Compiles and installs but get an error when importing.

>>> from pydsstools.heclib.dss.HecDss import Open
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/pydsstools/heclib/dss/HecDss.py", line 15, in <module>
    from ...core import Open as _Open
  File "/usr/local/lib/python3.8/dist-packages/pydsstools/core/__init__.py", line 28, in <module>
    from .._lib import *
  File "/usr/local/lib/python3.8/dist-packages/pydsstools/_lib/__init__.py", line 1, in <module>
    from .x64 import core_heclib
  File "pydsstools/src/core_heclib.pyx", line 1, in init pydsstools._lib.x64.core_heclib
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
gyanz commented

@jeffsuperglide I have not had problem compiling from source. Nevertheless, renaming hecdatetime.h makes sense. Regarding the import error, it looks like there is mismatch in numpy version during compilation and runtime. Can you provide your numpy and cython version, and other build environment information?

@gyanz I'm using Docker and switched images from ubuntu:20.04 to osgeo/gdal testing something else and that helped. Probably was the numpy version but didn't investigate.

I see where hecdatetime.h is from https://github.com/HydrologicEngineeringCenter/hec-dss. I'll talk to @ktarbet.

Did run into another issue with put_grid with ('grid_type','sht-time'), and getPyDateTimeFromString(dateString) not liking the D-part and E-part format for grids being ddMMMYYYY:HHmm. Error was hour must be in 0..23.

I added re.split() if parser.parse(dateString) exception thrown to deal with the different HecTime formats.

From pydsstools/src/hectime.pyx. Additionaly, import re added to core_heclib_imports.py

def getPyDateTimeFromString(dateString):
    # Returns python datetime object from string
    try:
        datetime_obj = parser.parse(dateString)
        return datetime_obj
    except:
        _,msg,_ = sys.exc_info()
        if "hour must be in 0..23" in str(msg):
            _date, _time = re.split(' |:', dateString, maxsplit=1)
            _time=_time.replace("24","23",1)
            dateString = ' '.join([_date, _time])
            try:
                datetime_obj = parser.parse(dateString)
                datetime_obj = datetime_obj + timedelta(hours=1)
                return datetime_obj
            except:
                pass
...

@gyanz I was wondering if this change is also implemented if pydsstools has been installed using the last wheel file provided.

Did run into another issue with put_grid with ('grid_type','sht-time'), and getPyDateTimeFromString(dateString) not liking the D-part and E-part format for grids being ddMMMYYYY:HHmm. Error was hour must be in 0..23.

I added re.split() if parser.parse(dateString) exception thrown to deal with the different HecTime formats.

From pydsstools/src/hectime.pyx. Additionaly, import re added to core_heclib_imports.py

def getPyDateTimeFromString(dateString):
    # Returns python datetime object from string
    try:
        datetime_obj = parser.parse(dateString)
        return datetime_obj
    except:
        _,msg,_ = sys.exc_info()
        if "hour must be in 0..23" in str(msg):
            _date, _time = re.split(' |:', dateString, maxsplit=1)
            _time=_time.replace("24","23",1)
            dateString = ' '.join([_date, _time])
            try:
                datetime_obj = parser.parse(dateString)
                datetime_obj = datetime_obj + timedelta(hours=1)
                return datetime_obj
            except:
                pass
...

I installed pydsstools from wheel and when trying to write grids with ('grid_type', 'specified-time') the following error occurs:

"Exception: For %s grid type, DPart and EPart of pathname must be datetime string"

The D-part and E-part are formatted as requested for grids being ddMMMYYYY:HHmm

So I was thinking if this is related to this issue and if there is a way to add the change to my pydsstool installation if I installed it from wheel.

I tried to change it in the scripts accordingly but it didn't work. I guess pydsstools is called from the compiled exe files? Sorry I come from an R background and am not that familiar with all the different python installations.

Or is it already implemented in the wheel and the error has another cause?

Thank you for your help!