Skip to content

Commit

Permalink
change filenames to full path
Browse files Browse the repository at this point in the history
  • Loading branch information
changliao1025 committed Jul 17, 2023
1 parent e789515 commit b4f6ca6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 67 deletions.
14 changes: 5 additions & 9 deletions pyflowline/classes/_visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def plot(self,

def _plot_mesh(self, sFilename_output_in=None, aExtent_in=None, pProjection_map_in = None):

sFilename_in = self.sFilename_mesh
sFilename_in = self.sFilename_mesh
sMesh_type = self.sMesh_type

map_vector_polygon_data(sFilename_in,
Expand Down Expand Up @@ -141,8 +141,7 @@ def basin_plot(self,
iFlag_color = 0
else:
if sVariable_in == 'flowline_simplified':
sFilename_out = self.sFilename_flowline_simplified
sFilename_json = os.path.join(sWorkspace_output_basin, sFilename_out)
sFilename_json = self.sFilename_flowline_simplified
sTitle = 'Simplified flowline'
iFlag_color = 1
if aExtent_in is None:
Expand All @@ -151,8 +150,7 @@ def basin_plot(self,
iFlag_label=0
else:
if sVariable_in == 'flowline_conceptual':
sFilename_out = self.sFilename_flowline_conceptual
sFilename_json = os.path.join(sWorkspace_output_basin, sFilename_out)
sFilename_json = self.sFilename_flowline_conceptual
sTitle = 'Conceptual flowline'
iFlag_color = 1
if aExtent_in is None:
Expand All @@ -161,8 +159,7 @@ def basin_plot(self,
iFlag_label=0
else:
if sVariable_in == 'aof':
sFilename_out = 'area_of_difference.geojson'
sFilename_json = os.path.join(sWorkspace_output_basin, sFilename_out)
sFilename_json = self.sFilename_area_of_difference
sTitle = 'Conceptual flowline'
iFlag_label = 1
self.plot_area_of_difference(iCase_index,
Expand Down Expand Up @@ -203,8 +200,7 @@ def _compare_with_raster_dem_method(self, sFilename_dem_flowline, sFilename_in,
#this is a reserved function
def _plot_area_of_difference(self, iCase_index, iMesh_type, sMesh_type, sFilename_figure_in, aExtent_in = None, pProjection_map_in = None):

sFilename_json = self.sFilename_area_of_difference
sFilename_json = os.path.join(self.sWorkspace_output_basin, sFilename_json)
sFilename_json = self.sFilename_area_of_difference

sFilename_in = self.sFilename_mesh
sFilename_out = sFilename_figure_in
Expand Down
108 changes: 57 additions & 51 deletions pyflowline/classes/basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,23 @@ class pybasin(object):
sFilename_flowline_conceptual_info=''
sFilename_confluence_simplified_info=''
sFilename_confluence_conceptual_info=''

aFlowline_basin_filtered=None
aFlowline_basin_simplified=None
aFlowline_basin_conceptual=None
pVertex_outlet=None
aConfluence_basin_simplified= None
aConfluence_basin_conceptual= None


#for hexwatershed compatibility
sFilename_elevation=''
sFilename_slope=''
sFilename_drainage_area=''
sFilename_flow_direction =''
sFilename_distance_to_outlet = ''



iFlag_visual = importlib.util.find_spec("cartopy")
if iFlag_visual is not None:
Expand Down Expand Up @@ -194,12 +204,12 @@ def __init__(self, aParameter):
if 'sFilename_flowline_filter' in aParameter:
self.sFilename_flowline_filter = aParameter['sFilename_flowline_filter']
else:
self.sFilename_flowline_filter = ''
self.sFilename_flowline_filter = ''

if 'sWorkspace_output_basin' in aParameter:
self.sWorkspace_output_basin = aParameter['sWorkspace_output_basin']
else:
self.sWorkspace_output_basin = '.'
self.sWorkspace_output_basin = '.'

Path(self.sWorkspace_output_basin).mkdir(parents=True, exist_ok=True)

Expand All @@ -208,16 +218,15 @@ def __init__(self, aParameter):
if 'sFilename_dam' in aParameter:
self.sFilename_dam = aParameter['sFilename_dam']
else:
self.sFilename_dam = ''
self.sFilename_dam = ''

if 'sFilename_flowline_topo' in aParameter:
self.sFilename_flowline_topo = aParameter['sFilename_flowline_topo']
else:
self.sFilename_flowline_topo =''
self.sFilename_flowline_topo = ''

self.sBasinID = "{:08d}".format(self.lBasinID)


if not os.path.isfile(self.sFilename_flowline_filter):
print("The filtered flowline file does not exist!")
exit
Expand All @@ -230,20 +239,30 @@ def __init__(self, aParameter):
exit
pass

#geojson
self.sFilename_flowline_segment_index_before_intersect = 'flowline_segment_index_before_intersect.geojson'
self.sFilename_flowline_simplified = 'flowline_simplified.geojson'
self.sFilename_flowline_split = 'flowline_split.geojson'
self.sFilename_flowline_intersect = 'flowline_intersect_mesh.geojson'
self.sFilename_flowline_conceptual = 'flowline_conceptual.geojson'
self.sFilename_flowline_edge = 'flowline_edge.geojson'
self.sFilename_area_of_difference = 'area_of_difference.geojson'

self.sFilename_basin_info = 'basin_info.json'
self.sFilename_flowline_conceptual_info = 'flowline_conceptual_info.json'
self.sFilename_flowline_simplified_info = 'flowline_simplified_info.json'
self.sFilename_confluence_conceptual_info = 'confluence_conceptual_info.json'
self.sFilename_confluence_simplified_info = 'confluence_simplified_info.json'
#geojson, full path of the file
self.sFilename_flowline_segment_index_before_intersect = os.path.join(str(self.sWorkspace_output_basin ),'flowline_segment_index_before_intersect.geojson')
self.sFilename_flowline_simplified = os.path.join(str(self.sWorkspace_output_basin ),'flowline_simplified.geojson')
self.sFilename_flowline_split = os.path.join(str(self.sWorkspace_output_basin ),'flowline_split.geojson')
self.sFilename_flowline_intersect = os.path.join(str(self.sWorkspace_output_basin ),'flowline_intersect_mesh.geojson')
self.sFilename_flowline_conceptual = os.path.join(str(self.sWorkspace_output_basin ),'flowline_conceptual.geojson')
self.sFilename_flowline_edge = os.path.join(str(self.sWorkspace_output_basin ),'flowline_edge.geojson')
self.sFilename_area_of_difference = os.path.join(str(self.sWorkspace_output_basin ),'area_of_difference.geojson')

self.sFilename_basin_info = os.path.join(str(self.sWorkspace_output_basin ), 'basin_info.json')
self.sFilename_flowline_conceptual_info = os.path.join(str(self.sWorkspace_output_basin ), 'flowline_conceptual_info.json')
self.sFilename_flowline_simplified_info = os.path.join(str(self.sWorkspace_output_basin ), 'flowline_simplified_info.json')
self.sFilename_confluence_conceptual_info = os.path.join(str(self.sWorkspace_output_basin ),'confluence_conceptual_info.json')
self.sFilename_confluence_simplified_info = os.path.join(str(self.sWorkspace_output_basin ),'confluence_simplified_info.json')


#full paths are required for the following files
#for hexwatershed compatibility
self.sFilename_elevation = os.path.join(str(self.sWorkspace_output_basin ), "elevation.geojson" )
self.sFilename_slope = os.path.join(str(self.sWorkspace_output_basin ), "slope.geojson" )
self.sFilename_drainage_area = os.path.join(str(self.sWorkspace_output_basin ), "drainage_area.geojson" )
self.sFilename_flow_direction = os.path.join(str(self.sWorkspace_output_basin ), "flow_direction.geojson" )
self.sFilename_distance_to_outlet = os.path.join(str(self.sWorkspace_output_basin ), "distance_to_outlet.geojson" )

return

def flowline_simplification(self):
Expand Down Expand Up @@ -485,25 +504,23 @@ def flowline_simplification(self):
aFlowline_basin_simplified, aStream_segment = define_stream_segment_index(aFlowline_basin_simplified)
ptimer.stop()
if self.iFlag_debug ==1:
sFilename_out = self.sFilename_flowline_segment_index_before_intersect
sFilename_out = os.path.join(sWorkspace_output_basin, sFilename_out)
sFilename_out = self.sFilename_flowline_segment_index_before_intersect
export_flowline_to_geojson( aFlowline_basin_simplified, sFilename_out, \
aAttribute_data=[aStream_segment], aAttribute_field=['iseg'], aAttribute_dtype=['int'])
#build stream order
ptimer.start()
aFlowline_basin_simplified, aStream_order = define_stream_order(aFlowline_basin_simplified)
ptimer.stop()
sFilename_out = self.sFilename_flowline_simplified
sFilename_out = os.path.join(sWorkspace_output_basin, sFilename_out)
sFilename_out = self.sFilename_flowline_simplified
export_flowline_to_geojson( aFlowline_basin_simplified, sFilename_out, \
aAttribute_data=[aStream_segment, aStream_order], aAttribute_field=['iseg','iord'], aAttribute_dtype=['int','int'])

if self.iFlag_break_by_distance==1:
ptimer.start()
aFlowline_basin_simplified_split = split_flowline_by_length(aFlowline_basin_simplified, self.dThreshold_break_by_distance)
ptimer.stop()

sFilename_out = self.sFilename_flowline_split
sFilename_out = os.path.join(sWorkspace_output_basin, sFilename_out)
export_flowline_to_geojson( aFlowline_basin_simplified_split, sFilename_out )

self.aFlowline_basin_simplified= aFlowline_basin_simplified
Expand All @@ -527,15 +544,13 @@ def reconstruct_topological_relationship(self, iMesh_type, sFilename_mesh):
ptimer = pytimer()

sWorkspace_output_basin = self.sWorkspace_output_basin
sFilename_flowline = self.sFilename_flowline_simplified
sFilename_flowline_in = os.path.join(sWorkspace_output_basin, sFilename_flowline)
sFilename_flowline_in = self.sFilename_flowline_simplified
sFilename_flowline_intersect_out = self.sFilename_flowline_intersect


sFilename_flowline_intersect = self.sFilename_flowline_intersect
sFilename_flowline_intersect_out = os.path.join(sWorkspace_output_basin, sFilename_flowline_intersect)
ptimer.start()
aCell, aCell_intersect_basin, aFlowline_intersect_all = intersect_flowline_with_mesh(iMesh_type, sFilename_mesh, \
sFilename_flowline_in, sFilename_flowline_intersect_out)

ptimer.stop()
sys.stdout.flush()

Expand Down Expand Up @@ -612,12 +627,10 @@ def reconstruct_topological_relationship(self, iMesh_type, sFilename_mesh):

#edge based
aFlowline_basin_edge, aEdge = split_flowline_to_edge(aFlowline_basin_conceptual)
sFilename_out = self.sFilename_flowline_edge
sFilename_out = os.path.join(sWorkspace_output_basin, sFilename_out)
sFilename_out = self.sFilename_flowline_edge
export_flowline_to_geojson( aFlowline_basin_edge, sFilename_out)

sFilename_out = self.sFilename_flowline_conceptual
sFilename_out = os.path.join(sWorkspace_output_basin, sFilename_out)
export_flowline_to_geojson( aFlowline_basin_conceptual, sFilename_out, \
aAttribute_data=[aStream_segment, aStream_order], aAttribute_field=['iseg','iord'], aAttribute_dtype=['int','int'])

Expand Down Expand Up @@ -674,9 +687,8 @@ def analyze(self):
point['dLongitude_degree'] = self.dLongitude_outlet_degree
point['dLatitude_degree'] = self.dLatitude_outlet_degree
pVertex_outlet_initial=pyvertex(point)
if self.aFlowline_basin_simplified is None:
sFilename_flowline = self.sFilename_flowline_simplified
sFilename_flowline_in = os.path.join(self.sWorkspace_output_basin, sFilename_flowline)
if self.aFlowline_basin_simplified is None:
sFilename_flowline_in = self.sFilename_flowline_simplified
aFlowline_simplified,pSpatial_reference = read_flowline_geojson( sFilename_flowline_in )

self.aFlowline_basin_simplified = aFlowline_simplified
Expand All @@ -691,8 +703,7 @@ def analyze(self):
self.dLength_flowline_simplified = self.calculate_flowline_length(self.aFlowline_basin_simplified)

if self.aFlowline_basin_conceptual is None:
sFilename_flowline = self.sFilename_flowline_conceptual
sFilename_flowline_in = os.path.join(self.sWorkspace_output_basin, sFilename_flowline)
sFilename_flowline_in = self.sFilename_flowline_conceptual
aFlowline_conceptual, pSpatial_reference = read_flowline_geojson( sFilename_flowline_in )
self.aFlowline_basin_conceptual = aFlowline_conceptual

Expand Down Expand Up @@ -739,7 +750,6 @@ def export_basin_info_to_json(self):
Export the basin basin object to json
"""
sFilename_json = self.sFilename_basin_info
sFilename_json = os.path.join(str(Path(self.sWorkspace_output_basin) ) , sFilename_json )

aSkip = ['aFlowline_basin_filtered', \
'aFlowline_basin_simplified','aFlowline_basin_conceptual','aConfluence_basin_simplified',
Expand All @@ -763,17 +773,14 @@ def export_flowline_info_to_json(self):
"""
iFlag_export_simplified=0
if iFlag_export_simplified==1:
sFilename_json = self.sFilename_flowline_simplified_info
sFilename_json = os.path.join(str(Path(self.sWorkspace_output_basin) ) , sFilename_json )
sFilename_json = self.sFilename_flowline_simplified_info
with open(sFilename_json, 'w', encoding='utf-8') as f:
sJson = json.dumps([json.loads(ob.tojson()) for ob in self.aFlowline_basin_simplified], indent = 4)
f.write(sJson)
f.close()

sFilename_json = self.sFilename_flowline_conceptual_info
sFilename_json = os.path.join(str(Path(self.sWorkspace_output_basin) ) , sFilename_json )



with open(sFilename_json, 'w', encoding='utf-8') as f:
sJson = json.dumps([json.loads(ob.tojson()) for ob in self.aFlowline_basin_conceptual], indent = 4)
f.write(sJson)
Expand All @@ -787,15 +794,15 @@ def export_confluence_info_to_json(self):
#iFlag_export_confluence =0
if self.aConfluence_basin_simplified is not None:
sFilename_json = self.sFilename_confluence_simplified_info
sFilename_json = os.path.join(str(Path(self.sWorkspace_output_basin) ) , sFilename_json )

with open(sFilename_json, 'w', encoding='utf-8') as f:
sJson = json.dumps([json.loads(ob.tojson()) for ob in self.aConfluence_basin_simplified], indent = 4)
f.write(sJson)
f.close()

if self.aConfluence_basin_conceptual is not None:
sFilename_json = self.sFilename_confluence_conceptual_info
sFilename_json = os.path.join(str(Path(self.sWorkspace_output_basin) ) , sFilename_json )


with open(sFilename_json, 'w', encoding='utf-8') as f:
sJson = json.dumps([json.loads(ob.tojson()) for ob in self.aConfluence_basin_conceptual], indent = 4)
Expand Down Expand Up @@ -924,11 +931,11 @@ def evaluate_area_of_difference(self, iMesh_type, sMesh_type):
sMesh_type (str): The mesh type
"""

sFilename_simplified = self.sFilename_flowline_simplified
sFilename_simplified= os.path.join(self.sWorkspace_output_basin, sFilename_simplified)

sFilename_simplified = self.sFilename_flowline_simplified


sFilename_flowline_edge = self.sFilename_flowline_edge
sFilename_flowline_edge= os.path.join(self.sWorkspace_output_basin, sFilename_flowline_edge)

#intersect first
sFilename_output= os.path.join(self.sWorkspace_output_basin, 'flowline_intersect_flowline.json')
Expand Down Expand Up @@ -1014,8 +1021,7 @@ def evaluate_area_of_difference(self, iMesh_type, sMesh_type):

aFlowline_all = aFlowline_simplified_split + aFlowline_conceptual_split

sFilename_area_of_difference = self.sFilename_area_of_difference
sFilename_output = os.path.join(self.sWorkspace_output_basin, sFilename_area_of_difference)
sFilename_output = self.sFilename_area_of_difference
#remove headwater not needed here

aPolygon_out, dArea = calculate_area_of_difference_simplified(aFlowline_all, aVertex_all, sFilename_output)
Expand Down
7 changes: 5 additions & 2 deletions pyflowline/classes/pycase.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,12 @@ def __init__(self, aConfig_in,


#model generated files

self.sFilename_mesh = os.path.join(str(Path(self.sWorkspace_output) ) , sMesh_type + ".geojson" )
self.sFilename_mesh_info= os.path.join(str(Path(self.sWorkspace_output) ) , sMesh_type + "_mesh_info.json" )
sFilename_mesh_kml = os.path.join(str(Path(self.sWorkspace_output) ) , sMesh_type + ".kml" )
self.sFilename_mesh_kml = os.path.join(str(Path(self.sWorkspace_output) ) , sMesh_type + ".kml" ) #for google service



return

Expand Down Expand Up @@ -470,7 +473,7 @@ def mesh_generation(self, iFlag_antarctic_in=None):
dResolution_meter = self.dResolution_meter
sFilename_dem = self.sFilename_dem
sFilename_spatial_reference = self.sFilename_spatial_reference
sFilename_mesh = self.sFilename_mesh
sFilename_mesh = self.sFilename_mesh
if iMesh_type !=4: #mpas
spatial_reference_target = osr.SpatialReference()
spatial_reference_target.ImportFromEPSG(4326)
Expand Down
7 changes: 2 additions & 5 deletions pyflowline/mesh/dggrid/create_dggrid_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,8 @@ def create_dggrid_mesh(iFlag_global,
iFlag_antarctic_in=None,
sFilename_boundary_in = None ):

#use dggrid table to determine the resolution index


sFilename_cell = sWorkspace_output + slash + 'cells'

#use dggrid table to determine the resolution index
sFilename_cell = sWorkspace_output + slash + 'cells'
if sGrid_type_in is not None:
sGrid_type = sGrid_type_in
else:
Expand Down

0 comments on commit b4f6ca6

Please sign in to comment.