<jupyter_start><jupyter_text>Reset properties in NetCDF mapfile* Velocities* Concentrations* Turbulent energy and dissipation* Vertical and horizontal eddy viscosity and diffusivity* Transport layer composition<jupyter_code>import xarray as xr
from JulesD3D.processNetCDF import fixMeshGrid, addUnderlayerCoords, makeVelocity
import numpy as np
from IPython.display import Markdown as md
filename = '/Users/julesblom/ThesisResults/Slope0.85/trim-36km_200m_W60ChannelRun45_compressed.nc'

trim = xr.open_dataset(filename)
new_write_filename = filename[0:-14] + '.nc'
md(f"# {new_write_filename} \n ## Double check it")
sand = 0 
silt = 1
last_timestep = -1

# this has happened
if silt == sand:
    raise Exception("You stupid")
interfaces_shape = trim.W.isel(time=last_timestep).shape
centers_shape = trim.V1.isel(time=last_timestep).shape
all_ones_centers = np.ones(centers_shape)

all_zeros_centers = np.zeros(centers_shape)
all_zeros_interfaces = np.zeros(interfaces_shape)<jupyter_output><empty_output><jupyter_text>Reset velocity<jupyter_code>trim['V1'][last_timestep] = all_zeros_centers      # Horizontal velocity U component
trim['U1'][last_timestep] = all_zeros_centers      # Horizontal velocity U component
trim['WPHY'][last_timestep] = all_zeros_centers    # Vertical velocity component?
trim['W'][last_timestep] = all_zeros_interfaces    # Velocity angle?<jupyter_output><empty_output><jupyter_text>Reset Eddies<jupyter_code>trim['VICWW'][last_timestep] = all_zeros_interfaces # Vertical eddy viscosity-3D
trim['DICWW'][last_timestep] = all_zeros_interfaces # Vertical eddy diffusivity-3D
trim['VICUV'][last_timestep] = all_zeros_centers    # Horizontal eddy viscosity<jupyter_output><empty_output><jupyter_text>Reset Water Level<jupyter_code>water_level_shape = trim.S1.isel(time=0).shape
reset_water_level = np.zeros(water_level_shape)

trim['S1'][last_timestep] = reset_water_level<jupyter_output><empty_output><jupyter_text>Reset concentrations<jupyter_code>test_conc_shape = trim.R1.isel(time=last_timestep).shape
reset_concentrations = np.zeros(test_conc_shape)
trim['R1'][last_timestep] = reset_concentrations<jupyter_output><empty_output><jupyter_text>Reset density<jupyter_code>initial_density = float(trim.RHOCONST.values)
reset_densities = all_ones_centers * initial_density

trim['RHO'][last_timestep] = reset_densities<jupyter_output><empty_output><jupyter_text>Reset transport layer  Volume fraction<jupyter_code>vol_frac_sand_transport_layer_end = trim.LYRFRAC.isel(time=last_timestep, LSEDTOT=sand, nlyr=0)
vol_frac_silt_transport_layer_end = trim.LYRFRAC.isel(time=last_timestep, LSEDTOT=silt, nlyr=0)
# Replace transport layer with 50%/50% composition
replaced_vol_frac_sand = vol_frac_sand_transport_layer_end.where(vol_frac_sand_transport_layer_end.values == 0, 0.5)
replaced_vol_frac_silt = vol_frac_silt_transport_layer_end.where(vol_frac_silt_transport_layer_end.values == 0, 0.5)
# Reset volume composition in transport layer at final timestep
trim.LYRFRAC[last_timestep, sand, 0] = replaced_vol_frac_sand.values
trim.LYRFRAC[last_timestep, silt, 0] = replaced_vol_frac_silt.values<jupyter_output><empty_output><jupyter_text>Mass of sediment<jupyter_code># for 50 cm thick transport layer!
initial_sand_mass = 400 # 16000 # [kg/m2]
initial_silt_mass = 125 # 5000  # [kg/m2]
mass_sand_transport_layer_end = trim.MSED.isel(time=last_timestep, LSEDTOT=sand, nlyr=0)
mass_silt_transport_layer_end = trim.MSED.isel(time=last_timestep, LSEDTOT=silt, nlyr=0)

replaced_mass_sand = mass_sand_transport_layer_end.where(mass_sand_transport_layer_end.values == 0, initial_sand_mass)
replaced_mass_silt = mass_silt_transport_layer_end.where(mass_silt_transport_layer_end.values == 0, initial_silt_mass)
# Reset mass of sediment in transport layer at final timestep
trim.MSED[last_timestep, sand, 0] = replaced_mass_sand.values
trim.MSED[last_timestep, silt, 0] = replaced_mass_silt.values<jupyter_output><empty_output><jupyter_text>Write to NetCDFWrite only last timestep to save space<jupyter_code>only_last_timestep = trim.isel(time=-1)
only_last_timestep.load().to_netcdf(new_write_filename, mode='w', engine='netcdf4', format='NETCDF3_64BIT') 
trim.time.size
only_last_timestep.time.size<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09773904851625059, 'fraction_numerical': 0.017192651907677815, 'mean_word_length': 9.308252427184467, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '625111', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1573, 'n_words': 241, 'path': 'QuickNEasyReset.ipynb', 'repo_name': 'JulesBlm/Delft3D-Python-Thesis', 'size': '4246'}