Esempio n. 1
0
def prepare_normals(means, sigmas, weights, normalize, axis):
    isnan_mean = np.isnan(means)
    isnan_sigmas = np.isnan(sigmas)
    if np.any(isnan_mean != isnan_sigmas):
        raise ValueError('mean and sigma NaNs do not match')
    if np.any(sigmas == 0):
        raise ValueError('sigmas cannot be 0')
    if weights is None:
        weights = np.ones(means.shape)
    if normalize:
        weights = weights * (
            1 / np.nansum(weights * ~isnan_mean, axis=axis, keepdims=True))
    return isnan_mean, isnan_sigmas, weights
Esempio n. 2
0
names = 'vr', 'vr_stderr', 'theta', 'theta_stderr'
vr, vr_sigma, theta, theta_sigma = [glimpse.Raster.read(
    os.path.join('velocity', name + '.tif'))
    for name in names]

# ---- Load canonical bed ----
# bed

bed = glimpse.Raster.read('bed.tif')

# ---- Build track template ----

grid = glimpse.helpers.box_to_grid(dem_interpolant.means[0].box2d,
    step=grid_step, snap=(0, 0))
track_template = glimpse.Raster(np.ones(grid[0].shape, dtype=bool),
    x=grid[0], y=grid[1][::-1])
xy = glimpse.helpers.grid_to_points((track_template.X, track_template.Y))
selected = glimpse.helpers.points_in_polygon(xy, cg.Glacier())
# Filter by velocity availability
# NOTE: Use nearest to avoid NaN propagation (and on same grid anyway)
selected &= ~np.isnan(vx.sample(xy, order=0))
mask = selected.reshape(track_template.shape)
track_points = xy[mask.ravel()]
track_ids = np.ravel_multi_index(np.nonzero(mask), track_template.shape)

# Write to file
track_template.Z &= mask
track_template.Z = track_template.Z.astype(np.uint8)
track_template.write(os.path.join(cartesian_path, 'template.tif'), crs=32606)
track_template.write(os.path.join(cylindrical_path, 'template.tif'), crs=32606)
Esempio n. 3
0
#-------------------------

#----------------------------
# Prepare DEM
path = glob.glob(join(DEM_DIR, "*.tif"))[0]
dem = glimpse.Raster.read(path, d=10)
print("DEM PATH: {}".format(path))
dem.crop(zlim=(0, np.inf))
dem.fill_crevasses(mask=~np.isnan(dem.Z), fill=True)

# ---- Prepare viewshed ----

for obs in observers:
    dem.fill_circle(obs.xyz, radius=100)
viewshed = dem.copy()
viewshed.Z = np.ones(dem.shape, dtype=bool)
for obs in observers:
    viewshed.Z &= dem.viewshed(obs.xyz)

print("\n *****Viewshed Done**** \n")
# ---- Run Tracker ----
xy = []
xy0 = np.array((7361411.0, 533528.0))
#xy.append(xy0)

xy = xy0  #qu+ np.vstack([xy for xy in itertools.product(range(-200, 200, 25), range(-200, 200, 25))])

# Helheim vels around 0.8 m/day

time_unit = datetime.timedelta(days=1)
motion_models = [
Esempio n. 4
0
json = glimpse.helpers.read_json('observers.json',
    object_pairs_hook=collections.OrderedDict)
stations = set([station for x in json for station in x])
station_xy = np.vstack([f['geometry']['coordinates'][:, 0:2]
    for station, f in cg.Stations().items()
    if station in stations])
box = glimpse.helpers.bounding_box(cg.Glacier())
XY = glimpse.helpers.box_to_grid(box, step=(grid_size, grid_size),
    snap=(0, 0), mode='grid')
xy = glimpse.helpers.grid_to_points(XY)
distances = glimpse.helpers.pairwise_distance(xy, station_xy, metric='euclidean')
selected = distances.min(axis=1) < max_distance
box = glimpse.helpers.bounding_box(xy[selected]) + 0.5 * np.array([-1, -1, 1, 1]) * grid_size
shape = np.diff([box[1::2], box[0::2]], axis=1) / grid_size
dem_template = glimpse.Raster(np.ones(shape.astype(int).ravel(), dtype=bool),
    x=box[0::2], y=box[1::2][::-1])
dem_points = glimpse.helpers.grid_to_points((dem_template.X, dem_template.Y))

# ---- Select DEMs ----

dem_sigmas = {
    'aerometric': 1.5,
    'ifsar': 1.5 + 0.5, # additional time uncertainty
    'arcticdem': 3,
    'tandem': 3 # after bulk corrections
}
dem_keys = [
    ('20040618', 'aerometric'),
    ('20040707', 'aerometric'),
    ('20050811', 'aerometric'),
Esempio n. 5
0
import cg
from cg import glimpse
from glimpse.imports import (datetime, np, os, shapely, re, matplotlib, scipy)
import glob
root = '/volumes/science/data/columbia'

grid_step = (100, 100)  # m

# ---- Build template ----

box = glimpse.helpers.bounding_box(cg.Glacier())
x, y = glimpse.helpers.box_to_grid(box,
                                   step=grid_step,
                                   snap=(0, 0),
                                   mode='vectors')
template = glimpse.Raster(np.ones((len(y), len(x)), dtype=float),
                          x=x,
                          y=y[::-1])
points = glimpse.helpers.grid_to_points((template.X, template.Y))

# ---- Select velocity grids ----

velocity_keys = [
    ('20040618_20040707', 'aerometric'),
    ('20050811_20050827', 'aerometric'),
    ('20060712_20060727', 'aerometric'),
    ('20090803_20090827', 'aerometric'),
    ('20100525_20100602', 'aerometric'),
    ('20110211_20110222', 'terrasar'),
    ('20110222_20110305', 'terrasar'),
    ('20110305_20110316', 'terrasar'),