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

Generalize `filter.py` for several dates

Generalize `filter.py` to act on a triplet of shapefiles containing
several dates, with renumber option. Create file `ishape_last.txt`.
parent c58c21b7
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
"""Note: the creation of ishape_last.txt assumes no missing date in
the output."""
import shapefile
import argparse
from os import path
......@@ -7,9 +10,9 @@ from os import path
def accept(shape_rec_extr, shape_rec_outer, shape_rec_max):
"""Filtering function."""
# return 6 <= shape_rec_extr.shape.points[0][0] <= 12 \
# and - 33 <= shape_rec_extr.shape.points[0][1] <= - 27
return shape_rec_extr.record.date_index == 20456
return 1.625 <= shape_rec_extr.shape.points[0][0] <= 15.625 \
and - 38.375 <= shape_rec_extr.shape.points[0][1] <= - 30.375
##return shape_rec_extr.record.date_index == 20456
parser = argparse.ArgumentParser()
parser.add_argument("input_dir", help = "containing the three input shapefiles")
......@@ -33,12 +36,21 @@ with shapefile.Reader(path.join(args.input_dir, "extremum")) as extremum, \
extremum_filt.fields = extremum.fields[1:]
outermost_cont_filt.fields = outermost_cont.fields[1:]
max_speed_cont_filt.fields = max_speed_cont.fields[1:]
if args.renumber: eddy_index = 0
if args.renumber:
last_date_written = None
ishape_last = []
for shape_rec_extr, shape_rec_outer, shape_rec_max \
in zip(extremum, outermost_cont, max_speed_cont):
if accept(shape_rec_extr, shape_rec_outer, shape_rec_max):
if args.renumber: eddy_index += 1
if args.renumber:
if shape_rec_extr.record.date_index == last_date_written:
eddy_index += 1
else:
ishape_last.append((len(extremum_filt) - 1))
eddy_index = 1
last_date_written = shape_rec_extr.record.date_index
for sr, w in zip([shape_rec_extr, shape_rec_outer, shape_rec_max],
[extremum_filt, outermost_cont_filt,
......@@ -47,3 +59,12 @@ with shapefile.Reader(path.join(args.input_dir, "extremum")) as extremum, \
if args.renumber: r["eddy_index"] = eddy_index
w.record(*r)
w.shape(sr.shape)
if args.renumber:
ishape_last.append((len(extremum_filt) - 1))
file = path.join(args.output_dir, "ishape_last.txt")
with open(file, "w") as f:
for i in ishape_last[1:]:
f.write(str(i) + "\n")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment