<jupyter_start><jupyter_text>IntroductionThis Notebook explores the qualitative change in Rocky Mountain National Park, Colorado from Spring snow-on conditions to Summer snow-off conditions in 2018.  FunctionsThese functions differ in style from some PEP 8 and other Python conventions in order to centralize, consolidate, and modularize the setup process to fit both Jupyter envrionments (Jupyter Notebook, JupyterLab, Binder) and the Google Colab environment.<jupyter_code>def initialize_earth_engine():
    """Initializes the Earth Engine Python API.

    Returns
    -------
    str

    Example
    -------
        >>> initialize_earth_engine()
        Imported ee. Initialized Earth Engine Python API.
    """
    # Import ee if not already imported
    import sys
    if "ee" not in sys.modules:
        import ee
        global ee

    # Initialize Earth Engine Python API
    try:
        ee.Initialize()
    except Exception:
        ee.Authenticate()
        ee.Initialize()

    return print("Imported ee. Initialized Earth Engine Python API.")

def import_geemap():
    """Imports the geemap package (environment-dependent, Google Colab
    vs. Jupyter/Binder).

    Returns
    -------
    environment : str
        Message indicating the geemap has been imported into the
        environment. The message differs based on the environment.

    Example
    -------
        >>> import_geemap()
        Notebook running in Jupyter/Binder. Imported geemap as gm.
    """
    # Check for Google Colab
    try:
        import google.colab
    # Notebook running in Jupyter/Binder
    except ImportError:
        running_in_colab = False
    # Notebook running in Google Colab
    else:
        running_in_colab = True

    # Import geemap based on environment (Google Colab vs. Jupyter/Binder)
    if running_in_colab:
        import subprocess
        subprocess.check_call(["python", "-m", "pip", "install", "geemap"])
        import geemap.eefolium as gm
        global gm
        environment = print(
            "Notebook running in Google Colab. Imported geemap.folium as gm."
        )
    else:
        import geemap as gm
        global gm
        environment = print(
            "Notebook running in Jupyter/Binder. Imported geemap as gm."
        )

    return environment<jupyter_output><empty_output><jupyter_text>Environment SetupThe only two modules imported in this example are `ee` and `gm`. They are not listed here, as they are included in the functions above. If the functions in the below two cells succeed, they will print messages indicating the modules were imported. As stated above, the functions differ in style from some PEP 8 and other Python conventions in this case.<jupyter_code># Initialize Earth Engine Python API
initialize_earth_engine()
# Import geemap
import_geemap()<jupyter_output><empty_output><jupyter_text>Data Acquisition and Preprocessing<jupyter_code># Get boundary for Rocky Mountain National Park, Colorado
rmnp_boundary = ee.FeatureCollection(
    "users/calekochenour/Rocky_Mountain_National_Park__Boundary_Polygon"
)

# Get Landsat 8 collection
landsat8_t1_sr = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")

# Filter Landsat 8 Tier 1 SR to snow-on conditions near RMNP, 2018
co_snow_on_2018 = (
    landsat8_t1_sr.filterDate("2018-03-01", "2018-04-30")
    .filterBounds(rmnp_boundary)
    .sort("CLOUD_COVER")
    .first()
)

# Filter Landsat 8 Tier 1 SR to snow-off conditions near RMNP, 2018
co_snow_off_2018 = (
    landsat8_t1_sr.filterDate("2018-07-01", "2018-08-31")
    .filterBounds(rmnp_boundary)
    .sort("CLOUD_COVER")
    .first()
)

# Clip snow-on and snow-off imagery to RMNP boundary
rmnp_snow_on_2018 = co_snow_on_2018.clip(rmnp_boundary)
rmnp_snow_off_2018 = co_snow_off_2018.clip(rmnp_boundary)<jupyter_output><empty_output><jupyter_text>Data Processing No data processsing in this example.  Data Postprocessing No data postprocessing in this example.  Data Visualization<jupyter_code># Create interactive map for visualization and set options
if "rmnp_map" in globals():
    del rmnp_map
    rmnp_map = gm.Map()
    rmnp_map.setOptions("SATELLITE")
    rmnp_map.setCenter(lon=-105.6836, lat=40.3428, zoom=10)
else:
    rmnp_map = gm.Map()
    rmnp_map.setOptions("SATELLITE")
    rmnp_map.setCenter(lon=-105.6836, lat=40.3428, zoom=10)
# Define Landsat visualization parameters
l8_vis_params_rgb = {"bands": ["B4", "B3", "B2"], "min": 0, "max": 3000}
l8_vis_params_cir = {"bands": ["B5", "B4", "B3"], "min": 0, "max": 3000}

# Define RMNP boundary visualization parameters
rmnp_boundary_vis = (
    ee.Image()
    .byte()
    .paint(**{"featureCollection": rmnp_boundary, "color": 1, "width": 3})
)

# Add snow-on and snow-off images to map, RGB and CIR
rmnp_map.addLayer(
    rmnp_snow_on_2018,
    l8_vis_params_rgb,
    "Landsat 8 - RGB - 2018 - RMNP - Snow On",
)

rmnp_map.addLayer(
    rmnp_snow_on_2018,
    l8_vis_params_cir,
    "Landsat 8 - CIR - 2018 - RMNP - Snow On",
)

rmnp_map.addLayer(
    rmnp_snow_off_2018,
    l8_vis_params_rgb,
    "Landsat 8 - RGB - 2018 - RMNP - Snow Off",
)

rmnp_map.addLayer(
    rmnp_snow_off_2018,
    l8_vis_params_cir,
    "Landsat 8 - CIR - 2018 - RMNP - Snow Off",
)

# Add RMNP boundary to map
rmnp_map.addLayer(rmnp_boundary_vis, {"palette": "FF0000"}, "RMNP Boundary")
# Display map
rmnp_map<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09223300970873786, 'fraction_numerical': 0.033607169529499624, 'mean_word_length': 3.4346026490066226, 'pattern_counts': {'":': 10, '<': 17, '<?xml version=': 0, '>': 23, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '167625', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1743, 'n_words': 513, 'path': '01-code-scripts/01-qualitative-change-detection.ipynb', 'repo_name': 'calekochenour/earth-engine-env', 'size': '5356'}