Example #1
0
def main():
    """main program"""
    arguments = parse_args()

    if arguments.color:
        colorlogs()
        # redirect stdout to /dev/null under osx so we get only 1 output stream
        f = open(os.devnull, 'w')
        sys.stderr = f

    logger.info('Subgridpy')
    logger.setLevel(logging.DEBUG)

    if arguments.scenariodir:
        logger.info('Using scenario dir: %s' % arguments.scenariodir)

    scenario = EventContainer(arguments.scenariodir)
    # scenario events from arguments
    if arguments.bui:
        if str(arguments.bui) in AREA_WIDE_RAIN.keys():
            scenario.add(
                AreaWideGrid, sim_time_start=0, sim_time_end=None,
                rain_definition=str(arguments.bui), type=None)
    if arguments.radar:
        scenario.add(
            RadarGrid, sim_time_start=0, sim_time_end=None,
            radar_dt=arguments.radar, sync=1, multiplier=1, type=None)

    logger.info('---- Scenario summary ----')
    for line in scenario.summary():
        logger.info(line)


    subgrid = SubgridWrapper(mdu=arguments.mdu,
                             set_logger=arguments.verbose,
                             output_dir=arguments.outputdir)

    subgrid.start()
    # Should not be needed
    # subgrid.library.initmodel()

    rain_grid_container = RainGridContainer(subgrid)
    if arguments.radar:
        subgrid.subscribe_dataset(rain_grid_container.memcdf_name)

    if arguments.tend:
        t_end = arguments.tend
    else:
        # default
        t_end = subgrid.get_nd('tend')
    logger.info('End time (seconds): %r', t_end)

    t = subgrid.get_nd('t1')  # by reference
    while t < t_end:
        apply_events(subgrid, scenario, rain_grid_container)
        subgrid.update(-1)
        t = subgrid.get_nd('t1')  # by reference

    clean_events(scenario, rain_grid_container)
            logger.info("loaded 1d levee testcase")
            for i in xrange(100):
                subgrid.update(-1)
            mode = 1
            value = 30
            size = 45.0
            xc = 147790
            yc = 527080
            node = 231
            dps_pre = subgrid.get_nd('dps').copy()
            subgrid.changebathy(xc, yc, size, value, mode)
            dps_post = subgrid.get_nd('dps').copy()

            quad_grid = make_quad_grid(subgrid)
            nods = set(quad_grid[100:110, 100:110].ravel())
            dps_pre = subgrid.get_nd('dps')
            dps_pre[100:110, 100:110] = dps_pre[100:110, 100:110] + 5.0

            subgrid.update_tables('dps', list(nods))
            for i in xrange(100):
                subgrid.update(-1)
            dps_post = subgrid.get_nd('dps').copy()
            npt.assert_allclose(dps_post, dps_pre, rtol=0.01)


if __name__ == '__main__':
    # run test from command line
    colorlogs()
    logging.basicConfig(level=logging.DEBUG)
    unittest.main()
Example #3
0
"""
Test the library on desired behavior by running it on several models.
"""
import os
import unittest

from python_subgrid.tests.utils import colorlogs
from python_subgrid.tools.scenario import EventContainer
from python_subgrid.tools.scenario import RadarGrid

colorlogs()
# We don't want to know about ctypes here
# only in the test_wrapper and the wrapper itself.


class TestCase(unittest.TestCase):
    def setUp(self):
        self.scenario_path = "python_subgrid/tests/scenario"
        self.radar_grid_path = os.path.join(self.scenario_path, EventContainer.radar_grids_filename)
        self.area_wide_rain_grid_path = os.path.join(self.scenario_path, EventContainer.area_wide_rain_grids_filename)
        self.radar_url_template = (
            "http://opendap.nationaleregenradar.nl/"
            "thredds/dodsC/radar/TF0005_A/{year}/{month}/01/"
            "RAD_TF0005_A_{year}{month}01000000.h5"
        )

    def tearDown(self):
        pass

    def test_smoke(self):
        EventContainer()
def main():
    """main program"""
    arguments = parse_args()

    if arguments.color:
        colorlogs()
        # redirect stdout to /dev/null under osx so we get only 1 output stream
        f = open(os.devnull, 'w')
        sys.stderr = f

    logger.info('Subgridpy')
    logger.setLevel(logging.DEBUG)

    if arguments.scenariodir:
        logger.info('Using scenario dir: %s' % arguments.scenariodir)

    scenario = EventContainer(arguments.scenariodir)
    # scenario events from arguments
    if arguments.bui:
        if str(arguments.bui) in AREA_WIDE_RAIN.keys():
            scenario.add(AreaWideGrid,
                         sim_time_start=0,
                         sim_time_end=None,
                         rain_definition=str(arguments.bui),
                         type=None)
    if arguments.radar:
        scenario.add(RadarGrid,
                     sim_time_start=0,
                     sim_time_end=None,
                     radar_dt=arguments.radar,
                     sync=1,
                     multiplier=1,
                     type=None)

    logger.info('---- Scenario summary ----')
    for line in scenario.summary():
        logger.info(line)

    subgrid = SubgridWrapper(mdu=arguments.mdu,
                             set_logger=arguments.verbose,
                             output_dir=arguments.outputdir)

    subgrid.start()
    # Should not be needed
    # subgrid.library.initmodel()

    rain_grid_container = RainGridContainer(subgrid)
    if arguments.radar:
        subgrid.subscribe_dataset(rain_grid_container.memcdf_name)

    if arguments.tend:
        t_end = arguments.tend
    else:
        # default
        t_end = subgrid.get_nd('tend')
    logger.info('End time (seconds): %r', t_end)

    t = subgrid.get_nd('t1')  # by reference
    while t < t_end:
        apply_events(subgrid, scenario, rain_grid_container)
        subgrid.update(-1)
        t = subgrid.get_nd('t1')  # by reference

    clean_events(scenario, rain_grid_container)