Skip to content

Commit

Permalink
test the jigsaw workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
changliao1025 committed Oct 16, 2024
1 parent 5fa88c3 commit 79c176d
Show file tree
Hide file tree
Showing 97 changed files with 3,902,370 additions and 450 deletions.
2 changes: 1 addition & 1 deletion examples/susquehanna/run_simulation_mpas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


from pyflowline.configuration.read_configuration_file import pyflowline_read_configuration_file
from pyflowline.configuration.change_json_key_value import pyflowline_change_json_key_value
from pyflowline.configuration.change_json_key_value import change_json_key_value
from pyflowline.configuration import path_manager as pyflowline_path_manager


Expand Down
17 changes: 11 additions & 6 deletions pyflowline/classes/_hpc.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import os
import stat
from pathlib import Path


from pyearth.system.python.retrieve_python_environment import retrieve_python_environment
def _pyflowline_create_hpc_job(self, sSlurm_in=None):
"""create a HPC job for this simulation
"""
os.chdir(self.sWorkspace_output)

sConda_env_path , sConda_env_name = retrieve_python_environment()
# part 1 python script

sFilename_pyflowline = os.path.join(
str(Path(self.sWorkspace_output)), "run_pyflowline.py")
ofs_pyflowline = open(sFilename_pyflowline, 'w')

sLine = '#!/qfs/people/liao313/.conda/envs/pyflowline/bin/' + 'python3' + '\n'
sLine = '#!/qfs/people/liao313/.conda/envs/' + sConda_env_name + '/bin/' + 'python3' + '\n'
ofs_pyflowline.write(sLine)
sLine = 'import os' + '\n'
ofs_pyflowline.write(sLine)
sLine = "os.environ['PROJ_LIB']=" + '"'+ sConda_env_path + '/share/proj' +'"'+ '\n'
ofs_pyflowline.write(sLine)
sLine = "os.environ['LD_LIBRARY_PATH']=" + '"' + sConda_env_path + '/lib:${LD_LIBRARY_PATH}"' + '\n'
ofs_pyflowline.write(sLine)
sLine = 'from pyflowline.configuration.read_configuration_file import pyflowline_read_configuration_file' + '\n'
ofs_pyflowline.write(sLine)
Expand Down Expand Up @@ -64,7 +69,7 @@ def _pyflowline_create_hpc_job(self, sSlurm_in=None):
ofs.write(sLine)
sLine = '#SBATCH --job-name=' + self.sCase + '\n'
ofs.write(sLine)
sLine = '#SBATCH -t 1:00:00' + '\n'
sLine = '#SBATCH -t 4:00:00' + '\n'
ofs.write(sLine)
sLine = '#SBATCH --nodes=1' + '\n'
ofs.write(sLine)
Expand Down Expand Up @@ -93,7 +98,7 @@ def _pyflowline_create_hpc_job(self, sSlurm_in=None):
ofs.write(sLine)
sLine = 'source /share/apps/python/miniconda4.12.0/etc/profile.d/conda.sh' + '\n'
ofs.write(sLine)
sLine = 'conda activate hexwatershed' + '\n'
sLine = 'conda activate '+ sConda_env_name + '\n'
ofs.write(sLine)
sLine = 'cd $SLURM_SUBMIT_DIR\n'
ofs.write(sLine)
Expand Down
27 changes: 21 additions & 6 deletions pyflowline/classes/pycase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
import stat
from pathlib import Path
import json
Expand Down Expand Up @@ -559,6 +560,11 @@ def pyflowline_setup(self):
sWorkspace_output = self.sWorkspace_output + slash + '..'+ slash + 'jigsaw'
sWorkspace_output = os.path.abspath(sWorkspace_output)

#check if the folder exists
if os.path.exists(sWorkspace_output):
#delete the folder
shutil.rmtree(sWorkspace_output)

Path(sWorkspace_output).mkdir(parents=True, exist_ok=True)
self.sWorkspace_jigsaw = sWorkspace_output
#then copy the binary file to the folder
Expand All @@ -567,6 +573,10 @@ def pyflowline_setup(self):
sFilename_new = sWorkspace_output + slash + 'jigsaw'
copy2(self.sFilename_dggrid, sFilename_new)
os.chmod(sFilename_new, stat.S_IREAD | stat.S_IWRITE | stat.S_IXUSR)
#make this binary as the default one and overwrite other binaries
# Add the destination directory ahead of the system PATH
os.environ["PATH"] = sWorkspace_output + os.pathsep + os.environ["PATH"]
# Verify that the binary is in the PATH and is the default
pass
else:
if system == 'Windows':
Expand Down Expand Up @@ -600,6 +610,10 @@ def pyflowline_setup(self):
sWorkspace_output = self.sWorkspace_output + slash + '..'+ slash + 'dggrid'
sWorkspace_output = os.path.abspath(sWorkspace_output)

if os.path.exists(sWorkspace_output):
#delete the folder
shutil.rmtree(sWorkspace_output)

Path(sWorkspace_output).mkdir(parents=True, exist_ok=True)
self.sWorkspace_dggrid = sWorkspace_output
#then copy the binary file to the folder
Expand Down Expand Up @@ -996,22 +1010,23 @@ def pyflowline_mesh_generation(self, iFlag_antarctic_in=None, iFlag_arctic_in=No

if self.iFlag_run_jigsaw == 1: #run the jigsaw mesh generation workflow, the user also need to provide a json configuration file for jisgaw

sFilename_jigsaw_geometry_in = os.path.join(self.sWorkspace_jigsaw, 'jigsaw.msh')
sWorkspace_jigsaw = self.sWorkspace_jigsaw
aFilename_river = list()
aFilename_watershed_boundary = list()
aFilenamae_lake_boundary = list()
aFilename_coastline = list()

run_jigsaw_mpas_workflow(sFilename_jigsaw_geometry_in,
aConfig_jigsaw_in = self.aConfig_jissaw,
sFilename_mesh_netcdf = run_jigsaw_mpas_workflow(sWorkspace_jigsaw,
aConfig_in = self.aConfig_jissaw,
aFilename_river_in=aFilename_river,
aFilename_watershed_boundary_in= aFilename_watershed_boundary,
aFilenamae_lake_boundary_in = aFilenamae_lake_boundary,
aFilename_coastline_in = aFilename_coastline)

pass
print('The generated MPAS mesh is: ',sFilename_mesh_netcdf)

iFlag_use_mesh_dem = self.iFlag_use_mesh_dem
sFilename_mesh_netcdf = self.sFilename_mesh_netcdf
self.sFilename_mesh_netcdf = sFilename_mesh_netcdf
dLatitude_top = self.dLatitude_top
dLatitude_bot = self.dLatitude_bot
dLongitude_left = self.dLongitude_left
Expand All @@ -1028,7 +1043,7 @@ def pyflowline_mesh_generation(self, iFlag_antarctic_in=None, iFlag_arctic_in=No
#create a polygon based on
#read boundary
pBoundary_wkt, aExtent = gdal_read_geojson_boundary(self.sFilename_mesh_boundary_geojson)

print(sFilename_mesh_netcdf)
aMpas = create_mpas_mesh(iFlag_global, iFlag_use_mesh_dem, iFlag_save_mesh,
sFilename_mesh_netcdf, sFilename_mesh,
iFlag_antarctic_in=iFlag_antarctic_in,
Expand Down
20 changes: 20 additions & 0 deletions pyflowline/classes/vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def __init__(self, aParameter):
except:
print('Initialization of vertex failed!')

#calcualte x y z based on dLongitude and dLatitude and earth radius
self.dX_meter, self.dY_meter, self.dZ_meter = self.calculate_xyz()


return

def toNvector(self):
Expand Down Expand Up @@ -179,6 +183,22 @@ def calculate_distance(self, other):
dDistance = calculate_distance_based_on_longitude_latitude(lon1, lat1, lon2, lat2)
return dDistance

def calculate_xyz(self):
"""
Calculate the x, y, z based on dLongitude and dLatitude
Returns:
tuple: The x, y, z
"""
dX_meter = 0.0
dY_meter = 0.0
dZ_meter = 0.0
dRadius = 6371000.0 #earth radius in meter
dX_meter = dRadius * np.cos(self.dLatitude_radian) * np.cos(self.dLongitude_radian)
dY_meter = dRadius * np.cos(self.dLatitude_radian) * np.sin(self.dLongitude_radian)
dZ_meter = dRadius * np.sin(self.dLatitude_radian)
return dX_meter, dY_meter, dZ_meter

def tojson(self):
"""
Convert a vecter object to a json string
Expand Down
Loading

0 comments on commit 79c176d

Please sign in to comment.