<jupyter_start><jupyter_text>Identify SWOT Orbits<jupyter_code>import sys
import imp
import json
import requests
import numpy as np
import pandas as pd
from tqdm import tqdm
from IPython.display import HTML
tqdm.pandas()
def import_from_github(url: str):
    with requests.get(url) as response: 
        module = imp.new_module("swot")
        exec(response.text, module.__dict__)
        return module

swot = import_from_github("https://raw.githubusercontent.com/jjmcnelis/trusted-methods/main/py/swot.py")<jupyter_output><empty_output><jupyter_text>Science<jupyter_code>var = ['data_01_time', 
       'data_01_latitude', 
       'data_01_longitude', 
       'data_01_ku_ssha',   ]
def get_swot_nadir_granules_for_cycles(ShortName:   str, 
                                       start_cycle: int=1, 
                                       end_cycle:   int=1, 
                                       variables:   list=var):

    # Get the unique collection 'concept-id' for the target collection
    ccid = requests.get(url=f"https://cmr.earthdata.nasa.gov/search/collections.umm_json",
                        params={'ShortName': ShortName}).json() \
                   .get("items")[0].get("meta").get("concept-id")

    # Make a data frame of cycles and pull down granule metadata from CMR for each one in a series
    cycles = pd.DataFrame({'cycle': list(range(start_cycle, end_cycle+1))})

    cycles['granules'] = cycles.cycle.progress_apply(lambda x: swot.nadir_query_example(ccid, cycle=x))
    
    # Melt the cycles table into a tall table of granules, one per row
    df          = pd.concat(cycles.granules.tolist())[["Granule UR"]].set_index("Granule UR")
    df['file']  = df.index.to_series()
    df['dap']   = df.apply(lambda x: f"https://opendap.earthdata.nasa.gov/collections/{ccid}/granules/{x.file}", axis=1)
    df['url']   = df.dap.apply(lambda x: f"{x}.nc4?{','.join(var)}")
    df['path']  = swot.download_all(df.url.tolist())
    df['cycle'] = df.file.apply(lambda x: x.split("_")[2][4:])
    df['pass']  = df.file.apply(lambda x: x.split("_")[3])
    df['start'] = df.file.apply(lambda x: "T".join(x.split("_")[4:6])).apply(lambda x: swot.dt.strptime(x,"%Y%m%dT%H%M%S"))
    df['end']   = df.file.apply(lambda x: "T".join(x.split("_")[6:8])).apply(lambda x: swot.dt.strptime(x,"%Y%m%dT%H%M%S"))

    return df
df = get_swot_nadir_granules_for_cycles("SWOT_SIMULATED_L2_NADIR_SSH_ECCO_LLC4320_SCIENCE_V1", 
                                        start_cycle=1, 
                                        end_cycle=4)
df.iloc[0]
c1 = swot.xr.open_mfdataset(sorted(df[df.cycle=='001'].path.tolist()), combine='by_coords')

print(c1)
import matplotlib.pyplot as plt

c1.plot.scatter(y="data_01_latitude", x="data_01_longitude", hue="data_01_ku_ssha", 
                vmin=-0.4, vmax=0.4, cmap="jet",
                aspect=2.5, size=6, s=1, )

plt.ylim(-67.,  67.)
plt.xlim(  0., 360.)
plt.tight_layout()
plt.title(f"ssha for cycle 1")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15690866510538642, 'fraction_numerical': 0.019739043158246906, 'mean_word_length': 3.024226110363392, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '522775', 'license': 'MIT', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1090, 'n_words': 181, 'path': 'ipynb/swot_nadir_example.ipynb', 'repo_name': 'jjmcnelis/my-most-trusted-methods', 'size': '2989'}