def test_no_dap_data_for_requested_run(self):
        models = [self.transport]
        # Start is after available time
        model = CachingModelController(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(
                "http://thredds.axiomalaska.com/thredds/dodsC/PWS_L2_FCST.nc")

        # Start is OK but Ending is after available time
        model = CachingModelController(latitude=self.start_lat,
                                       longitude=self.start_lon,
                                       depth=self.start_depth,
                                       start=datetime.utcnow() -
                                       timedelta(days=2),
                                       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(
                "http://thredds.axiomalaska.com/thredds/dodsC/PWS_L2_FCST.nc")
    def test_run_from_multiple_files_with_cache(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat)
        model = CachingModelController(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,
                                       se_shoreline=False,
                                       time_chunk=10,
                                       horiz_chunk=4)

        model.setup_run("/data/lm/tests/pws_das_2014*.nc",
                        cache_path=self.cache_path,
                        remove_cache=False)
        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"))
        self.assertTrue(os.path.exists(self.cache_path))
        os.remove(self.cache_path)
    def test_timechunk_greater_than_timestep(self):
        models = [self.transport]
        model = CachingModelController(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,
                                       time_chunk=48,
                                       horiz_chunk=2)

        model.setup_run("/data/lm/tests/pws_das_2014*.nc",
                        cache_path=self.cache_path,
                        remove_cache=False)
        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"))

        self.assertTrue(os.path.exists(self.cache_path))
        os.remove(self.cache_path)
    def test_run_from_dap_without_cache(self):
        models = [self.transport]
        p = Point(self.start_lon, self.start_lat)
        model = CachingModelController(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)

        model.setup_run(
            "http://thredds.axiomalaska.com/thredds/dodsC/PWS_L2_FCST.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"))

        # We didn't pass remove_cache=False, so it should have been removed by the CachingModelController.
        self.assertFalse(os.path.exists(self.cache_path))