# Path: pyteltools/geom/Shapefile.py
# def get_shape_type(input_filename):
# def get_lines(input_filename, shape_type):
# def get_open_polylines(input_filename):
# def get_polygons(input_filename):
# def get_all_fields(input_filename):
# def get_attribute_names(input_filename):
# def get_numeric_attribute_names(input_filename):
# def get_points(input_filename, indices=None, with_z=False):
# def write_shp_points_z(output_filename, z_name, points):
# def write_shp_lines(output_filename, shape_type, lines, attribute_name):
# 
# Path: pyteltools/slf/Serafin.py
# class Serafin:
#     """!
#     @brief A Serafin object corresponds to a single Serafin in file IO stream
# 
#     # Attributes:
#     - language <str>: language for variables ('fr' or 'en')
#     - mode <str>: file open mode
#     - file <_io.BufferedReader>: input Serafin stream
#     - filename <str>: path to file
#     - file_size <int>: size of file
#     """
#     def __init__(self, filename, mode, language):
#         self.language = language
#         self.mode = mode
# 
#         self.file = None  # will be opened when called using `with` statement
#         self.filename = filename
#         self.file_size = None
# 
#     def __enter__(self):
#         self.file = open(self.filename, self.mode)
#         return self
# 
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         self.file.close()
#         return False
# 
# Path: pyteltools/utils/cli_base.py
# LINE_WIDTH = 80
# class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
# class PyTelToolsArgParse(argparse.ArgumentParser):
#     def __init__(self, add_args=[], description=None, *args, **kwargs):
#     def add_known_argument(self, arg_id):
#     def _add_auto_arguments(self):
#     def _title_group(label):
#     def add_argument_group(self, name, *args, **kwargs):
#     def add_group_general(self, add_args=[]):
#     def parse_args(self, *args, **kwargs):


import numpy as np
import sys
from shapefile import ShapefileException
from shapely.geometry import Point
from pyteltools.conf import settings
from pyteltools.geom import Shapefile
from pyteltools.slf import Serafin
from pyteltools.utils.cli_base import logger, PyTelToolsArgParse
                if polygons is not None:
                    mask_nodes = np.zeros(output_header.nb_nodes, dtype=bool)
                    for idx_node, (x, y) in enumerate(zip(output_header.x, output_header.y)):
                        point = Point(x, y)
                        for polygon in polygons:
                            if polygon.contains(point):
                                mask_nodes[idx_node] = True
                                break
                    logger.info('Number of nodes inside polygon(s): %i (over %i)'
                                % (mask_nodes.sum(), output_header.nb_nodes))
                else:
                    mask_nodes = np.ones(output_header.nb_nodes, dtype=bool)
            else:
                if not resin.header.same_2d_mesh(output_header):
                    logger.critical('The mesh of %s is different from the first one' % in_slf)
                    sys.exit(1)

            for time_index, time in enumerate(resin.time):
                for j, var_ID in enumerate(var_IDs):
                    values = resin.read_var_in_frame(time_index, var_ID)
                    if time_index == 0 and i == 0:
                        out_values[j, :] = values
                    else:
                        out_values[j, mask_nodes] = fun(out_values[j, mask_nodes], values[mask_nodes])

    with Serafin.Write(args.out_slf, args.lang, overwrite=args.force) as resout:
        resout.write_header(output_header)
        resout.write_entire_frame(output_header, 0.0, out_values)



# Path: pyteltools/geom/Shapefile.py
# def get_shape_type(input_filename):
# def get_lines(input_filename, shape_type):
# def get_open_polylines(input_filename):
# def get_polygons(input_filename):
# def get_all_fields(input_filename):
# def get_attribute_names(input_filename):
# def get_numeric_attribute_names(input_filename):
# def get_points(input_filename, indices=None, with_z=False):
# def write_shp_points_z(output_filename, z_name, points):
# def write_shp_lines(output_filename, shape_type, lines, attribute_name):
# 
# Path: pyteltools/slf/Serafin.py
# class Serafin:
#     """!
#     @brief A Serafin object corresponds to a single Serafin in file IO stream
# 
#     # Attributes:
#     - language <str>: language for variables ('fr' or 'en')
#     - mode <str>: file open mode
#     - file <_io.BufferedReader>: input Serafin stream
#     - filename <str>: path to file
#     - file_size <int>: size of file
#     """
#     def __init__(self, filename, mode, language):
#         self.language = language
#         self.mode = mode
# 
#         self.file = None  # will be opened when called using `with` statement
#         self.filename = filename
#         self.file_size = None
# 
#     def __enter__(self):
#         self.file = open(self.filename, self.mode)
#         return self
# 
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         self.file.close()
#         return False
# 
# Path: pyteltools/utils/cli_base.py
# LINE_WIDTH = 80
# class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
# class PyTelToolsArgParse(argparse.ArgumentParser):
#     def __init__(self, add_args=[], description=None, *args, **kwargs):
#     def add_known_argument(self, arg_id):
#     def _add_auto_arguments(self):
#     def _title_group(label):
#     def add_argument_group(self, name, *args, **kwargs):
#     def add_group_general(self, add_args=[]):
#     def parse_args(self, *args, **kwargs):


# Path: cli/slf_max_over_files.py
import numpy as np
import sys
from shapefile import ShapefileException
from shapely.geometry import Point
from pyteltools.conf import settings
from pyteltools.geom import Shapefile
from pyteltools.slf import Serafin
from pyteltools.utils.cli_base import logger, PyTelToolsArgParse

                if polygons is not None:
                    mask_nodes = np.zeros(output_header.nb_nodes, dtype=bool)
                    for idx_node, (x, y) in enumerate(zip(output_header.x, output_header.y)):
                        point = Point(x, y)
                        for polygon in polygons:
                            if polygon.contains(point):
                                mask_nodes[idx_node] = True
                                break
                    logger.info('Number of nodes inside polygon(s): %i (over %i)'
                                % (mask_nodes.sum(), output_header.nb_nodes))
                else:
                    mask_nodes = np.ones(output_header.nb_nodes, dtype=bool)
            else:
                if not resin.header.same_2d_mesh(output_header):
                    logger.critical('The mesh of %s is different from the first one' % in_slf)
                    sys.exit(1)

            for time_index, time in enumerate(resin.time):
                for j, var_ID in enumerate(var_IDs):
                    values = resin.read_var_in_frame(time_index, var_ID)
                    if time_index == 0 and i == 0:
                        out_values[j, :] = values
                    else:
                        out_values[j, mask_nodes] = fun(out_values[j, mask_nodes], values[mask_nodes])

    with Serafin.Write(args.out_slf, args.lang, overwrite=args.force) as resout:
        resout.write_header(output_header)
        resout.write_entire_frame(output_header, 0.0, out_values)



parser = PyTelToolsArgParse(description=__doc__)