wolfhece.analyze_poly ===================== .. py:module:: wolfhece.analyze_poly Module Contents --------------- .. py:class:: Array_analysis_onepolygon(wa: wolfhece.wolf_array.WolfArray, polygon: wolfhece.PyVertexvectors.vector, buffer_size: float = 0.0) Class for values analysis of an array based on a polygon. This class select values insides a polygon and plot statistics of the values. The class is designed to be used with the WolfArray class and the vector class from the PyVertexvectors module. Plots of the values distribution can be generated using seaborn or plotly. .. py:attribute:: _wa .. py:attribute:: _selected_cells :value: None .. py:attribute:: _values :value: None .. py:property:: centroid :type: shapely.geometry.Point Get the centroid of the polygon as a Point object. :return: Shapely Point object representing the centroid of the polygon .. py:method:: values(which: Literal['Mean', 'Std', 'Median', 'Sum', 'Volume', 'Values', 'Area']) -> pandas.DataFrame | float Get the values as a pandas DataFrame :param which: Mean, Std, Median, Sum, Volume, Values .. py:method:: as_vector(add_values: bool = True) Return a copy of the polygon with the values as attributes. .. py:method:: select_cells(mode: Literal['polygon', 'buffer'] = 'polygon', **kwargs) Select the cells inside the polygon. :param mode: 'polygon' or 'buffer' :param kwargs: 'polygon' for polygon selection or 'buffer' for buffer size For polygon selection, the polygon must be provided in kwargs or use the polygon set during initialization. For buffer selection, the buffer size in meter must be provided in kwargs. .. py:method:: _select_cells_polygon(selection_poly: wolfhece.PyVertexvectors.vector = None) Select the cells inside the polygon .. py:method:: _select_cells_buffer(buffer_size: float = 0.0) Select the cells inside the buffer of the polygon .. py:method:: compute_values() Get the values of the array inside the polygon .. py:method:: _add_area2values() Add the area of the polygon to the values .. py:property:: n_selected_cells :type: int Get the number of selected cells .. py:method:: get_selection() -> numpy.ndarray Get the selected cells as a numpy array of coordinates. :return: numpy array of shape (n, 2) with the coordinates of the selected cells .. py:method:: reset_selection() Reset the selection of cells .. py:method:: plot_values(show: bool = True, bins: int = 100, engine: Literal['seaborn', 'plotly'] = 'seaborn') Plot a histogram of the values .. py:method:: plot_values_seaborn(bins: int = 100, show: bool = True) Plot a histogram of the values .. py:method:: plot_values_plotly(bins: int = 100, show: bool = True) Plot a histogram of the values .. py:property:: has_values :type: bool Check if there useful values .. py:property:: has_strictly_positive_values :type: bool Check if there useful values .. py:method:: distribute_values(bins: list[float]) Distribute the values in bins :param bins: list of bin edges :return: pandas DataFrame with the counts of values in each bin .. py:class:: Array_analysis_polygons(wa: wolfhece.wolf_array.WolfArray, polygons: wolfhece.PyVertexvectors.zone, buffer_size: float = 0.0) Class for values analysis of an array based on a polygon. This class select values insides a polygon and plot statistics of the values. The class is designed to be used with the WolfArray class and the vector class from the PyVertexvectors module. Plots of the values distribution can be generated using seaborn or plotly. .. py:attribute:: _wa .. py:attribute:: _polygons .. py:attribute:: _has_buffer .. py:attribute:: _zone .. py:attribute:: _active_categories .. py:method:: as_zone(add_values: bool = True) -> wolfhece.PyVertexvectors.zone Convert the analysis to a zone of polygons .. py:property:: _areas :type: list[float] Get the areas of the polygons in the zone .. py:property:: all_categories :type: list[str] Get the name of the building categories from the Polygons .. py:property:: active_categories :type: list[str] Get the active categories for the analysis .. py:method:: activate_category(category_name: str) Activate a category for the analysis :param category_name: name of the category to activate .. py:method:: deactivate_category(category_name: str) Deactivate a category for the analysis :param category_name: name of the category to deactivate .. py:method:: _check_names() Check if the names of the polygons are unique .. py:method:: reset_selection() Reset the selection of cells in all polygons .. py:method:: get_values() -> pandas.DataFrame Get the values of all polygons in the zones as a pandas DataFrame. One column per polygon with the values. .. py:method:: get_geometries() -> pandas.DataFrame Get the centroids of all polygons in the zone as a pandas DataFrame. :return: pandas DataFrame with the centroids of the polygons .. py:method:: get_geodataframe_with_values(epsg: int = 31370) -> geopandas.GeoDataFrame Create a GeoDataFrame with the centroids and values of the polygons. Values are added as a column named 'Values' as Numpy array. .. py:property:: polygons :type: wolfhece.PyVertexvectors.zone Get the zone of polygons .. py:property:: keys :type: list[str] Get the names of the polygons in the zone .. py:method:: update_values() Update the polygons values in the zone .. py:method:: plot_values(show: bool = True, bins: int = 100, engine: Literal['seaborn', 'plotly'] = 'seaborn') Plot a histogram of the values .. py:method:: plot_values_seaborn(bins: int = 100, show: bool = True) Plot a histogram of the values .. py:method:: plot_values_plotly(bins: int = 100, show: bool = True) Plot a histogram of the values .. py:method:: count_strictly_positive() -> int Count the number of polygons with values greater than zero .. py:method:: values(which: Literal['Mean', 'Std', 'Median', 'Sum', 'Volume', 'Area']) -> pandas.Series Get the values as a pandas DataFrame :param which: Mean, Std, Median, Sum, Volume :return: pandas DataFrame with the values for each polygon .. py:method:: distribute_polygons(bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area']) -> pandas.DataFrame Distribute the values of each polygon in bins :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area' :return: pandas DataFrame with the counts of values in each bin for each polygon .. py:method:: plot_distributed_values(bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'], show: bool = True, engine: Literal['seaborn', 'plotly'] = 'seaborn') Plot the distribution of values in bins for each polygon :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area' :param show: whether to show the plot :param engine: 'seaborn' or 'plotly' .. py:method:: plot_distribution_seaborn(distribution: pandas.DataFrame, show: bool = True) Plot the distribution of values in bins using seaborn :param distribution: pandas DataFrame with the counts of values in each bin :param show: whether to show the plot .. py:method:: plot_distribution_plotly(distribution: pandas.DataFrame, show: bool = True) Plot the distribution of values in bins using plotly :param distribution: pandas DataFrame with the counts of values in each bin :param show: whether to show the plot .. py:method:: clustering(n_clusters: int = 5, operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'] = 'Mean') Perform clustering on the polygons based on their values. .. py:class:: Array_analysis_zones(wa: wolfhece.wolf_array.WolfArray, zones: wolfhece.PyVertexvectors.Zones, buffer_size: float = 0.0) Class for values analysis of an array based on a Zones instance. This class select values insides a zone of polygons and plot statistics of the values. .. py:attribute:: _wa .. py:attribute:: _zones .. py:attribute:: _polygons .. py:method:: as_zones(add_values: bool = True) -> wolfhece.PyVertexvectors.Zones Convert the analysis to a Zones instance .. py:method:: reset_selection() Reset the selection of cells in all polygons .. py:property:: keys :type: list[str] Get the names of the polygons in the zones .. py:method:: update_values() Update the polygons values in the zones .. py:method:: get_values() -> dict[str, pandas.DataFrame] Get the values of all polygons in the zones as a dictionary of pandas DataFrames .. py:method:: plot_values(show: bool = True, bins: int = 100, engine: Literal['seaborn', 'plotly'] = 'seaborn') Plot a histogram of the values .. py:method:: plot_values_seaborn(bins: int = 100, show: bool = True) Plot a histogram of the values .. py:method:: plot_values_plotly(bins: int = 100, show: bool = True) Plot a histogram of the values .. py:method:: distribute_zones(bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area']) -> dict[str, pandas.DataFrame] Distribute the values of each zone in bins :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area' :return: pandas DataFrame with the counts of values in each bin for each zone .. py:method:: values(which: Literal['Mean', 'Std', 'Median', 'Sum', 'Volume', 'Area']) -> dict[str, pandas.Series] Get the values as a dictionnary of pandas Series :param which: Mean, Std, Median, Sum, Volume :return: pandas DataFrame with the values for each polygon .. py:class:: Arrays_analysis_zones(arrays: dict[str, wolfhece.wolf_array.WolfArray], zones: wolfhece.PyVertexvectors.Zones, buffer_size: float = 0.0) Class for analysis multiples arrays based on a Zones instance. Each array must have the same shape. .. py:attribute:: _arrays .. py:attribute:: _zones .. py:attribute:: _xlabel :value: 'Value' .. py:attribute:: _polygons .. py:attribute:: _active_categories .. py:attribute:: _active_arrays .. py:method:: as_zones(add_values: bool = True) -> wolfhece.PyVertexvectors.Zones Convert the analysis to a Zones instance .. py:property:: _areas :type: dict[str, list[float]] Get the areas of the polygons in the zones .. py:property:: all_categories :type: list[str] Get the name of the building categories from the Zones .. py:property:: all_arrays :type: list[str] Get the names of all arrays .. py:method:: activate_array(array_name: str) Activate an array for the analysis :param array_name: name of the array to activate .. py:method:: deactivate_array(array_name: str) Deactivate an array for the analysis :param array_name: name of the array to deactivate .. py:method:: activate_category(category_name: str) Activate a category for the analysis :param category_name: name of the category to activate .. py:method:: deactivate_category(category_name: str) Deactivate a category for the analysis :param category_name: name of the category to deactivate .. py:property:: active_arrays :type: list[str] Get the active arrays for the analysis .. py:property:: active_categories :type: list[str] Get the active categories for the analysis .. py:method:: get_values() -> dict[str, dict[str, pandas.DataFrame]] Get the values of all polygons in the zones as a dictionary of pandas DataFrames .. py:method:: values(which: Literal['Mean', 'Std', 'Median', 'Sum', 'Volume', 'Area']) -> dict[str, dict[str, pandas.Series]] Get the values of all polygons in the zones as a dictionary of pandas Series :param which: Mean, Std, Median, Sum, Volume, Area :return: dictionary with zone names as keys and dictionaries of array names and their values as values .. py:method:: update_values() Update the polygons values in the zones for all arrays .. py:method:: count_strictly_positive() -> dict[str, int] Count the number of polygons with values greater than zero for each array .. py:method:: count_strictly_positive_as_df(merge_zones: bool = False) -> pandas.DataFrame Count the number of polygons with strictly positive values for each array as a pandas DataFrame :return: pandas DataFrame with the counts of strictly positive values for each array in each zone .. py:method:: distribute_zones(bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area']) -> dict[str, dict[str, pandas.DataFrame]] Distribute the values of each zone in bins for each array :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area' :return: dictionary with zone names as keys and dictionaries of array names and their distributions as values .. py:method:: distribute_zones_as_df(bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'], merge_zones: bool = False) -> pandas.DataFrame Distribute the values of each zone in bins for each array as a pandas DataFrame. Date are tabulated in a DataFrame with columns 'Zone', 'Array', 'Bin Edges', 'Count'. It is more convenient for plotting and analysis. :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area' :return: pandas DataFrame with the counts of values in each bin for each array in each zone .. py:method:: _values_as_df(which: Literal['Mean', 'Std', 'Median', 'Sum', 'Volume', 'Area'], merge_zones: bool = False) -> pandas.DataFrame Get a full DataFrame with all arrays, zones and values for each polygon. :param merge_zones: whether to merge the zones in the DataFrame :return: pandas DataFrame with the counts of strictly positive values for each array in each zone .. py:method:: plot_count_strictly_positive(show: bool = True, engine: Literal['seaborn', 'plotly'] = 'seaborn', merge_zones: bool = False) Plot the count of strictly positive values for each array in each zone :param show: whether to show the plot :param engine: 'seaborn' or 'plotly' .. py:method:: save_plot_count_strictly_positive(filepath: pathlib.Path | str, merge_zones: bool = False, dpi: int = 300) Save the plot of the count of strictly positive values for each array in each zone. :param filepath: path to the image file (png) :param merge_zones: whether to merge the zones in the plot :param dpi: resolution of the saved plot :return: None .. py:method:: _plot_count_strictly_positive_seaborn(show: bool = True, merge_zones: bool = False) Plot the count of strictly positive values for each array in each zone using seaborn :param counts: dictionary with zone names as keys, and dictionaries of array names and their counts as values :param show: whether to show the plot .. py:method:: _plot_count_strictly_positive_plotly(show: bool = True, merge_zones: bool = False) Plot the count of strictly positive values for each array in each zone using plotly :param counts: dictionary with zone names as keys, and dictionaries of array names and their counts as values :param show: whether to show the plot .. py:method:: plot_distributed_values(bins: list[float] = [0.0, 0.3, 1.3, -1.0], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'] = 'Median', show: bool = True, engine: Literal['seaborn', 'plotly'] = 'seaborn', merge_zones: bool = False) Plot the distribution of values in bins for each array in each zone or merged zones. :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area' :param show: whether to show the plot :param engine: 'seaborn' or 'plotly' :param merge_zones: whether to merge the zones in the plot .. py:method:: save_plot_distributed_values(filepath: pathlib.Path | str, bins: list[float] = [0.0, 0.3, 1.3, -1], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'] = 'Median', merge_zones: bool = False, dpi: int = 300) Save the plot of the distribution of values in bins for each array in each zone or merged zones. :param filepath: path to the image file (png) :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area :param merge_zones: whether to merge the zones in the plot :return: None .. py:method:: _plot_distributed_values_seaborn(bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'], show: bool = True, merge_zones: bool = False) Plot the distribution of values in bins for each array in each zone using seaborn :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area' :param show: whether to show the plot :param merge_zones: whether to merge the zones in the plot .. py:method:: _get_distributed_values(bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'], merge_zones: bool = False) Save the distribution of values in bins for each array in each zone as a CSV file. :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area :param merge_zones: whether to merge the zones in the plot .. py:method:: save_distributed_values(filepath: pathlib.Path | str, bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'], merge_zones: bool = False) Save the distribution of values in bins for each array in each zone as a CSV file. :param filepath: path to the CSV file :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area :param merge_zones: whether to merge the zones in the plot .. py:method:: save_distributed_values_table(filepath: pathlib.Path | str, bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'], merge_zones: bool = False) Create a table of the distribution of values in bins for each array in each zone. :param filepath: path to the image file (png) :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area :param merge_zones: whether to merge the zones in the plot :return: pandas DataFrame with the counts of values in each bin for each array in each zone .. py:method:: _plot_distributed_values_plotly(bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'], show: bool = True, merge_zones: bool = False) Plot the distribution of values in bins for each array in each zone using plotly :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area' :param show: whether to show the plot :param merge_zones: whether to merge the zones in the plot .. py:method:: _plot_distributed_areas_seaborn(bins: list[float], operator: Literal['Mean', 'Median', 'Sum', 'Volume', 'Area'], show: bool = True, merge_zones: bool = False) Plot the distribution of values in bins for each array in each zone using seaborn :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area' :param show: whether to show the plot :param merge_zones: whether to merge the zones in the plot .. py:class:: Building_Waterdepth_analysis(arrays: dict[str, wolfhece.wolf_array.WolfArray], zones: wolfhece.PyVertexvectors.Zones | pathlib.Path | str, buffer_size: float = 0.0, merge_zones: bool = False, thershold_area: float = 0.0) Bases: :py:obj:`Arrays_analysis_zones` .. autoapi-inheritance-diagram:: wolfhece.analyze_poly.Building_Waterdepth_analysis :parts: 1 :private-bases: Class for water depth analysis of multiple arrays based on a Zones instance. This class is designed to analyze water depth data from multiple arrays and zones. It inherits from Arrays_analysis_zones and provides additional methods specific to water depth analysis. .. py:attribute:: _xlabel .. py:method:: plot_distributed_areas(bins=[0, 0.3, 1.3, -1], operator='Median', show=True, engine='seaborn', merge_zones=False) .. py:method:: save_plot_distributed_areas(filepath, bins=[0, 0.3, 1.3, -1], operator='Median', merge_zones=False, dpi=300) Save the plot of the distribution of areas in bins for each array in each zone or merged zones. :param filepath: path to the image file (png) :param bins: list of bin edges :param operator: 'Mean', 'Median', 'Sum', 'Volume', 'Area :param merge_zones: whether to merge the zones in the plot :param dpi: resolution of the saved plot :return: None .. py:class:: Slope_analysis(wa: wolfhece.wolf_array.WolfArray, trace: wolfhece.PyVertexvectors.vector) Class for slope analysis of in an array based on a trace vector. This class allows to select cells inside a polygon or a buffer around a trace vector and compute the slope of the dike. The slope is computed as the difference in elevation between the trace and the cell divided by the distance to the trace. The slope is computed for each cell inside the polygon or buffer and accessed in a Pandas Dataframe. Plots of the slope distribution can be generated using seaborn or plotly. The class is designed to be used with the WolfArray class and the vector class from the PyVertexvectors module. .. py:attribute:: _wa .. py:attribute:: _trace .. py:attribute:: _selection_poly :value: None .. py:attribute:: _buffer_size :value: 0.0 .. py:attribute:: _selected_cells :value: None .. py:attribute:: _slopes :value: None .. py:property:: slopes :type: pandas.DataFrame Get the slopes as a pandas DataFrame .. py:method:: select_cells(mode: Literal['polygon', 'buffer'] = 'polygon', **kwargs) Select the cells inside the trace .. py:method:: _select_cells_buffer(buffer_size: float = 0.0) Select the cells inside the buffer of the trace .. py:method:: _select_cells_polygon(selection_poly: wolfhece.PyVertexvectors.vector) Select the cells inside the polygon .. py:method:: compute_slopes() Get the slope of the dike .. py:method:: plot_slopes(show: bool = True, bins: int = 100, engine: Literal['seaborn', 'plotly'] = 'seaborn') Plot a histogram of the slopes .. py:method:: plot_slopes_seaborn(bins: int = 100, show: bool = True) Plot a histogram of the slopes .. py:method:: plot_slopes_plotly(bins: int = 100, show: bool = True) Plot a histogram of the slopes