From ad06181e1364779c6bf14345010dd97a49c048ed Mon Sep 17 00:00:00 2001 From: changliao1025 Date: Mon, 6 May 2024 13:04:25 -0700 Subject: [PATCH 1/3] update visual --- pyflowline/classes/_visual.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pyflowline/classes/_visual.py b/pyflowline/classes/_visual.py index 618fe04..cca2db0 100644 --- a/pyflowline/classes/_visual.py +++ b/pyflowline/classes/_visual.py @@ -34,12 +34,12 @@ def plot(self, if sVariable_in is None: sVariable_in = 'flowline_conceptual' else: - if sVariable_in == 'mesh': + if sVariable_in == 'mesh': iFlag_type_in = 3 else: if sVariable_in == 'overlap': iFlag_type_in = 4 - + if iFlag_type_in == 1: #point based, such as dam #currently, this feature is not supported @@ -48,13 +48,13 @@ def plot(self, if iFlag_type_in == 2: #polyline based, only flowline aLegend = list() - sText = 'Case: ' + "{:0d}".format( int(self.iCase_index) ) + sText = 'Case: ' + "{:0d}".format( int(self.iCase_index) ) aLegend.append(sText) sText = 'Mesh type: ' + self.sMesh_type.title() aLegend.append(sText) sResolution = 'Resolution: ' + "{:0d}".format( int(self.dResolution_meter) ) + 'm' - aLegend.append(sResolution) - for pBasin in self.aBasin: + aLegend.append(sResolution) + for pBasin in self.aBasin: pBasin.basin_plot(iFlag_type_in, self.sMesh_type, iFlag_title_in= iFlag_title_in, @@ -86,15 +86,15 @@ def plot(self, return -def _plot_mesh(self, - sFilename_output_in=None, - aExtent_in=None, +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, + map_vector_polygon_data(1, sFilename_in, sFilename_output_in = sFilename_output_in, sTitle_in = sMesh_type, aExtent_in = aExtent_in, @@ -116,7 +116,7 @@ def _plot_mesh_with_flowline(self, aFilename_in.append(self.sFilename_mesh) aFiletype_in.append(3) aFlag_color.append(0) - + aVariable_in.append(None) for pBasin in self.aBasin: From 187b60b0860a97cf5d02aa22d7495736491d3b9f Mon Sep 17 00:00:00 2001 From: changliao1025 Date: Mon, 6 May 2024 13:07:38 -0700 Subject: [PATCH 2/3] file naming duplicate --- .../pyflowline_read_configuration_file.py | 173 ------------------ .../configuration/read_configuration_file.py | 17 +- 2 files changed, 1 insertion(+), 189 deletions(-) delete mode 100644 pyflowline/configuration/pyflowline_read_configuration_file.py diff --git a/pyflowline/configuration/pyflowline_read_configuration_file.py b/pyflowline/configuration/pyflowline_read_configuration_file.py deleted file mode 100644 index 65b0ca7..0000000 --- a/pyflowline/configuration/pyflowline_read_configuration_file.py +++ /dev/null @@ -1,173 +0,0 @@ -import os -from pathlib import Path -import datetime -import json -from pyflowline.classes.pycase import flowlinecase - -pDate = datetime.datetime.today() -sDate_default = "{:04d}".format(pDate.year) + \ - "{:02d}".format(pDate.month) + "{:02d}".format(pDate.day) - -<<<<<<<< HEAD:pyflowline/configuration/read_configuration_file.py -def pyflowline_read_configuration_file( - sFilename_configuration_in, - iFlag_standalone_in=None, - iFlag_use_mesh_dem_in=None, - iCase_index_in=None, - iResolution_index_in=None, - dResolution_degree_in=None, - dResolution_meter_in=None, - sMesh_type_in=None, - sModel_in=None, - sDate_in=None, - sDggrid_type_in=None, - sWorkspace_output_in=None): -======== - -def pyflowline_read_configuration_file(sFilename_configuration_in, - iFlag_standalone_in=None, - iFlag_use_mesh_dem_in=None, - iCase_index_in=None, - iResolution_index_in = None, - dResolution_degree_in=None, - dResolution_meter_in=None, - sMesh_type_in=None, - sModel_in=None, - sDate_in=None, - sDggrid_type_in = None, - sWorkspace_output_in=None): ->>>>>>>> main:pyflowline/configuration/pyflowline_read_configuration_file.py - """read a model configuration - - Args: - sFilename_configuration_in (str or Path): _description_ - iFlag_standalone_in (int, optional): _description_. Defaults to None. - iFlag_use_mesh_dem_in (int, optional): _description_. Defaults to None. - iCase_index_in (int, optional): _description_. Defaults to None. - dResolution_degree_in (float, optional): _description_. Defaults to None. - dResolution_meter_in (float, optional): _description_. Defaults to None. - sMesh_type_in (str, optional): _description_. Defaults to None. - sModel_in (str, optional): _description_. Defaults to None. - sDate_in (str, optional): _description_. Defaults to None. - sWorkspace_output_in (str or Path, optional): _description_. Defaults to None. - - Returns: - _type_: _description_ - """ - # Ensure input filenames are strings - if isinstance(sFilename_configuration_in, Path): - sFilename_configuration_in = str(sFilename_configuration_in) - if isinstance(sWorkspace_output_in, Path): - sWorkspace_output_in = str(sWorkspace_output_in) - - if not os.path.isfile(sFilename_configuration_in): - print(sFilename_configuration_in + ' does not exist') - return - - # Opening JSON file - with open(sFilename_configuration_in) as json_file: - aConfig = json.load(json_file) - - if iCase_index_in is not None: - iCase_index = iCase_index_in - else: - iCase_index = int(aConfig['iCase_index']) - - if iResolution_index_in is not None: - iResolution_index = iResolution_index_in - else: - if "iResolution_index" in aConfig: - iResolution_index = int( aConfig['iResolution_index']) - else: - iResolution_index = 10 - - pass - - if iFlag_standalone_in is not None: - iFlag_standalone = iFlag_standalone_in - else: - iFlag_standalone = int(aConfig['iFlag_standalone']) - - if iFlag_use_mesh_dem_in is not None: - iFlag_use_mesh_dem = iFlag_use_mesh_dem_in - else: - iFlag_use_mesh_dem = int(aConfig['iFlag_use_mesh_dem']) - - if sMesh_type_in is not None: - sMesh_type = sMesh_type_in - else: - sMesh_type = aConfig['sMesh_type'] - pass - - if sDggrid_type_in is not None: - sDggrid_type = sDggrid_type_in - else: - if "sDggrid_type" in aConfig: - sDggrid_type = aConfig["sDggrid_type"] - else: - sDggrid_type = 'ISEA3H' - - if sModel_in is not None: - sModel = sModel_in - else: - sModel = aConfig['sModel'] - pass - - if sDate_in is not None: - sDate = sDate_in - else: - sDate = aConfig['sDate'] - pass - - if dResolution_degree_in is not None: - dResolution_degree = dResolution_degree_in - else: - dResolution_degree = aConfig['dResolution_degree'] - pass - - if dResolution_meter_in is not None: - dResolution_meter = dResolution_meter_in - else: - dResolution_meter = aConfig['dResolution_meter'] - pass - - if sWorkspace_output_in is not None: - sWorkspace_output = sWorkspace_output_in - else: - sWorkspace_output = aConfig['sWorkspace_output'] - # try to create this output folder first using - - try: - print("Creating the specified output workspace (if it does not exist): \n", sWorkspace_output) - Path(sWorkspace_output).mkdir(parents=True, exist_ok=True) - print("The specified output workspace is: \n", sWorkspace_output) - except ValueError: - print("The specified output workspace cannot be created!") - exit - - aConfig['iCase_index'] = iCase_index - aConfig['iFlag_standalone'] = iFlag_standalone - aConfig['iFlag_use_mesh_dem'] = iFlag_use_mesh_dem - aConfig["iResolution_index"] = iResolution_index - aConfig['dResolution_degree'] = dResolution_degree - aConfig['dResolution_meter'] = dResolution_meter - - aConfig['sDate'] = sDate - aConfig['sModel'] = sModel - aConfig['sMesh_type'] = sMesh_type - aConfig["sDggrid_type"] = sDggrid_type - aConfig['sWorkspace_output'] = sWorkspace_output - - aConfig["sFilename_model_configuration"] = sFilename_configuration_in - - # based on global variable, a few variables are calculate once - # calculate the modflow simulation period - # https://docs.python.org/3/library/datetime.html#datetime-objects - - # aConfig - - # simulation - - oPyflowline = flowlinecase(aConfig) - - return oPyflowline diff --git a/pyflowline/configuration/read_configuration_file.py b/pyflowline/configuration/read_configuration_file.py index 65b0ca7..219d48e 100644 --- a/pyflowline/configuration/read_configuration_file.py +++ b/pyflowline/configuration/read_configuration_file.py @@ -8,21 +8,6 @@ sDate_default = "{:04d}".format(pDate.year) + \ "{:02d}".format(pDate.month) + "{:02d}".format(pDate.day) -<<<<<<<< HEAD:pyflowline/configuration/read_configuration_file.py -def pyflowline_read_configuration_file( - sFilename_configuration_in, - iFlag_standalone_in=None, - iFlag_use_mesh_dem_in=None, - iCase_index_in=None, - iResolution_index_in=None, - dResolution_degree_in=None, - dResolution_meter_in=None, - sMesh_type_in=None, - sModel_in=None, - sDate_in=None, - sDggrid_type_in=None, - sWorkspace_output_in=None): -======== def pyflowline_read_configuration_file(sFilename_configuration_in, iFlag_standalone_in=None, @@ -36,7 +21,7 @@ def pyflowline_read_configuration_file(sFilename_configuration_in, sDate_in=None, sDggrid_type_in = None, sWorkspace_output_in=None): ->>>>>>>> main:pyflowline/configuration/pyflowline_read_configuration_file.py + """read a model configuration Args: From dba356069102f82904de9ee803e1ffc7c57496cb Mon Sep 17 00:00:00 2001 From: changliao1025 Date: Mon, 6 May 2024 13:08:21 -0700 Subject: [PATCH 3/3] remove old file --- ...line_create_template_configuration_file.py | 187 ------------------ 1 file changed, 187 deletions(-) delete mode 100644 pyflowline/configuration/pyflowline_create_template_configuration_file.py diff --git a/pyflowline/configuration/pyflowline_create_template_configuration_file.py b/pyflowline/configuration/pyflowline_create_template_configuration_file.py deleted file mode 100644 index 81ad2bc..0000000 --- a/pyflowline/configuration/pyflowline_create_template_configuration_file.py +++ /dev/null @@ -1,187 +0,0 @@ -import os -from pathlib import Path -#use this function to generate an initial json file for hexwatershed -import json -#once it's generated, you can modify it and use it for different simulations -from pyflowline.classes.pycase import flowlinecase -from pyflowline.classes.basin import pybasin - -def pyflowline_create_template_basin_configuration_file( - sFilename_basins_json, - nBasin, - sWorkspace_input_in, - sWorkspace_output_in): - """generate basin configuration - - Args: - sFilename_basins_json (str or Path): the filename - nBasin (int): the total number of basin - sWorkspace_input_in (str or Path): the input data path - sWorkspace_output (str or Path): the output path - - Returns: - basin: a basin object - """ - - # Ensure input pathnames are strings - sFilename_basins_json = str(sFilename_basins_json) - sWorkspace_input_in = str(sWorkspace_input_in) - sWorkspace_output_in = str(sWorkspace_output_in) - - aBasin_out = list() - for i in range(nBasin): - sBasin = "{:03d}".format(i+1) - aConfig_basin = {} - aConfig_basin['iFlag_dam'] = 0 - aConfig_basin['iFlag_disconnected'] = 0 - aConfig_basin['lBasinID'] = i + 1 - aConfig_basin['dLatitude_outlet_degree'] = -180 - aConfig_basin['dLongitude_outlet_degree'] = 180 - aConfig_basin['dAccumulation_threshold'] = -90 - aConfig_basin['dThreshold_small_river'] = 90 - aConfig_basin['sFilename_dam'] = str(Path(sWorkspace_input_in) / 'ICoM_dams.csv') - aConfig_basin['sFilename_flowline_filter'] = str(Path(sWorkspace_input_in) / 'streamord7above.shp') - aConfig_basin['sFilename_flowline_raw'] = str(Path(sWorkspace_input_in) / 'allflowline.shp') - aConfig_basin['sFilename_flowline_topo'] = str(Path(sWorkspace_input_in) / 'flowline.csv') - aConfig_basin['sWorkspace_output_basin'] = str(Path(sWorkspace_output_in) / sBasin ) - pBasin = pybasin(aConfig_basin) - aBasin_out.append(pBasin) - pass - - #export basin config to a file - with open(sFilename_basins_json, 'w', encoding='utf-8') as f: - sJson = json.dumps([json.loads(ob.tojson()) for ob in aBasin_out], indent = 4) - f.write(sJson) - f.close() - - return aBasin_out - -def pyflowline_create_template_configuration_file( - sFilename_json, - sWorkspace_input, - sWorkspace_output, - iFlag_standalone_in=None, - iFlag_use_mesh_dem_in=None, - iCase_index_in=None, - dResolution_degree_in=None, - dResolution_meter_in=None, - sDate_in=None, - sMesh_type_in=None, - sModel_in=None): - """generate pyflowline config template file - - Args: - sFilename_json (str or Path): _description_. - sWorkspace_input (str or Path): _description_. - sWorkspace_output (str or Path): _description_. - iFlag_standalone_in (int, optional): _description_. Defaults to None. - iFlag_use_mesh_dem_in (int, optional): _description_. Defaults to None. - iCase_index_in (int, optional): _description_. Defaults to None. - dResolution_degree_in (float, optional): _description_. Defaults to None. - dResolution_meter_in (float, optional): _description_. Defaults to None. - sDate_in (str, optional): _description_. Defaults to None. - sMesh_type_in (str, optional): _description_. Defaults to None. - sModel_in (str, optional): _description_. Defaults to None. - - Returns: - _type_: _description_ - """ - - # Ensure input pathnames are strings - sFilename_json = str(sFilename_json) - sWorkspace_input = str(sWorkspace_input) - sWorkspace_output = str(sWorkspace_output) - - if os.path.exists(sFilename_json): - os.remove(sFilename_json) - - if iCase_index_in is not None: - iCase_index = iCase_index_in - else: - iCase_index = 1 - - if iFlag_standalone_in is not None: - iFlag_standalone = iFlag_standalone_in - else: - iFlag_standalone = 1 - - if iFlag_use_mesh_dem_in is not None: - iFlag_use_mesh_dem = iFlag_use_mesh_dem_in - else: - iFlag_use_mesh_dem = 0 - - #if iFlag_use_shapefile_extent_in is not None: - # iFlag_use_shapefile_extent = iFlag_use_shapefile_extent_in - #else: - # iFlag_use_shapefile_extent = 0 - - if sMesh_type_in is not None: - sMesh_type = sMesh_type_in - else: - sMesh_type = 'hexagon' - pass - if sDate_in is not None: - sDate = sDate_in - else: - sDate = '20220202' - pass - - nBasin = 1 - - # Use a dict to initialize the class - aConfig = {} - - #aConfig['iFlag_use_shapefile_extent'] = iFlag_use_shapefile_extent - aConfig['iFlag_use_mesh_dem'] = iFlag_use_mesh_dem - aConfig['iFlag_save_mesh'] = 1 - aConfig['iFlag_simplification']=1 - aConfig['iFlag_create_mesh']=1 - aConfig['iFlag_intersect']=1 - aConfig['iFlag_resample_method']=1 - aConfig['iFlag_global']=0 - aConfig['iFlag_multiple_outlet']=0 - aConfig['iFlag_elevation_profile']=1 - 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'] = 50000 - aConfig['dLongitude_left'] = -180 - aConfig['dLongitude_right'] = 180 - aConfig['dLatitude_bot'] = -90 - aConfig['dLatitude_top'] = 90 - aConfig['sFilename_model_configuration'] = sFilename_json - aConfig['sWorkspace_input'] = sWorkspace_input - aConfig['sWorkspace_output'] = sWorkspace_output - aConfig['sRegion'] = 'susquehanna' - aConfig['sModel'] = 'pyflowline' - aConfig['iCase_index'] = iCase_index - aConfig['sMesh_type'] = sMesh_type - aConfig['sJob'] = 'pyflowline' - aConfig['sDate']= sDate - #full path - aConfig['sFilename_mesh_netcdf'] = str(Path(sWorkspace_input) / 'lnd_cull_mesh.nc') - aConfig['sFilename_spatial_reference'] = str(Path(sWorkspace_input) / 'boundary_proj.shp') - #relative path - aConfig['flowline_info'] = 'flowline_info.json' - aConfig['sFilename_mesh_info'] = 'mesh_info.json' - aConfig['sFilename_elevation'] = 'elevation.json' - oModel = flowlinecase(aConfig) - - # Generate basin - sDirname = os.path.dirname(sFilename_json) - sFilename = Path(sFilename_json).stem + '_basins.json' - sFilename_basins_json = os.path.join(sDirname, sFilename) - - aBasin = pyflowline_create_template_basin_configuration_file( - sFilename_basins_json, - nBasin, - sWorkspace_input, - oModel.sWorkspace_output) - - oModel.aBasin = aBasin - oModel.sFilename_basins = sFilename_basins_json - oModel.export_config_to_json(sFilename_json) - - return oModel