<jupyter_start><jupyter_text>Explore the value of `land_adj_sedfrac_min`A minimum percentage of each grid cell that is sediments (`land_adj_sedfrac_min`) is applied to all land-adjacent grid cells.This notebook compares the implications of the value of `land_adj_sedfrac_min` for each grid.<jupyter_code>%load_ext autoreload
%autoreload 2
from itertools import product

import numpy as np
import xarray as xr

import matplotlib.pyplot as plt

import pop_tools
import util<jupyter_output><empty_output><jupyter_text>Parameters<jupyter_code>land_adj_sedfrac_mins = {
    'POP_gx3v7': 0.015, 
    'POP_gx1v7': 0.03,
    'POP_tx0.1v3': 0.2, 
}
land_adj_sedfrac_mins<jupyter_output><empty_output><jupyter_text>Read the grids<jupyter_code>grids = {}
for dst_grid in util.POP_grids:
    grids[dst_grid] = pop_tools.get_grid(dst_grid)<jupyter_output><empty_output><jupyter_text>Prepare `fesedfrac` Read pre-computed [`fesedfrac`](_sedfrac_compute.ipynb)<jupyter_code>sedfracs = {}
for dst_grid in util.POP_grids:
    with xr.open_dataset(util.sedfrac_file(dst_grid)) as dstmp:
        sedfracs[dst_grid] = dstmp.sedfrac.reset_index('z_t', drop=True).compute()<jupyter_output><empty_output><jupyter_text>Determine land-adjacent points and apply `land_adj_sedfrac_min`<jupyter_code>land_adjacent = {}
for dst_grid in util.POP_grids:
    land_adjacent[dst_grid] = util.compute_topo_adjacent_points(dst_grid)
for dst_grid in util.POP_grids:
    i_pacific = util.nlon_pacific_xsection[dst_grid]
    j_acc = util.nlat_acc_xsection[dst_grid]
    
    plt.figure()
    land_adjacent[dst_grid].isel(z_t=2).plot()
    h = plt.title(f'{dst_grid} min k={3}')

    plt.figure()
    land_adjacent[dst_grid].isel(nlon=i_pacific).plot(yincrease=False)
    h = plt.title(f'{dst_grid} Pacific transect')

    plt.figure()
    land_adjacent[dst_grid].isel(nlat=j_acc).plot(yincrease=False)
    h = plt.title(f'{dst_grid} ACC transect')
sedarea_totals = {}
for dst_grid in util.POP_grids:
        sedarea_totals[dst_grid] = (
            sedfracs[dst_grid] * grids[dst_grid].TAREA
        ).sum().values
sedarea_totals 
sedarea_profile = {}
for dst_grid in util.POP_grids:
        sedarea_profile[dst_grid] = (
            sedfracs[dst_grid] * grids[dst_grid].TAREA
        ).sum(
            ['nlat', 'nlon']
        ).assign_coords(
            z_t=grids[dst_grid].z_t
        )
        sedarea_profile[dst_grid].attrs['long_name'] = 'Area'
        sedarea_profile[dst_grid].attrs['units'] = 'cm^2'

for dst_grid in util.POP_grids:
    (sedarea_profile[dst_grid].cumsum('z_t')).plot(
        marker='.',
        label=dst_grid,
    )
    
plt.legend();
plt.title('cumulative area with depth');
for dst_grid in util.POP_grids:
    (sedarea_profile[dst_grid].sel(z_t=slice(0, 2000e2)).cumsum('z_t')).plot(
        marker='.',
        label=dst_grid,
    )
    
plt.legend();
plt.title('cumulative area with depth');
sedfrac_mods = {}
for dst_grid in util.POP_grids:
    sedfrac_mods[dst_grid] = util.apply_topo_adj_sedfrac_min(
         sedfracs[dst_grid], 
         land_adjacent[dst_grid], 
         land_adj_sedfrac_mins[dst_grid],
    )
    
sedarea_totals = {}
for dst_grid in util.POP_grids:
        sedarea_totals[dst_grid] = (
            sedfrac_mods[dst_grid] * grids[dst_grid].TAREA
        ).sum().values
sedarea_totals 
sedarea_mod_profile = {}
for dst_grid in util.POP_grids:
        sedarea_mod_profile[dst_grid] = (
            sedfrac_mods[dst_grid] * grids[dst_grid].TAREA
        ).sum(
            ['nlat', 'nlon']
        ).assign_coords(
            z_t=grids[dst_grid].z_t
        )
        sedarea_profile[dst_grid].attrs['long_name'] = 'Area'
        sedarea_profile[dst_grid].attrs['units'] = 'cm^2'

for dst_grid in util.POP_grids:
    (sedarea_mod_profile[dst_grid].cumsum('z_t')).plot(
        marker='.',
        label=dst_grid,
    )
    
plt.legend();
plt.title('cumulative area with depth');
for dst_grid in util.POP_grids:
    (sedarea_mod_profile[dst_grid].sel(z_t=slice(0, 2000e2)).cumsum('z_t')).plot(
        marker='.',
        label=dst_grid,
    )
    
plt.legend();
plt.title('cumulative area with depth');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12457831325301205, 'fraction_numerical': 0.007951807228915662, 'mean_word_length': 3.889281507656066, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '545591', 'license': 'Apache-2.0', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1594, 'n_words': 238, 'path': 'notebooks/_sedfrac_apply_land_adj_min.ipynb', 'repo_name': 'marbl-ecosys/forcing-Fe-sedflux', 'size': '4150'}