Skip to content

Commit

Permalink
test square
Browse files Browse the repository at this point in the history
  • Loading branch information
changliao1025 committed Apr 7, 2022
1 parent 3fc5836 commit 703b8f3
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 35 deletions.
Binary file modified bin/hexwatershed
Binary file not shown.
26 changes: 17 additions & 9 deletions pyhexwatershed/classes/pycase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand Down
26 changes: 13 additions & 13 deletions tests/configurations/pyhexwatershed_susquehanna_hexagon.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@
"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,
"iFlag_stream_burning_topology": 1,
"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",
"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/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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
44 changes: 44 additions & 0 deletions tests/configurations/pyhexwatershed_susquehanna_square.json
Original file line number Diff line number Diff line change
@@ -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"
}
30 changes: 30 additions & 0 deletions tests/configurations/pyhexwatershed_susquehanna_square_basins.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
8 changes: 4 additions & 4 deletions tests/example/create_model_condfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions tests/example/run_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 703b8f3

Please sign in to comment.