<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Example Aggregations
Aggregating data with MDF
Searches using Forge.search() are limited to 10,000 results. However, there are two methods to circumvent this restriction
Step1:  aggregate_source - NIST XPS DB
Example
Step2:  aggregate - Multiple Datasets
Example
<ASSISTANT_TASK:>
Python Code:
import json
from mdf_forge.forge import Forge
mdf = Forge()
Explanation: Example Aggregations
Aggregating data with MDF
Searches using Forge.search() are limited to 10,000 results. However, there are two methods to circumvent this restriction: Forge.aggregate_source() and Forge.aggregate().
End of explanation
# First, let's aggregate all the nist_xps_db data.
all_entries = mdf.aggregate_sources("nist_xps_db")
print(len(all_entries))
# Now, let's parse out the enery_uncertainty_ev and print the results for analysis.
uncertainties = {}
for record in all_entries:
    if record["mdf"]["resource_type"] == "record":
        unc = record.get("nist_xps_db_v1", {}).get("energy_uncertainty_ev", 0)
        if not uncertainties.get(unc):
            uncertainties[unc] = 1
        else:
            uncertainties[unc] += 1
print(json.dumps(uncertainties, sort_keys=True, indent=4, separators=(',', ': ')))
Explanation: aggregate_source - NIST XPS DB
Example: We want to collect all records from the NIST XPS Database and analyze the binding energies. This database has almost 30,000 records, so we have to use aggregate().
End of explanation
# First, let's aggregate everything that has "Ga" in the list of elements.
all_results = mdf.aggregate("material.elements:Ga")
print(len(all_results))
# Now, let's parse out the other elements in each record and keep a running tally to print out.
elements = {}
for record in all_results:
    if record["mdf"]["resource_type"] == "record":
        elems = record["material"]["elements"]
        for elem in elems:
            if elem in elements.keys():
                elements[elem] += 1
            else:
                elements[elem] = 1
print(json.dumps(elements, sort_keys=True, indent=4, separators=(',', ': ')))
Explanation: aggregate - Multiple Datasets
Example: We want to analyze how often elements are studied with Gallium (Ga), and what the most frequent elemental pairing is. There are more than 10,000 records containing Gallium data.
End of explanation
<END_TASK>