def test_no_local_data_for_requested_run(self):
        models = [self.transport]
        # Start is after available time
        model = BaseModelController(latitude=self.start_lat,
                                    longitude=self.start_lon,
                                    depth=self.start_depth,
                                    start=datetime.utcnow() +
                                    timedelta(days=30),
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False)

        with self.assertRaises(BaseDataControllerError):
            model.setup_run("/data/lm/tests/pws_das_2014*.nc")

        # Start is OK but Ending is after available time
        model = BaseModelController(latitude=self.start_lat,
                                    longitude=self.start_lon,
                                    depth=self.start_depth,
                                    start=datetime(2014, 1, 1, 0),
                                    step=self.time_step,
                                    nstep=500,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False)

        with self.assertRaises(BaseDataControllerError):
            model.setup_run("/data/lm/tests/pws_das_2014*.nc")
    def test_bad_dataset(self):
        models = [self.transport]
        model = BaseModelController(latitude=self.start_lat,
                                    longitude=self.start_lon,
                                    depth=self.start_depth,
                                    start=self.start_time,
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False)

        with self.assertRaises(BaseDataControllerError):
            model.setup_run("http://example.com/thisisnotadataset.nc")
    def test_bad_dataset(self):
        models = [self.transport]
        model = BaseModelController(latitude=self.start_lat,
                                    longitude=self.start_lon,
                                    depth=self.start_depth,
                                    start=self.start_time,
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False)

        with self.assertRaises(BaseDataControllerError):
            model.setup_run("http://example.com/thisisnotadataset.nc")
    def test_run_10m_shoreline(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat)
        model = BaseModelController(geometry=p,
                                    depth=self.start_depth,
                                    start=self.start_time,
                                    step=self.time_step,
                                    nstep=300,
                                    npart=2,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=True,
                                    shoreline_index_buffer=0.05)

        model.setup_run("/data/lm/tests/pws_das_2014*.nc")
        model.run()

        # Not a caching controller, no cache path should exist
        self.assertFalse(os.path.exists(self.cache_path))
    def test_start_on_land_from_point_no_depth(self):
        # Set the start position and time for the models
        start_lat = 60.15551950079041
        start_lon = -148.1999130249019

        p = Point(start_lon, start_lat)
        models = [self.transport]
        model = BaseModelController(geometry=p,
                                    start=self.start_time,
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=True)

        with raises(ModelError):
            model.setup_run("/data/lm/tests/pws_das_2014*.nc")
            model.run()
    def test_no_local_data_for_requested_run(self):
        models = [self.transport]
        # Start is after available time
        model = BaseModelController(latitude=self.start_lat,
                                    longitude=self.start_lon,
                                    depth=self.start_depth,
                                    start=datetime.utcnow() + timedelta(days=30),
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False)

        with self.assertRaises(BaseDataControllerError):
            model.setup_run("/data/lm/tests/pws_das_2014*.nc")

        # Start is OK but Ending is after available time
        model = BaseModelController(latitude=self.start_lat,
                                    longitude=self.start_lon,
                                    depth=self.start_depth,
                                    start=datetime(2014, 1, 1, 0),
                                    step=self.time_step,
                                    nstep=500,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False)

        with self.assertRaises(BaseDataControllerError):
            model.setup_run("/data/lm/tests/pws_das_2014*.nc")
    def test_time_method_nearest(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat)
        model = BaseModelController(geometry=p,
                                    depth=self.start_depth,
                                    start=self.start_time,
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False,
                                    time_method="nearest")

        model.setup_run("/data/lm/tests/pws_das_2014*.nc")
        model.run(output_formats=self.output_formats,
                  output_path=self.output_path)

        self.assertTrue(
            os.path.exists(
                os.path.join(self.output_path, "simple_trackline.geojson")))
        self.draw_trackline(
            os.path.join(self.output_path, "simple_trackline.geojson"))

        # Not a caching controller, no cache path should exist
        self.assertFalse(os.path.exists(self.cache_path))
    def test_run_from_point_with_wfs_shoreline(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat)
        model = BaseModelController(
            geometry=p,
            depth=self.start_depth,
            start=self.start_time,
            step=self.time_step,
            nstep=self.num_steps,
            npart=self.num_particles,
            models=models,
            use_bathymetry=False,
            use_shoreline=True,
            shoreline_path='http://geo.asascience.com/geoserver/shorelines/ows',
            shoreline_feature='shorelines:10m_land_polygons')

        model.setup_run("/data/lm/tests/pws_das_2014*.nc")
        model.run(output_formats=self.output_formats,
                  output_path=self.output_path)

        self.assertTrue(
            os.path.exists(
                os.path.join(self.output_path, "simple_trackline.geojson")))
        self.draw_trackline(
            os.path.join(self.output_path, "simple_trackline.geojson"))

        # Not a caching controller, no cache path should exist
        self.assertFalse(os.path.exists(self.cache_path))
    def test_run_from_polygon(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat).buffer(0.001)
        model = BaseModelController(geometry=p,
                                    depth=self.start_depth,
                                    start=datetime(2014, 1, 2, 0),
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False,
                                    time_chunk=10,
                                    horiz_chunk=4)

        model.setup_run("/data/lm/tests/pws_das_2014*.nc")
        model.run(output_formats=self.output_formats,
                  output_path=self.output_path)

        self.assertTrue(
            os.path.exists(
                os.path.join(self.output_path, "simple_trackline.geojson")))
        self.draw_trackline(
            os.path.join(self.output_path, "simple_trackline.geojson"))

        # Not a caching controller, no cache path should exist
        self.assertFalse(os.path.exists(self.cache_path))
    def test_time_method_nearest(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat)
        model = BaseModelController(geometry=p,
                                    depth=self.start_depth,
                                    start=self.start_time,
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False,
                                    time_method="nearest")

        model.setup_run("/data/lm/tests/pws_das_2014*.nc")
        model.run(output_formats=self.output_formats, output_path=self.output_path)

        self.assertTrue(os.path.exists(os.path.join(self.output_path, "simple_trackline.geojson")))
        self.draw_trackline(os.path.join(self.output_path, "simple_trackline.geojson"))

        # Not a caching controller, no cache path should exist
        self.assertFalse(os.path.exists(self.cache_path))
    def test_run_from_point_with_wfs_shoreline(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat)
        model = BaseModelController(geometry=p,
                                    depth=self.start_depth,
                                    start=self.start_time,
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=True,
                                    shoreline_path='http://geo.asascience.com/geoserver/shorelines/ows',
                                    shoreline_feature='shorelines:10m_land_polygons')

        model.setup_run("/data/lm/tests/pws_das_2014*.nc")
        model.run(output_formats=self.output_formats, output_path=self.output_path)

        self.assertTrue(os.path.exists(os.path.join(self.output_path, "simple_trackline.geojson")))
        self.draw_trackline(os.path.join(self.output_path, "simple_trackline.geojson"))

        # Not a caching controller, no cache path should exist
        self.assertFalse(os.path.exists(self.cache_path))
    def test_run_from_polygon(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat).buffer(0.001)
        model = BaseModelController(geometry=p,
                                    depth=self.start_depth,
                                    start=datetime(2014, 1, 2, 0),
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=False,
                                    time_chunk=10,
                                    horiz_chunk=4)

        model.setup_run("/data/lm/tests/pws_das_2014*.nc")
        model.run(output_formats=self.output_formats, output_path=self.output_path)

        self.assertTrue(os.path.exists(os.path.join(self.output_path, "simple_trackline.geojson")))
        self.draw_trackline(os.path.join(self.output_path, "simple_trackline.geojson"))

        # Not a caching controller, no cache path should exist
        self.assertFalse(os.path.exists(self.cache_path))
 def test_time_method_bad(self):
     models = [self.transport]
     p = Point(self.start_lon, self.start_lat)
     with self.assertRaises(TypeError):
         BaseModelController(geometry=p,
                             depth=self.start_depth,
                             start=self.start_time,
                             step=self.time_step,
                             nstep=self.num_steps,
                             npart=self.num_particles,
                             models=models,
                             use_bathymetry=False,
                             use_shoreline=False,
                             time_method="umm_what_am_i")
    def test_run_10m_shoreline(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat)
        model = BaseModelController(geometry=p,
                                    depth=self.start_depth,
                                    start=self.start_time,
                                    step=self.time_step,
                                    nstep=300,
                                    npart=2,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=True,
                                    shoreline_index_buffer=0.05)

        model.setup_run("/data/lm/tests/pws_das_2014*.nc")
        model.run()

        # Not a caching controller, no cache path should exist
        self.assertFalse(os.path.exists(self.cache_path))
    def test_start_on_land_from_point_no_depth(self):
        # Set the start position and time for the models
        start_lat = 60.15551950079041
        start_lon = -148.1999130249019

        p = Point(start_lon, start_lat)
        models = [self.transport]
        model = BaseModelController(geometry=p,
                                    start=self.start_time,
                                    step=self.time_step,
                                    nstep=self.num_steps,
                                    npart=self.num_particles,
                                    models=models,
                                    use_bathymetry=False,
                                    use_shoreline=True)

        with raises(ModelError):
            model.setup_run("/data/lm/tests/pws_das_2014*.nc")
            model.run()