Skip to content

Instantly share code, notes, and snippets.

View grujdin's full-sized avatar

Ion Grujdin grujdin

  • CEOSpaceTech, University Politehnica of Bucharest, Romania
View GitHub Profile
@grujdin
grujdin / CompositeImages_ADM2.py
Last active May 5, 2025 21:21
Display geometry of each ADM2 Unit.
import os
import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
import geopandas as gpd
from shapely.geometry import Polygon
from shapely.ops import unary_union
def poslist_to_polygon(poslist_str):
"""
@grujdin
grujdin / CompositeImages_ADM1.py
Last active May 5, 2025 21:22
Retrieve geometries of the ADM2 Units belonging to each ADM1 Unit from GAUL/g2015_2014_2.xml file and join them in a single image for each ADM1 Unit.
import os
import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
import geopandas as gpd
from shapely.geometry import Polygon
from shapely.ops import unary_union
import matplotlib.patches as mpatches
def poslist_to_polygon(poslist_str):
"""
@grujdin
grujdin / CompositeImages_ADM0.py
Last active May 5, 2025 21:22
Retrieve the geometries of ADM1 Units belonging to each ADM0 Unit and join them in a single image for each ADM0 Unit.
import os
import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
import geopandas as gpd
from shapely.geometry import Polygon
from shapely.ops import unary_union
import matplotlib.patches as mpatches
import time
def poslist_to_polygon(poslist_str):
# Import necessary libraries
import pandas as pd
from calendar import monthrange
# Load the Excel file containing disaster data into a pandas DataFrame
df = pd.read_excel('D:/ProjDB/GAUL/public_emdat_GDIS_GAUL_FIDs.xlsx')
# Define a function to format the start and end dates into ISO 8601 format
def format_dates(row):
"""
import pandas as pd
import xml.etree.ElementTree as ET
###############################################################################
# 1) Define file paths
###############################################################################
excel_file_path = 'D:/ProjDB/GAUL/public_emdat_GDIS_GAUL_aligned.xlsx'
# GAUL Level-2 XML (for FID_2)
xml_file_path_2 = 'D:/ProjDB/GAUL/g2015_2014_2_GeomExtract.xml'
import pandas as pd
import json
import xml.etree.ElementTree as ET
from xml.dom import minidom
###############################################################################
# 1) Define File Paths
###############################################################################
file_path = 'D:/ProjDB/EMDAT/public_emdat_GDIS_aligned.xlsx'
#--------------------- Align EM-DAT database format to GDIS database ----------------------
#
# This script processes EM-DAT disaster event data to align its format with the GDIS database.
# Key tasks include:
# - Splitting multi-location events into separate observations for each named location.
# - Normalizing and cleaning location names for consistency.
# - Expanding province-prefecture mappings when applicable.
# - Matching locations to administrative units using fuzzy matching.
# - Assigning unique serial codes to processed events.
# - Saving the cleaned and structured data into a new Excel file.