2.5. Loading model data outputs — PyPAGO 1.0.1 documentation

# 2.5. Loading model data outputs

When the model section gridfile has been generated (and eventually the model domain file), the user can now load the model outputs.

## 2.5.1. Loading section data

Loading data on sections is achieved by using the `pypago.data.loaddata_sec_T()` and `pypago.data.loaddata_sec_UV()` functions, depending of the grid (T, U or V) in which the variable is stored.

### 2.5.1.1. Loading sections from T points

Loading sections from T points is achieved by using the `pypago.data.loaddata_sec_T()` function.

Its arguments are i) the list of `pypago.sections.GridSection` objects ii) the NetCDF filename containing the variables to process iii) a dictionnary containing the variables to process (dictionnary values) and the name in which they will appear in the output object (dictionary keys). In the example below, the `votemper` and the `vosaline` variables are read from the input file and are stored as `temp` and `sal` attributes, respectively.

### 2.5.1.2. Loading sections from UV points

Loading sections from U/V points is achieved by using the `pypago.data.loaddata_sec_UV()`

Its arguments are i) the list of `pypago.sections.GridSection` objects ii) the names of the NetCDF files containing the variables on the U and V points iii) a dictionnary containing the two names of the variables to process (dictionnary values, which is a list since the variable may have two different names depending of the file) and the name in which the variable will appear in the output object (dictionary keys). In the example below, we process the velocity field, whose name is uo in the grid U file and vo in the grid V file. This velocity field will be stored as the vel attribute.

Note

If in your model run, tracer transports (for instance heat transport) have been stored on U/V points, you may use this function to extract them. It gives better precision when computing heat budgets within closed domains.

### 2.5.1.3. Loading time

Loading the NetCDF time is achieved by using the `pypago.data.loadtime()` function (which uses the `pypago.pyio.read_time()` function) as follows:

The time is added as a time attribute.

Note

The name of the time variable is specified in the `param.py` file

### 2.5.1.4. Example

    import pypago.pyio
    import pypago.data

    modelsec = pypago.pyio.load('data/indian_gridsec.pygo')

    filenameT = 'data/dyna_grid_T.nc'
    filenameU = 'data/dyna_grid_U.nc'
    filenameV = 'data/dyna_grid_V.nc'

    # loading data on T points
    dirvarT = {'temp':'votemper', 'salt': 'vosaline'}
    modelsec = pypago.data.loaddata_sec_u(modelsec, filenameT, dirvarT)

    # loading data on U/V points
    dirvarUV = {'vel':['vozocrtx', 'vomecrty']}
    modelsec = pypago.data.loaddata_sec_uv(modelsec, filenameU, filenameV, dirvarUV)

    # loading time array
    modelsec = pypago.data.loadtime(modelsec, filenameT)

    pypago.pyio.save(modelsec, 'data/indian_datasec.pygo')

    In [1]: import pypago.pyio

    In [2]: data = pypago.pyio.load('data/indian_datasec.pygo')

    In [3]: print(data[0])
    Gridded section, NEMO model:
      -areavect: (31, 70)
      -depthvect: (31, 70)
      -dire: (1,)
      -faces: (70,)
      -i: (2,)
      -imax: 40
      -imin: 140
      -j: (2,)
      -jmax: 100
      -jmin: 10
      -lengthvect: (70,)
      -lvect: (70,)
      -modelname: NEMO
      -name: section4
      -nlon: 182
      -orient: (70,)
      -salt: (73, 31, 70)
      -temp: (73, 31, 70)
      -time: (73,)
      -veci: (70,)
      -vecj: (70,)
      -vel: (73, 31, 70)

## 2.5.2. Loading domain data

### 2.5.2.1. Loading data

Loading data on domain areas is achieved by using the `pypago.data.loaddata_area_T()` function. The philosophy is the same as when loading section data from T points. However, a major difference is that here, 2D variables (for instance, surface heat fluxes) can be loaded. In the above example, the 3D (time, latitude, longitude) `votemper` and `vosaline` variables are loaded as `temp` and `salt`, respectively, while the 2D variable `sohefldo` is loaded as `hf`.

### 2.5.2.2. Loading time

Time is loaded as for sections, i.e. by using the `pypago.data.loadtime()` function.

### 2.5.2.3. Example

    import pypago.pyio
    import pypago.data

    modelareas = pypago.pyio.load('data/natl_domain.pygo')

    filenameT = 'data/dyna_grid_T.nc'

    dirvarT = {'temp':'votemper', 'salt': 'vosaline',
               'hf':'sohefldo', 'ssh':'sossheig'}

    modelareas = pypago.data.loaddata_area_t(modelareas, filenameT, dirvarT)

    modelareas = pypago.data.loadtime(modelareas, filenameT)

    pypago.pyio.save(modelareas, 'data/natl_datadom.pygo')

    In [4]: import pypago.pyio

    In [5]: data = pypago.pyio.load('data/natl_datadom.pygo')

    In [6]: print(data[0])
    Domain area, NEMO model:
      -hf: (73, 461)
      -i: (461,)
      -imax: 160
      -imin: 90
      -j: (461,)
      -jmax: 147
      -jmin: 80
      -mask: (68, 71)
      -modelname: NEMO
      -name: natldom
      -nlon: 182
      -salt: (73, 31, 461)
      -secnames: ['section1', 'section2', 'section3', 'section4']
      -signs: [1, 1, 1, -1]
      -ssh: (73, 461)
      -surface: (461,)
      -temp: (73, 31, 461)
      -time: (73,)
      -volume: (31, 461)