Skip to content

Commit 4dd2d33

Browse files
committed
Added update_package function
1 parent a187b2e commit 4dd2d33

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ The **segment-geospatial** package draws its inspiration from [segment-anything-
2525
- [Segmenting satellite imagery](https://samgeo.gishub.org/examples/satellite)
2626
- [Automatically generating object masks](https://samgeo.gishub.org/examples/automatic_mask_generator)
2727

28+
## Demos
29+
30+
- Automatic mask generator
31+
32+
![](https://i.imgur.com/I1IhDgz.gif)
33+
2834
## Acknowledgements
2935

3036
This package was made possible by the following open source projects. Credit goes to the developers of these projects.

docs/examples/automatic_mask_generator.ipynb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@
210210
"sam.show_anns(axis='off', alpha=1, output='annotations.tif')"
211211
]
212212
},
213+
{
214+
"cell_type": "code",
215+
"execution_count": null,
216+
"metadata": {},
217+
"outputs": [],
218+
"source": [
219+
"m.add_raster('annotations.tif', opacity=0.5, layer_name='Masks')\n",
220+
"m"
221+
]
222+
},
213223
{
214224
"cell_type": "markdown",
215225
"metadata": {},

docs/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ The **segment-geospatial** package draws its inspiration from [segment-anything-
2525
- [Segmenting satellite imagery](https://samgeo.gishub.org/examples/satellite)
2626
- [Automatically generating object masks](https://samgeo.gishub.org/examples/automatic_mask_generator)
2727

28+
## Demos
29+
30+
- Automatic mask generator
31+
32+
![](https://i.imgur.com/I1IhDgz.gif)
33+
2834
## Acknowledgements
2935

3036
This package was made possible by the following open source projects. Credit goes to the developers of these projects.

samgeo/common.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ def overlay_images(
10891089
print(
10901090
"The TkAgg backend is not supported in Google Colab. The overlay_images function will not work on Colab."
10911091
)
1092+
return
10921093

10931094
matplotlib.use(backend)
10941095

@@ -1202,3 +1203,45 @@ def blend_images(
12021203
plt.show()
12031204
else:
12041205
return blend_img
1206+
1207+
1208+
def update_package(out_dir=None, keep=False, **kwargs):
1209+
"""Updates the package from the GitHub repository without the need to use pip or conda.
1210+
1211+
Args:
1212+
out_dir (str, optional): The output directory. Defaults to None.
1213+
keep (bool, optional): Whether to keep the downloaded package. Defaults to False.
1214+
**kwargs: Additional keyword arguments to pass to the download_file() function.
1215+
"""
1216+
1217+
import shutil
1218+
1219+
try:
1220+
if out_dir is None:
1221+
out_dir = os.getcwd()
1222+
url = (
1223+
"https://github.com/opengeos/segment-geospatial/archive/refs/heads/main.zip"
1224+
)
1225+
filename = "segment-geospatial-main.zip"
1226+
download_file(url, filename, **kwargs)
1227+
1228+
pkg_dir = os.path.join(out_dir, "segment-geospatial-main")
1229+
work_dir = os.getcwd()
1230+
os.chdir(pkg_dir)
1231+
1232+
if shutil.which("pip") is None:
1233+
cmd = "pip3 install ."
1234+
else:
1235+
cmd = "pip install ."
1236+
1237+
os.system(cmd)
1238+
os.chdir(work_dir)
1239+
1240+
if not keep:
1241+
shutil.rmtree(pkg_dir)
1242+
os.remove(filename)
1243+
1244+
print("Package updated successfully.")
1245+
1246+
except Exception as e:
1247+
raise Exception(e)

0 commit comments

Comments
 (0)