gyanz / pydsstools

Python library for simple HEC-DSS functions
MIT License
83 stars 36 forks source link

Cant view grids after opening file. #13

Closed danhamill closed 3 years ago

danhamill commented 4 years ago

After running Example 10:

import numpy as np
import numpy.ma as ma
from affine import Affine
from pydsstools.heclib.dss.HecDss import Open
from pydsstools.heclib.utils import gridInfo

dss_file = "example.dss"

pathname_out1 = "/GRID/RECORD/DATA/01jan2019:1200/01jan2019:1300/Ex10a/"
pathname_out2 = "/GRID/RECORD/DATA/01jan2019:1200/01jan2019:1300/Ex10b/"

with Open(dss_file) as fid:
    # Type 1: data is numpy array
    # np.nan is considered as nodata
    data = np.reshape(np.array(range(100),dtype=np.float32),(10,10))
    data[0] = np.nan # assign nodata to first row
    grid_info = gridInfo()
    cellsize = 100 # feet
    xmin,ymax = (1000,5000) # grid top-left corner coordinates
    affine_transform = Affine(cellsize,0,xmin,0,-cellsize,ymax)
    grid_info.update([('grid_type','specified'),
                      ('grid_crs','unknown'),
                      ('grid_transform',affine_transform),
                      ('data_type','per-aver'),
                      ('data_units','mm'),
                      ('opt_time_stamped',False)])
    fid.put_grid(pathname_out1,data,grid_info)

    # Type 2: data is numpy masked array, where masked values are considered nodata
    data = np.reshape(np.array(range(100),dtype=np.float32),(10,10))
    data = ma.masked_where((data >= 10) & (data <30),data) # mask second and third rows
    fid.put_grid(pathname_out2,data,grid_info)

I cant seem to view the grids in DSS. I have tried DSSvue version 3.0.00.212. I see the traceback from DSSvue of:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: hec.heclib.util.Heclib.Hec_zgridRetrieve([ILhec/heclib/grid/GridContainer;Z)I
        at hec.heclib.util.Heclib.Hec_zgridRetrieve(Native Method)
        at hec.heclib.util.Heclib.zgridRetrieve(Heclib.java:790)
        at hec.heclib.dss.HecDssGrid.read(HecDssGrid.java:41)
        at hec.heclib.grid.GriddedData.retrieveGriddedContainer(GriddedData.java:182)
        at hec.heclib.grid.GriddedData.retrieveGriddedData(GriddedData.java:210)
        at hec.dssgui.CombinedDataManager.getGriddedDataLocal(CombinedDataManager.java:1673)
        at hec.dssgui.CombinedDataManager.readGriddedData(CombinedDataManager.java:1606)
        at hec.dssgui.CombinedDataManager.readData(CombinedDataManager.java:1487)
        at hec.dssgui.ListSelection.readData(ListSelection.java:3212)
        at hec.dssgui.ListSelection.readData(ListSelection.java:3001)
        at hec.dssgui.ListSelection.getSelectedDataContainers(ListSelection.java:2846)
        at hec.dssgui.ListSelection.plot(ListSelection.java:3595)
        at hec.dssgui.ListSelection$VueActionListener.actionPerformed(ListSelection.java:13340)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
        at java.awt.Component.processMouseEvent(Component.java:6525)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
        at java.awt.Component.processEvent(Component.java:6290)
        at java.awt.Container.processEvent(Container.java:2234)
        at java.awt.Component.dispatchEventImpl(Component.java:4881)
        at java.awt.Container.dispatchEventImpl(Container.java:2292)
        at java.awt.Component.dispatchEvent(Component.java:4703)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
        at java.awt.Container.dispatchEventImpl(Container.java:2278)
        at java.awt.Window.dispatchEventImpl(Window.java:2750)
        at java.awt.Component.dispatchEvent(Component.java:4703)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
        at java.awt.EventQueue.access$500(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:709)
        at java.awt.EventQueue$3.run(EventQueue.java:703)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
        at java.awt.EventQueue$4.run(EventQueue.java:731)
        at java.awt.EventQueue$4.run(EventQueue.java:729)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Any ideas on what is going on here?

gyanz commented 4 years ago

I was able to view the grid record in DssVue after removing the start and end dates from the path name:

pathname_out2 = "/GRID/RECORD/DATA///Ex10b/"

I may have used incompatible date format in the example.

gyanz commented 3 years ago

@danhamill Does the latest version resolve this issue?

gyanz commented 3 years ago

@danhamill You may need to use more recent version HEC-DSSVue.

danhamill commented 3 years ago

I just tested in pydsstools version 2.0 and I could view the grids in dssvue 3.1.