Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export plan results #35

Closed
lucasglasner opened this issue May 27, 2024 · 3 comments
Closed

Export plan results #35

lucasglasner opened this issue May 27, 2024 · 3 comments

Comments

@lucasglasner
Copy link

Hi, thanks for this package.
Is there any method to export quickly water surface, depth and velocity rasters? (i.e netcdf, vtk, .tifs?)

Cheers,
Lucas

@thwllms
Copy link
Contributor

thwllms commented May 30, 2024

Hi @lucasglasner, thanks for the question about this. I don't think we have plans to export rasters via this library since that raster data isn't inherently contained within the HDF files (as far I know).

There's a little-known utility within the HEC-RAS installation itself that can do this, though, if you've configured the results maps for the model already in RAS Mapper. Call RasProcess.exe with the StoreAllMaps command and point it to a model's .rasmap file:

& "C:\Program Files (x86)\HEC\HEC-RAS\6.5\RasProcess.exe" StoreAllMaps .\Muncie.rasmap

We're trying to keep the scope of rashdf focused on extracting data from the RAS HDF files to GeoDataFrame or similar objects in memory, so I don't think we'll be adding anything to call RasProcess.exe in this library.

@thwllms thwllms closed this as completed May 30, 2024
@lucasglasner
Copy link
Author

Hi @thwllms, thank you for your answer. I've been trying to export data from a large number of HEC-RAS simulations (>50) and this project has been of great help in doing so.

After some research, i found that the plan HDF file has by default (v6.5) the WSE and face velocity as 2D arrays of size (n°timesteps, n°grid cells) stored in Results/Unsteady/Output/Output Blocks/Base Output/Unsteady Time Series/2D Flow Areas . I also found that is possible (with some extra options) to write in the plan HDF file many other variables. If it helps i programmed a humble routine for the RasPlanHdf class to access the simulation data as a python dictionary. It could be useful for adding attributes/columns to the grid GeoDataFrame (i.e water depth at last timestep, speed, shear stress, etc).

def get_results_unsteady_variables(self):
    """Returns data for all variables found in the unsteady results. 
    
    Returns
    -------
    data
        Dictionary with simulation stored results
    """    
    PATH      = f'{self.RESULTS_UNSTEADY_PATH}/Output/Output Blocks/Base Output'
    # Get Simulation Time
    TIME_PATH = f'{PATH}/Unsteady Time Series/Time Date Stamp'
    time      = map(lambda x: x.decode('utf-8'), np.array(self[TIME_PATH][()]))
    time      = pd.to_datetime(list(time))
    
    # Get aviable data for all areas
    DATA_PATH = f'{PATH}/Unsteady Time Series/2D Flow Areas'
    mesh_area_names = self.mesh_area_names()
    if not mesh_area_names:
        raise RuntimeError('No area found in geometry')
    
    data = {key:{} for key in mesh_area_names}
    for i, mesh_name in enumerate(mesh_area_names):
        AREA_PATH = f'{DATA_PATH}/{mesh_name}'
        varnames  = list(self[AREA_PATH].keys())
        for j, varname in enumerate(varnames):
            if varname not in ['Boundary Conditions', 'Computations']:
                data[mesh_name][varname] = self[AREA_PATH][varname][()]
    data['time'] = time
    return data

RasPlanHdf.get_results_unsteady_variables = get_results_unsteady_variables   

With this routine i've been trying to interpolate the simulation results to regular cartesian coordinates with scipy and export the results as .tif, however i cannot replicate the exact solution of the Ras Mapper "Export to raster" utility. Do you know how the program interpolates the simulation results from the unstructured grid to the regular raster grid?

@thwllms
Copy link
Contributor

thwllms commented Jun 13, 2024

@lucasglasner the HEC-RAS interpolation / mapping routine for 2D models is a subject of much speculation and debate in my little corner of the water resources field. Unfortunately RAS isn't open-source and the mapping algorithm isn't really documented in detail. Some companies like the one I work for have developed their own alternative mapping programs to extract data from the HDF files and produce their own inundation layers to make up for certain perceived issues with the HEC-RAS inundation maps. Interpolating to regular Cartesian coordinates with scipy like you described is arguably a valid approach.

Thanks for writing up that code -- there are actually two pull requests open right now for extracting output data like in your example, if you want to check them out. Hopefully they'll be merged in the coming weeks and released to PyPI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants