Skip to content
AAVADIPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ENA 2023 Project (ESPAC-style)

This project turns the original ENA_2023.zip delivery into a reproducible local data workspace:

  • inputs/: immutable original files, ZIP contents, and extracted module folders
  • scripts/: Python pipeline scripts
  • outputs/: SQLite database plus derived CSV outputs
  • reports/: inventories and profiling reports
  • notebooks/: exploratory and derivation notebooks built on top of the SQLite database

Required local source files

The raw source files must exist in the project root:

  • ENA_2023.zip
  • DICCIONARIO DE DATOS ENA_2023.pdf

Script 01_extract_ena_2023.py also copies both files into inputs/original/ so the project keeps an internal record of the raw inputs used.

Clone and reproduce locally

Clone the public repository:

git clone https://github.com/AAVADI/ENA2023.git
cd ENA2023

Then place the raw source files in the project root:

  • ENA_2023.zip
  • DICCIONARIO DE DATOS ENA_2023.pdf

Run the full scripted pipeline:

powershell -ExecutionPolicy Bypass -File scripts/run_pipeline.ps1

Or run the steps manually:

python scripts/01_extract_ena_2023.py
python scripts/02_load_csvs_to_sqlite.py
python scripts/03_build_summaries.py

Finally, open and run notebooks/2_ena_2023_sqlite_explorer.ipynb if you also want the crop-only LCI outputs in outputs/.

Execution sequence from ENA_2023.zip

The extraction and processing flow is:

  1. scripts/01_extract_ena_2023.py
  2. scripts/02_load_csvs_to_sqlite.py
  3. scripts/03_build_summaries.py
  4. notebooks/2_ena_2023_sqlite_explorer.ipynb for crop-only LCI derivations

Step 1. Extract the original ZIP and nested module RAR files

python scripts/01_extract_ena_2023.py

What it does:

  • reads ENA_2023.zip from the project root
  • extracts the ZIP into inputs/zip_contents/ENA_2023/
  • finds every nested *.rar module inside that extracted ZIP
  • extracts each module into inputs/extracted_modules/<module_name>/
  • copies the raw ZIP and dictionary PDF into inputs/original/
  • writes an inventory to reports/01_file_inventory.csv

Important note:

  • this step requires bsdtar to be available either on PATH or in one of the locations checked by the script

Step 2. Load all extracted CSV files into SQLite

python scripts/02_load_csvs_to_sqlite.py

What it does:

  • scans inputs/extracted_modules/ recursively for all CSV files produced by step 1
  • loads each CSV into outputs/01_ena_2023.sqlite
  • creates one SQLite table per CSV, using sanitized names of the form <module>__<csv_name>
  • writes structural metadata to outputs/02_table_row_counts.csv, outputs/02_table_columns.csv, reports/02_table_catalog.csv, and reports/02_sqlite_overview.json

Step 3. Build general summary outputs from SQLite

python scripts/03_build_summaries.py

What it does:

  • opens outputs/01_ena_2023.sqlite
  • inspects all tables
  • builds region-level summaries for any table containing a REGION column
  • exports outputs/03_summary_by_region.csv, outputs/03_region_totals.csv, and outputs/03_data_overview.json

One-command pipeline run

The same three steps can be run with:

powershell -ExecutionPolicy Bypass -File scripts/run_pipeline.ps1

Main outputs after scripts 01-03

  • outputs/01_ena_2023.sqlite: consolidated database of all extracted ENA CSV tables
  • outputs/02_table_row_counts.csv: row counts and source CSV paths per table
  • outputs/02_table_columns.csv: column inventory and sample values per table
  • outputs/03_summary_by_region.csv: per-table grouped summaries by REGION
  • outputs/03_region_totals.csv: total rows by region across all summarized tables
  • outputs/03_data_overview.json: high-level overview of the SQLite contents

Notebook 2_ena_2023_sqlite_explorer.ipynb

This notebook is not part of the raw extraction/loading pipeline. It is a downstream analysis notebook that starts from outputs/01_ena_2023.sqlite and produces crop-only LCI-style outputs.

What the notebook does

It:

  • reads the SQLite database created by script 02_load_csvs_to_sqlite.py
  • builds a crop-only name list from crop-related ENA modules
  • creates a core crop-geography-area-yield table
  • normalizes production inputs into a long LCI-style input table
  • merges crop and input data into a final crop-only LCI table
  • derives wide crop-by-region files and per-hectare monetary indicators
  • estimates some 2023 representative prices and converts selected inputs into kg/ha, m3/ha, or fuel L/ha

How to use the notebook

Run scripts 01, 02, and 03 first so outputs/01_ena_2023.sqlite already exists.

Then open and run:

  • notebooks/2_ena_2023_sqlite_explorer.ipynb

Important note:

  • the notebook sets PROJECT_ROOT = Path.cwd().resolve().parent, so it expects to be launched with the working directory inside notebooks/

Main outputs created by the notebook

The notebook writes these derived files to outputs/:

  • 04_crop_names_only.csv
  • 04_lci_core_crop_geo_yield_area.csv
  • 04_lci_inputs_normalized.csv
  • 04_lci_table_crop_only.csv
  • 04_lci_table_crop_only_part01.csv and following chunk files as needed
  • 04_lci_summary_crop_region.csv
  • 05_lci_crop_region_inputs_wide.csv
  • 05_lci_crop_region_inputs_wide_per_ha.csv
  • 05_input_prices_pen_per_kg_2023.csv
  • 05_input_prices_assumed_2023_other_units.csv
  • 06_lci_crop_region_inputs_kg_ha.csv

Data provenance

  • Raw source ZIP: ENA_2023.zip
  • Raw source dictionary: DICCIONARIO DE DATOS ENA_2023.pdf
  • Source record: reports/00_sources.md

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages