Potential Carbon and Hydrogen Storage Facilities Near Import/Export Ports
Identifying potential carbon and hydrogen storage facilities near lng ports.
carbonhydrogengislngpythoncarbonshipping
2 Minutes, 33 Seconds
2022-05-06 08:30 +0000
Potential Carbon Storage Facilities Near Import/Export Ports
Import and Procedural Functions
import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpd
import folium
import contextily as cx
import rtree
from zlib import crc32
import hashlib
from shapely.geometry import Point, LineString, Polygon
import numpy as np
from scipy.spatial import cKDTree
from shapely.geometry import Point
from haversine import Unit
from geopy.distance import distance
Restrictions
- Must be near a pipeline terminal
- Must be Near a petrolium Port
Query Plan
Imports
- Import LNG terminal Data
- Import well data
Filtering
- for each well calculate nearest terminal
- for each well calculate distance from nearest terminal
- eliminate wells further than 15 miles from a terminal
Data Frame Import
Wells DataFrame
## Importing our DataFrames
gisfilepath = "/Users/jnapolitano/Projects/data/energy/non-active-wells.geojson"
wells_df = gpd.read_file(gisfilepath)
wells_df = wells_df.to_crs(epsg=3857)
Terminal DataFrame
## Importing our DataFrames
gisfilepath = "/Users/jnapolitano/Projects/data/energy/Liquified_Natural_Gas_Import_Exports_and_Terminals.geojson"
terminal_df = gpd.read_file(gisfilepath)
terminal_df = terminal_df.to_crs(epsg=3857)
Eliminating SUSPENDED Terminal from the DataFrame
terminal_df.drop(terminal_df[terminal_df['STATUS'] == 'SUSPENDED'].index, inplace = True)
terminal_df.rename(columns={"NAME": "TERMINAL_NAME"})
terminal_df['TERMINAL_GEO'] = terminal_df['geometry'].copy()
terminal_df.columns
Index(['OBJECTID', 'TERMID', 'NAME', 'ADDRESS', 'CITY', 'STATE', 'ZIP', 'ZIP4',
'TELEPHONE', 'TYPE', 'STATUS', 'POPULATION', 'COUNTY', 'COUNTYFIPS',
'COUNTRY', 'LATITUDE', 'LONGITUDE', 'NAICS_CODE', 'NAICS_DESC',
'SOURCE', 'SOURCEDATE', 'VAL_METHOD', 'VAL_DATE', 'WEBSITE', 'EPA_ID',
'ALT_NAME', 'OWNER', 'POSREL', 'JRSDCTN', 'CONTYPE', 'IE_PORT',
'BERTHS', 'STORAGE', 'STORCAP', 'CURRENTCAP', 'APPCAP', 'OPYEAR',
'IMPEXPCTRY', 'VOLUME', 'PRICE', 'geometry', 'TERMINAL_GEO'],
dtype='object')
Plotting Terminal by TYPE
terminal_map =terminal_df.explore(
column="TYPE", # make choropleth based on "PORT_NAME" column
popup=True, # show all values in popup (on click)
tiles="Stamen Terrain", # use "CartoDB positron" tiles
cmap='Set1', # use "Set1" matplotlib colormap
#style_kwds=dict(color="black"),
marker_kwds= dict(radius=6),
#tooltip=['NAICS_DESC','REGION', 'COMMODITY' ],
legend =True, # use black outline)
categorical=True,
)
terminal_map
Terminal Impressions
According to the data there is not an export nor import location on The Western Side of the United States.
East Asian import or carbon capture export demands could justfity port development. Another study must be conducted.
Filtering Wells by Terminal Distance in Scipy
Edit
This method does not accuraletly calculate distance. The algorith used below calculates distance on a euclidan plane. In order to calculate a correct answer we must account for sphericity.
I include the code below as reference and a learning opportunity
def ckdnearest(gdA, gdB):
nA = np.array(list(gdA.geometry.apply(lambda x: (x.x, x.y))))
nB = np.array(list(gdB.geometry.apply(lambda x: (x.x, x.y))))
btree = cKDTree(nB)
dist, idx = btree.query(nA, k=1)
gdB_nearest = gdB.iloc[idx].drop(columns="geometry").reset_index(drop=True)
gdf = pd.concat(
[
gdA.reset_index(drop=True),
gdB_nearest,
pd.Series(dist, name='dist')
],
axis=1)
return gdf
c = ckdnearest(wells_df, terminal_df)
c.describe()
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
nearest_wells_df= wells_df.sjoin_nearest(terminal_df, distance_col="distance_euclidian")
nearest_wells_df.describe()
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
Calculating Distance in Kilometers from Import/Export Terminal
#df.geopy.distance.distance(coords_1, coords_2).km
#df.apply(lambda row: distance(row['point'], row['point_next']).km if row['point_next'] is not None else float('nan'), axis=1)
# Thanks to https://stackoverflow.com/questions/55909305/using-geopy-in-a-dataframe-to-get-distances
nearest_wells_df['true_distance_km'] = nearest_wells_df.apply(lambda row: distance((row['LATITUDE_left'], row['LONGITUDE_left']), (row['LATITUDE_right'], row['LONGITUDE_right'])).km if row['geometry'] is not None else float('nan'), axis=1)
nearest_wells_df.describe()
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
Filtering Wells within 50 KM of a Terminal
filtered_wells = nearest_wells_df.loc[nearest_wells_df['true_distance_km'] < 50].copy()
filtered_wells.describe()
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
Map of Wells within 50 km of an Import/Export Terminal by Type
filtered_wells.explore(
column="STATUS_left", # make choropleth based on "PORT_NAME" column
popup=True, # show all values in popup (on click)
tiles="Stamen Terrain", # use "CartoDB positron" tiles
cmap='Set1', # use "Set1" matplotlib colormap
#style_kwds=dict(color="black"),
marker_kwds= dict(radius=6),
#tooltip=['NAICS_DESC','REGION', 'COMMODITY' ],
legend =True, # use black outline)
categorical=True,)