PROJECT 095 · PYTHON SOURCE
Spatial concentration of recorded area
Study-specific code. Shared modules, dependency versions, and reproduction instructions are included in all project files.
Download Python file ↓from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT))
import numpy as np
import pandas as pd
from scipy.stats import spearmanr
from sklearn.decomposition import PCA
from sklearn.ensemble import IsolationForest
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import confusion_matrix, precision_score, recall_score
from portfolio.data import load
from portfolio.constants import *
from portfolio.methods import result, sql, rates, associations, distribution, regression, classification, cluster
from portfolio.engine import execute
META = {'id': 95, 'dataset': 'fires', 'title': 'Spatial concentration of recorded area', 'question': 'Which source grid cells contain the greatest recorded burned area?', 'method': 'Grid-cell counts, sums and medians without inventing latitude or longitude.', 'action': 'Obtain land-area exposure and event identifiers before using this as a spatial risk map.', 'limitations': 'The sample consists of recorded fire observations, not all places and times at risk. Zero recorded area is not evidence of no ignition. No precise dates or event identifiers are supplied. This is not an emergency forecasting system. '}
def analyze():
df = load('fires').copy()
t=df.groupby(['x','y']).area.agg(records='size',hectares='sum',median_hectares='median').reset_index().sort_values('hectares',ascending=False);t['cell']=t.x.astype(str)+','+t.y.astype(str)
out=result(t,'cell','hectares','Recorded hectares','Coordinates are local source grid indices, not geographic coordinates. Repeated observations may describe related events.')
return out
if __name__ == "__main__":
execute(Path(__file__).parent, META, analyze)