<jupyter_start><jupyter_text>Read  CHILE GEM SARA Model (csv format)<jupyter_code>path = '/Users/pittore/Documents/PROJECTS/BMBF/RIESGOS/data/GEM_sara_chile/chl-l3-exposure'
infile = 'chl-l3-exposure_total.csv'
sara_data = pd.read_csv(os.path.join(path,infile))

#clean 'name' and use it as ID
sara_data['name'] = sara_data.Region.str.normalize('NFKD').str.encode('ascii', errors='ignore').str.decode('utf-8')
#save all names in an array
sara_names = sara_data['name'].unique()

#group data based on 'name'
datagrp = sara_data.groupby('name')<jupyter_output><empty_output><jupyter_text>Read Chile admin_3 areas from GADM<jupyter_code>chile_map = '/Users/pittore/Documents/PROJECTS/BMBF/RIESGOS/data/GADM_chile/gadm36_CHL_3.json'
chile_map_gpd = gpd.read_file(chile_map)
chile_map_gpd['name'] = chile_map_gpd.NAME_3.str.normalize('NFKD').str.encode('ascii', errors='ignore').str.decode('utf-8')
len(chile_map_gpd)<jupyter_output><empty_output><jupyter_text>Associate exposure model for each admin area and change geometry type to MultiPolygon<jupyter_code>from shapely.geometry import MultiPolygon

outmodel = chile_map_gpd[['name','GID_3','geometry']]
outmodel['expo'] = ""
#outmodel.head()
outmodel = outmodel.set_index('name')

for gcname,gc in outmodel.iterrows():
    if (gcname in sara_names):
            testgrp = datagrp.get_group(gcname)
            #add initial damage state - by default Null Damage (D0)
            testgrp['Damage'] = 'D0'
            outmodel.at[gcname,'expo'] = testgrp.to_json()
    #convert polygons into multipolygons to avoid errors in file output
    if (gc.geometry.geom_type == 'Polygon'):
        outmodel.at[gcname,'geometry'] = MultiPolygon([gc.geometry])

outmodel.columns = ['gid', 'geometry', 'expo']
outmodel = outmodel.reset_index()
outmodel.head()<jupyter_output><empty_output><jupyter_text>Drop geocells with empty exposure<jupyter_code>blacklist  = outmodel[outmodel.expo ==''].index
outmodel1 = outmodel.drop(blacklist)<jupyter_output><empty_output><jupyter_text>Save to GEOPACKAGE<jupyter_code>#ioschema = gpd.io.file.infer_schema(outmodel)
#ioschema['geometry']='MultiPolygon'
#ioschema
outmodel1.to_file("output.gpkg", driver="GPKG")#,schema = ioschema)<jupyter_output><empty_output><jupyter_text>Display the boundary of the model<jupyter_code>map_osa = folium.Map(location=[-32,-71],tiles='Stamen Terrain',zoom_start=10)
map_osa.choropleth(geo_data=outmodel1,fill_opacity=0.3)
#map_osa.choropleth(geo_data=chile_map,fill_opacity=0.3)
#folium.Marker([-32, -71], popup='test').add_to(map_osa)
map_osa
#map_osa = folium.Map(location=[df.iloc[event_index].latitude,df.iloc[event_index].longitude])
#map_osm.create_map(path='osm.html')
#map_osa.save('testfolium.html')
#map_osa<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.147677793904209, 'fraction_numerical': 0.010522496371552975, 'mean_word_length': 7.108823529411764, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '84288', 'license': 'Apache-2.0', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1062, 'n_words': 149, 'path': 'assetmaster_modelcreator.ipynb', 'repo_name': 'GFZ-Centre-for-Early-Warning/assetmaster', 'size': '2756'}