<jupyter_start><jupyter_text>Transform Bathymetry.dat to netcdf<jupyter_code>import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
import matplotlib as mpl
import cmocean
def transform_bathymetry(infile, outfile):
    """Transform MOHID Bathymetry.dat to netcdf file
    :arg infile: path of bathymetry dt file
    :arg outfile: desired path with name of output netcdf file and .nc extension
    """
    f = open(infile, 'r')
    grid = np.zeros([896*396])
    begin = False
    counter = 0
    for i, line in enumerate(f):
        if 'GridData2D' in line:
            begin = True
            continue
        if ('GridData2D' in line) and begin:
            break
        elif begin:
            a = float(line.split()[0])
            grid[counter] = a
            counter += 1
    grid = grid.reshape([896, 396])  
    grid = xr.DataArray(grid, coords  = [np.arange(896), np.arange(396)], dims= ['grid_y', 'grid_x'])
    grid = xr.Dataset({'Bathymetry': grid})
    grid.to_netcdf(outfile, format = 'NETCDF4',engine = 'netcdf4')<jupyter_output><empty_output><jupyter_text>Load NEMO-adjusted bathymetry file, 1x- and 4x- MOHID-adjusted version of the NEMO-adjusted bathymetry.<jupyter_code># Load the .dat file for the NEMO-adjusted bathymetry and convert to NetCDF
in_orig = '/Users/rmueller/Projects/MIDOSS/MIDOSS-MOHID-grid/AfterNEMOBathy201702_rdm.dat'
out_orig = '/Users/rmueller/Projects/MIDOSS/MIDOSS-MOHID-grid/AfterNEMOBathy201702_rdm.nc'
transform_bathymetry(in_orig, out_orig)

# Load the .dat file for the 1x MOHID adjusted version of the NEMO-adjusted bathymetry and convert to NetCDF
in_v01 = '/Users/rmueller/Projects/MIDOSS/MIDOSS-MOHID-grid/AfterNEMOBathy201702_rdm_v01.dat'
out_v01 = '/Users/rmueller/Projects/MIDOSS/MIDOSS-MOHID-grid/AfterNEMOBathy201702_rdm_v01.nc'
transform_bathymetry(in_v01, out_v01)
# Load the .dat file for the 4x MOHID adjusted version of the NEMO-adjusted bathymetry and convert to NetCDF
in_v04 = '/Users/rmueller/Projects/MIDOSS/MIDOSS-MOHID-grid/AfterNEMOBathy201702_rdm_v04.dat'
out_v04 = '/Users/rmueller/Projects/MIDOSS/MIDOSS-MOHID-grid/AfterNEMOBathy201702_rdm_v04.nc'
transform_bathymetry(in_v04, out_v04)
bathy_nemo = xr.open_dataset(out_orig)
bathy_mohid_v1 = xr.open_dataset(out_v01)
bathy_mohid_v4 = xr.open_dataset(out_v04)
bathy_nemo<jupyter_output><empty_output><jupyter_text>Plot NEMO-adjusted grid<jupyter_code>bathy_nemo.Bathymetry.plot()<jupyter_output><empty_output><jupyter_text>Plot difference(s) between NEMO-adjusted grid and MOHID-adjusted grid(s)<jupyter_code>bathy_diff_01 = bathy_nemo.Bathymetry - bathy_mohid_v1.Bathymetry
bathy_diff_01.plot()
bathy_diff_04 = bathy_nemo.Bathymetry - bathy_mohid_v4.Bathymetry
bathy_diff_04.plot()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10138081395348837, 'fraction_numerical': 0.03815406976744186, 'mean_word_length': 4.723492723492724, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '169148', 'license': 'Apache-2.0', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1087, 'n_words': 205, 'path': 'notebooks/grid/Transform_bathy_dat_to_nc.ipynb', 'repo_name': 'MIDOSS/analysis-rachael', 'size': '2752'}