Duplicate detection functions
Module containing functions for finding and removing the duplicates among the input databases. Used for e.g. dup_detection.ipynb, dup_decision.ipynb, dup_removal.ipynb)
dod2k_utilities.ut_duplicate_search
This script includes functions which search for duplicates.
Last updated 19/12/2025 by LL for publication of dod2k v2.0
Update 22/10/24 updated duplicate_decisions: - created backup decision file which is intermediately saved - outputs URL which can be copied and pasted into browser - implemented a composite option in the decision process, to create a composite of two records - removed date (YY-MM-DD) of decision output filename Update 8/10/24 changed colours of figure in dup_plot (dropped highlighting differing metadata). replaced db_name with df.name
Update 2/10/24 Implemented a commenting option in duplicate_decisions to comment on decision process and on individual decisions.
Update 27/9/24 Updated directory names and changed the correlation and distances output in find_duplicates to only output data from potential duplicates (replaced saving all pairs)
Update 9/9/24 Introduced timestamps and contact details into duplicate decision output csv and changed the file= and dirnames for streamlining purposes. Update 23/8/24 Replaced the function cleanup_database and split into two: plot_duplicates: plots the candidate pairs, saves figures and a summary csv sheet. cleanup_database_2: goes through the candidate pairs and makes decisions based on the options: a) raw input b) keep all records c) automatically keep only updated records and eliminate the other candidate. Decisions and metadata are saved in csv file.
Update 22/8/24: Fixed a bug in find_duplicates logical algorithm- wrong bracket closure. Also changed location_crit to account for nans in elevation. Calculation of z-scores only divided by std if std!=0 to avoid nans.
Update 15/8/24: updated numerical checks for duplicate detection: implemented check for correlation and rmse of records plus correlation and rmse of first difference.
Update 13/8/24: updated keys to account for updated dataframe terminology. Revised loading/saving of data in find_duplicates find_duplicates: updated the logic for duplicate detection: overlap_crit now accounts for short records (allows short records to pass through without overlap check) corr_crit only one numerical criterion needs to be satisfied for the data (either correlation or rmse or 1st difference) location_crit now includes elevation too
cleanup_database: updated plot to include URL, Database and streamlined table Script written by Lucie Luecke, 6/7/23
collect_dup_details(df_decisions, header)
Generate duplicate details dictionary from decision records.
Creates a nested dictionary structure containing information about all duplicate relationships and decisions made during the duplicate review process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_decisions
|
DataFrame
|
DataFrame containing duplicate decisions with columns: - 'Decision 1', 'Decision 2': Decision for each record (KEEP/REMOVE/COMPOSITE) - 'datasetId 1', 'datasetId 2': IDs of the duplicate pair - 'originalDatabase 1', 'originalDatabase 2': Source databases - 'Decision type': Type of decision (MANUAL/AUTO) - 'Decision comment': Comments on the decision (for manual decisions) |
required |
header
|
list
|
Header information from the decision file containing operator details: [0]: File description [1]: Operator name and initials [3]: Creation timestamp |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dup_details |
dict
|
Nested dictionary with structure: {record_id: { duplicate_count: { 'duplicate ID': str, 'duplicate database': str, 'duplicate decision': str, 'decision type': str, 'operator': str (for manual decisions), 'note': str (for manual decisions) } }} |
Notes
- Only processes pairs where at least one record is not kept (true duplicates)
- Each record gets an entry for every duplicate relationship it has
- Manual decisions include operator details extracted from the header
- Automatic decisions have 'N/A' for operator and note fields
The returned dictionary can be used to populate the 'duplicateDetails' field in the final deduplicated database.
Source code in dod2k_utilities/ut_duplicate_search.py
2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 | |
collect_record_decisions(df_decisions)
Collect per-record decisions from a pairwise decision table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_decisions
|
DataFrame
|
DataFrame containing pairwise record comparisons. Must include
the columns |
required |
Returns:
| Name | Type | Description |
|---|---|---|
decisions |
dict
|
Dictionary mapping each dataset ID to a list of decisions associated with that record across all comparisons. |
Notes
Each row contributes two entries: one for 'datasetId 1' paired
with 'Decision 1' and one for 'datasetId 2' paired with
'Decision 2'. Records appearing in multiple rows accumulate
multiple decision entries in their corresponding list.
Source code in dod2k_utilities/ut_duplicate_search.py
2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 | |
define_hierarchy(df, hierarchy='default')
Define priority hierarchy for different paleoclimate databases.
Assigns a numerical hierarchy value to each record based on its original database, used for automatic duplicate resolution when records are identical. Lower values indicate higher priority.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing proxy records with an 'originalDatabase' column. |
required |
hierarchy
|
str or dict
|
Hierarchy definition method. If 'default', uses predefined hierarchy. If dict, should contain keys for database names with priority values: - 'pages2k': priority for PAGES 2k database - 'fe23': priority for FE23 (Breitenmoser et al. 2014) - 'ch2k': priority for CoralHydro2k - 'iso2k': priority for Iso2k - 'sisal': priority for SISAL Default is 'default'. |
'default'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The input DataFrame with added 'Hierarchy' column containing priority values for each record. |
Notes
Default hierarchy (lower number = higher priority): 1. PAGES 2k v2.2.0 (highest priority) 2. SISAL v3 3. CoralHydro2k v1.0.1 4. Iso2k v1.1.2 5. FE23 (Breitenmoser et al. 2014) 99. All other databases (lowest priority)
The hierarchy is used in duplicate_decisions functions to automatically choose which record to keep when duplicates are identical.
Examples:
>>> df = define_hierarchy(df) # Use default hierarchy
>>> custom = {'PAGES 2k v2.2.0', 'Hierarchy': 2, 'SISAL v3': 1, 'FE23 (Breitenmoser et al. (2014))': 3, 'CoralHydro2k v1.0.': 4, 'Iso2k v1.1.2': 5}
>>> df = define_hierarchy(df, hierarchy=custom) # Custom hierarchy
Source code in dod2k_utilities/ut_duplicate_search.py
1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 | |
density_scatter(x, y, ax=None, fig=None, sort=True, bins=20, **kwargs)
Scatter plot colored by 2d histogram
Source code in dod2k_utilities/ut_duplicate_search.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 | |
dup_plot(df, ii, jj, id_1, id_2, time_1, time_2, time_12, data_1, data_2, int_1, int_2, pot_dup_corr, keys_to_print=['originalDatabase', 'originalDataURL', 'datasetId', 'archiveType', 'proxy | variableName', 'geo_siteName', 'lat | lon | elev', 'mean | std | units', 'year'], dup_mdata_row=[], plot_text=True, fig_scale=1)
Plots the duplicate candidates. Plots the record data as a timeseries of anomalies in a common panel (w.r.t. shared time period) and prints out the most relevant metadata. Highlights identical metadata in orange and different metadata in green.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing proxy records and metadata. |
required |
ii
|
int
|
Index of the first record. |
required |
jj
|
int
|
Index of the second record. |
required |
id_1
|
str
|
Dataset ID of the first record. |
required |
id_2
|
str
|
Dataset ID of the second record. |
required |
time_1
|
array - like
|
Time vector for the first record. |
required |
time_2
|
array - like
|
Time vector for the second record. |
required |
time_12
|
array - like
|
Shared time points between both records. |
required |
data_1
|
array - like
|
Data values of the first record. |
required |
data_2
|
array - like
|
Data values of the second record. |
required |
int_1
|
array - like
|
Indices of shared times in the first record. |
required |
int_2
|
array - like
|
Indices of shared times in the second record. |
required |
pot_dup_corr
|
float
|
Correlation between the two records. |
required |
keys_to_print
|
list of str
|
List of metadata keys to display. Default is a standard set of keys. |
['originalDatabase', 'originalDataURL', 'datasetId', 'archiveType', 'proxy | variableName', 'geo_siteName', 'lat | lon | elev', 'mean | std | units', 'year']
|
dup_mdata_row
|
list
|
Stores metadata differences for output. |
[]
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
Figure object of the duplicate plot. |
dup_mdata_row |
list
|
Metadata rows generated for display. |
Source code in dod2k_utilities/ut_duplicate_search.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 | |
duplicate_decisions_multiple(df, operator_details=False, choose_recollection=True, plot=True, remove_identicals=True, dist_tolerance_km=8, backup=True, comment=True, automate_db_choice=False)
Review potential duplicate pairs in a proxy database and decide which records to keep, remove, or combine.
This function walks through each potential duplicate pair identified in a dataset, displays metadata and optionally plots the data, and allows the operator to make decisions. Decisions are saved to a CSV file, and a duplicate-free dataframe can be generated.
Copied from duplicate_decisions but improved handling of multiple duplicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The dataframe containing proxy data and metadata. Expected columns include: - 'geo_meanLat', 'geo_meanLon' : Latitude and longitude of the site. - 'year', 'paleoData_values' : Time vector and proxy values. - 'archiveType', 'paleoData_proxy' : Archive type and proxy type. - 'datasetId' : Unique identifier or dataset name. - 'geo_siteName' : Site name. - 'originalDatabase' : Name of the original database. - 'geo_meanElev' : Mean elevation of the site (optional for duplicate checks). - 'Hierarchy' : Numeric value representing dataset priority (used for auto-decisions). - 'originalDataURL' : URL of the original dataset. |
required |
operator_details
|
tuple or bool
|
Tuple containing (initials, fullname, email) of the operator. If False, user input is requested. Default is False. |
False
|
choose_recollection
|
bool
|
If True, automatically selects the record that is a recollection or update when applicable. Default is True. |
True
|
plot
|
bool
|
If True, generate plots for manual inspection of duplicate pairs. Default is True. |
True
|
remove_identicals
|
bool
|
If True, automatically remove records that are identical in data and metadata. Default is True. |
True
|
dist_tolerance_km
|
float
|
Maximum distance (in km) for considering records as recollection updates. Default is 8 km. |
8
|
Returns:
| Type | Description |
|---|---|
None
|
Decisions are saved as CSV backup and final CSV in the |
Notes
- Automatic decisions are made based on data identity, metadata identity, perfect correlation, and recollection indicators in site names.
- Manual decisions are prompted via command-line input if automatic rules do not apply.
- Decision types include:
- 'AUTO: UPDATE' : Automatically select record that is a recollection/update.
- 'AUTO: IDENTICAL' : Automatically select record based on hierarchy if records are identical.
- 'MANUAL' : Decision requires operator input.
- Figures are saved with a standardized naming convention and linked in the CSV output.
Source code in dod2k_utilities/ut_duplicate_search.py
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 | |
find_duplicates(df, dist_tolerance_km=8, n_points_thresh=10, corr_thresh=0.9, rmse_thresh=0.1, corr_diff_thresh=0.9, rmse_diff_thresh=0.1, elev_tolerance=0, ignore_same_database=False, save=True, print_output=False)
Identify potential duplicate records in a dataset using metadata and time series similarity.
This is a simpler version of find_duplicates_optimized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing proxy records with metadata. Expected columns include: ['geo_meanLat', 'geo_meanLon', 'geo_meanElev', 'year', 'paleoData_values', 'archiveType', 'paleoData_proxy', 'geo_siteName', 'originalDatabase', 'originalDataURL', 'datasetId']. |
required |
dist_tolerance_km
|
float
|
Maximum allowed geographical distance between duplicates (km). Default is 8. |
8
|
n_points_thresh
|
int
|
Minimum number of overlapping time points required. Default is 10. |
10
|
corr_thresh
|
float
|
Minimum correlation threshold for duplicate detection. Default is 0.9. |
0.9
|
rmse_thresh
|
float
|
Maximum RMSE allowed for duplicate detection. Default is 0.1. |
0.1
|
corr_diff_thresh
|
float
|
Minimum correlation of first differences threshold. Default is 0.9. |
0.9
|
rmse_diff_thresh
|
float
|
Maximum RMSE of first differences allowed. Default is 0.1. |
0.1
|
elev_tolerance
|
float
|
Maximum allowed elevation difference. Default is 0. |
0
|
ignore_same_database
|
bool
|
If True, ignores potential duplicates within the same database. Default is False. |
False
|
save
|
bool
|
If True, saves results as a CSV file. Default is True. |
True
|
print_output
|
bool
|
If True, prints progress and matching information. Default is False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
pot_dup_inds |
list of list of int
|
Indices of detected potential duplicates. |
pot_dup_IDs |
list of list of str
|
Dataset IDs of detected potential duplicates. |
distances_km |
ndarray
|
Matrix of pairwise distances between records. |
correlations |
ndarray
|
Matrix of pairwise correlations between records. |
Source code in dod2k_utilities/ut_duplicate_search.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
find_duplicates_optimized(df, dist_tolerance_km=8, n_points_thresh=10, corr_thresh=0.9, rmse_thresh=0.1, corr_diff_thresh=0.9, rmse_diff_thresh=0.1, elev_tolerance=0, ignore_same_database=False, save=True, print_output=False, return_data=False)
Identify potential duplicate records in a dataset based on metadata and time series similarity.
Based on find_duplicates, optimized by Feng Zhu
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing proxy records with metadata. Expected columns include: ['geo_meanLat', 'geo_meanLon', 'geo_meanElev', 'year', 'paleoData_values', 'archiveType', 'paleoData_proxy', 'geo_siteName', 'originalDatabase', 'originalDataURL', 'datasetId']. |
required |
dist_tolerance_km
|
float
|
Maximum allowed geographical distance between duplicates (km). Default is 8. |
8
|
n_points_thresh
|
int
|
Minimum number of overlapping time points required. Default is 10. |
10
|
corr_thresh
|
float
|
Minimum correlation threshold for duplicate detection. Default is 0.9. |
0.9
|
rmse_thresh
|
float
|
Maximum RMSE allowed for duplicate detection. Default is 0.1. |
0.1
|
corr_diff_thresh
|
float
|
Minimum correlation of first differences threshold. Default is 0.9. |
0.9
|
rmse_diff_thresh
|
float
|
Maximum RMSE of first differences allowed. Default is 0.1. |
0.1
|
elev_tolerance
|
float
|
Maximum allowed elevation difference. Default is 0. |
0
|
ignore_same_database
|
bool
|
If True, ignores potential duplicates within the same database. Default is False. |
False
|
save
|
bool
|
If True, saves results as a CSV file. Default is True. |
True
|
print_output
|
bool
|
If True, prints progress and matching information. Default is False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
pot_dup_inds |
list of list of int
|
Indices of detected potential duplicates. |
pot_dup_IDs |
list of list of str
|
Dataset IDs of detected potential duplicates. |
distances_km |
ndarray
|
Matrix of pairwise distances between records. |
correlations |
ndarray
|
Matrix of pairwise correlations between records. |
Source code in dod2k_utilities/ut_duplicate_search.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
join_composites_metadata(df, comp_ID_pairs, df_decisions, header)
Create composite records from overlapping duplicate proxy datasets and generate metadata.
This function combines pairs of proxy records that were identified as duplicates and decided to be composited. It standardizes the data as z-scores, averages overlapping periods, merges metadata, and generates a composite DataFrame. A scatter plot of the original and composite data is created and saved for visual inspection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Original DataFrame containing proxy data and metadata. Must include columns: - 'paleoData_values' : proxy values - 'year' : time vector - 'geo_meanLat', 'geo_meanLon', 'geo_meanElev' : site coordinates - 'archiveType', 'geo_siteName', 'paleoData_proxy' : metadata - 'climateInterpretation_variable', 'dataSetName', 'originalDatabase', 'originalDataURL', 'paleoData_notes', 'duplicateDetails' - 'datasetId' : unique record identifier |
required |
comp_ID_pairs
|
DataFrame
|
DataFrame listing pairs of record IDs to be composited. Must include columns: - 'datasetId 1', 'datasetId 2' - 'originalDatabase 1', 'originalDatabase 2' - 'Decision type', 'Decision comment' |
required |
df_decisions
|
DataFrame
|
DataFrame containing the decisions made during duplicate evaluation. Used to annotate the composite metadata with decision type and comments. |
required |
header
|
list
|
Metadata header from the duplicate decision process. Used for documenting operator details in the composite notes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
df_comp |
DataFrame
|
A new DataFrame containing the composited proxy records, including: - Combined 'paleoData_values' as z-scores - Merged 'year' vector - Updated metadata fields, including a composite 'datasetId' - Detailed 'duplicateDetails' recording the composition process |
Notes
- For numerical metadata that differs between records, the mean is taken.
- For categorical metadata, entries are concatenated into a composite string.
- Overlapping periods are averaged, and non-overlapping periods are appended.
- A scatter plot is generated for each composite showing the original records
and the resulting composite, and it is saved using
save_fig. - The function maintains provenance of original datasets, including notes and URLs, in the 'duplicateDetails' field.
Source code in dod2k_utilities/ut_duplicate_search.py
2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 | |
plot_duplicates(df, save_figures=True, write_output=True, display=False)
Generate plots of potential duplicate records in a proxy database and optionally save their metadata.
This function identifies potential duplicate entries in a paleoclimate proxy dataset,
visualizes them using the dup_plot function, and saves the metadata of duplicates as a CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The dataframe containing proxy data and metadata. Expected columns include: - 'geo_meanLat', 'geo_meanLon' : Latitude and longitude of the site. - 'year', 'paleoData_values' : Time vector and proxy values. - 'archiveType', 'paleoData_proxy' : Archive type and proxy type. - 'datasetId' : Unique identifier or dataset name. - 'geo_siteName' : Site name. - 'originalDatabase' : Name of the original database. |
required |
save_figures
|
bool
|
If True, save the generated figures to disk. Default is True. |
True
|
write_output
|
bool
|
If True, save the duplicate metadata to a CSV file. Default is True. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
The function primarily generates plots and writes metadata; it does not return any objects. |
Notes
- The function assumes that potential duplicates have already been identified by a separate
process (e.g.,
find_duplicates) and that a corresponding CSV exists indf.name/dup_detection/. - Metadata printed and saved includes site names, coordinates, dataset IDs, original database, and summary statistics (mean, std, units, etc.).
- Figures are saved in PDF format by default using
save_fig.
Source code in dod2k_utilities/ut_duplicate_search.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 | |