def dem(suffix=''): # This DEM covers a larger area, but doesn't have the extra processing # around the junction base_fn = os.path.join(here, "junction-composite-dem.tif") if suffix == '': jct_fn = os.path.join(here, 'junction-composite-20190117-no_adcp.tif') elif suffix == 'smooth': jct_fn = os.path.join(here, 'junction-composite-20200603-w_smooth.tif') elif suffix == 'smoothadcp': jct_fn = os.path.join(here, 'junction-composite-20200604-w_smooth.tif') elif suffix == 'smoothadcp2': # this includes adcp-derived bathy above the junction, while # the above uses dwr multibeam above the junction jct_fn = os.path.join(here, 'junction-composite-20200605-w_smooth.tif') elif suffix == 'adcp': jct_fn = None else: raise Exception("Unknown bathy suffix/version: %s" % suffix) if jct_fn is not None: # Specify priority to be sure jct fn wins out f = field.MultiRasterField([(jct_fn, 10), (base_fn, 0)]) else: f = field.GdalGrid(base_fn) return f
def factory(attrs): geo_bounds = attrs['geom'].bounds if attrs['src_name'].startswith('py:'): expr = attrs['src_name'][3:] # something like 'ConstantField(-1.0)' # a little sneaky... make it look like it's running # after a "from stompy.spatial.field import *" # and also it gets fields of the shapefile field_hash = dict(field.__dict__) # convert the attrs into a dict suitable for passing to eval attrs_dict = {} for name in attrs.dtype.names: attrs_dict[name] = attrs[name] return eval(expr, field_hash, attrs_dict) # Otherwise assume src_name is a file name or file pattern. for p in paths: full_path = os.path.join(p, attrs['src_name']) files = glob.glob(full_path) if len(files) > 1: mrf = field.MultiRasterField(files) return mrf elif len(files) == 1: gg = field.GdalGrid(files[0], geo_bounds=geo_bounds) gg.default_interpolation = 'linear' return gg log.warning("Source %s was not found -- ignoring" % attrs['src_name']) return None
def dem(): srcs = [ os.path.join( data_root, "bathy_interp/master2017/tiles_2m_20171024/merged_2m.tif"), os.path.join(data_root, "bathy_dwr/gtiff/dem_bay_delta*.tif"), os.path.join(data_root, "ncei/coastal_relief-farallones_clip-utm-merge.tif") ] mrf = field.MultiRasterField(srcs) return mrf
def factory(attrs): geo_bounds = attrs['geom'].bounds if attrs['src_name'] == 'dwr_2m_dems': mrf = field.MultiRasterField([os.path.join(dwr_dem_path, "*_2m*tif")]) return mrf elif attrs['src_name'] == 'dwr_10m_dems': #mrf=field.MultiRasterField([os.path.join(dwr_dem_path,"dem_bay_delta_10m_v3_20121109_*.tif")]) # In this case there is only one that matters -- tile 4. gg = field.GdalGrid(os.path.join( dwr_dem_path, "dem_bay_delta_10m_v3_20121109_4.tif"), geo_bounds=geo_bounds) gg.default_interpolation = 'linear' return gg elif attrs['src_name'].endswith('.tif'): for p in tif_paths: fn = opj(p, attrs['src_name']) if os.path.exists(fn): gg = field.GdalGrid(fn, geo_bounds=geo_bounds) gg.default_interpolation = 'linear' return gg raise Exception("Could not find tif %s" % attrs['src_name']) elif attrs['src_name'].startswith('py:'): expr = attrs['src_name'][3:] # something like 'ConstantField(-1.0)' # a little sneaky... make it look like it's running # after a "from stompy.spatial.field import *" # and also it gets fields of the shapefile field_hash = dict(field.__dict__) # convert the attrs into a dict suitable for passing to eval attrs_dict = {} for name in attrs.dtype.names: attrs_dict[name] = attrs[name] return eval(expr, field_hash, attrs_dict) assert False
import pandas as pd import matplotlib.pyplot as plt from matplotlib import cm, collections import numpy as np from shapely import ops ## upper_ll = [-120.930408, 37.309940] lower_ll = [-121.271098, 37.691794] release_xy = proj_utils.mapper('WGS84', 'EPSG:26910')([upper_ll, lower_ll]) ## dem_mrg = field.MultiRasterField([ "../../../bathy/junction-composite-20200605-w_smooth.tif", "/home/rusty/data/bathy_dwr/gtiff/dem_bay_delta_10m_v3_20121109_2.tif" ]) clip = (646390., 648336., 4184677., 4187210.) dem = dem_mrg.extract_tile(clip) ## aerial = field.GdalGrid( "../../../gis/aerial/m_3712114_sw_10_h_20160621_20161004-UTM.tif") aerial.F = aerial.F[:, :, :3] # drop alpha - seems mis-scaled ## #grid=unstructured_grid.UnstructuredGrid.read_ugrid("../../../model/grid/snubby_junction/snubby-06.nc") grid = unstructured_grid.UnstructuredGrid.read_ugrid( "../../../model/suntans/snubby-08-edit60-with_bathysmooth.nc")
@memoize.memoize() def lidar_mask(): mask = np.isfinite(levee_burn().F) mask_open = ndimage.binary_dilation(mask, iterations=5) lidar_mask = field.SimpleGrid(extents=levee_burn().extents, F=mask_open) return lidar_mask #plt.figure(1).clf() ; lidar_mask.plot() ## lidar_src = field.MultiRasterField(["../bathy/lidar/tiles/*.tif"]) @memoize.memoize() def lidar_resamp(): lidar_resamp_fn = 'lidar-levees.tif' if not os.path.exists(lidar_resamp_fn): # Will compile the lidar data here: lidar_levees = field.SimpleGrid(extents=lidar_mask().extents, F=np.zeros(lidar_mask().F.shape, np.float32)) lidar_levees.F[:, :] = np.nan lidar_resamp = lidar_src.to_grid(bounds=lidar_mask().extents, dx=lidar_mask().dx,
from stompy.spatial import field from stompy.grid import unstructured_grid g = unstructured_grid.UnTRIM08Grid('junction_29_w_depth_2007.grd') g.delete_cell_field('subgrid') g.delete_edge_field('subgrid') ## # There is too much weird stuff in the depth data on that grid. # Start over from DEMs mrf = field.MultiRasterField(["/Users/rusty/data/bathy_dwr/gtiff/*.tif"]) ## edge_xy = g.edges_center() g.add_edge_field('depth', mrf(edge_xy)) ## g.add_node_field('depth', mrf(g.nodes['x'])) ## from stompy.grid import depth_connectivity six.moves.reload_module(depth_connectivity)