def show_extent(extent, context=None): ''' Show the region covered by extent, plotted against the supplied context (default to continental) :param extent: extent of interest :param context: extent to plot relative to, defaults to extent.default() :return: None ''' if context is None: context = extents.default() c_ext = extent.translate_to_origin(context.geospatial_reference()) to_plot = _od() to_plot.extent = context to_plot.data = _np.ma.ones(context.shape) to_plot.data.mask = context.mask to_plot.data[c_ext.indices()][c_ext.mask == False] = 2.0 gridview = _layout.GridView(1, 1) cmap = _layout.highlight_map((0.1, 0.3, 0.1), (1.0, 0, 0), (0.1, 0.4, 0.8)) gridview[0, 0] = _layout.NoBarView(to_plot, { 'title': extent.__repr__(), 'cmap': cmap }) gridview.draw()
def test_extent_all(): e = extents.default() print(e.shape) assert (e.shape == extents.load_mask_grid().shape) print(len(e.cell_list())) assert (len(e.cell_list()) == 281655)
def test_big_filewrite(): import awrams.models.awral.settings as settings settings.CLIMATE_DATA = '/mnt/awramsi_test_data/AWAP/' from awrams.utils import extents from awrams.utils import datetools as dt outputs = build_output_graph() test_simple_outputs(dt.dates('2000-2015'), extents.default(), output_mapping=outputs)
def __init__(self, data, extent=None): self.data = data if extent is None: self.coords = extent_to_spatial_coords(default()) else: self.coords = extent_to_spatial_coords(extent) if (len(self.coords[0]), len(self.coords[1])) != data.shape: Exception("data array shape does not match extent shape")
def test_contains(): bb0 = extents.from_boundary_offset(0, 0, 399, 399) bb1 = extents.from_boundary_offset(50, 50, 100, 100) assert bb0.contains(bb1) assert not bb1.contains(bb0) assert bb0.contains(extents.from_cell_offset(250, 250)) assert extents.default().contains(bb0)
def test_catchment_contains(): try: from osgeo import ogr except ImportError: return cdb = CatchmentDB() c = cdb.get_by_id(410033) assert (c.contains(c)) assert default().contains(c)
def __init__(self, path, nc_var, mode='r+', extent=None): self.file_manager_type = FlatFileManager self.fm = None #SplitFileManager.open_existing(path,pattern,nc_var) self.path = path self.nc_var = nc_var self._file_mode = mode self.coords = None if extent is None: self.coords = extent_to_spatial_coords(default()) else: self.coords = extent_to_spatial_coords(extent) self._init = True self._open = True
def test_contains(): e = extents.default() b1 = extents.from_boundary_offset(200, 200, 210, 210) assert e.contains(b1) b2 = extents.from_boundary_offset(675, 835, 685, 845) assert not e.contains(b2) b3 = extents.from_boundary_offset(700, 900, 710, 910) assert not e.contains(b3) # translate parent_ref to local (from global) b1t = b1.translate_localise_origin() assert e.contains(b1t)
def __init__(self, control_p, req_p, read_ahead=3): ctx = zmq.Context() self.control_s = ctx.socket(zmq.PUSH) self.control_s.connect(control_p) self.req_s = ctx.socket(zmq.PAIR) self.req_s.bind(req_p) self.client_logger = configure_logging_to_zmq_client(self.req_s) self.pid = os.getpid() self.cur_ds = {} self.variables = [] self.cur_data = {} self.read_ahead = read_ahead self.data_extent = extents.default()
def test_output_graph_processing_flatfm(): from awrams.utils import extents from awrams.utils import datetools as dt import awrams.models.awral.description awrams.models.awral.description.CLIMATE_DATA = os.path.join( os.path.dirname(__file__), '..', '..', 'test_data', 'simulation') from awrams.utils.nodegraph import nodes, graph from awrams.simulation.ondemand import OnDemandSimulator from awrams.models import awral input_map = awral.get_default_mapping() output_map = { 's0_save': nodes.write_to_ncfile(os.path.dirname(__file__), 's0', extent=extents.default()) } # outputs = graph.OutputGraph(output_map) runner = OnDemandSimulator(awral, input_map.mapping, omapping=output_map) print("RUNNER NEW: multiple cells, multiple years") period = dt.dates('2010-2012') extent = extents.from_boundary_offset(200, 200, 201, 201) r = runner.run(period, extent) output_map = { 's0_save': nodes.write_to_ncfile(os.path.dirname(__file__), 's0', mode='r+') } # outputs = graph.OutputGraph(output_map) runner = OnDemandSimulator(awral, input_map.mapping, omapping=output_map) print("RUNNER NEW (FILES EXISTING): multiple cells, multiple years") period = dt.dates('2013-2014') extent = extents.from_boundary_offset(200, 200, 201, 201) r = runner.run(period, extent) print("RUNNER OLD (FILES EXISTING): single cell, single year") period = dt.dates('2015') extent = extents.from_cell_offset(202, 202) r = runner.run(period, extent)
def set_inputs(self, file_maps): self.file_maps = file_maps self.variables = [] for v in list(self.file_maps.keys()): self.variables.append(v) self.cur_ds[v] = None ref_ds = db_opener(list(self.file_maps[v].values())[0], 'r') lats = ref_ds.variables['latitude'] lons = ref_ds.variables['longitude'] #+++ # Only here since climate data still has wider extents than our mask grid if len(lats) > 681 or len(lons) > 841: self.data_extent = extents.default() else: self.data_extent = extents.from_boundary_coords( lats[0], lons[0], lats[-1], lons[-1]) ref_ds.close() self.req_s.send_pyobj(message('OK'))