Skip to content

Instantly share code, notes, and snippets.

View rasha-salim's full-sized avatar
🌏
Working from home

Rasha G. Salim rasha-salim

🌏
Working from home
View GitHub Profile
import rasterio
from rasterio import features
from rasterio.io import MemoryFile
import math
import geopandas as gpd
import os
w = 400
h = 400
def getGeojson():
# Store the mask coordinates into a geojson file
bounds = getImgBounds()
dataset = rasterio.open(png_path)
bands = [1]
data = dataset.read(bands)
transform = rasterio.transform.from_bounds(bounds[0], bounds[1], bounds[2], bounds[3], data.shape[1], data.shape[2])
crs = rasterio.crs.CRS({"init": "epsg:4326"}) # 3857 Google Maps Projection 4326 World wide (3D)
with MemoryFile() as memfile:
meta = {"count": 1, "width": data.shape[1], "height": data.shape[2], "transform": transform, "nodata": 0, "crs": crs, "dtype":data.dtype}
def getGeojson():
# Store the mask coordinates into a geojson file
bounds = getImgBounds()
dataset = rasterio.open(png_path)
bands = [1]
data = dataset.read(bands)
transform = rasterio.transform.from_bounds(bounds[0], bounds[1], bounds[2], bounds[3], data.shape[1], data.shape[2])
crs = rasterio.crs.CRS({"init": "epsg:4326"}) # 3857 Google Maps Projection 4326 World wide (3D)
with MemoryFile() as memfile:
meta = {"count": 1, "width": data.shape[1], "height": data.shape[2], "transform": transform, "nodata": 0, "crs": crs, "dtype":data.dtype}
import os
import math
import rasterio
from rasterio import features
# Specify the image parameters
w = 400
h = 400
zoom = 8
lat = -19.361500892883598
@rasha-salim
rasha-salim / uploading_data_hub.py
Last active May 12, 2021 19:49
Passing our images to hub Dataset object and upload it to server
# I just extracted the input, rgb, and segmentation to separate arrays for convenience
inputs = []
masks = []
rgb_inputs = []
for pairs in images_target:
inputs.append(pairs['input'])
masks.append(pairs['mask'])
rgb_inputs.append(pairs['input_rgb'])
# Pass the data to our Dataset instance we created earlier
@rasha-salim
rasha-salim / reading_lcn_dataset.py
Created February 7, 2021 09:08
Reading LandCoverNet dataset into array before uploading it to activeloop
inputs_dir = '/content/landcovernet/inputs' # The directory where our input resides
targets_dir = '/content/landcovernet/targets' # The directory where our target resides
# First stack all the bands togather
def process_tiffs(inputs_dir, target_dir):
data = []
sub_dir_list = []
images_target = {}
stacked_imgs = []
list_bands = []
inputs_dir = '/content/landcovernet/inputs' # The directory where our input resides
targets_dir = '/content/landcovernet/targets' # The directory where our target resides
# First stack all the bands togather
def process_tiffs(inputs_dir, target_dir):
data = []
sub_dir_list = []
images_target = {}
stacked_imgs = []
list_bands = []
@rasha-salim
rasha-salim / reading_landcovernet_data
Created February 7, 2021 09:05
Reading our data into a numpy array
inputs_dir = '/content/landcovernet/inputs' # The directory where our input resides
targets_dir = '/content/landcovernet/targets' # The directory where our target resides
# First stack all the bands togather
def process_tiffs(inputs_dir, target_dir):
data = []
sub_dir_list = []
images_target = {}
stacked_imgs = []
list_bands = []
@rasha-salim
rasha-salim / creating_dataset.py
Created February 7, 2021 08:45
Createing Dataset object in activeloop hub
import hub
from hub.schema import Image
from hub.schema import Tensor
from hub.schema import Mask
from hub.schema import Segmentation
# include your user anme and a name for your dataset
tag = "rasha/landCoverNet_Omdena_Sample"
ds = {}
# Define youe dataset object
@rasha-salim
rasha-salim / PY0101EN-5-1-Numpy1D.ipynb
Created May 6, 2020 13:20
Created on Skills Network Labs
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.