# victoriano/social-sciences-microdata architecture

> Architecture diagram of the GitHub repository victoriano/social-sciences-microdata, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/victoriano/social-sciences-microdata
- Repository: https://github.com/victoriano/social-sciences-microdata

## Overview

The project is a collection of Python scripts designed to automate the retrieval and processing of public microdata – focusing on social science datasets from Spain. The project’s purpose, as outlined in the README, is to download, convert, merge, and enrich data (often in difficult formats such as fixed-width TXT, SPSS, or proprietary files) to prepare it for analysis. This makes it ideal for exploratory data analysis and research into societal trends, demographics, and political or economic behaviors.

##### Main Components
- Data Acquisition Modules:
- For the Barometro_CIS dataset: Look at the scripts under Spain/Barometro_CIS. Identify “download_barometros” directory (scripts like download_barometros.py and get_barometros_index.py) which are responsible for automatically fetching the raw survey data.
- For the Encuesta_de_Presupuestos_Familiares_INE dataset: Identify the download scripts within Spain/Encuesta_de_Presupuestos_Familiares_INE (e.g., download_unzip_epfs_since_2016.py) and note the structured subdirectories for each year’s raw Parquet files.
- Data Processing and Merging Modules:
- For Barometro_CIS: Scripts such as merge_barometros.py and process_barometro_merged.py are used to merge, clean, and convert the survey data into more analysis-friendly formats (CSV or Parquet).
- For Encuesta_de_Presupuestos_Familiares_INE: Scripts in directories like “datamarts” (e.g., create_gastos_master.py) and other processing scripts (spss_to_csv_or_parquet.py, convert_epf_to_csv.py in the txt_to_csv_processing_2023 folder) handle format conversions, enrichment, and consolidation of datasets.
- Data Storage Formats:
- The output of the processing pipelines is stored in CSV and Parquet files, as evidenced by files such as processed_barometros.parquet and various year-tagged Parquet files under the corresponding directories.
- Potential Integration and Extensibility Points:
- Although not explicitly shown in the code, the design implies an extensible architecture that allows new data sources (e.g., the pending “Microdatos Elecciones Generales al Parlamento” dataset) to be added and processed similarly.

##### Relationships and Interactions
- Data Flow:
- Raw Data (downloaded via individual download modules) → Data Cleaning & Merging (processing and merging scripts) → Enriched Data Storage (output files in CSV/Parquet).
- Dependencies:
- Each dataset’s processing module depends on the raw data obtained by its respective download scripts.
- There is a sequential dependency where ingestion feeds directly into transformation/merging and ultimately into a final datastore.
- Potential Scheduling/Automation:
- While not depicted in the file tree, these scripts are likely called on a schedule (via cron jobs or an orchestrator) to ensure data is kept up to date.

##### Architectural Patterns and Technologies
- Architectural Pattern:
- The project follows a pipeline (or ETL) design, with clear stages of extraction (download scripts), transformation (cleaning, merging, processing scripts), and loading (writing CSV/Parquet files).
- Technologies and Frameworks:
- Python is the primary language.
- Data storage formats include CSV and Parquet.
- The use of scripts that translate SPSS or fixed-width TXT into more efficient and queryable Parquet files indicates a focus on data efficiency for large, disaggregated microdata.

## Diagram (Mermaid)

```mermaid
graph TD
    EX["Public Microdata Sources"]:::external

    subgraph "Barometro_CIS Pipeline"
        B_Download1["download_barometros.py"]:::download
        B_Download2["get_barometros_index.py"]:::download
        B_Process1["merge_barometros.py"]:::processing
        B_Process2["process_barometro_merged.py"]:::processing
        B_Storage(("processed_barometros.parquet")):::storage
        B_Download1 --> B_Process1
        B_Download2 --> B_Process1
        B_Process1 --> B_Process2
        B_Process2 --> B_Storage
    end

    subgraph "INE Pipeline"
        INE_Download["download_unzip_epfs_since_2016.py"]:::download
        INE_Raw(("Raw Parquet Files")):::storage
        INE_Conv1["spss_to_csv_or_parquet.py"]:::processing
        INE_Conv2["convert_epf_to_csv.py"]:::processing
        INE_Conv3["enrich_csv.py"]:::processing
        INE_Datamarts["create_gastos_master.py"]:::processing
        INE_Download --> INE_Raw
        INE_Raw --> INE_Conv1
        INE_Conv1 --> INE_Conv2
        INE_Conv2 --> INE_Conv3
        INE_Conv3 --> INE_Datamarts
    end

    EX -->|"ingests data"| B_Download1
    EX -->|"ingests data"| INE_Download

    click B_Download1 "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Barometro_CIS/download_barometros/download_barometros.py"
    click B_Download2 "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Barometro_CIS/download_barometros/get_barometros_index.py"
    click B_Process1 "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Barometro_CIS/merge_barometros.py"
    click B_Process2 "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Barometro_CIS/process_barometro_merged.py"
    click B_Storage "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Barometro_CIS/processed_barometros.parquet"
    click INE_Download "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Encuesta_de_Presupuestos_Familiares_INE/download_epfs_since2016/download_unzip_epfs_since_2016.py"
    click INE_Raw "https://github.com/victoriano/social-sciences-microdata/tree/main/Spain/Encuesta_de_Presupuestos_Familiares_INE/download_epfs_since2016/parquet_raw_files"
    click INE_Conv1 "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Encuesta_de_Presupuestos_Familiares_INE/download_epfs_since2016/spss_to_csv_or_parquet.py"
    click INE_Conv2 "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Encuesta_de_Presupuestos_Familiares_INE/download_epfs_since2016/txt_to_csv_processing_2023/convert_epf_to_csv.py"
    click INE_Conv3 "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Encuesta_de_Presupuestos_Familiares_INE/download_epfs_since2016/txt_to_csv_processing_2023/enrich_csv.py"
    click INE_Datamarts "https://github.com/victoriano/social-sciences-microdata/blob/main/Spain/Encuesta_de_Presupuestos_Familiares_INE/datamarts/create_gastos_master.py"

    classDef download fill:#ffadad,stroke:#000,stroke-width:2px;
    classDef processing fill:#ffd6a5,stroke:#000,stroke-width:2px;
    classDef storage fill:#caffbf,stroke:#000,stroke-width:2px;
    classDef external fill:#a0c4ff,stroke:#000,stroke-width:2px;
```
