-
Notifications
You must be signed in to change notification settings - Fork 47
Open
GlacioHack/geoutils
#668Labels
[POC] Conception To reviewTickets needs approval about it conceptionTickets needs approval about it conception
Description
Context
To kick off the implementation of classification layers in an object-oriented way, the first step is to define a base ClassificationLayer class. This class will act as the foundation for all specific classification types (e.g., SegmentationClassificationLayer, SlopeClassificationLayer, FusionClassificationLayer). The purpose of the base class is to encapsulate the common functionality shared by all classification types while allowing flexibility for subclasses to implement their specific logic.
Code
In a new python file classification.py in xDEM source code, write the ClassificationLayer abstract class:
- Define Common Attributes: The base class should define attributes that will be common accross all classification layers, such as:
demDEM on which the classification will be applied to.namename for the classification layer.req_statslist of required statistics to compute (optional, all statistics ingeoutils.Rastercomputed by default).req_stats_classeslist of the classes on which the statistics will be applied (optional, all classes by default).class_namesdict connecting the class names to the class indexes (set toNone).classificationresult of the classification, ageoutils.Maskobject, (set toNone).stats_dictrequired statistics for required classes in a dict (set toNone).
- Abstract Method: Since different classification layers will have their own classification logic (e.g., segmentation masks vs. slope ranges), the base class should declare abstract methods that the subclasses are required to implement, such as
apply_classification(). This method will be used to compute theclassificationattribute, which will be ageoutils.Maskobject, in which each band will represent one class mask. - Statistics computation: A common feature across all classification layers is the ability to compute statistics on the classified pixels (e.g., mean, standard deviation). The base class should provide a
get_stats()method that takes into account the two last attributes. The output, asstatsattribute, should be a dict, in which the first layer represent the classes, and the second the statistics. This method should use for each required classes theDEM.set_mask()to apply the classification mask and theDEM.get_stats()method to compute the required statistics. The result will be a dict stored understatsattribute. - Saving results: An other common feature is the ability to save the results. The
save()method shoud have anoutput_dirin input, and save:- The
classificationobject with theMask.save()method, undername.tif; - The
class_nameattribute, that represents the name of each class in a dict, undername_classes.json; - The
statsattribute, undername_stats.jsonORname_stats.csv.
- The
Documentation
We need to start a documentation page on this subject.
Metadata
Metadata
Assignees
Labels
[POC] Conception To reviewTickets needs approval about it conceptionTickets needs approval about it conception