def test_ondemand_region():
    from awrams.utils import extents
    from awrams.simulation.ondemand import OnDemandSimulator
    from awrams.models import awral
    ### test region
    extent = extents.from_boundary_coords(-32, 115, -35, 118)
    sim = OnDemandSimulator(awral,
                            input_map.mapping,
                            omapping=output_map.mapping)
    r = sim.run(period, extent)
def test_server():
    from awrams.utils import extents
    from awrams.simulation.server import Server
    from awrams.models import awral

    extent = extents.from_boundary_coords(-32, 115, -35, 118)

    get_initial_states_dict(input_map, period, extent)
    insert_climatology(input_map)

    sim = Server(awral)
    sim.run(input_map, output_map, period, extent)
Beispiel #3
0
 def get_data(idx, extent, sfm):
     if not extent:
         a = sfm[np.s_[idx, :]]
         return a, 'slice', None
     else:
         try:
             s = [idx]
             s.extend(x for x in extent)
             a = sfm[np.s_[s]]
             return a, 'slice', None
         except:
             gb = from_boundary_coords(*extent, compute_areas=False)
             print(gb.x_size, gb.y_size)
             a = sfm[np.s_[idx,
                           slice(gb.x_min, gb.x_max),
                           slice(gb.y_min, gb.y_max)]]
             extent = (gb.lon_min, gb.lon_max, gb.lat_min, gb.lat_max)
             return a, 'geobounds', extent
Beispiel #4
0
    def __init__(self, inputs, periods, extent, existing_inputs=False):

        if existing_inputs:
            mapped_inputs = inputs
        else:
            from awrams.utils.ts.gridded_time_series import SplitDataSet
            mapped_inputs = dict(
                (k, SplitDataSet(k, path)) for k, path in list(inputs.items()))

        self.bridge = StreamingInputBridge()
        self.bridge.setup(mapped_inputs, periods, extent)

        self.extent = extents.from_boundary_coords(
            *self.bridge.geo_ref.bounds_args(),
            parent_ref=self.bridge.geo_ref,
            compute_areas=False)

        self.cur_chunk = NULL_CHUNK
        self.cur_chunk_idx = -1
        self.cur_period_idx = -1

        self._terminated = False
def test_climatology_region():
    import numpy as np
    from awrams.utils import extents
    from awrams.utils import datetools as dt
    from awrams.simulation.ondemand import OnDemandSimulator
    from awrams.models import awral

    ### test region
    period = dt.dates('dec 2010')
    extent = extents.from_boundary_coords(-32, 115, -35, 118)

    sim = OnDemandSimulator(awral,
                            input_map.mapping)  #,omapping=output_map.mapping)
    r, i = sim.run(period, extent, return_inputs=True)
    ### this should be true
    assert np.isnan(i['solar_f']).any()

    insert_climatology(input_map)
    sim = OnDemandSimulator(awral,
                            input_map.mapping)  #,omapping=output_map.mapping)
    r, i = sim.run(period, extent, return_inputs=True)
    assert not np.isnan(i['solar_f']).any()
    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'))
Beispiel #7
0
    def get_extent(self, use_mask=True):
        from awrams.utils.extents import from_boundary_coords
        lat, lon = self.get_coord('latitude'), self.get_coord('longitude')

        if use_mask is True:
            ref_data = self.awra_var[0]
            if not hasattr(ref_data, 'mask'):
                try:  ### maybe using h5py which doesn't return an ma
                    mask = np.ma.masked_values(
                        ref_data, self.awra_var.attrs['_FillValue'][0])
                    mask = mask.mask
                except AttributeError:
                    mask = False
            else:
                mask = ref_data.mask
        else:
            mask = False

        return from_boundary_coords(lat[0],
                                    lon[0],
                                    lat[-1],
                                    lon[-1],
                                    compute_areas=False,
                                    mask=mask)
def test_initial_states_region():
    import numpy as np

    from awrams.utils import extents
    from awrams.utils import datetools as dt

    from awrams.utils.nodegraph import nodes, graph
    from awrams.simulation.ondemand import OnDemandSimulator
    from awrams.models import awral

    period = dt.dates('dec 2010')
    ### test a region
    extent = extents.from_boundary_offset(400, 170, 407, 177)
    print(extent)

    ### simulation with default initial states
    sim = OnDemandSimulator(awral, input_map.mapping)
    r, i = sim.run(period, extent, return_inputs=True)
    outputs_default = r['final_states']

    ### simulation with initial states read from nc files
    get_initial_states(input_map)
    sim = OnDemandSimulator(awral, input_map.mapping)
    r, i = sim.run(period, extent, return_inputs=True)
    outputs_init = r['final_states']

    ### compare final states with default states simulation
    ### should be different
    for k, o in outputs_init.items():
        assert not (o == outputs_default[k]).any()

    ### save initial states to compare
    ini_states = {}
    for k in i:
        try:
            if k.startswith('init'):
                ini_states[k] = i[k]
        except:
            pass

    ### simulation with initial states read from dict
    get_initial_states_dict(input_map, period, extent)
    sim = OnDemandSimulator(awral, input_map.mapping)
    r, i = sim.run(period, extent, return_inputs=True)
    outputs_init_dict = r['final_states']

    ### compare final states with other ini states simulation
    ### should be same
    for k, o in outputs_init_dict.items():
        assert (o == outputs_init[k]).any()

    ### compare initial states from both methods
    ### should be same
    for k in i:
        try:
            if k.startswith('init'):
                assert ini_states[k] == i[k]
        except:
            pass

    extent = extents.from_boundary_coords(-30, 120.5, -30.35, 120.85)
    print(extent)

    ### simulation with initial states read from nc files
    get_initial_states(input_map)
    sim = OnDemandSimulator(awral, input_map.mapping)
    r, i = sim.run(period, extent, return_inputs=True)
    outputs_init = r['final_states']

    ### compare final states with other ini states simulation
    ### should be same
    for k, o in outputs_init_dict.items():
        assert (o == outputs_init[k]).any()

    ### compare initial states from both methods
    ### should be same
    for k in i:
        try:
            if k.startswith('init'):
                assert ini_states[k] == i[k]
        except:
            pass