diff --git a/bin/hexwatershed b/bin/hexwatershed index 5e6e763..55c3e38 100755 Binary files a/bin/hexwatershed and b/bin/hexwatershed differ diff --git a/pyhexwatershed/classes/pycase.py b/pyhexwatershed/classes/pycase.py index af44512..0350e86 100644 --- a/pyhexwatershed/classes/pycase.py +++ b/pyhexwatershed/classes/pycase.py @@ -319,6 +319,8 @@ def setup(self): self.pPyFlowline.setup() sFilename_hexwatershed = os.path.join(str(Path(self.sWorkspace_bin) ) , self.sFilename_hexwatershed ) + #for debug + sFilename_hexwatershed = '/qfs/people/liao313/bin/hexwatershed' #copy the binary file sFilename_new = os.path.join(str(Path(self.sWorkspace_output_hexwatershed) ) , "hexwatershed" ) copy2(sFilename_hexwatershed, sFilename_new) @@ -387,12 +389,12 @@ def assign_elevation_to_cells(self): aX= list() aY=list() for j in range(nVertex): - aX.append( pCell.aVertex[j].dLongitude_center_degree ) - aY.append( pCell.aVertex[j].dLatitude_center_degree ) + aX.append( pCell.aVertex[j].dLongitude_degree ) + aY.append( pCell.aVertex[j].dLatitude_degree ) pass - aX.append( pCell.aVertex[0].dLongitude_center_degree ) - aY.append( pCell.aVertex[0].dLongitude_center_degree ) - aX_out,aY_out = reproject_coordinates_batch(x1,y1,pSrs,pSpatialRef_target) + aX.append( pCell.aVertex[0].dLongitude_degree ) + aY.append( pCell.aVertex[0].dLatitude_degree ) + aX_out,aY_out = reproject_coordinates_batch(aX,aY,pSrs,pSpatialRef_target) for j in range(nVertex + 1): x1 = aX_out[j] y1 = aY_out[j] @@ -439,11 +441,11 @@ def assign_elevation_to_cells(self): if(len(aElevation) >0 and np.mean(aElevation)!=-9999): dElevation = float(np.mean(aElevation) ) - pCell.dElevation = dElevation + pCell.dElevation_mean = dElevation pCell.dz = dElevation aCell_mid.append(pCell) else: - pCell.dElevation=-9999.0 + pCell.dElevation_mean=-9999.0 pass else: @@ -468,11 +470,11 @@ def assign_elevation_to_cells(self): else: dElevation = aDem_in[lRow_index, lColumn_index] if( dElevation!=-9999): - pCell.dElevation = dElevation + pCell.dElevation_mean = dElevation pCell.dz = dElevation aCell_mid.append(pCell) else: - pCell.dElevation=-9999.0 + pCell.dElevation_mean=-9999.0 pass pass @@ -488,17 +490,23 @@ def assign_elevation_to_cells(self): for i in range(ncell): pCell = aCell_mid[i] aNeighbor = pCell.aNeighbor + aNeighbor_distance = pCell.aNeighbor_distance nNeighbor = pCell.nNeighbor aNeighbor_new = list() + aNeighbor_distance_new = list() nNeighbor_new = 0 for j in range(nNeighbor): lNeighbor = int(aNeighbor[j]) if lNeighbor in aCellID: nNeighbor_new = nNeighbor_new +1 aNeighbor_new.append(lNeighbor) + aNeighbor_distance_new.append(aNeighbor_distance[j]) pCell.nNeighbor= len(aNeighbor_new) pCell.aNeighbor = aNeighbor_new + pCell.nNeighbor_land= len(aNeighbor_new) + pCell.aNeighbor_land = aNeighbor_new + pCell.aNeighbor_distance = aNeighbor_distance_new aCell_out.append(pCell) #now update the cell information diff --git a/pyhexwatershed/pyhexwatershed_generate_template_configuration_file.py b/pyhexwatershed/pyhexwatershed_generate_template_configuration_file.py index b35522b..71dedfe 100644 --- a/pyhexwatershed/pyhexwatershed_generate_template_configuration_file.py +++ b/pyhexwatershed/pyhexwatershed_generate_template_configuration_file.py @@ -46,6 +46,8 @@ def pyhexwatershed_generate_template_configuration_file(sFilename_json, sWorkspa else: iFlag_use_shapefile_extent = 0 + + if sMesh_type_in is not None: sMesh_type = sMesh_type_in else: @@ -56,6 +58,12 @@ def pyhexwatershed_generate_template_configuration_file(sFilename_json, sWorkspa else: sDate = '20220202' pass + + if dResolution_meter_in is not None: + dResolution_meter = dResolution_meter_in + else: + dResolution_meter = 10000 + pass nBasin =1 @@ -72,17 +80,17 @@ def pyhexwatershed_generate_template_configuration_file(sFilename_json, sWorkspa aConfig['iFlag_simplification']=1 aConfig['iFlag_create_mesh']=1 aConfig['iFlag_intersect']=1 - aConfig['iFlag_resample_method']=1 + aConfig['iFlag_resample_method']=2 aConfig['iFlag_global']=0 aConfig['iFlag_multiple_outlet']=0 - aConfig['iFlag_elevation_profile']=1 + aConfig['iFlag_elevation_profile']=0 aConfig['iFlag_rotation']=0 aConfig['iFlag_stream_burning_topology']=1 aConfig['iFlag_save_elevation']=1 aConfig['nOutlet'] = nBasin aConfig['dResolution_degree'] = 0.5 - aConfig['dResolution_meter'] = 10000 + aConfig['dResolution_meter'] =dResolution_meter aConfig['dLongitude_left'] = -180 aConfig['dLongitude_right'] = 180 aConfig['dLatitude_bot'] = -90 diff --git a/tests/configurations/pyhexwatershed_susquehanna_hexagon.json b/tests/configurations/pyhexwatershed_susquehanna_hexagon.json index f3adeb4..19bb9dc 100644 --- a/tests/configurations/pyhexwatershed_susquehanna_hexagon.json +++ b/tests/configurations/pyhexwatershed_susquehanna_hexagon.json @@ -5,15 +5,15 @@ "dLongitude_left": -180.0, "dLongitude_right": 180.0, "dResolution_degree": 0.5, - "dResolution_meter": 10000.0, - "iCase_index": 1, + "dResolution_meter": 5000.0, + "iCase_index": 2, "iFlag_create_mesh": 1, - "iFlag_elevation_profile": 1, + "iFlag_elevation_profile": 0, "iFlag_flowline": 1, "iFlag_global": 0, "iFlag_intersect": 1, "iFlag_multiple_outlet": 0, - "iFlag_resample_method": 1, + "iFlag_resample_method": 2, "iFlag_save_elevation": 1, "iFlag_save_mesh": 1, "iFlag_simplification": 1, @@ -21,17 +21,17 @@ "iFlag_use_mesh_dem": 0, "iMesh_type": 1, "nOutlet": 1, - "pPyFlowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/pyflowline", - "sCase": "pyhexwatershed20220404001", + "pPyFlowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/pyflowline", + "sCase": "pyhexwatershed20220404002", "sDate": "20220404", - "sFilename_basins": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/configuration_basin.json", + "sFilename_basins": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/configuration_basin.json", "sFilename_dem": "/qfs/people/liao313/data/hexwatershed/susquehanna/raster/dem/dem_ext.tif", - "sFilename_elevation": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/pyflowline/hexagon_elevation.json", + "sFilename_elevation": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/pyflowline/hexagon_elevation.json", "sFilename_hexwatershed": "hexwatershed", - "sFilename_mesh": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/pyflowline/hexagon.json", - "sFilename_mesh_info": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/pyflowline/hexagon_mesh_info.json", + "sFilename_mesh": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/pyflowline/hexagon.json", + "sFilename_mesh_info": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/pyflowline/hexagon_mesh_info.json", "sFilename_mesh_netcdf": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/lnd_cull_mesh.nc", - "sFilename_model_configuration": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/configuration.json", + "sFilename_model_configuration": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/configuration.json", "sFilename_spatial_reference": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/boundary_proj.shp", "sJob": "pyhexwatershed", "sMesh_type": "hexagon", @@ -39,6 +39,6 @@ "sRegion": "susquehanna", "sWorkspace_bin": "/qfs/people/liao313/workspace/python/pyhexwatershed/bin", "sWorkspace_output": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/", - "sWorkspace_output_hexwatershed": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/hexwatershed", - "sWorkspace_output_pyflowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/pyflowline" + "sWorkspace_output_hexwatershed": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/hexwatershed", + "sWorkspace_output_pyflowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/pyflowline" } \ No newline at end of file diff --git a/tests/configurations/pyhexwatershed_susquehanna_hexagon_basins.json b/tests/configurations/pyhexwatershed_susquehanna_hexagon_basins.json index adb404d..57c88c2 100644 --- a/tests/configurations/pyhexwatershed_susquehanna_hexagon_basins.json +++ b/tests/configurations/pyhexwatershed_susquehanna_hexagon_basins.json @@ -18,13 +18,13 @@ "sFilename_flowline_conceptual_info": "flowline_conceptual_info.json", "sFilename_flowline_edge": "flowline_edge.json", "sFilename_flowline_filter": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/streamord7above.shp", - "sFilename_flowline_filter_json": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/pyflowline/001/flowline_filter.json", + "sFilename_flowline_filter_json": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/pyflowline/001/flowline_filter.json", "sFilename_flowline_intersect": "flowline_intersect_mesh.json", "sFilename_flowline_raw": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/allflowline.shp", "sFilename_flowline_segment_index_before_intersect": "flowline_segment_index_before_intersect.json", "sFilename_flowline_simplified": "flowline_simplified.json", "sFilename_flowline_simplified_info": "flowline_simplified_info.json", "sFilename_flowline_topo": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/flowline.csv", - "sWorkspace_output_basin": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404001/pyflowline/001" + "sWorkspace_output_basin": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404002/pyflowline/001" } ] \ No newline at end of file diff --git a/tests/configurations/pyhexwatershed_susquehanna_square.json b/tests/configurations/pyhexwatershed_susquehanna_square.json new file mode 100644 index 0000000..e1c2f8a --- /dev/null +++ b/tests/configurations/pyhexwatershed_susquehanna_square.json @@ -0,0 +1,44 @@ +{ + "dAccumulation_threshold": 100000.0, + "dLatitude_bot": -90.0, + "dLatitude_top": 90.0, + "dLongitude_left": -180.0, + "dLongitude_right": 180.0, + "dResolution_degree": 0.5, + "dResolution_meter": 10000.0, + "iCase_index": 3, + "iFlag_create_mesh": 1, + "iFlag_elevation_profile": 0, + "iFlag_flowline": 1, + "iFlag_global": 0, + "iFlag_intersect": 1, + "iFlag_multiple_outlet": 0, + "iFlag_resample_method": 2, + "iFlag_save_elevation": 1, + "iFlag_save_mesh": 1, + "iFlag_simplification": 1, + "iFlag_stream_burning_topology": 1, + "iFlag_use_mesh_dem": 0, + "iMesh_type": 2, + "nOutlet": 1, + "pPyFlowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline", + "sCase": "pyhexwatershed20220404003", + "sDate": "20220404", + "sFilename_basins": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/configuration_basin.json", + "sFilename_dem": "/qfs/people/liao313/data/hexwatershed/susquehanna/raster/dem/dem_ext.tif", + "sFilename_elevation": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/square_elevation.json", + "sFilename_hexwatershed": "hexwatershed", + "sFilename_mesh": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/square.json", + "sFilename_mesh_info": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/square_mesh_info.json", + "sFilename_mesh_netcdf": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/lnd_cull_mesh.nc", + "sFilename_model_configuration": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/configuration.json", + "sFilename_spatial_reference": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/boundary_proj.shp", + "sJob": "pyhexwatershed", + "sMesh_type": "square", + "sModel": "pyhexwatershed", + "sRegion": "susquehanna", + "sWorkspace_bin": "/qfs/people/liao313/workspace/python/pyhexwatershed/bin", + "sWorkspace_output": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/", + "sWorkspace_output_hexwatershed": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/hexwatershed", + "sWorkspace_output_pyflowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline" +} \ No newline at end of file diff --git a/tests/configurations/pyhexwatershed_susquehanna_square_basins.json b/tests/configurations/pyhexwatershed_susquehanna_square_basins.json new file mode 100644 index 0000000..efcba14 --- /dev/null +++ b/tests/configurations/pyhexwatershed_susquehanna_square_basins.json @@ -0,0 +1,30 @@ +[ + { + "dAccumulation_threshold": -90.0, + "dLatitude_outlet_degree": -180.0, + "dLongitude_outlet_degree": 180.0, + "dThreshold_small_river": 90.0, + "iFlag_dam": 0, + "iFlag_disconnected": 0, + "lBasinID": 1, + "lCellID_outlet": -1, + "sBasinID": "001", + "sFilename_area_of_difference": "area_of_difference.json", + "sFilename_basin_info": "basin_info.json", + "sFilename_confluence_conceptual_info": "confluence_conceptual_info.json", + "sFilename_confluence_simplified_info": "confluence_simplified_info.json", + "sFilename_dam": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/ICoM_dams.csv", + "sFilename_flowline_conceptual": "flowline_conceptual.json", + "sFilename_flowline_conceptual_info": "flowline_conceptual_info.json", + "sFilename_flowline_edge": "flowline_edge.json", + "sFilename_flowline_filter": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/streamord7above.shp", + "sFilename_flowline_filter_json": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/001/flowline_filter.json", + "sFilename_flowline_intersect": "flowline_intersect_mesh.json", + "sFilename_flowline_raw": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/allflowline.shp", + "sFilename_flowline_segment_index_before_intersect": "flowline_segment_index_before_intersect.json", + "sFilename_flowline_simplified": "flowline_simplified.json", + "sFilename_flowline_simplified_info": "flowline_simplified_info.json", + "sFilename_flowline_topo": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/flowline.csv", + "sWorkspace_output_basin": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/001" + } +] \ No newline at end of file diff --git a/tests/example/create_model_condfiguration.py b/tests/example/create_model_condfiguration.py index c0ecf79..146171a 100644 --- a/tests/example/create_model_condfiguration.py +++ b/tests/example/create_model_condfiguration.py @@ -23,9 +23,9 @@ #python notebook.py --sMesh_type hexagon --iCase_index 1 --dResolution_meter 50000 --sDate 20220201 pArgs = parser.parse_args() if len(sys.argv) == 1: - sMesh_type = 'hexagon' - iCase_index = 1 - dResolution_meter=10000 + sMesh_type = 'square' + iCase_index = 3 + dResolution_meter=5000 sDate='20220404' else: if len(sys.argv)> 1: @@ -47,7 +47,7 @@ sWorkspace_output = '/compyfs/liao313/04model/pyhexwatershed/susquehanna' sWorkspace_bin = realpath( sPath + '/bin' ) -sFilename_configuration_in = sPath + '/tests/configurations/pyhexwatershed_susquehanna_hexagon.json' +sFilename_configuration_in = sPath + '/tests/configurations/pyhexwatershed_susquehanna_square.json' sWorkspace_data = realpath( sPath + '/data/susquehanna' ) oPyhexwatershed = pyhexwatershed_generate_template_configuration_file(sFilename_configuration_in,sWorkspace_bin, sWorkspace_input, sWorkspace_output, iFlag_use_mesh_dem_in = 0, sMesh_type_in=sMesh_type, iCase_index_in = iCase_index, sDate_in = sDate) print(oPyhexwatershed.tojson()) diff --git a/tests/example/run_simulation.py b/tests/example/run_simulation.py index b7fdbe4..e71f022 100644 --- a/tests/example/run_simulation.py +++ b/tests/example/run_simulation.py @@ -23,9 +23,9 @@ #python notebook.py --sMesh_type hexagon --iCase_index 1 --dResolution_meter 50000 --sDate 20220201 pArgs = parser.parse_args() -sMesh_type = 'hexagon' -iCase_index = 1 -dResolution_meter=10000 +sMesh_type = 'square' +iCase_index = 3 +dResolution_meter=5000 sDate='20220404' sPath = str( Path().resolve() ) iFlag_option = 1 @@ -103,7 +103,7 @@ aCell_out = oPyhexwatershed.assign_elevation_to_cells() oPyhexwatershed.pPyFlowline.export() oPyhexwatershed.export_config_to_json() - + #exit() oPyhexwatershed.run_hexwatershed() oPyhexwatershed.analyze() oPyhexwatershed.export()