@@ -291,7 +291,7 @@ def taxonomic_percentajes(df):
291
291
1. Calcula el total de ocurrencias en el DataFrame.
292
292
2. Calcula el porcentaje de géneros que están presentes en el catálogo de vida (Species2000).
293
293
3. Calcula el porcentaje de especies presentes en el DataFrame.
294
- 4. Calcula el porcentaje de calidad para la jerarquía taxonómica.
294
+ 4. Calcula el porcentaje de calidad para la jerarquía taxonómica en tres partes: reuino, clase/orden y familia
295
295
5. Calcula el porcentaje de identificadores disponibles en el DataFrame.
296
296
6. Calcula el porcentaje total de calidad taxonómica combinando los porcentajes ponderados.
297
297
7. Imprime el resultado del porcentaje total de calidad taxonómica.
@@ -330,22 +330,56 @@ def taxonomic_percentajes(df):
330
330
logger .debug (f"ERROR specificEpithet - { e } " )
331
331
percentaje_species = 0
332
332
333
+ # Porcentaje de calidad para el reino
334
+ try :
335
+ percentaje_kingdom = (
336
+ df .value_counts (
337
+ subset = ["kingdom" ],
338
+ dropna = False ,
339
+ )
340
+ .reset_index (name = "N" )
341
+ .apply (kingdom_weights , axis = 1 )
342
+ .sum ()
343
+ / total_data
344
+ * 100
345
+ )
346
+ except Exception as e :
347
+ logger .debug (f"ERROR kingdom - { e } " )
348
+ percentaje_kingdom = 0
349
+
350
+ # Porcentaje de calidad para la jerarquía taxonómica
351
+ try :
352
+ percentaje_class_order = (
353
+ df .value_counts (
354
+ subset = ["class" , "order" ],
355
+ dropna = False ,
356
+ )
357
+ .reset_index (name = "N" )
358
+ .apply (class_order_weights , axis = 1 )
359
+ .sum ()
360
+ / total_data
361
+ * 100
362
+ )
363
+ except Exception as e :
364
+ logger .debug (f"ERROR class_order - { e } " )
365
+ percentaje_class_order = 0
366
+
333
367
# Porcentaje de calidad para la jerarquía taxonómica
334
368
try :
335
- percentaje_hierarchy = (
369
+ percentaje_family = (
336
370
df .value_counts (
337
- subset = ["higherClassification" , "kingdom" , "class" , "order" , " family" ],
371
+ subset = ["family" ],
338
372
dropna = False ,
339
373
)
340
374
.reset_index (name = "N" )
341
- .apply (hierarchy_weights , axis = 1 )
375
+ .apply (family_weights , axis = 1 )
342
376
.sum ()
343
377
/ total_data
344
378
* 100
345
379
)
346
380
except Exception as e :
347
- logger .debug (f"ERROR hierarchy - { e } " )
348
- percentaje_hierarchy = 0
381
+ logger .debug (f"ERROR family - { e } " )
382
+ percentaje_family = 0
349
383
350
384
# Porcentaje de identificadores disponibles en el DataFrame
351
385
try :
@@ -358,15 +392,19 @@ def taxonomic_percentajes(df):
358
392
percentaje_taxonomic = (
359
393
0.2 * percentaje_genus
360
394
+ 0.1 * percentaje_species
361
- + 0.09 * percentaje_hierarchy
395
+ + 0.03 * percentaje_kingdom
396
+ + 0.03 * percentaje_class_order
397
+ + 0.03 * percentaje_family
362
398
+ 0.06 * percentaje_identifiers
363
399
)
364
400
365
401
return {
366
402
"Taxonomic" : percentaje_taxonomic ,
367
403
"Genus" : 0.2 * percentaje_genus ,
368
404
"Species" : 0.1 * percentaje_species ,
369
- "Hierarchy" : 0.09 * percentaje_hierarchy ,
405
+ "Kingdom" : 0.03 * percentaje_kingdom ,
406
+ "Class/Order" : 0.03 * percentaje_class_order ,
407
+ "Family" : 0.03 * percentaje_family ,
370
408
"Identifiers" : 0.06 * percentaje_identifiers ,
371
409
}
372
410
@@ -629,6 +667,24 @@ def hierarchy_weights(row):
629
667
)
630
668
631
669
670
+ def kingdom_weights (row ):
671
+ """Returns N for each not empty sublevel (kingdom)."""
672
+ N = row .N
673
+ return N if pd .notnull (row .kingdom ) else 0
674
+
675
+
676
+ def class_order_weights (row ):
677
+ """Returns N for each not empty sublevel (class/order)."""
678
+ N = row .N
679
+ return N if pd .notnull (row ["class" ]) or pd .notnull (row .order ) else 0
680
+
681
+
682
+ def family_weights (row ):
683
+ """Returns N for each not empty sublevel (family)."""
684
+ N = row .N
685
+ return N if pd .notnull (row .family ) else 0
686
+
687
+
632
688
def is_valid_country_code (row ):
633
689
"""If the countryCode column from the row is valid, return the column N. Otherwise
634
690
return 0.
0 commit comments