Beispiel #1
0
    def processHistoricInsectDisturbances(self, dist):
        pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3], 1).start()
        mpb_shp_severity_to_dist_type_lookup = {
            "V": "Mountain Pine Beetle - Very Severe Impact",
            "S": "Mountain Pine Beetle - Severe Impact",
            "M": "Mountain Pine Beetle - Moderate Impact",
            "L": "Mountain Pine Beetle - Low Impact",
            "4": "Mountain Pine Beetle - Very Severe Impact",
            "3": "Mountain Pine Beetle - Severe Impact",
            "2": "Mountain Pine Beetle - Moderate Impact",
            "1": "Mountain Pine Beetle - Low Impact"
        }

        for file_name in self.scan_for_layers(dist.getWorkspace(), dist.getFilter()):
            file_name_no_ext = os.path.basename(os.path.splitext(file_name)[0])
            year = int(file_name_no_ext[-4:])
            if year in range(self.historic_range[0], self.historic_range[1]+1):
                self.layers.append(DisturbanceLayer(
                    self.rule_manager,
                    VectorLayer("insect_{}".format(year), file_name, Attribute("Severity", substitutions=mpb_shp_severity_to_dist_type_lookup)),
                    year=year,
                    disturbance_type=Attribute("Severity"),
                    transition=TransitionRule(
                        regen_delay=0,
                        age_after=-1)))
        pp.finish()
Beispiel #2
0
 def processRollbackDisturbances(self):
     rollback_dist_lookup = {
         1: "Wild Fires",
         2: "Clearcut harvesting with salvage"
     }
     rollback_name_lookup = {
         1: "fire",
         2: "harvest"
     }
     pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3], 1).start()
     for year in range(self.rollback_range[0], self.rollback_range[1]+1):
         for dist_code in rollback_dist_lookup:
             label = rollback_dist_lookup[dist_code]
             name = rollback_name_lookup[dist_code]
             self.layers.append(DisturbanceLayer(
                 self.rule_manager,
                 VectorLayer("rollback_{}_{}".format(name, year),
                             self.rollback_disturbances.getPath(),
                             [
                                 Attribute("DistYEAR_n", filter=lambda v, yr=year: v == yr),
                                 Attribute("DistType", filter=lambda v, dt=dist_code: v == dt, substitutions=rollback_dist_lookup),
                                 Attribute("RegenDelay")
                             ]),
                 year=year,
                 disturbance_type=Attribute("DistType"),
                 transition=TransitionRule(
                     regen_delay=Attribute("RegenDelay"),
                     age_after=0)))
     pp.finish()
Beispiel #3
0
    def processHistoricHarvestDisturbances(self, dist, sb_percent, cc_dt, sb_dt):
        pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3], 1).start()
        harvest_poly_shp = self.scan_for_layers(dist.getWorkspace(), dist.getFilter())[0]
        _, rollback_end_year = self.rollback_range
        _, historic_end_year = self.historic_range
        year_range = range(rollback_end_year + 1, historic_end_year + 1)
        workspace = self.inventory.getWorkspace()
        if year_range:
            sb = GenerateSlashburn(self.ProgressPrinter)
            sb_shp = sb.generateSlashburn(self.inventory, harvest_poly_shp, dist.getYearField(), year_range, sb_percent)

        for year in year_range:
            self.layers.append(DisturbanceLayer(
                self.rule_manager,
                VectorLayer("harvest_{}".format(year),
                            workspace,
                            Attribute(dist.getYearField(), filter=ValueFilter(year, True)),
                            layer='MergedDisturbances'),
                year=year,
                disturbance_type=cc_dt,
                transition=TransitionRule(
                    regen_delay=0,
                    age_after=0)))
                    
            self.layers.append(DisturbanceLayer(
                self.rule_manager,
                VectorLayer("slashburn_{}".format(year),
                            sb_shp,
                            Attribute(dist.getYearField(), filter=ValueFilter(year, True))),
                year=year,
                disturbance_type=sb_dt,
                transition=TransitionRule(
                    regen_delay=0,
                    age_after=0)))
        pp.finish()
Beispiel #4
0
    def processGenericHistoricDisturbances(self, dist, dist_type_attr, year_attr, dist_type_lookup):
        pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3], 1).start()

        historic_start_year, _ = self.historic_range
        _, future_end_year     = self.future_range
        year_range = range(historic_start_year, future_end_year + 1)
        
        for file_name in self.scan_for_layers(dist.getWorkspace(), dist.getFilter()):
            for year in year_range:
                self.layers.append(DisturbanceLayer(
                    self.rule_manager,
                    VectorLayer("insect_{}".format(year), file_name, Attribute(dist_type_attr, substitutions=dist_type_lookup)),
                    year=Attribute(year_attr, filter=ValueFilter(year, True)),
                    disturbance_type=Attribute(dist_type_attr)))
        pp.finish()
Beispiel #5
0
    def processGeneralLayers(self):
        pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3],1).start()
        general_lyrs = []
        for raster in self.inventory.getRasters():
            if raster.getAttrTable() == None:
                self.layers.append(RasterLayer(raster.getPath()))
            else:
                self.layers.append(RasterLayer(raster.getPath(),
                    nodata_value=255,
                    attributes = [raster.getAttr()],
                    attribute_table = raster.getAttrTable()))
            general_lyrs.append(os.path.basename(raster.getPath()).split('.')[0])

        for attr in self.spatial_boundaries.getAttributes():
            attr_field = self.spatial_boundaries.getAttrField(attr)
            self.layers.append(VectorLayer(attr, self.spatial_boundaries.getPathPSPU(),
                Attribute(attr_field)))
            general_lyrs.append(attr)

        self.layers.append(RasterLayer(self.NAmat.getPath(), nodata_value=1.0e38))
        general_lyrs.append(os.path.basename(self.NAmat.getPath()).split('.')[0])

        pp.finish()

        return general_lyrs
Beispiel #6
0
    def processProjectedDisturbances(self, dist):
        pp = self.ProgressPrinter.newProcess("{}_{}".format(inspect.stack()[0][3],dist.getScenario()), 1).start()
        futureDistTypeLookup = dist.getLookupTable()
        future_start_year = self.future_range[0]

        for file_name in self.scan_for_layers(dist.getWorkspace(), dist.getFilter()):
            file_name_no_ext = os.path.basename(os.path.splitext(file_name)[0])
            year = future_start_year + int(file_name_no_ext.split("_")[-1])
            if year in range(self.historic_range[1]+1, self.future_range[1]+1):
                self.layers.append(DisturbanceLayer(
                    self.rule_manager,
                    VectorLayer("Proj{}_{}".format("Disturbance", year), file_name, Attribute("dist_type_", substitutions=futureDistTypeLookup)),
                    year=year,
                    disturbance_type=Attribute("dist_type_"),
                    transition=TransitionRule(
                        regen_delay=0,
                        age_after=0)))
        pp.finish()
Beispiel #7
0
    def processProjectedDisturbances(self, scenario, params):
        future_start_year, future_end_year = self.future_range
        if future_start_year > future_end_year:
            return
            
        pp = self.ProgressPrinter.newProcess("{}_{}".format(inspect.stack()[0][3], scenario), 1).start()
        percent_sb = params[0]
        actv_percent_sb = params[1]
        actv_percent_harv = params[2]
        placeholder = ProjectedDisturbancesPlaceholder(self.inventory, self.rollback_disturbances,
            self.future_range, self.rollback_range, self.activity_start_year, self.ProgressPrinter)
        projectedDisturbances = placeholder.generateProjectedDisturbances(scenario, percent_sb, actv_percent_sb, actv_percent_harv)

        projected_dist_lookup = {
            7:  "Wild Fires",
            6:  "{} CC".format("Base" if scenario.lower() == "base" else "CBM_{}".format(scenario)),
            13: "SlashBurning"
        }
        
        projected_name_lookup = {
            7:  "fire",
            6:  "harvest",
            13: "slashburn"
        }
        
        for year in range(self.historic_range[1]+1, self.future_range[1]+1):
            for dist_code in projected_dist_lookup:
                label = projected_dist_lookup[dist_code]
                name = projected_name_lookup[dist_code]
                self.layers.append(DisturbanceLayer(
                    self.rule_manager,
                    VectorLayer("projected_{}_{}".format(name, year),
                                projectedDisturbances,
                                [
                                    Attribute("DistYEAR_n", filter=ValueFilter(year)),
                                    Attribute("DistType", filter=ValueFilter(dist_code), substitutions=projected_dist_lookup),
                                    Attribute("RegenDelay")
                                ]),
                    year=year,
                    disturbance_type=Attribute("DistType"),
                    transition=TransitionRule(
                        regen_delay=Attribute("RegenDelay"),
                        age_after=0)))
        pp.finish()
Beispiel #8
0
    def processHistoricInsectDisturbances(self, dist, attr, dist_type_lookup):
        pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3], 1).start()

        historic_start_year, _ = self.historic_range
        _, future_end_year     = self.future_range
        year_range = range(historic_start_year, future_end_year + 1)
        
        for file_name in self.scan_for_layers(dist.getWorkspace(), dist.getFilter()):
            file_name_no_ext = os.path.basename(os.path.splitext(file_name)[0])
            year = int(file_name_no_ext[-4:])
            if year in year_range:
                self.layers.append(DisturbanceLayer(
                    self.rule_manager,
                    VectorLayer("insect_{}".format(year), file_name, Attribute(attr, substitutions=dist_type_lookup)),
                    year=year,
                    disturbance_type=Attribute(attr),
                    transition=TransitionRule(
                        regen_delay=0,
                        age_after=-1)))
        pp.finish()
Beispiel #9
0
 def processHistoricHarvestDisturbances(self, dist):
     pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3], 1).start()
     cutblock_shp = self.scan_for_layers(dist.getWorkspace(), dist.getFilter())[0]
     for year in range(self.rollback_range[1]+1, self.historic_range[1]+1):
         self.layers.append(DisturbanceLayer(
             self.rule_manager,
             VectorLayer("harvest_{}".format(year), cutblock_shp, Attribute("HARV_YR", filter=lambda v, yr=year: v == yr)),
             year=year,
             disturbance_type="Clearcut harvesting with salvage",
             transition=TransitionRule(
                 regen_delay=0,
                 age_after=0)))
     pp.finish()
Beispiel #10
0
    def processRollbackDisturbances(self, dist_lookup, name_lookup):
        pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3], 1).start()

        for year in range(self.rollback_range[0], self.rollback_range[1] + 1):
            for dist_code in dist_lookup:
                label = dist_lookup[dist_code]
                name = name_lookup[dist_code]
                self.layers.append(DisturbanceLayer(
                    self.rule_manager,
                    VectorLayer("rollback_{}_{}".format(name, year),
                                self.rollback_disturbances.getPath(),
                                [
                                    Attribute("DistYEAR_n", filter=ValueFilter(year)),
                                    Attribute("DistType", filter=ValueFilter(dist_code), substitutions=dist_lookup),
                                    Attribute("RegenDelay")
                                ]),
                    year=year,
                    disturbance_type=Attribute("DistType"),
                    transition=TransitionRule(
                        regen_delay=Attribute("RegenDelay"),
                        age_after=0)))
        pp.finish()
Beispiel #11
0
 def processHistoricFireDisturbances(self, dist):
     pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3], 1).start()
     for file_name in self.scan_for_layers(dist.getWorkspace(), dist.getFilter()):
         # Assume filenames are like "Wildfire_1990.shp", "Wildfire_NBAC_1991.shp"
         # i.e. the last 4 characters before the extension are the year.
         file_name_no_ext = os.path.basename(os.path.splitext(file_name)[0])
         year = file_name_no_ext[-4:]
         if year in range(self.rollback_range[1]+1, self.historic_range[1]+1):
             self.layers.append(DisturbanceLayer(
                 self.rule_manager,
                 VectorLayer("fire_{}".format(year), file_name, Attribute("Shape_Leng")),
                 year=year,
                     disturbance_type="Wild Fires",
                     transition=TransitionRule(
                         regen_delay=0,
                         age_after=0)))
     pp.finish()
Beispiel #12
0
    def processHistoricFireDisturbances(self, dist, dt):
        pp = self.ProgressPrinter.newProcess(inspect.stack()[0][3], 1).start()

        _, rollback_end_year = self.rollback_range
        _, historic_end_year = self.historic_range
        workspace = self.inventory.getWorkspace()
        for year in range(rollback_end_year + 1, historic_end_year + 1):
            self.layers.append(DisturbanceLayer(
                self.rule_manager,
                # The [:4] is specifically to deal with the case of NBAC where the year is followed by the date and time
                VectorLayer("fire_{}".format(year),
                            workspace,
                            Attribute(dist.getYearField(), filter=SliceValueFilter(year, slice_len=4)),
                            layer='MergedDisturbances'),
                year=year,
                disturbance_type=dt,
                transition=TransitionRule(
                    regen_delay=0,
                    age_after=0)))
        pp.finish()
Beispiel #13
0
                                os.path.abspath(layer_path),
                                attributes=[
                                    "type", "disturbanceType",
                                    "relDensityUpdate", "fertilityUpdate",
                                    "coverTypeUpdate"
                                ],
                                attribute_table=csv_to_dict(
                                    os.path.join(layer_root, "disturbances",
                                                 "fire_AT.csv"), "ID",
                                    [
                                        "type", "disturbanceType",
                                        "relDensityUpdate", "fertilityUpdate",
                                        "coverTypeUpdate"
                                    ])),
                            year=year,
                            disturbance_type=Attribute("disturbanceType"),
                            transition=TransitionRule(regen_delay=0,
                                                      age_after=0,
                                                      classifiers=[
                                                          "type",
                                                          "disturbanceType",
                                                          "coverTypeUpdate",
                                                          "fertilityUpdate",
                                                          "relDensityUpdate"
                                                      ])))

            else:
                for layer_path in scan_for_layers(
                        os.path.join(layer_root, "disturbances"),
                        d + "_*.tif"):
                    # Extract the year from the filename.