Analysis of iceberg distribution in a Greenland fjord

Icebergs represent nearly half of the mass loss from the Greenland Ice Sheet and provide a distributed source of freshwater along fjords which can alter fjord circulation, nutrient levels, and ultimately the Meridional Overturning Circulation. Here I present analysis of iceberg percentage coverage in 2km x 2km grid cells, thereby displaying the density of icebergs in Sermilik Fjord, SE Greenland.

Libraries

import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpd
import geoplot as gplt
import matplotlib as mpl
import mpld3

import warnings
warnings.filterwarnings('ignore')

%matplotlib inline
plt.rcParams['figure.figsize'] = (12, 9)
import contextily as ctx

%load_ext sql
%sql postgresql://
%config SqlMagic.autopandas=True

import ipypostgis
%load_ext ipypostgis
import pandas as pd
import rpy2
%matplotlib inline
%reload_ext rpy2.ipython
# make PostGIS commands available to this notebook.
path = %env PATH
pg_path = '/usr/lib/postgresql/11/bin/:/usr/lib/postgresql/12/bin/'
if pg_path not in path: path = f'{path}:{pg_path}'
%env PATH=$path
env: PATH=/opt/tljh/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/lib/postgresql/11/bin/:/usr/lib/postgresql/12/bin/

Objective

The goal of this project is to analyze iceberg distribution in Sermilik Fjord, South East Greenland. Through this project I want to understand, how the calving processes are impacting Sermilik Fjord (one of the fastest moving glaciers in Greenland) using iceberg distribution.

In order to improve the understanding, I will need to perform the following tasks:

  1. Visualize iceberg distribution.
  2. Determine the frequency size distribution of icebergs in Sermilik Fjord.
  3. Calculate percentage ice-cover within 2km x 2km grid cells in Sermilik Fjord.

Data Preparation

List of tables in the project

  1. iceberg_dist: Original iceberg table that houses the iceberg data
  2. grid_Sermilik: A grid table that houses 2km x 2km polygon grid cells in Sermilik Fjord
  3. overlap_pt_grid: A table that captures the point table (iceberg_dist) intersection with grid polygon table (grid_Sermilik)
  4. overlap_pt_grid_sum: Table that sums areas of all points that are within a grid cell
  5. overlap_pt_grid_percent: Table that calculates and holds ice cover percentage per grid cell

Creating new TABLE called iceberg_dist

%%sql
DROP TABLE IF EXISTS iceberg_dist; 
CREATE TABLE iceberg_dist (
  id SERIAL,
  Area_sqm decimal,
  x decimal,
  y decimal,
  totalArea decimal,
  PRIMARY KEY (id)
)
 * postgresql://
Done.
Done.

Copying all the .csv data from ./data directory

!psql -c "\COPY iceberg_dist FROM ./data/S1A_IW_GRDH_1SSH_20160114T085511_20160114T085536_009488_00DC4E_3DA0.tif.csv WITH CSV HEADER;"
COPY 15483

Viewing the iceberg_dist TABLE after copying all the csv

%%sql
select * from iceberg_dist;
 * postgresql://
15483 rows affected.
idarea_sqmxytotalarea
011100334165.16864305234-2586242.8126422013None
121000334102.532279416-2586287.176278565None
231100334526.07773396146-2586311.903551292None
34400334296.532279416-2586374.176278565None
45500333993.532279416-2586383.176278565None
..................
1547815479400323846.532279416-2659994.176278565None
15479154801600322935.282279416-2660027.926278565None
15480154812500321834.732279416-2660056.3762785653None
1548115482700321598.6751365588-2660054.890564279None
1548215483800321726.532279416-2660064.176278565None

15483 rows × 5 columns

%%sql
iceberg_df << 
SELECT *
FROM iceberg_dist;
 * postgresql://
15483 rows affected.
Returning data to local variable iceberg_df
iceberg_df

idarea_sqmxytotalarea
011100334165.16864305234-2586242.8126422013None
121000334102.532279416-2586287.176278565None
231100334526.07773396146-2586311.903551292None
34400334296.532279416-2586374.176278565None
45500333993.532279416-2586383.176278565None
..................
1547815479400323846.532279416-2659994.176278565None
15479154801600322935.282279416-2660027.926278565None
15480154812500321834.732279416-2660056.3762785653None
1548115482700321598.6751365588-2660054.890564279None
1548215483800321726.532279416-2660064.176278565None

15483 rows × 5 columns

%%sql
ALTER TABLE iceberg_dist
ADD COLUMN geom_2 geometry(Point, 3413);
 * postgresql://
Done.
%%sql
select * from iceberg_dist
 * postgresql://
15483 rows affected.
idarea_sqmxytotalareageom_2
011100334165.16864305234-2586242.8126422013NoneNone
121000334102.532279416-2586287.176278565NoneNone
231100334526.07773396146-2586311.903551292NoneNone
34400334296.532279416-2586374.176278565NoneNone
45500333993.532279416-2586383.176278565NoneNone
.....................
1547815479400323846.532279416-2659994.176278565NoneNone
15479154801600322935.282279416-2660027.926278565NoneNone
15480154812500321834.732279416-2660056.3762785653NoneNone
1548115482700321598.6751365588-2660054.890564279NoneNone
1548215483800321726.532279416-2660064.176278565NoneNone

15483 rows × 6 columns

%%sql
UPDATE iceberg_dist 
SET geom_2 = ST_SetSRID(ST_MakePoint(x, y), 3413);

 * postgresql://
15483 rows affected.
%%sql
select * from iceberg_dist;
 * postgresql://
15483 rows affected.
idarea_sqmxytotalareageom_2
011100334165.16864305234-2586242.8126422013None0101000020550D0000AAC3B0AC54651441DFA8046841BB...
121000334102.532279416-2586287.176278565None0101000020550D0000F0DA0D215A641441C84B909657BB...
231100334526.07773396146-2586311.903551292None0101000020550D0000D97D994FF86A14419991A7F363BB...
34400334296.532279416-2586374.176278565None0101000020550D0000F0DA0D2162671441C84B901683BB...
45500333993.532279416-2586383.176278565None0101000020550D0000F0DA0D21A6621441C84B909687BB...
.....................
1547815479400323846.532279416-2659994.176278565None0101000020550D0000F0DA0D211AC41341C84B90164D4B...
15479154801600322935.282279416-2660027.926278565None0101000020550D0000F0DA0D21DDB51341C84B90F65D4B...
15480154812500321834.732279416-2660056.3762785653None0101000020550D0000BDA7DAEDAAA4134162E529306C4B...
1548115482700321598.6751365588-2660054.890564279None0101000020550D000082FF56B3FAA01341A302FE716B4B...
1548215483800321726.532279416-2660064.176278565None0101000020550D0000F0DA0D21FAA21341C84B9016704B...

15483 rows × 6 columns

%%sql
iceberg_df << 
SELECT *
FROM iceberg_dist;
 * postgresql://
15483 rows affected.
Returning data to local variable iceberg_df
iceberg_gdf = spdb_geodataframe_postgis(iceberg_df,geom_col='geom_2')
iceberg_gdf
idarea_sqmxytotalareageom_2
011100334165.16864305234-2586242.8126422013NonePOINT (334165.1686430523 -2586242.812642201)
121000334102.532279416-2586287.176278565NonePOINT (334102.532279416 -2586287.176278565)
231100334526.07773396146-2586311.903551292NonePOINT (334526.0777339615 -2586311.903551292)
34400334296.532279416-2586374.176278565NonePOINT (334296.532279416 -2586374.176278565)
45500333993.532279416-2586383.176278565NonePOINT (333993.532279416 -2586383.176278565)
.....................
1547815479400323846.532279416-2659994.176278565NonePOINT (323846.532279416 -2659994.176278565)
15479154801600322935.282279416-2660027.926278565NonePOINT (322935.282279416 -2660027.926278565)
15480154812500321834.732279416-2660056.3762785653NonePOINT (321834.732279416 -2660056.376278565)
1548115482700321598.6751365588-2660054.890564279NonePOINT (321598.6751365588 -2660054.890564279)
1548215483800321726.532279416-2660064.176278565NonePOINT (321726.532279416 -2660064.176278565)

15483 rows × 6 columns

Plots

Study area

fig, (ax1,ax2) = plt.subplots(nrows=1, ncols=2, figsize=(29, 19))

shp_greenland = gpd.read_file('./shps/GreenlandFullRest_3413.shp')
shp_greenland.plot(ax=ax1,figsize=(39,19),facecolor='#402039')
lg = mpl.patches.Patch(color='#402039',label='Greenland')
ax1.legend(handles=[lg])
ax1.axvspan(300000, 350000, color='red', alpha=0.25)
ax1.axhspan(-2700000, -2500000, color='red', alpha=0.25)

shp_greenland.plot(ax=ax2,figsize=(39,19),facecolor='#402039')
ax2.set_xlim(300000, 360000)
ax2.set_ylim(-2700000, -2500000)
lg2 = mpl.patches.Patch(color='#402039',label='Sermilik Fjord')
ax2.legend(handles=[lg2])

plt.show()

Iceberg size distribution in Sermilik Fjord, SE Greenland

#fig,_ = plt.subplots()
ax2 = shp_greenland.plot(figsize=(39,19),facecolor='#402039')
ax2.set_xlim(300000, 360000)
ax2.set_ylim(-2680000, -2550000)

iceberg_gdf.plot(ax=ax2,column='area_sqm',figsize = (29,19),markersize=10,cmap='YlGnBu',alpha=1,
                       edgecolor='black',lw=0.1)
plt.title('Iceberg distribution in Sermilik Fjord',fontsize=18)
norm1 = mpl.colors.Normalize(vmin=int(iceberg_gdf['area_sqm'].min()),vmax=int(iceberg_gdf['area_sqm'].max()),
                             clip=True)
cbar1 = plt.cm.ScalarMappable(norm=norm1, cmap='YlGnBu')
ax_cbar = fig.colorbar(cbar1, ax=ax2)

#ctx.add_basemap(ax,url=ctx.providers.Stamen.TonerLite)

Iceberg Frequency Size distribution

fig, ax = plt.subplots()
fig.suptitle('Frequency size distribution of icebergs in Sermilik Fjord',fontsize=18)
iceberg_gdf = iceberg_gdf.sort_values(by='area_sqm')
(iceberg_gdf['area_sqm'].value_counts()).plot(figsize=(20,9),ax=ax ,kind='line',grid='dotted',
            color='#A83847',lw=3,logy=True,legend=True)
ax.set_xlabel('Area of iceberg (m$^2$)',fontsize=14)
ax.set_ylabel('Frequency',fontsize=14)

Text(0, 0.5, 'Frequency')

Grids representing Sermilik Fjord

Loading the shapefiles as geodataframe
#Loading Sermilik shps
shp_Sermilik_gdf = gpd.read_file('./shps/sermilik_extend_100m_buff.shp')
grid_Sermilik_gdf = gpd.read_file('./shps/Sermilik_grid.shp')
Converting shapefiles into database tables

Sermilik Shapefile to Table

!shp2pgsql -s 3413 -d -I shps/sermilik_extend_100m_buff.shp shp_Sermilik | psql
Field distance is an FTDouble with width 24 and precision 15
Field inner is an FTDouble with width 24 and precision 15
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
SET
SET
              dropgeometrycolumn               
-----------------------------------------------
 public.shp_sermilik.geom effectively removed.
(1 row)

DROP TABLE
BEGIN
CREATE TABLE
ALTER TABLE
                      addgeometrycolumn                       
--------------------------------------------------------------
 public.shp_sermilik.geom SRID:3413 TYPE:MULTIPOLYGON DIMS:2 
(1 row)

INSERT 0 1
CREATE INDEX
COMMIT
ANALYZE

Gridded Sermilik Shapefile to Table

!shp2pgsql -s 3413 -d -I shps/Sermilik_grid.shp grid_Sermilik | psql

Field __xmin is an FTDouble with width 21 and precision 5
Field __xmax is an FTDouble with width 21 and precision 5
Field ymin is an FTDouble with width 21 and precision 5
Field ymax is an FTDouble with width 21 and precision 5
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
SET
SET
               dropgeometrycolumn               
------------------------------------------------
 public.grid_sermilik.geom effectively removed.
(1 row)

DROP TABLE
BEGIN
CREATE TABLE
ALTER TABLE
                       addgeometrycolumn                       
---------------------------------------------------------------
 public.grid_sermilik.geom SRID:3413 TYPE:MULTIPOLYGON DIMS:2 
(1 row)

INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
CREATE INDEX
COMMIT
ANALYZE
%%sql
select * from grid_Sermilik;
 * postgresql://
238 rows affected.
gidid__xmin__xmaxyminymaxareageom
017332372.11979334372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
128334372.11979336372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
239336372.11979338372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
3410338372.11979340372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
4511340372.11979342372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
...........................
233234469320372.11979322372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...
234235470322372.11979324372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...
235236471324372.11979326372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...
236237472326372.11979328372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...
237238473328372.11979330372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...

238 rows × 8 columns

#Display gridded Sermilik Fjord table at 2km x 2km
grid_Sermilik_gdf
idxminxmaxyminymaxAreageometry
07332372.11979334372.11979-2.588145e+06-2.586145e+064000000POLYGON ((332372.119793 -2586144.85392, 334372...
18334372.11979336372.11979-2.588145e+06-2.586145e+064000000POLYGON ((334372.119793 -2586144.85392, 336372...
29336372.11979338372.11979-2.588145e+06-2.586145e+064000000POLYGON ((336372.119793 -2586144.85392, 338372...
310338372.11979340372.11979-2.588145e+06-2.586145e+064000000POLYGON ((338372.119793 -2586144.85392, 340372...
411340372.11979342372.11979-2.588145e+06-2.586145e+064000000POLYGON ((340372.119793 -2586144.85392, 342372...
........................
233469320372.11979322372.11979-2.660145e+06-2.658145e+064000000POLYGON ((320372.119793 -2658144.85392, 322372...
234470322372.11979324372.11979-2.660145e+06-2.658145e+064000000POLYGON ((322372.119793 -2658144.85392, 324372...
235471324372.11979326372.11979-2.660145e+06-2.658145e+064000000POLYGON ((324372.119793 -2658144.85392, 326372...
236472326372.11979328372.11979-2.660145e+06-2.658145e+064000000POLYGON ((326372.119793 -2658144.85392, 328372...
237473328372.11979330372.11979-2.660145e+06-2.658145e+064000000POLYGON ((328372.119793 -2658144.85392, 330372...

238 rows × 7 columns

#Displaying Sermilik Fjord with 2km x 2km grid cell overlapping original Sermilik Fjord shapefile
#ax = shp_Sermilik_gdf.plot(figsize=(20,9))
#grid_Sermilik_gdf.plot(ax=ax,column='Area',figsize=(20,9),facecolor='none',edgecolor='black')

Percentage Ice Cover

Overlap display of iceberg data with gridded Sermilik geodataframe
ax2 = shp_greenland.plot(figsize=(39,19),facecolor='#402039')
ax2.set_xlim(300000, 360000)
ax2.set_ylim(-2680000, -2550000)

shp_Sermilik_gdf.plot(ax=ax2,figsize=(20,19),alpha=0.5)
iceberg_gdf.plot(ax=ax2,column='area_sqm',figsize = (29,19),markersize=10,cmap='YlGnBu',alpha=1,
                       edgecolor='black',lw=0.1)
grid_Sermilik_gdf.plot(ax=ax2,column='Area',figsize=(29,19),facecolor='none',edgecolor='black')
norm1 = mpl.colors.Normalize(vmin=int(iceberg_gdf['area_sqm'].min()),vmax=int(iceberg_gdf['area_sqm'].max()),
                             clip=True)
cbar1 = plt.cm.ScalarMappable(norm=norm1, cmap='YlGnBu')
ax_cbar = fig.colorbar(cbar1, ax=ax2)

%%sql
select * from grid_Sermilik;
 * postgresql://
238 rows affected.
gidid__xmin__xmaxyminymaxareageom
017332372.11979334372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
128334372.11979336372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
239336372.11979338372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
3410338372.11979340372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
4511340372.11979342372.11979-2588144.85392-2586144.8539240000000106000020550D00000100000001030000000100000005...
...........................
233234469320372.11979322372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...
234235470322372.11979324372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...
235236471324372.11979326372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...
236237472326372.11979328372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...
237238473328372.11979330372.11979-2660144.85392-2658144.8539240000000106000020550D00000100000001030000000100000005...

238 rows × 8 columns

%%sql
select * from iceberg_dist;
 * postgresql://
15483 rows affected.
idarea_sqmxytotalareageom_2
011100334165.16864305234-2586242.8126422013None0101000020550D0000AAC3B0AC54651441DFA8046841BB...
121000334102.532279416-2586287.176278565None0101000020550D0000F0DA0D215A641441C84B909657BB...
231100334526.07773396146-2586311.903551292None0101000020550D0000D97D994FF86A14419991A7F363BB...
34400334296.532279416-2586374.176278565None0101000020550D0000F0DA0D2162671441C84B901683BB...
45500333993.532279416-2586383.176278565None0101000020550D0000F0DA0D21A6621441C84B909687BB...
.....................
1547815479400323846.532279416-2659994.176278565None0101000020550D0000F0DA0D211AC41341C84B90164D4B...
15479154801600322935.282279416-2660027.926278565None0101000020550D0000F0DA0D21DDB51341C84B90F65D4B...
15480154812500321834.732279416-2660056.3762785653None0101000020550D0000BDA7DAEDAAA4134162E529306C4B...
1548115482700321598.6751365588-2660054.890564279None0101000020550D000082FF56B3FAA01341A302FE716B4B...
1548215483800321726.532279416-2660064.176278565None0101000020550D0000F0DA0D21FAA21341C84B9016704B...

15483 rows × 6 columns

%%sql
SELECT ST_SRID(geom_2) FROM iceberg_dist;--select * from grid_Sermilik;
 * postgresql://
15483 rows affected.
st_srid
03413
13413
23413
33413
43413
......
154783413
154793413
154803413
154813413
154823413

15483 rows × 1 columns

New table that captures the point table intersect with grid polygon table : “overlap_pt_grid”

%%sql
DROP TABLE IF EXISTS overlap_pt_grid;
CREATE TABLE overlap_pt_grid AS 
SELECT grid_Sermilik.*,iceberg_dist.x, iceberg_dist.y, iceberg_dist.area_sqm, iceberg_dist.geom_2,
ST_Intersection(iceberg_dist.geom_2,grid_Sermilik.geom)
FROM grid_Sermilik, iceberg_dist WHERE ST_Intersects(iceberg_dist.geom_2, grid_Sermilik.geom);


 * postgresql://
Done.
15483 rows affected.
%%sql
select * from overlap_pt_grid where id=124;
 * postgresql://
67 rows affected.
gidid__xmin__xmaxyminymaxareageomxyarea_sqmgeom_2st_intersection
074124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...334001.3142957648-2604372.527777203367000101000020550D0000BCBFD641C562144111348E43AADE...0101000020550D0000BCBFD641C562144111348E43AADE...
174124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...333337.532279416-2604163.17627856525000101000020550D0000F0DA0D2166581441C84B909641DE...0101000020550D0000F0DA0D2166581441C84B909641DE...
274124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...333591.38190347614-2604243.6875567604133000101000020550D000071B411875D5C144124DC01D869DE...0101000020550D000071B411875D5C144124DC01D869DE...
374124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...333406.532279416-2604184.1762785654000101000020550D0000F0DA0D217A591441C84B90164CDE...0101000020550D0000F0DA0D217A591441C84B90164CDE...
474124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...333448.1989460827-2604234.73183412069000101000020550D00009B85B8CB205A14418FBDAC5D65DE...0101000020550D00009B85B8CB205A14418FBDAC5D65DE...
..........................................
6274124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...333107.532279416-2605861.1762785655000101000020550D0000F0DA0D21CE541441C84B909692E1...0101000020550D0000F0DA0D21CE541441C84B909692E1...
6374124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...332461.5794492273-2606017.242316301212000101000020550D000064235B51B64A14417638049FE0E1...0101000020550D000064235B51B64A14417638049FE0E1...
6474124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...333196.532279416-2605984.1762785654000101000020550D0000F0DA0D2132561441C84B9016D0E1...0101000020550D0000F0DA0D2132561441C84B9016D0E1...
6574124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...333203.932279416-2606053.57627856525000101000020550D00008A74A7BA4F561441FB7EC3C9F2E1...0101000020550D00008A74A7BA4F561441FB7EC3C9F2E1...
6674124332372.11979334372.11979-2606144.85392-2604144.8539240000000106000020550D00000100000001030000000100000005...332641.532279416-2606134.1762785654000101000020550D0000F0DA0D21864D1441C84B90161BE2...0101000020550D0000F0DA0D21864D1441C84B90161BE2...

67 rows × 13 columns

Table with sum of all points that overlap/within a grid cell: “overlap_pt_grid_sum”

%%sql
DROP TABLE IF EXISTS overlap_pt_grid_sum;
CREATE TABLE overlap_pt_grid_sum AS 
select overlap_pt_grid.id, overlap_pt_grid.geom, overlap_pt_grid.area,
    overlap_pt_grid.__xmin,overlap_pt_grid.__xmax,overlap_pt_grid.ymin,overlap_pt_grid.ymax, 
    sum(overlap_pt_grid.area_sqm)

from overlap_pt_grid 
group by overlap_pt_grid.__xmin,overlap_pt_grid.__xmax,overlap_pt_grid.ymin,overlap_pt_grid.ymax,
overlap_pt_grid.id, overlap_pt_grid.geom, overlap_pt_grid.area;
 * postgresql://
Done.
219 rows affected.
%%sql
select * from overlap_pt_grid_sum;
 * postgresql://
219 rows affected.
idgeomarea__xmin__xmaxyminymaxsum
0740106000020550D00000100000001030000000100000005...4000000336372.11979338372.11979-2598144.85392-2596144.85392330500
1750106000020550D00000100000001030000000100000005...4000000338372.11979340372.11979-2598144.85392-2596144.8539269900
22500106000020550D00000100000001030000000100000005...4000000324372.11979326372.11979-2626144.85392-2624144.85392229900
31240106000020550D00000100000001030000000100000005...4000000332372.11979334372.11979-2606144.85392-2604144.85392147100
43940106000020550D00000100000001030000000100000005...4000000326372.11979328372.11979-2648144.85392-2646144.85392259500
...........................
2141230106000020550D00000100000001030000000100000005...4000000330372.11979332372.11979-2606144.85392-2604144.85392367100
215860106000020550D00000100000001030000000100000005...4000000334372.11979336372.11979-2600144.85392-2598144.85392312500
216190106000020550D00000100000001030000000100000005...4000000330372.11979332372.11979-2590144.85392-2588144.8539242300
2172410106000020550D00000100000001030000000100000005...4000000332372.11979334372.11979-2624144.85392-2622144.85392179300
2181260106000020550D00000100000001030000000100000005...4000000336372.11979338372.11979-2606144.85392-2604144.8539219800

219 rows × 8 columns

%%sql
select *,(sum/area)*100 as percent from overlap_pt_grid_sum;
 * postgresql://
219 rows affected.
idgeomarea__xmin__xmaxyminymaxsumpercent
0740106000020550D00000100000001030000000100000005...4000000336372.11979338372.11979-2598144.85392-2596144.853923305008.26250000000000000000
1750106000020550D00000100000001030000000100000005...4000000338372.11979340372.11979-2598144.85392-2596144.85392699001.74750000000000000000
22500106000020550D00000100000001030000000100000005...4000000324372.11979326372.11979-2626144.85392-2624144.853922299005.74750000000000000000
31240106000020550D00000100000001030000000100000005...4000000332372.11979334372.11979-2606144.85392-2604144.853921471003.67750000000000000000
43940106000020550D00000100000001030000000100000005...4000000326372.11979328372.11979-2648144.85392-2646144.853922595006.48750000000000000000
..............................
2141230106000020550D00000100000001030000000100000005...4000000330372.11979332372.11979-2606144.85392-2604144.853923671009.17750000000000000000
215860106000020550D00000100000001030000000100000005...4000000334372.11979336372.11979-2600144.85392-2598144.853923125007.81250000000000000000
216190106000020550D00000100000001030000000100000005...4000000330372.11979332372.11979-2590144.85392-2588144.85392423001.05750000000000000000
2172410106000020550D00000100000001030000000100000005...4000000332372.11979334372.11979-2624144.85392-2622144.853921793004.48250000000000000000
2181260106000020550D00000100000001030000000100000005...4000000336372.11979338372.11979-2606144.85392-2604144.85392198000.49500000000000000000

219 rows × 9 columns

%%sql
select * from overlap_pt_grid_sum;
 * postgresql://
219 rows affected.
idgeomarea__xmin__xmaxyminymaxsum
0740106000020550D00000100000001030000000100000005...4000000336372.11979338372.11979-2598144.85392-2596144.85392330500
1750106000020550D00000100000001030000000100000005...4000000338372.11979340372.11979-2598144.85392-2596144.8539269900
22500106000020550D00000100000001030000000100000005...4000000324372.11979326372.11979-2626144.85392-2624144.85392229900
31240106000020550D00000100000001030000000100000005...4000000332372.11979334372.11979-2606144.85392-2604144.85392147100
43940106000020550D00000100000001030000000100000005...4000000326372.11979328372.11979-2648144.85392-2646144.85392259500
...........................
2141230106000020550D00000100000001030000000100000005...4000000330372.11979332372.11979-2606144.85392-2604144.85392367100
215860106000020550D00000100000001030000000100000005...4000000334372.11979336372.11979-2600144.85392-2598144.85392312500
216190106000020550D00000100000001030000000100000005...4000000330372.11979332372.11979-2590144.85392-2588144.8539242300
2172410106000020550D00000100000001030000000100000005...4000000332372.11979334372.11979-2624144.85392-2622144.85392179300
2181260106000020550D00000100000001030000000100000005...4000000336372.11979338372.11979-2606144.85392-2604144.8539219800

219 rows × 8 columns

Ice cover percentage per grid cell table: “overlap_pt_grid_percent”

%%sql
DROP TABLE IF EXISTS overlap_pt_grid_percent;
CREATE TABLE overlap_pt_grid_percent AS 
select *,(sum/area)*100 as percent 
from overlap_pt_grid_sum;
 * postgresql://
Done.
219 rows affected.
%%sql
select * from overlap_pt_grid_percent;
 * postgresql://
219 rows affected.
idgeomarea__xmin__xmaxyminymaxsumpercent
0740106000020550D00000100000001030000000100000005...4000000336372.11979338372.11979-2598144.85392-2596144.853923305008.26250000000000000000
1750106000020550D00000100000001030000000100000005...4000000338372.11979340372.11979-2598144.85392-2596144.85392699001.74750000000000000000
22500106000020550D00000100000001030000000100000005...4000000324372.11979326372.11979-2626144.85392-2624144.853922299005.74750000000000000000
31240106000020550D00000100000001030000000100000005...4000000332372.11979334372.11979-2606144.85392-2604144.853921471003.67750000000000000000
43940106000020550D00000100000001030000000100000005...4000000326372.11979328372.11979-2648144.85392-2646144.853922595006.48750000000000000000
..............................
2141230106000020550D00000100000001030000000100000005...4000000330372.11979332372.11979-2606144.85392-2604144.853923671009.17750000000000000000
215860106000020550D00000100000001030000000100000005...4000000334372.11979336372.11979-2600144.85392-2598144.853923125007.81250000000000000000
216190106000020550D00000100000001030000000100000005...4000000330372.11979332372.11979-2590144.85392-2588144.85392423001.05750000000000000000
2172410106000020550D00000100000001030000000100000005...4000000332372.11979334372.11979-2624144.85392-2622144.853921793004.48250000000000000000
2181260106000020550D00000100000001030000000100000005...4000000336372.11979338372.11979-2606144.85392-2604144.85392198000.49500000000000000000

219 rows × 9 columns

%%sql
percent_df << 
SELECT *
FROM overlap_pt_grid_percent;
 * postgresql://
219 rows affected.
Returning data to local variable percent_df
percent_gdf = spdb_geodataframe_postgis(percent_df,geom_col='geom')
percent_gdf
idgeomarea__xmin__xmaxyminymaxsumpercent
074(POLYGON ((336372.119793 -2596144.85392, 33837...4000000336372.11979338372.11979-2598144.85392-2596144.853923305008.26250000000000000000
175(POLYGON ((338372.119793 -2596144.85392, 34037...4000000338372.11979340372.11979-2598144.85392-2596144.85392699001.74750000000000000000
2250(POLYGON ((324372.119793 -2624144.85392, 32637...4000000324372.11979326372.11979-2626144.85392-2624144.853922299005.74750000000000000000
3124(POLYGON ((332372.119793 -2604144.85392, 33437...4000000332372.11979334372.11979-2606144.85392-2604144.853921471003.67750000000000000000
4394(POLYGON ((326372.119793 -2646144.85392, 32837...4000000326372.11979328372.11979-2648144.85392-2646144.853922595006.48750000000000000000
..............................
214123(POLYGON ((330372.119793 -2604144.85392, 33237...4000000330372.11979332372.11979-2606144.85392-2604144.853923671009.17750000000000000000
21586(POLYGON ((334372.119793 -2598144.85392, 33637...4000000334372.11979336372.11979-2600144.85392-2598144.853923125007.81250000000000000000
21619(POLYGON ((330372.119793 -2588144.85392, 33237...4000000330372.11979332372.11979-2590144.85392-2588144.85392423001.05750000000000000000
217241(POLYGON ((332372.119793 -2622144.85392, 33437...4000000332372.11979334372.11979-2624144.85392-2622144.853921793004.48250000000000000000
218126(POLYGON ((336372.119793 -2604144.85392, 33837...4000000336372.11979338372.11979-2606144.85392-2604144.85392198000.49500000000000000000

219 rows × 9 columns

Iceberg cover percentage per grid cell in Sermilik Fjord, SE Greenland

fig, (ax1,ax2) = plt.subplots(nrows=1, ncols=2, figsize=(29, 19))
#Iceberg points overlap 2km x 2km grid cells
shp_greenland.plot(ax=ax1,figsize=(29,19),facecolor='#402039')
ax1.set_xlim(300000, 360000)
ax1.set_ylim(-2680000, -2550000)
iceberg_gdf.plot(ax=ax1,column='area_sqm',figsize = (29,19),markersize=10,cmap='YlGnBu',alpha=1,edgecolor='black',lw=0.1)
norm1 = mpl.colors.Normalize(vmin=int(iceberg_gdf['area_sqm'].min()),vmax=int(iceberg_gdf['area_sqm'].max()),clip=True)
cbar1 = plt.cm.ScalarMappable(norm=norm1, cmap='YlGnBu')
ax_cbar = fig.colorbar(cbar1, ax=ax1)
grid_Sermilik_gdf.plot(ax=ax1,column='Area',figsize=(29,19),facecolor='none',edgecolor='black')

#Gridded map with colorbar plot
shp_greenland.plot(ax=ax2,figsize=(29,19),facecolor='#402039')
ax2.set_xlim(300000, 360000)
ax2.set_ylim(-2680000, -2550000)
percent_gdf.plot(ax=ax2,column='percent',figsize = (29,19),markersize=10,cmap='YlGnBu',alpha=1,legend=False)
norm = mpl.colors.Normalize(vmin=int(percent_gdf['percent'].min()),vmax=int(percent_gdf['percent'].max()),clip=True)
cbar = plt.cm.ScalarMappable(norm=norm, cmap='YlGnBu')
ax_cbar = fig.colorbar(cbar, ax=ax2)
#ctx.add_basemap(ax2,url=ctx.providers.Stamen.TonerLite)

References

Copernicus Sentinel data [2016]. Retrieved from ASF DAAC [2019], processed by ESA