Skip to content

Commit d975348

Browse files
authored
Merge pull request #40 from fabianazioti/delete
Improvements
2 parents 497eabc + b8c3468 commit d975348

File tree

10 files changed

+380
-66
lines changed

10 files changed

+380
-66
lines changed

docs/sphinx/cli.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Output::
2020

2121
To list the available classification systems in a service, use the ``classification-systems`` command and provides a URL to the ``--url`` option::
2222

23-
lccs --url 'http://brazildatacube.dpi.inpe.br/dev/lccs/' classification-systems
23+
lccs --url 'https://brazildatacube.dpi.inpe.br/dev/lccs/' classification-systems
2424

2525

2626
The above command will return a list of classification system names as::
@@ -32,21 +32,21 @@ The above command will return a list of classification system names as::
3232

3333
To get more information about a specific classification system, use the ``classification-systems-describe`` command::
3434

35-
lccs --url 'http://brazildatacube.dpi.inpe.br/dev/lccs/' classification-systems-describe --system_name 'PRODES-1.0'
35+
lccs --url 'https://brazildatacube.dpi.inpe.br/dev/lccs/' classification-systems-description --system_name 'PRODES-1.0'
3636

3737
Output::
3838

3939
- authority_name: Projeto de Mapeamento Anual da Cobertura e Uso do Solo no Brasil (MapBiomas)
4040
- description: O Projeto de Mapeamento Anual da Cobertura e Uso do Solo do Brasil é uma iniciativa que envolve uma rede colaborativa com especialistas nos biomas, usos da terra, sensoriamento remoto, SIG e ciência da computação que utiliza processamento em nuvem e classificadores automatizados desenvolvidos e operados a partir da plataforma Google Earth Engine para gerar uma série histórica de mapas anuais de cobertura e uso da terra do Brasil.
4141
- id: 32
42-
- links: [{'href': 'http://brazildatacube.dpi.inpe.br/dev/lccs/classification_system', 'rel': 'parent', 'title': 'Link to this document', 'type': 'application/json'}, ..]
42+
- links: [{'href': 'https://brazildatacube.dpi.inpe.br/dev/lccs/classification_system', 'rel': 'parent', 'title': 'Link to this document', 'type': 'application/json'}, ..]
4343
- name: Mapbiomas5
4444
- version: 5
4545

4646

4747
List the available classes of a classification system, use the ``classes`` command::
4848

49-
lccs --url 'http://brazildatacube.dpi.inpe.br/dev/lccs/' classes --system_name 'PRODES-1.0'
49+
lccs --url 'https://brazildatacube.dpi.inpe.br/dev/lccs/' classes --system_name 'PRODES-1.0'
5050

5151
The above command will return a list of classes of PRODES as::
5252

@@ -59,21 +59,21 @@ The above command will return a list of classes of PRODES as::
5959

6060
To get more information about a specific class, use the ``class-describe`` command::
6161

62-
lccs --url 'http://brazildatacube.dpi.inpe.br/dev/lccs/' class-describe --system_name 'PRODES-1.0' --class_name 'Desflorestamento'
62+
lccs --url 'https://brazildatacube.dpi.inpe.br/dev/lccs/' class-describe --system_name 'PRODES-1.0' --class_name 'Desflorestamento'
6363

6464
The above command will return a::
6565

6666
- classification_system_id: 1
6767
- code: DESFLORESTAMENTO
6868
- description:
6969
- id: 1
70-
- links: [[{'href': 'http://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/1/classes/1', 'rel': 'self', 'title': 'Link to this document', 'type': 'application/json'},...]
70+
- links: [[{'href': 'https://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/1/classes/1', 'rel': 'self', 'title': 'Link to this document', 'type': 'application/json'},...]
7171
- name: Desflorestamento
7272

7373

7474
Retrieve all available classification system mappings, use the ``available-mappings`` command::
7575

76-
lccs --url 'http://brazildatacube.dpi.inpe.br/dev/lccs/' available-mappings --system_name_source 'TerraClass_AMZ'
76+
lccs --url 'https://brazildatacube.dpi.inpe.br/dev/lccs/' available-mappings --system_name_source 'TerraClass_AMZ'
7777

7878
The above command will return a list of classification systems as::
7979

@@ -82,15 +82,15 @@ The above command will return a list of classification systems as::
8282

8383
To get a mapping between classification systems, use the ``mappings`` command::
8484

85-
lccs --url 'http://brazildatacube.dpi.inpe.br/dev/lccs/' mappings --system_id_source 'TerraClass_AMZ' --system_id_target 'PRODES'
85+
lccs --url 'https://brazildatacube.dpi.inpe.br/dev/lccs/' mappings --system_id_source 'TerraClass_AMZ' --system_id_target 'PRODES'
8686

8787

8888
Output::
8989

9090
Classification Source: TerraClass_AMZ
9191
Classification Target: PRODES
92-
{'degree_of_similarity': 1.0, 'description': '', 'links': [{'href': 'http://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/TerraClass_AMZ/classes/Agricultura Anual', 'rel': 'item', 'title': 'Link to the source class', 'type': 'application/json'}, {'href': 'http://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/TerraClass_AMZ/classes/Desmatamento', 'rel': 'item', 'title': 'Link to target class', 'type': 'application/json'}], 'source': 'Agricultura Anual', 'source_id': 85, 'target': 'Desmatamento', 'target_id': 175}
93-
{'degree_of_similarity': 1.0, 'description': '', 'links': [{'href': 'http://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/TerraClass_AMZ/classes/Área Não Observada', 'rel': 'item', 'title': 'Link to the source class', 'type': 'application/json'}, {'href': 'http://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/TerraClass_AMZ/classes/Nuvem', 'rel': 'item', 'title': 'Link to target class', 'type': 'application/json'}], 'source': 'Área Não Observada', 'source_id': 86, 'target': 'Nuvem', 'target_id': 179}
92+
{'degree_of_similarity': 1.0, 'description': '', 'links': [{'href': 'https://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/TerraClass_AMZ/classes/Agricultura Anual', 'rel': 'item', 'title': 'Link to the source class', 'type': 'application/json'}, {'href': 'https://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/TerraClass_AMZ/classes/Desmatamento', 'rel': 'item', 'title': 'Link to target class', 'type': 'application/json'}], 'source': 'Agricultura Anual', 'source_id': 85, 'target': 'Desmatamento', 'target_id': 175}
93+
{'degree_of_similarity': 1.0, 'description': '', 'links': [{'href': 'https://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/TerraClass_AMZ/classes/Área Não Observada', 'rel': 'item', 'title': 'Link to the source class', 'type': 'application/json'}, {'href': 'https://brazildatacube.dpi.inpe.br/dev/lccs/classification_system/TerraClass_AMZ/classes/Nuvem', 'rel': 'item', 'title': 'Link to target class', 'type': 'application/json'}], 'source': 'Área Não Observada', 'source_id': 86, 'target': 'Nuvem', 'target_id': 179}
9494

9595
.. note::
9696

examples/class_metadata.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
classification_system = service.classification_system('PRODES-1.0')
1818

1919
# Return the metadata of a specific class
20-
class_metadata = classification_system.get_class('Desflorestamento')
21-
print(class_metadata)
20+
class_metadata = classification_system.classes('Desmatamento')
2221

2322
# You can access specific attributes
2423
print(class_metadata.id)

examples/classes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
classification_system = service.classification_system('PRODES-1.0')
1818

1919
# Returns all classes belonging to a specific classification system.
20-
classes = classification_system.classes
20+
classes = classification_system.classes()
2121
print(classes)
2222

examples/ex-01.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
print(class_system.name)
2828

2929
# Return a classes of a classification system
30-
classes = class_system.classes
30+
classes = class_system.classes()
3131
for i in classes:
3232
print(i.name)
3333

3434
# Return a specific class of a classification system
35-
prodes_desflorestamento = class_system.get_class('Desflorestamento')
35+
prodes_desflorestamento = class_system.classes('Desmatamento')
3636
print(prodes_desflorestamento.name)
3737

3838
# Get all available mappings for a specific classification system

lccs/class_system.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, data, validate=False):
2323
"""
2424
self._validate = validate
2525
super(ClassificationSystem, self).__init__(data or {})
26-
self._get_classes()
26+
self['classes'] = dict()
2727

2828
@property
2929
def links(self):
@@ -55,27 +55,27 @@ def authority_name(self):
5555
""":return: authority_name of classification system."""
5656
return self['authority_name']
5757

58-
@property
59-
def classes(self):
58+
def classes(self, class_name=None):
6059
""":return: classes of the classification system."""
61-
return self['classes']
62-
63-
def get_class(self, class_name):
64-
""":return: a specif class of of the classification system."""
65-
for i in self.classes:
66-
if i.name == class_name:
67-
return ClassificationSystemClass(i, self._validate)
68-
69-
def _get_classes(self, filter=None):
70-
""":return: get classes of the classification system.."""
71-
classes = list()
72-
for link in self['links']:
73-
if link['rel'] == 'classes':
74-
data = Utils._get(link['href'], params=filter)
75-
for i in data:
76-
if 'rel' in i and i['rel'] == 'child':
77-
classes.append(ClassificationSystemClass(Utils._get(i['href'], self._validate), self._validate))
78-
self['classes'] = classes
60+
return self._get_classes(class_name)
61+
62+
def _get_classes(self, class_name):
63+
""":return: get classes of the classification system."""
64+
if not bool(self['classes']):
65+
self._classes_links = next(Utils._get(link['href']) for link in self['links'] if link['rel'] == 'classes')
66+
67+
for i in self._classes_links:
68+
if i['rel'] == 'child':
69+
class_data = ClassificationSystemClass(Utils._get(i['href'], self._validate), self._validate)
70+
if 'class_parent_id' in class_data:
71+
parent_class_uri = i['href'].rsplit('/', maxsplit=1)[0] + f'/{class_data.class_parent_id}'
72+
class_data['class_parent_name'] = ClassificationSystemClass(Utils._get(parent_class_uri)).name
73+
self['classes'][f"{class_data.name}"] = class_data
74+
75+
if class_name is not None:
76+
return self['classes'][f'{class_name}'] if class_name in self['classes'].keys() else {}
77+
78+
return self['classes'].values()
7979

8080
def _repr_html_(self):
8181
"""HTML repr."""

lccs/classes.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ def code(self):
4343

4444
@property
4545
def class_parent_id(self):
46-
""":return: the class code."""
47-
return self['class_parent_id']
46+
""":return: the class parent id."""
47+
return self['class_parent_id'] if 'class_parent_id' in self else None
48+
49+
@property
50+
def class_parent_name(self):
51+
""":return: the class parent name."""
52+
return self['class_parent_name'] if 'class_parent_name' in self else None

0 commit comments

Comments
 (0)