<jupyter_start><jupyter_text>Connect to API<jupyter_code>client = ODPClient(api_key=getpass(prompt='Insert your personal ODP API key:'), 
                       project="odp", client_name="odp")<jupyter_output>Insert your personal ODP API key:········<jupyter_text>Run function you will need to fetch polygons of different regions<jupyter_code>def get_poly(df):
    polys=[]
    for i in notebook.tqdm(range(len(df))):
        if df['poly_count'][i]>1:
            m_polys=[]
            for i in range(df['poly_count'][i]):
                df_p = client.sequences.data.retrieve(id=df['id'][i], start=1, end=None).to_pandas()
                m_polys.append(Polygon(zip(df_p[df_p.polygonId==i]['lat'], df_p[df_p.polygonId==i]['lon'])))
            polys.append(MultiPolygon(m_polys))
        else:
            polys.append(Polygon(zip(client.sequences.data.retrieve(id=df['id'][i], start=1, end=None).to_pandas()['lat'], client.sequences.data.retrieve(id=df['id'][i], start=1, end=None).to_pandas()['lon'])))
    df['geometry']=polys<jupyter_output><empty_output><jupyter_text>Get casts and data from Antarctic EEZ First get all sequences of Marine Regions and EEZs that belong to Antarctica<jupyter_code>seqs = client.sequences.list(external_id_prefix = 'marine-regions-Intersect_EEZ_IHO', metadata={'SOVEREIGN1': 'ANTARCTICA'}, limit=-1).to_pandas()
seqs.head()<jupyter_output><empty_output><jupyter_text>Create a dataframe with marine regions, eezs, and associated polygons<jupyter_code>df_ant = pd.DataFrame({'marine_regions':[seqs.iloc[i]['metadata']['MARREGION'] for i in range(len(seqs))], 
                      'MRGID':[seqs.iloc[i]['metadata']['MRGID'] for i in range(len(seqs))],
                      'IHO_Sea':[seqs.iloc[i]['metadata']['IHO_SEA'] for i in range(len(seqs))],
                      'EEZ':[seqs.iloc[i]['metadata']['EEZ'] for i in range(len(seqs))],
                      'SOVEREIGN1':[seqs.iloc[i]['metadata']['SOVEREIGN1'] for i in range(len(seqs))],
                      'id': seqs['id'],
                      'poly_count':[int(seqs.iloc[i]['metadata']['polygonCount']) for i in range(len(seqs))]})
get_poly(df_ant)
df_ant = gpd.GeoDataFrame(df_ant)
df_ant.head()<jupyter_output><empty_output><jupyter_text>Pull all casts from 2018 and find the ones that intersect with the Antarctic EEZ Polygons<jupyter_code>## Download casts from 2018 and turn into a geopandas dataframe
casts2018 = client.get_available_casts([-180, 180], [-90, 90], ['2018-01-01', '2018-12-31'], n_threads=35)
casts2018 = gpd.GeoDataFrame(
    casts2018, geometry=gpd.points_from_xy(casts2018.lon, casts2018.lat))
casts2018.head()
## Find intersect of casts and Antarctic EEZ
casts2018_ant = gpd.sjoin(casts2018, df_ant, how="inner", op='intersects')
casts2018_ant.head(2)<jupyter_output><empty_output><jupyter_text>You can then fetch the measurement data from each of these casts<jupyter_code>ant_data = client.download_data_from_casts(casts2018_ant.extId.unique(), n_threads=40)
ant_data.head()<jupyter_output><empty_output><jupyter_text>And you can plot the measurements for Temperature in the Antarctic EEZ<jupyter_code>plot_casts('Temperature', ant_data, cmap=cmocean.cm.thermal)<jupyter_output><empty_output><jupyter_text>Assign World Seas Marine Regions to casts<jupyter_code>seqs = client.sequences.list(external_id_prefix = 'marine-regions-Intersect_EEZ_IHO', limit=-1).to_pandas()
seqs.head()<jupyter_output><empty_output><jupyter_text>Create dataframe with name of marine region and polygons<jupyter_code>df_mr = pd.DataFrame({'marine_regions':[seqs.iloc[i]['metadata']['MARREGION'] for i in range(len(seqs))],
                      'iho_sea':[seqs.iloc[i]['metadata']['IHO_SEA'] for i in range(len(seqs))],
                      'MRGID':[seqs.iloc[i]['metadata']['MRGID'] for i in range(len(seqs))],
                      'poly_count':[int(seqs.iloc[i]['metadata']['polygonCount']) for i in range(len(seqs))],
                      'id':seqs['id']})
get_poly(df_mr)
df_mr = gpd.GeoDataFrame(df_mr)
df_mr.head()<jupyter_output><empty_output><jupyter_text>Join oceanographic data to Marine RegionsHere we find the intersect of points from the casts with the polygons from the marine regions. The resulting dataframe will have the associated marine regions for each cast location.<jupyter_code>casts2018_mr = gpd.sjoin(casts2018, df_mr, how="inner", op='intersects')
casts2018_mr.head(2)
def plot_marine_regions_data(df_casts, df_marine_regions, lat=[-90, 90], lon=[-180,180]):
    
    df_casts = df_casts[(df_casts.lat.between(lat[0], lat[1])) & (df_casts.lon.between(lon[0], lon[1]))]

    fig = plt.figure(figsize=(14, 14))
    colors = sns.color_palette('hls', n_colors=len(df_casts.marine_regions.unique()))
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    mr = df_casts.marine_regions.unique()
    legend_elements = []
    for i, j in enumerate(mr):
        df_marine_regions[df_marine_regions.marine_regions == j]['geometry'].plot(ax=ax, markersize=5, color=colors[i], zorder=1);
        legend_elements.append(Line2D([0], [0], color = colors[i], lw=4, label=mr[i]))
    

    sns.scatterplot(x="lon", y="lat", data=df_casts, color = 'navy', s=20, marker='o', edgecolor='white', linewidths=0.05)
    ax.set_extent([lon[0], lon[1], lat[0], lat[1]],crs=ccrs.PlateCarree())
    gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=1, color='gray', alpha=0.7, linestyle=':')
    gl.xformatter = LONGITUDE_FORMATTER
    gl.yformatter = LATITUDE_FORMATTER

    ax.legend(handles=legend_elements, loc='lower center',
               ncol=3, borderaxespad=-12)

    geo_map(ax)
plot_marine_regions_data(casts2018_mr, df_mr, lat=[-5,15], lon=[-100,-75])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15692092860883225, 'fraction_numerical': 0.027055332518764182, 'mean_word_length': 5.025236593059937, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '45802', 'license': 'Apache-2.0', 'n_tokens_mistral': 2256, 'n_tokens_neox': 2052, 'n_words': 360, 'path': 'Examples/Example Notebook Marine Regions.ipynb', 'repo_name': 'C4IROcean/python_sdk_example_notebooks', 'size': '5729'}