GHCND Big Data API Server

Setup and Environment

This document describes how to prepare the environment, ingest the NOAA GHCND dataset, and build the aggregated tables used by the API.

Dataset

The backend is built on top of the NOAA Global Historical Climatology Network – Daily (GHCND) dataset:

Download the dataset from Kaggle and unzip all files locally. You will need:

HDFS Layout

Upload the data into HDFS with at least the following layout:

Example commands (adapt paths as needed):

hdfs dfs -mkdir -p /ghcnd
hdfs dfs -mkdir -p /ghcnd/stations

hdfs dfs -put /data/ghcnd/daily/*.csv /ghcnd/
hdfs dfs -put /data/ghcnd/ghcnd-stations.csv /ghcnd/stations/

Prerequisites

<!-- core-site.xml -->
<configuration>
  <property>
    <name>fs.defaultFS</name>
    <value>hdfs://localhost:9000</value>
  </property>
</configuration>

Python Environment

Using pyenv as an example:

cd /root/UNI-BIG-DATA-COURSE-PROJECT-SERVER

pyenv install 3.13.0
pyenv virtualenv 3.13.0 ghcnd-api
pyenv local ghcnd-api

pip install fastapi uvicorn pyspark pandas

Adjust versions and package list as required.

Building Aggregated Tables

From the project root:

cd /root/UNI-BIG-DATA-COURSE-PROJECT-SERVER

# Preferred: use the helper script to run Spark jobs with consistent settings
scripts/run_spark.sh scripts/agg_tables/agg_table_monthly_aggregates.py
scripts/run_spark.sh scripts/agg_tables/agg_table_yearly_aggregates.py
scripts/run_spark.sh scripts/agg_tables/agg_table_coverage.py
scripts/run_spark.sh scripts/agg_tables/agg_table_distribution.py
scripts/run_spark.sh scripts/agg_tables/agg_table_extreme_events.py
scripts/run_spark.sh scripts/agg_tables/agg_table_yearly_extreme_events.py
scripts/run_spark.sh scripts/agg_tables/agg_table_extreme_events_yearly_summary.py
scripts/run_spark.sh scripts/agg_tables/agg_table_recent_extreme_events.py

The scripts/run_spark.sh wrapper configures Spark with appropriate memory limits, temporary directories, and Hadoop configuration, and writes a log file for each job (for example agg_table_yearly_aggregates_report.txt).

Verify the resulting tables:

hdfs dfs -ls /ghcnd/agg_tables/

You should see all expected tables under /ghcnd/agg_tables/.

Spark Session Configuration

The shared SparkSession is configured in app/spark.py:

from pyspark.sql import SparkSession

HDFS_NAMENODE = "hdfs://localhost:9000"

spark = (
    SparkSession.builder
    .appName("GHCND_API")
    .config("spark.hadoop.fs.defaultFS", HDFS_NAMENODE)
    .getOrCreate()
)

If your HDFS namenode is different, update HDFS_NAMENODE accordingly.