<jupyter_start><jupyter_text>Python Wrapper for CMR`A python library to interface with CMR - Granule Search Demo`This demo will show how to preform a search for **Granules** against CMR while inside a notebook.  Loading the libraryFrom the command line, make sure you call `runme.sh -p -i` to both backage and install the library through pip3.n  Import Modules<jupyter_code>import cmr.search.granule as gran<jupyter_output><empty_output><jupyter_text>Get Online HelpAt least some understanding of the CMR API will be needed from time to time, to assist with that the following call can be used to open a browser window to the API. For the fun of it, you can pass in an HTML anchor tag on the page and jump directly there.<jupyter_code>gran.open_api()
gran.open_api("#headers")<jupyter_output><empty_output><jupyter_text>Basic Search<jupyter_code>params = {}
params['provider'] = 'ORNL_DAAC' 
results = gran.search(params)
print("Found {} records.".format(len(results)))
for i in results:
    print (i)<jupyter_output><empty_output><jupyter_text>Perform a Filtered ResultSearch as before, but only return the meta section of the response.<jupyter_code>params = {}

params['provider'] = 'ORNL_DAAC'
config = {'env':'uat'}
results = gran.search(params, filters=[gran.meta_fields], config=config)
print("Found {} records.".format(len(results)))
for i in results:
    print (i)<jupyter_output><empty_output><jupyter_text>Perform a Chain of Filtered ResultsIn this example, perform many filters, each making an aditional change to the results<jupyter_code>params = {}

params['provider'] = 'ORNL_DAAC'
results = gran.search(params,
                      filters=[gran.meta_fields,
                               gran.drop_fields('concept-type'), 
                               gran.drop_fields('native-id'),
                               gran.drop_fields('format'),
                               gran.drop_fields('revision-date')])
print("Found {} records.".format(len(results)))
for i in results:
    print (i)<jupyter_output><empty_output><jupyter_text>Perform a Sorted SearchIn this example, perform two searches which sort the results in ascending and descending order<jupyter_code>def list_by_size(query):
    """Search and display the results in the same way"""
    results = gran.search(query, filters=[gran.umm_fields], limit=10)
    print("Found {} records.".format(len(results)))
    for i in results:
        print (i['DataGranule']['ArchiveAndDistributionInformation'][0]['Size'])

list_by_size({'provider': 'ORNL_DAAC', 'sort_key': 'data_size'})
print ("\nvs\n")
list_by_size({'provider': 'ORNL_DAAC', 'sort_key': '-data_size'})<jupyter_output><empty_output><jupyter_text>Help with Sort KeysCan not remember the sort keys, look them up<jupyter_code>gran.open_api("#sorting-granule-results")<jupyter_output><empty_output><jupyter_text>More helpGet a print out of the functions in this API<jupyter_code>print(gran.help_text('_filters'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11331540013449899, 'fraction_numerical': 0.0013449899125756557, 'mean_word_length': 4.844793713163065, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '471365', 'license': 'Apache-2.0', 'n_tokens_mistral': 928, 'n_tokens_neox': 903, 'n_words': 259, 'path': 'CMR/python/demos/notebooks/granules.ipynb', 'repo_name': 'littleidiot40/eo-metadata-tools', 'size': '2974'}