In [ ]:
from planet4 import markings
In [ ]:
d = dict(x=1, y=2, radius_1=3, radius_2=2, angle=35)
blotch = markings.Blotch(pd.Series(d))
In [ ]:
%matplotlib inline
In [ ]:
from planet4 import io, plotting
obsid = 'ESP_011544_0985'
id_ = 'bdb'
pm = io.PathManager(obsid=obsid, datapath='p4_analysis/p4_catalog')
In [ ]:
pm.obsid_final_blotches_path
In [ ]:
from planet4.catalog_production import ReleaseManager
In [ ]:
rm = ReleaseManager('v1.0')
In [ ]:
df = rm.read_blotch_file()
In [ ]:
df = pd.read_csv(pm.obsid_final_blotches_path)
In [ ]:
fans = pd.read_csv("/Users/klay6683/Dropbox/CTX_to_jpg/P4_catalog_v1/P4_catalog_v1.0_cut_0.5_fan.csv")
blotches = pd.read_csv("/Users/klay6683/Dropbox/CTX_to_jpg/P4_catalog_v1/P4_catalog_v1.0_cut_0.5_blotch.csv")
In [ ]:
id_
In [ ]:
blotches = blotches[blotches.tile_id == io.check_and_pad_id(id_)]
In [ ]:
fans = fans[fans.tile_id == io.check_and_pad_id(id_)]
In [ ]:
import geopandas as gp
In [ ]:
import shapely
In [ ]:
gs_blotch = gp.GeoSeries([markings.Blotch(row).to_shapely() for _,row in blotches.iterrows()])
gs_fans = gp.GeoSeries([markings.Fan(row).to_shapely() for _,row in fans.iterrows()])
In [ ]:
gs = pd.concat([gs_blotch, gs_fans], ignore_index=True, sort=True)
In [ ]:
id_ = 'bdb'
p4id = markings.ImageID(id_)
In [ ]:
%matplotlib ipympl
In [ ]:
p4id.plot_fans(data=fans)
ax =plt.gca()
p4id.plot_blotches(data=blotches, ax=ax)
In [ ]:
gs.plot()
ax = plt.gca()
ax.set_xlim((0, markings.IMG_X_SIZE))
ax.set_ylim((0, markings.IMG_Y_SIZE))
ax.invert_yaxis()
In [ ]:
gs.head()
In [ ]:
from shapely.ops import unary_union
In [ ]:
unionized = gs.unary_union
In [ ]:
x, y = markings.calc_fig_size(8)
In [ ]:
import seaborn as sns
sns.set_context('talk')
In [ ]:
squared_pixel_scale = fans.map_scale.iloc[0]**2
squared_pixel_scale
In [ ]:
area = unionized.area * squared_pixel_scale
area
In [ ]:
pixel_area = markings.IMG_X_SIZE * markings.IMG_Y_SIZE
tile_area = pixel_area * squared_pixel_scale
tile_area
In [ ]:
fraction = area / tile_area
fraction
In [ ]:
fig, ax = plt.subplots(ncols=2, figsize=(1.8*x, y), constrained_layout=True)
p4id.plot_fans(data=fans, ax=ax[0])
p4id.plot_blotches(data=blotches, ax=ax[0])
# p4id.show_subframe(ax=ax[1])
gp.GeoSeries(unionized).boundary.plot(ax=ax[1])
ax[1].set_xlim(-25, markings.IMG_X_SIZE+25)
ax[1].set_ylim(markings.IMG_Y_SIZE+25, -25)
ax[1].set_axis_off()
fig.suptitle(id_)
ax[0].set_title('Combined fans and blotches')
ax[1].set_title(f"""Union out of shapely fans and blotches.
Area: {area:.0f} $m^2$; Fraction: {fraction*100:.0f} %""")
fig.savefig('shapely_both.png', dpi=100)
In [ ]:
poly = unionized[0]
In [ ]:
poly.boundary.xy[0][0]
In [ ]:
df1 = gp.GeoDataFrame({'geometry': gs})
df1.head()
In [ ]:
unionized
In [ ]:
inters = gp.overlay(df1, df1, how='intersection')
inters.plot()
In [ ]:
fans.columns
In [ ]:
fans.l_s.value_counts()
In [ ]:
obsid = 'ESP_012643_0945'
obsid = 'ESP_013049_0950'
# obsid = 'ESP_011447_0950'
In [ ]:
fans = pd.read_csv("/Users/klay6683/Dropbox/CTX_to_jpg/P4_catalog_v1/P4_catalog_v1.0_cut_0.5_fan.csv")
blotches = pd.read_csv("/Users/klay6683/Dropbox/CTX_to_jpg/P4_catalog_v1/P4_catalog_v1.0_cut_0.5_blotch.csv")
In [ ]:
fans[fans.obsid.map(lambda x: x.endswith("_0950"))].obsid.value_counts()
In [ ]:
fans = fans.query("obsid == @obsid")
blotches = blotches.query("obsid == @obsid")
In [ ]:
fans.l_s.value_counts()
In [ ]:
gs_blotch = gp.GeoSeries([markings.Blotch(row).to_shapely() for _,row in blotches.iterrows()])
gs_fans = gp.GeoSeries([markings.Fan(row).to_shapely() for _,row in fans.iterrows()])
In [ ]:
gs = pd.concat([gs_blotch, gs_fans], ignore_index=True, sort=True)
In [ ]:
gs.shape
In [ ]:
unioned = gs.iloc[:2216].unary_union
In [ ]:
gs.iloc[2215]
In [ ]:
print(np.array(gs.iloc[2215].boundary)[:5])
np.array(gs.iloc[2215].boundary)[-5:]
In [ ]:
print(np.array(gs.iloc[2214].boundary)[:5])
np.array(gs.iloc[2214].boundary)[-5:]
In [ ]:
fans
In [ ]:
fans.columns
In [ ]:
fans.map_scale.value_counts()
In [ ]: