Skip to content
Snippets Groups Projects
Commit 789b6dbc authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Assume "{shpc_dir}/{orientation}/Slice_{slice}"

Assume that a slice is in a directory
"{shpc_dir}/{orientation}/Slice_{slice}" where shpc_dir can be any
name, orientation is "Anticyclones" or "Cyclones" and slice is an
integer. Do not read or create any longer a file "orientation.txt" in
the slice directory. Add procedure `get_slice_dir`. Add dummy
arguments cyclone and slice to procedure `shpc_open`. Add dummy
argument slice to procedure `shpc_create`.
parent 25a24463
No related branches found
No related tags found
No related merge requests found
Showing
with 70 additions and 91 deletions
add_subdirectory(Tests)
target_sources(test_get_1_outerm PRIVATE derived_types.f90
target_sources(test_get_1_outerm PRIVATE derived_types.f90 get_slice_dir.f90
spher_polyline_area.f90 shpc_create.f90 write_eddy.f90 shpc_close.f90
ccw_orient.f90)
target_sources(test_set_all_outerm PRIVATE derived_types.f90
target_sources(test_set_all_outerm PRIVATE derived_types.f90 get_slice_dir.f90
spher_polyline_area.f90 shpc_create.f90 write_eddy.f90 shpc_close.f90
ccw_orient.f90 write_snapshot.f90)
target_sources(test_max_speed_contour_ssh PRIVATE derived_types.f90)
target_sources(test_nearby_extr PRIVATE derived_types.f90 read_snapshot.f90
read_eddy.f90 read_field_indices.f90 shpc_open.f90 shpc_close.f90)
target_sources(test_set_max_speed PRIVATE derived_types.f90
read_eddy.f90 read_field_indices.f90 shpc_open.f90 shpc_close.f90
get_slice_dir.f90)
target_sources(test_set_max_speed PRIVATE derived_types.f90 get_slice_dir.f90
spher_polyline_area.f90 shpc_open.f90 shpc_close.f90 read_field_indices.f90
read_eddy.f90 shpc_create.f90 write_eddy.f90 ccw_orient.f90)
target_sources(test_spher_polyline_area PRIVATE spher_polyline_area.f90)
target_sources(inst_eddies PRIVATE write_eddy.f90 spher_polyline_area.f90
derived_types.f90 shpc_create.f90 shpc_close.f90 shpc_open.f90
read_field_indices.f90 write_snapshot.f90 ccw_orient.f90)
get_slice_dir.f90 read_field_indices.f90 write_snapshot.f90 ccw_orient.f90)
target_sources(test_write_eddy PRIVATE derived_types.f90 shpc_open.f90
shpc_close.f90 read_field_indices.f90 shpc_create.f90)
shpc_close.f90 read_field_indices.f90 shpc_create.f90 get_slice_dir.f90)
if(MPI_Fortran_HAVE_F08_MODULE)
target_sources(test_overlap PRIVATE derived_types.f90 read_snapshot.f90
spher_polyline_area.f90 read_eddy.f90 read_field_indices.f90 write_eddy.f90
shpc_open.f90 shpc_close.f90)
shpc_open.f90 shpc_close.f90 get_slice_dir.f90)
target_sources(test_read_snapshot PRIVATE derived_types.f90 shpc_create.f90
read_snapshot.f90 write_eddy.f90 read_eddy.f90 read_field_indices.f90
shpc_open.f90 shpc_close.f90)
shpc_open.f90 shpc_close.f90 get_slice_dir.f90)
target_sources(test_spher_polygon_area PRIVATE spher_polyline_area.f90)
target_sources(test_weight PRIVATE derived_types.f90)
target_sources(test_read_eddy PRIVATE derived_types.f90 shpc_create.f90
read_eddy.f90 write_eddy.f90 read_field_indices.f90 shpc_open.f90
shpc_close.f90)
shpc_close.f90 get_slice_dir.f90)
target_sources(test_send_recv PRIVATE read_field_indices.f90
read_snapshot.f90 write_eddy.f90 shpc_create.f90 read_eddy.f90
derived_types.f90 shpc_open.f90 shpc_close.f90)
derived_types.f90 shpc_open.f90 shpc_close.f90 get_slice_dir.f90)
target_sources(test_get_dispatch_snap PRIVATE read_field_indices.f90
read_snapshot.f90 shpc_create.f90 write_eddy.f90 read_eddy.f90
derived_types.f90 shpc_open.f90 shpc_close.f90)
derived_types.f90 shpc_open.f90 shpc_close.f90 get_slice_dir.f90)
target_sources(eddy_graph PRIVATE shpc_open.f90 shpc_close.f90
read_field_indices.f90 read_snapshot.f90 spher_polyline_area.f90
read_eddy.f90 write_eddy.f90 derived_types.f90)
read_eddy.f90 write_eddy.f90 derived_types.f90 get_slice_dir.f90)
endif()
......@@ -4,7 +4,7 @@ module shpc_create_m
contains
subroutine shpc_create(hshp, shpc_dir, cyclone)
subroutine shpc_create(hshp, shpc_dir, cyclone, slice)
! Libraries:
use jumble, only: new_unit
......@@ -12,17 +12,16 @@ contains
use shapelib_03, only: shp_create_03, dbf_add_field_03
use derived_types, only: shpc_slice_handler
use get_slice_dir_m, only: get_slice_dir
TYPE(shpc_slice_handler), intent(out):: hshp
character(len = *), intent(in):: shpc_dir
logical, intent(in):: cyclone
! Local:
integer unit
integer, intent(in):: slice
!---------------------------------------------------------------------
hshp%dir = shpc_dir
hshp%dir = get_slice_dir(shpc_dir, cyclone, slice)
! extremum shapefile:
call shp_create_03(hshp%dir // "/extremum", shpt_point, &
......@@ -68,17 +67,6 @@ contains
open(hshp%unit, file = hshp%dir // "/ishape_last.txt", status = "replace", &
action = "write")
hshp%cyclone = cyclone
call new_unit(unit)
open(unit, file = hshp%dir // "/orientation.txt", status = "replace", &
action = "write")
if (cyclone) then
write(unit, fmt = *) "cyclones"
else
write(unit, fmt = *) "anticyclones"
end if
close(unit)
end subroutine shpc_create
......
......@@ -4,27 +4,31 @@ module shpc_open_m
contains
subroutine shpc_open(hshp, shpc_dir, pszaccess, iostat)
subroutine shpc_open(hshp, shpc_dir, cyclone, slice, pszaccess, iostat)
! Opens a given slice of a given orientation in an SHPC.
! Libraries:
USE jumble, only: new_unit
use shapelib_03, only: shp_open_03
use derived_types, only: shpc_slice_handler
use get_slice_dir_m, only: get_slice_dir
use read_field_indices_m, only: read_field_indices
TYPE(shpc_slice_handler), intent(out):: hshp
character(len = *), intent(in):: shpc_dir
logical, intent(in):: cyclone
integer, intent(in):: slice
character(len = *), intent(in):: pszaccess ! should be "rb" or "rb+"
integer, optional, intent(out):: iostat
! Local:
integer unit, iostat_extr
character(len = 12) orientation
integer iostat_extr
!--------------------------------------------------------------------
hshp%dir = shpc_dir
hshp%dir = get_slice_dir(shpc_dir, cyclone, slice)
call shp_open_03(hshp%extremum, hshp%dir // "/extremum", pszaccess, &
iostat_extr)
if (present(iostat)) iostat = iostat_extr
......@@ -35,12 +39,6 @@ contains
call shp_open_03(hshp%max_speed, hshp%dir // "/max_speed_contour", &
pszaccess)
call read_field_indices(hshp)
call new_unit(unit)
open(unit, file = hshp%dir // "/orientation.txt", status = "old", &
action = "read", position = "rewind")
read(unit, fmt = *) orientation
close(unit)
hshp%cyclone = trim(adjustl(orientation)) == "cyclones"
call new_unit(hshp%unit)
if (pszaccess == "rb") then
......@@ -50,10 +48,14 @@ contains
open(hshp%unit, file = hshp%dir // "/ishape_last.txt", &
status = "old", action = "readwrite", position = "append")
end if
hshp%cyclone = cyclone
else
if (.not. present(iostat)) then
print *, "shpc_open: failed"
print *, "shpc_dir = ", shpc_dir
print *, "cyclone = ", cyclone
print *, "slice = ", slice
print *, "pszaccess = ", pszaccess
stop 1
end if
......
......@@ -26,7 +26,7 @@ def in_window(point, window):
return longit <= urcrnrlon and llcrnrlat <= point[1] <= urcrnrlat
def open_shpc(shpc_dir):
def open_shpc(shpc_dir, orientation, slice = 0):
if not path.isdir(shpc_dir):
sys.exit(f"open_shpc: {shpc_dir} is not an existing directory")
......@@ -34,14 +34,16 @@ def open_shpc(shpc_dir):
for layer in ["extremum", "outermost_contour", "max_speed_contour",
"centroid"]:
my_shapefile = path.join(shpc_dir, orientation, f"Slice_{slice}", layer)
try:
handler["readers"][layer] \
= shapefile.Reader(path.join(shpc_dir, layer))
handler["readers"][layer] = shapefile.Reader(my_shapefile)
except shapefile.ShapefileException:
print(f"Shapefile {layer} not found in {shpc_dir}.")
print(f"{my_shapefile}.shp not found.")
handler["d_init"] = handler["readers"]["extremum"].record(0).date
fname = path.join(shpc_dir, "ishape_last.txt")
fname = path.join(shpc_dir, orientation, f"Slice_{slice}",
"ishape_last.txt")
try:
handler["ishape_last"] = np.loadtxt(fname, dtype = int, ndmin = 1)
......@@ -49,13 +51,5 @@ def open_shpc(shpc_dir):
print("Could not read", fname)
handler["ishape_last"] = None
fname = path.join(shpc_dir, "orientation.txt")
try:
with open(fname) as f: line = f.readline()
except FileNotFoundError:
print("Could not read", fname)
else:
handler["cyclones"] = line.strip() == "cyclones"
handler["cyclones"] = orientation == "Cyclones"
return handler
......@@ -76,8 +76,8 @@ if __name__ == "__main__":
# Process arguments:
parser = argparse.ArgumentParser()
parser.add_argument("shpc_dir", help = "directories containing the "
"collections of shapefiles", nargs = "+")
parser.add_argument("shpc_dir", help = "directory containing the "
"collection of shapefiles")
parser.add_argument("-d", "--dates", type = int, nargs = 2,
metavar = ("d_min", "d_max"))
parser.add_argument("-l", "--light", help = "lighter plot",
......@@ -89,7 +89,8 @@ if __name__ == "__main__":
args = parser.parse_args()
#--
handlers = [util_eddies.open_shpc(shpc_dir) for shpc_dir in args.shpc_dir]
handlers = [util_eddies.open_shpc(args.shpc_dir, orientation)
for orientation in ["Anticyclones", "Cyclones"]]
# Do some checks on first input SHPC:
......
......@@ -16,12 +16,13 @@ import json
parser = argparse.ArgumentParser()
parser.add_argument("directory", help = "containing the three shapefiles")
parser.add_argument("orientation", choices = ["Anticyclones", "Cyclones"])
group = parser.add_mutually_exclusive_group()
group.add_argument("-i", "--ishape", type = int)
group.add_argument("-n", "--node", type = int)
args = parser.parse_args()
handler = util_eddies.open_shpc(args.directory)
handler = util_eddies.open_shpc(args.directory, args.orientation)
if args.ishape:
ishape = args.ishape
......
......@@ -158,14 +158,14 @@ if __name__ == "__main__":
action = "store_true")
parser.add_argument("--dashed", action = "store_true",
help = "dashed linestyle, useful for a second snapshot")
parser.add_argument("shpc_dir", help = "directories containing the "
"collections of shapefiles", nargs = "+")
parser.add_argument("shpc_dir", help = "directory containing the "
"collection of shapefiles")
parser.add_argument("--save", metavar = "format",
help = "Save file to specified format")
args = parser.parse_args()
if args.grid or args.window is None:
file = path.join(args.shpc_dir[0], "grid_nml.txt")
file = path.join(args.shpc_dir, "grid_nml.txt")
try:
grid_nml = f90nml.read(file)["grid_nml"]
......@@ -214,30 +214,27 @@ if __name__ == "__main__":
if args.window is None: plot_grid_bb(grid_nml, ax)
for shpc_dir in args.shpc_dir:
handler = util_eddies.open_shpc(shpc_dir)
if "cyclones" not in handler:
sys.exit(f"Missing orientation.txt in {shpc_dir}")
for orientation in ["Anticyclones", "Cyclones"]:
handler = util_eddies.open_shpc(args.shpc_dir, orientation)
if handler["ishape_last"] is None:
print(f"{shpc_dir}: We will use all the shapes.")
print(f"{orientation}: We will use all the shapes.")
handler["ishape_last"] = [len(handler["readers"]["extremum"]) - 1]
if len(handler["ishape_last"]) == 1:
if args.date is not None and args.date != handler["d_init"]:
sys.exit(f"{shpc_dir}: Bad value of date option")
sys.exit(f"{orientation}: Bad value of date option")
d = handler["d_init"]
else:
if args.date is None:
print(f"{shpc_dir}: No date option, plotting first date:",
print(f"{orientation}: No date option, plotting first date:",
handler["d_init"])
d = handler["d_init"]
else:
d = args.date
ishape_list = select_ishapes(d, handler, args.window)
if len(ishape_list) == 0: print(f"{shpc_dir}: No eddy found")
if len(ishape_list) == 0: print(f"{orientation}: No eddy found")
snapshot(ax, ishape_list, handler, dashed = args.dashed,
light = args.light)
......
......@@ -7,6 +7,7 @@ from os import path
parser = argparse.ArgumentParser()
parser.add_argument("directory", help = "containing the shapefiles")
parser.add_argument("orientation", choices = ["Anticyclones", "Cyclones"])
args = parser.parse_args()
n_valid = 0
......@@ -17,9 +18,10 @@ n_points = 0
n_missing_speed = np.zeros(3, dtype = int)
n_valid_speed = 0
with shapefile.Reader(path.join(args.directory, "extremum")) as extremum, \
shapefile.Reader(path.join(args.directory, "outermost_contour")) \
as outermost_contour:
with shapefile.Reader(path.join(args.directory, args.orientation, "Slice_0",
"extremum")) as extremum, \
shapefile.Reader(path.join(args.directory, args.orientation, "Slice_0",
"outermost_contour")) as outermost_contour:
n_extr = len(extremum)
for rec_extr, shape_rec_outer in zip(extremum.iterRecords(),
......@@ -89,8 +91,8 @@ n_max_speed = 0
n_points_valid = 0
n_points = 0
with shapefile.Reader(path.join(args.directory, "max_speed_contour")) \
as max_speed_contour:
with shapefile.Reader(path.join(args.directory, args.orientation, "Slice_0",
"max_speed_contour")) as max_speed_contour:
for shape_rec in max_speed_contour:
l = len(shape_rec.shape.points)
n_points += l
......
......@@ -4,8 +4,7 @@
"command":
[
"$src_dir/Inst_eddies/Analysis/plot_eddy_contours.py",
"$tests_old_dir/Region_6/SHPC_anti",
"$tests_old_dir/Region_6/SHPC_cyclo", "--save=png"
"$tests_old_dir/Region_6/SHPC", "--save=png"
]
},
{
......@@ -13,8 +12,7 @@
"command":
[
"$src_dir/Inst_eddies/Analysis/anim_eddy_contours.py",
"$tests_old_dir/Region_6/SHPC_anti",
"$tests_old_dir/Region_6/SHPC_cyclo", "--light"
"$tests_old_dir/Region_6/SHPC", "--light"
]
},
{
......@@ -22,7 +20,7 @@
"command":
[
"$src_dir/Inst_eddies/Analysis/eddy_dump.py",
"$tests_old_dir/Inst_eddies_loop/SHPC_cyclo"
"$tests_old_dir/Inst_eddies_loop/SHPC", "Cyclones"
],
"input": "20455, 3\n"
},
......@@ -31,9 +29,8 @@
"command":
[
"$src_dir/Inst_eddies/Analysis/plot_eddy_contours.py",
"$tests_old_dir/Extraction_eddies_region_4/SHPC_anti",
"$tests_old_dir/Extraction_eddies_region_4/SHPC_cyclo",
"--grid", "--save=png"
"$tests_old_dir/Extraction_eddies_region_4/SHPC", "--grid",
"--save=png"
],
"description": "With grid option.",
"symlink": [["$src_dir/Inst_eddies/Tests/Input/h_region_4.nc", "h.nc"]]
......@@ -43,7 +40,7 @@
"command":
[
"$src_dir/Inst_eddies/Analysis/plot_eddy_contours.py",
"$tests_old_dir/Extraction_eddies_region_5/SHPC_cyclo", "--window",
"$tests_old_dir/Extraction_eddies_region_5/SHPC", "--window",
"10", "-40", "15", "-35", "--save=png"
],
"description": "With window option."
......@@ -62,9 +59,7 @@
"command":
[
"$src_dir/Inst_eddies/Analysis/plot_eddy_contours.py",
"$tests_old_dir/Extraction_eddies_region_4/SHPC_anti",
"$tests_old_dir/Extraction_eddies_region_4/SHPC_cyclo",
"--save=png"
"$tests_old_dir/Extraction_eddies_region_4/SHPC", "--save=png"
],
"description": "With two SHPC as command line arguments."
},
......@@ -79,12 +74,11 @@
},
{
"title": "Animation_2_SHPC",
"description": "With two input SHPC and no option light.",
"description": "With two orientations and no option light.",
"command":
[
"$src_dir/Inst_eddies/Analysis/anim_eddy_contours.py",
"$tests_old_dir/Inst_eddies_loop/SHPC_cyclo",
"$tests_old_dir/Inst_eddies_loop/SHPC_anti"
"$tests_old_dir/Inst_eddies_loop/SHPC"
]
},
{
......@@ -92,7 +86,7 @@
"command":
[
"$src_dir/Inst_eddies/Analysis/stat.py",
"$tests_old_dir/Inst_eddies_py/SHPC_anti"
"$tests_old_dir/Inst_eddies_py/SHPC", "Anticyclones"
]
},
{
......@@ -100,7 +94,7 @@
"command":
[
"$src_dir/Inst_eddies/Analysis/filter.py",
"$PWD/Inst_eddies_4_anti",
"$PWD/Inst_eddies_4/Anticyclones/Slice_0",
"plouf"
],
"env": {"PYTHONPATH": "$src_dir/Inst_eddies/Tests/Input"}
......
anticyclones
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment