prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Predictor does not reset the scene's aoi_geometries and the raster source's extent_crop
  Currently, the `Predictor` re-uses a `SceneConfig` from the pipeline config in the bundle (instead of creating a new one) and resets its `label_source` and `aoi_uris`.
  https://github.com/azavea/raster-vision/blob/master/rastervision_core/rastervision/core/predictor.py#L70-L71
  
  However, it should also do this for `raster_source.extent_crop` (#1030) and `aoi_geometries` (#1033). In general, it should be done for every field that cannot be safely assumed to be the same for the input scene.
  
  Instead of having to add to this every time something new is added to the `SceneConfig` or any of its member classes, it might be better to create a new scene in the predictor with options from the command line.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `rastervision_core/rastervision/core/predictor.py`
  Content:
  ```
  1 from os.path import join
  2 import zipfile
  3 import logging
  4 
  5 from rastervision.pipeline import rv_config
  6 from rastervision.pipeline.config import (build_config, upgrade_config)
  7 from rastervision.pipeline.file_system.utils import (download_if_needed,
  8                                                      make_dir, file_to_json)
  9 from rastervision.core.data.raster_source import ChannelOrderError
  10 from rastervision.core.analyzer import StatsAnalyzerConfig
  11 
  12 log = logging.getLogger(__name__)
  13 
  14 
  15 class Predictor():
  16     """Class for making predictions based off of a model bundle."""
  17 
  18     def __init__(self,
  19                  model_bundle_uri,
  20                  tmp_dir,
  21                  update_stats=False,
  22                  channel_order=None):
  23         """Creates a new Predictor.
  24 
  25         Args:
  26             model_bundle_uri: URI of the model bundle to use. Can be any
  27                 type of URI that Raster Vision can read.
  28             tmp_dir: Temporary directory in which to store files that are used
  29                 by the Predictor. This directory is not cleaned up by this
  30                 class.
  31             channel_order: Option for a new channel order to use for the
  32                 imagery being predicted against. If not present, the
  33                 channel_order from the original configuration in the predict
  34                 package will be used.
  35         """
  36         self.tmp_dir = tmp_dir
  37         self.update_stats = update_stats
  38         self.model_loaded = False
  39 
  40         bundle_path = download_if_needed(model_bundle_uri, tmp_dir)
  41         bundle_dir = join(tmp_dir, 'bundle')
  42         make_dir(bundle_dir)
  43         with zipfile.ZipFile(bundle_path, 'r') as bundle_zip:
  44             bundle_zip.extractall(path=bundle_dir)
  45 
  46         config_path = join(bundle_dir, 'pipeline-config.json')
  47         config_dict = file_to_json(config_path)
  48         rv_config.set_everett_config(
  49             config_overrides=config_dict.get('rv_config'))
  50         config_dict = upgrade_config(config_dict)
  51         self.config = build_config(config_dict)
  52         self.scene = self.config.dataset.validation_scenes[0]
  53 
  54         if not hasattr(self.scene.raster_source, 'uris'):
  55             raise Exception(
  56                 'raster_source in model bundle must have uris as field')
  57 
  58         if not hasattr(self.scene.label_store, 'uri'):
  59             raise Exception(
  60                 'label_store in model bundle must have uri as field')
  61 
  62         for t in self.scene.raster_source.transformers:
  63             t.update_root(bundle_dir)
  64 
  65         if self.update_stats:
  66             stats_analyzer = StatsAnalyzerConfig(
  67                 output_uri=join(bundle_dir, 'stats.json'))
  68             self.config.analyzers = [stats_analyzer]
  69 
  70         self.scene.label_source = None
  71         self.scene.aoi_uris = None
  72         self.config.dataset.train_scenes = [self.scene]
  73         self.config.dataset.validation_scenes = [self.scene]
  74         self.config.dataset.test_scenes = []
  75         self.config.train_uri = bundle_dir
  76 
  77         if channel_order is not None:
  78             self.scene.raster_source.channel_order = channel_order
  79 
  80         self.pipeline = None
  81 
  82     def predict(self, image_uris, label_uri, vector_label_uri=None):
  83         """Generate predictions for the given image.
  84 
  85         Args:
  86             image_uris: URIs of the images to make predictions against.
  87                 This can be any type of URI readable by Raster Vision
  88                 FileSystems.
  89             label_uri: URI to save labels off into
  90             vector_label_uri: URI to save vectorized labels for semantic segmentation
  91                 model bundles that support it
  92         """
  93         if self.pipeline is None:
  94             self.scene.raster_source.uris = image_uris
  95             self.pipeline = self.config.build(self.tmp_dir)
  96             if not hasattr(self.pipeline, 'predict'):
  97                 raise Exception(
  98                     'pipeline in model bundle must have predict method')
  99 
  100         try:
  101             self.scene.raster_source.uris = image_uris
  102             self.scene.label_store.uri = label_uri
  103             if (hasattr(self.scene.label_store, 'vector_output')
  104                     and self.scene.label_store.vector_output):
  105                 if vector_label_uri:
  106                     for vo in self.scene.label_store.vector_output:
  107                         vo.uri = join(
  108                             vector_label_uri, '{}-{}.json'.format(
  109                                 vo.class_id, vo.get_mode()))
  110                 else:
  111                     self.scene.label_store.vector_output = []
  112             elif vector_label_uri:
  113                 log.warn(
  114                     'vector_label_uri was supplied but this model bundle does not '
  115                     'generate vector labels.')
  116 
  117             if self.update_stats:
  118                 self.pipeline.analyze()
  119             self.pipeline.predict()
  120         except ChannelOrderError:
  121             raise ValueError(
  122                 'The predict package is using a channel_order '
  123                 'with channels unavailable in the imagery.\nTo set a new '
  124                 'channel_order that only uses channels available in the '
  125                 'imagery, use the --channel-order option.')
  126
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/rastervision_core/rastervision/core/predictor.py b/rastervision_core/rastervision/core/predictor.py
  --- a/rastervision_core/rastervision/core/predictor.py
  +++ b/rastervision_core/rastervision/core/predictor.py
  @@ -69,6 +69,9 @@
   
           self.scene.label_source = None
           self.scene.aoi_uris = None
  +        self.scene.aoi_geometries = None
  +        self.scene.raster_source.extent_crop = None
  +
           self.config.dataset.train_scenes = [self.scene]
           self.config.dataset.validation_scenes = [self.scene]
           self.config.dataset.test_scenes = []
  
verification_info: {"golden_diff": "diff --git a/rastervision_core/rastervision/core/predictor.py b/rastervision_core/rastervision/core/predictor.py\n--- a/rastervision_core/rastervision/core/predictor.py\n+++ b/rastervision_core/rastervision/core/predictor.py\n@@ -69,6 +69,9 @@\n \n         self.scene.label_source = None\n         self.scene.aoi_uris = None\n+        self.scene.aoi_geometries = None\n+        self.scene.raster_source.extent_crop = None\n+\n         self.config.dataset.train_scenes = [self.scene]\n         self.config.dataset.validation_scenes = [self.scene]\n         self.config.dataset.test_scenes = []\n", "issue": "Predictor does not reset the scene's aoi_geometries and the raster source's extent_crop\nCurrently, the `Predictor` re-uses a `SceneConfig` from the pipeline config in the bundle (instead of creating a new one) and resets its `label_source` and `aoi_uris`.\r\nhttps://github.com/azavea/raster-vision/blob/master/rastervision_core/rastervision/core/predictor.py#L70-L71\r\n\r\nHowever, it should also do this for `raster_source.extent_crop` (#1030) and `aoi_geometries` (#1033). In general, it should be done for every field that cannot be safely assumed to be the same for the input scene.\r\n\r\nInstead of having to add to this every time something new is added to the `SceneConfig` or any of its member classes, it might be better to create a new scene in the predictor with options from the command line.\n", "before_files": [{"content": "from os.path import join\nimport zipfile\nimport logging\n\nfrom rastervision.pipeline import rv_config\nfrom rastervision.pipeline.config import (build_config, upgrade_config)\nfrom rastervision.pipeline.file_system.utils import (download_if_needed,\n                                                     make_dir, file_to_json)\nfrom rastervision.core.data.raster_source import ChannelOrderError\nfrom rastervision.core.analyzer import StatsAnalyzerConfig\n\nlog = logging.getLogger(__name__)\n\n\nclass Predictor():\n    \"\"\"Class for making predictions based off of a model bundle.\"\"\"\n\n    def __init__(self,\n                 model_bundle_uri,\n                 tmp_dir,\n                 update_stats=False,\n                 channel_order=None):\n        \"\"\"Creates a new Predictor.\n\n        Args:\n            model_bundle_uri: URI of the model bundle to use. Can be any\n                type of URI that Raster Vision can read.\n            tmp_dir: Temporary directory in which to store files that are used\n                by the Predictor. This directory is not cleaned up by this\n                class.\n            channel_order: Option for a new channel order to use for the\n                imagery being predicted against. If not present, the\n                channel_order from the original configuration in the predict\n                package will be used.\n        \"\"\"\n        self.tmp_dir = tmp_dir\n        self.update_stats = update_stats\n        self.model_loaded = False\n\n        bundle_path = download_if_needed(model_bundle_uri, tmp_dir)\n        bundle_dir = join(tmp_dir, 'bundle')\n        make_dir(bundle_dir)\n        with zipfile.ZipFile(bundle_path, 'r') as bundle_zip:\n            bundle_zip.extractall(path=bundle_dir)\n\n        config_path = join(bundle_dir, 'pipeline-config.json')\n        config_dict = file_to_json(config_path)\n        rv_config.set_everett_config(\n            config_overrides=config_dict.get('rv_config'))\n        config_dict = upgrade_config(config_dict)\n        self.config = build_config(config_dict)\n        self.scene = self.config.dataset.validation_scenes[0]\n\n        if not hasattr(self.scene.raster_source, 'uris'):\n            raise Exception(\n                'raster_source in model bundle must have uris as field')\n\n        if not hasattr(self.scene.label_store, 'uri'):\n            raise Exception(\n                'label_store in model bundle must have uri as field')\n\n        for t in self.scene.raster_source.transformers:\n            t.update_root(bundle_dir)\n\n        if self.update_stats:\n            stats_analyzer = StatsAnalyzerConfig(\n                output_uri=join(bundle_dir, 'stats.json'))\n            self.config.analyzers = [stats_analyzer]\n\n        self.scene.label_source = None\n        self.scene.aoi_uris = None\n        self.config.dataset.train_scenes = [self.scene]\n        self.config.dataset.validation_scenes = [self.scene]\n        self.config.dataset.test_scenes = []\n        self.config.train_uri = bundle_dir\n\n        if channel_order is not None:\n            self.scene.raster_source.channel_order = channel_order\n\n        self.pipeline = None\n\n    def predict(self, image_uris, label_uri, vector_label_uri=None):\n        \"\"\"Generate predictions for the given image.\n\n        Args:\n            image_uris: URIs of the images to make predictions against.\n                This can be any type of URI readable by Raster Vision\n                FileSystems.\n            label_uri: URI to save labels off into\n            vector_label_uri: URI to save vectorized labels for semantic segmentation\n                model bundles that support it\n        \"\"\"\n        if self.pipeline is None:\n            self.scene.raster_source.uris = image_uris\n            self.pipeline = self.config.build(self.tmp_dir)\n            if not hasattr(self.pipeline, 'predict'):\n                raise Exception(\n                    'pipeline in model bundle must have predict method')\n\n        try:\n            self.scene.raster_source.uris = image_uris\n            self.scene.label_store.uri = label_uri\n            if (hasattr(self.scene.label_store, 'vector_output')\n                    and self.scene.label_store.vector_output):\n                if vector_label_uri:\n                    for vo in self.scene.label_store.vector_output:\n                        vo.uri = join(\n                            vector_label_uri, '{}-{}.json'.format(\n                                vo.class_id, vo.get_mode()))\n                else:\n                    self.scene.label_store.vector_output = []\n            elif vector_label_uri:\n                log.warn(\n                    'vector_label_uri was supplied but this model bundle does not '\n                    'generate vector labels.')\n\n            if self.update_stats:\n                self.pipeline.analyze()\n            self.pipeline.predict()\n        except ChannelOrderError:\n            raise ValueError(\n                'The predict package is using a channel_order '\n                'with channels unavailable in the imagery.\\nTo set a new '\n                'channel_order that only uses channels available in the '\n                'imagery, use the --channel-order option.')\n", "path": "rastervision_core/rastervision/core/predictor.py"}], "after_files": [{"content": "from os.path import join\nimport zipfile\nimport logging\n\nfrom rastervision.pipeline import rv_config\nfrom rastervision.pipeline.config import (build_config, upgrade_config)\nfrom rastervision.pipeline.file_system.utils import (download_if_needed,\n                                                     make_dir, file_to_json)\nfrom rastervision.core.data.raster_source import ChannelOrderError\nfrom rastervision.core.analyzer import StatsAnalyzerConfig\n\nlog = logging.getLogger(__name__)\n\n\nclass Predictor():\n    \"\"\"Class for making predictions based off of a model bundle.\"\"\"\n\n    def __init__(self,\n                 model_bundle_uri,\n                 tmp_dir,\n                 update_stats=False,\n                 channel_order=None):\n        \"\"\"Creates a new Predictor.\n\n        Args:\n            model_bundle_uri: URI of the model bundle to use. Can be any\n                type of URI that Raster Vision can read.\n            tmp_dir: Temporary directory in which to store files that are used\n                by the Predictor. This directory is not cleaned up by this\n                class.\n            channel_order: Option for a new channel order to use for the\n                imagery being predicted against. If not present, the\n                channel_order from the original configuration in the predict\n                package will be used.\n        \"\"\"\n        self.tmp_dir = tmp_dir\n        self.update_stats = update_stats\n        self.model_loaded = False\n\n        bundle_path = download_if_needed(model_bundle_uri, tmp_dir)\n        bundle_dir = join(tmp_dir, 'bundle')\n        make_dir(bundle_dir)\n        with zipfile.ZipFile(bundle_path, 'r') as bundle_zip:\n            bundle_zip.extractall(path=bundle_dir)\n\n        config_path = join(bundle_dir, 'pipeline-config.json')\n        config_dict = file_to_json(config_path)\n        rv_config.set_everett_config(\n            config_overrides=config_dict.get('rv_config'))\n        config_dict = upgrade_config(config_dict)\n        self.config = build_config(config_dict)\n        self.scene = self.config.dataset.validation_scenes[0]\n\n        if not hasattr(self.scene.raster_source, 'uris'):\n            raise Exception(\n                'raster_source in model bundle must have uris as field')\n\n        if not hasattr(self.scene.label_store, 'uri'):\n            raise Exception(\n                'label_store in model bundle must have uri as field')\n\n        for t in self.scene.raster_source.transformers:\n            t.update_root(bundle_dir)\n\n        if self.update_stats:\n            stats_analyzer = StatsAnalyzerConfig(\n                output_uri=join(bundle_dir, 'stats.json'))\n            self.config.analyzers = [stats_analyzer]\n\n        self.scene.label_source = None\n        self.scene.aoi_uris = None\n        self.scene.aoi_geometries = None\n        self.scene.raster_source.extent_crop = None\n\n        self.config.dataset.train_scenes = [self.scene]\n        self.config.dataset.validation_scenes = [self.scene]\n        self.config.dataset.test_scenes = []\n        self.config.train_uri = bundle_dir\n\n        if channel_order is not None:\n            self.scene.raster_source.channel_order = channel_order\n\n        self.pipeline = None\n\n    def predict(self, image_uris, label_uri, vector_label_uri=None):\n        \"\"\"Generate predictions for the given image.\n\n        Args:\n            image_uris: URIs of the images to make predictions against.\n                This can be any type of URI readable by Raster Vision\n                FileSystems.\n            label_uri: URI to save labels off into\n            vector_label_uri: URI to save vectorized labels for semantic segmentation\n                model bundles that support it\n        \"\"\"\n        if self.pipeline is None:\n            self.scene.raster_source.uris = image_uris\n            self.pipeline = self.config.build(self.tmp_dir)\n            if not hasattr(self.pipeline, 'predict'):\n                raise Exception(\n                    'pipeline in model bundle must have predict method')\n\n        try:\n            self.scene.raster_source.uris = image_uris\n            self.scene.label_store.uri = label_uri\n            if (hasattr(self.scene.label_store, 'vector_output')\n                    and self.scene.label_store.vector_output):\n                if vector_label_uri:\n                    for vo in self.scene.label_store.vector_output:\n                        vo.uri = join(\n                            vector_label_uri, '{}-{}.json'.format(\n                                vo.class_id, vo.get_mode()))\n                else:\n                    self.scene.label_store.vector_output = []\n            elif vector_label_uri:\n                log.warn(\n                    'vector_label_uri was supplied but this model bundle does not '\n                    'generate vector labels.')\n\n            if self.update_stats:\n                self.pipeline.analyze()\n            self.pipeline.predict()\n        except ChannelOrderError:\n            raise ValueError(\n                'The predict package is using a channel_order '\n                'with channels unavailable in the imagery.\\nTo set a new '\n                'channel_order that only uses channels available in the '\n                'imagery, use the --channel-order option.')\n", "path": "rastervision_core/rastervision/core/predictor.py"}]}