leiap.report

This file contains functions related to the annual report

Functions

fields_summary_table(points, artifacts[, …]) Create table (in Spanish) with basic stats by field
points_per_group(points, grouper_col[, ct_col]) Count the points in the given group
artifacts_per_group(artifacts, grouper_col) Count the artifacts in the given group
pos_points_per_group(artifacts, grouper_col) Count the number of points with artifacts in the given group
time_span_chart(data) Create a chart showing all productions, their counts, their percentages, and their time spans
write_excel_table(unit, data, writer) Format data and add as worksheet to Excel output
make_report_tables(artifacts, group_col, …) Create and save Excel file with a Sheet for each group in groups
make_report_span_charts(artifacts, …[, …]) Create and save production span charts
leiap.report.fields_summary_table(points, artifacts, fid_col='geo_field', save_excel=False, excel_file='field_counts.xlsx', excel_sheet='field_data')[source]

Create table (in Spanish) with basic stats by field

Parameters:
  • points (DataFrame) – pandas DataFrame of survey points
  • artifacts (DataFrame) – pandas DataFrame of artifacts
  • fid_col (str, optional) – Column containing the field identifier to use for grouping
  • save_excel (bool, optional) – Specify whether to write DataFrame to an Excel sheet
  • excel_file (str, optional) – Filename for Excel
  • excel_sheet (str, optional) – Sheet name for Excel
Returns:

fields_data – DataFrame version of the created table

Return type:

DataFrame

Notes

The table is in the form:

Polígono | Parcela | Subparcela | Id | Núm. Pts. | Núm. Frags. | Pos. Pts. |
——– | ——- | ———- | —— | ——— | ———– | ——— |
03 | 027 | 0 | 030270 | 351 | 39 | 26 |
16 | 092 | a | 16092a | 105 | 58 | 51 |
leiap.report.points_per_group(points, grouper_col, ct_col='Núm. Pts.')[source]

Count the points in the given group

Parameters:
  • points (pandas DataFrame) – Point observations
  • grouper_col (str) – Column in points that you want to use to group, usually ‘geo_field’ or similar
  • ct_col (str, optional) – Name to give the new column
Returns:

df – Points grouped and counted according to the grouper_col

Return type:

pandas DataFrame

leiap.report.artifacts_per_group(artifacts, grouper_col, ct_col='Núm. Frags.')[source]

Count the artifacts in the given group

Parameters:
  • artifacts (pandas DataFrame) – Artifact observations
  • grouper_col (str) – Column in artifacts that you want to use to group, usually ‘geo_field’ or similar
  • ct_col (str, optional) – Name to give the new column
Returns:

df – Artifacts grouped and counted according to the grouper_col

Return type:

pandas DataFrame

leiap.report.pos_points_per_group(artifacts, grouper_col, pt_id_col='SurveyPointId', ct_col='Pos. Pts.')[source]

Count the number of points with artifacts in the given group

Parameters:
  • artifacts (pandas DataFrame) – Artifact observations
  • grouper_col (str) – Column in artifacts that you want to use to group, usually ‘geo_field’ or similar
  • pt_id_col (str, optional) – Column that contains unique point identifier, usually ‘SurveyPointId’
  • ct_col (str, optional) – Name to give the new column
Returns:

df – Number of points with artifacts grouped and counted according to the grouper_col

Return type:

pandas DataFrame

leiap.report.time_span_chart(data)[source]

Create a chart showing all productions, their counts, their percentages, and their time spans

Parameters:data (pandas DataFrame) – Data containing columns [‘Catalan’, ‘EarlyChrono’, ‘LateChrono’, ‘count’, ‘pct’]
Returns:fig
Return type:matplotlib Figure
leiap.report.write_excel_table(unit, data, writer)[source]

Format data and add as worksheet to Excel output

Parameters:
  • unit (str) – Name of field or other data group; will be used as Sheet name in Excel
  • data (pandas DataFrame) – Data to write to the file
  • writer (ExcelWriter) – Excel file
Returns:

Return type:

None

leiap.report.make_report_tables(artifacts, group_col, output_folder, fname='field_tables.xlsx')[source]

Create and save Excel file with a Sheet for each group in groups

Parameters:
  • artifacts (pandas DataFrame) –
  • group_col (str) – Name of column that contains group info
  • output_folder (str) – Folder to save the final Excel
  • fname (str, optional) – Name of the Excel file (the default is ‘field_tables.xlsx’)
Returns:

Return type:

None

leiap.report.make_report_span_charts(artifacts, group_col, output_folder, file_prefix='')[source]

Create and save production span charts

Parameters:
  • artifacts (pandas DataFrame) –
  • group_col (str) – Name of column that contains group info
  • output_folder (str) – Folder to save the final image
  • file_prefix (str, optional) – Extra text to add to the beginning of the file name (the default is an empty string ‘’, which adds no text). All file names will end with the unit from groups (e.g., the field number)
Returns:

Return type:

None