Changeset 6327 for TOOLS


Ignore:
Timestamp:
02/22/23 10:02:51 (14 months ago)
Author:
snguyen
Message:

Fix broken code in CreateRestartAtm4Oasis.bash and create_flxat.py for regular lon lat grids. Now works for files in both lonlat regular grid and ICO unstructured grid.

Location:
TOOLS/CPLRESTART
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/CPLRESTART/CreateRestartAtm4Oasis.bash

    r6228 r6327  
    6363    module load hdf5 
    6464    module load netcdf-c 
    65     module load nco 
    66     module load cdo 
    67     module load python3 
     65    module load nco/4.9.1 
     66    module load cdo/1.9.5 
     67    module load python3/3.7.2 
    6868    module load datadir/igcmg 
    6969    module list 
     
    182182python3 create_flxat.py --IsUnstructured=${IsUnstructured} --input flxat_fields_notime.nc --output tmp_flxat.nc 
    183183 
    184 [[ ${IsUnstructured} = yes ]] && ncks --fl_fmt=${FL_FMT} --history --append --variable bounds_lon,bounds_lat flxat.nc  tmp_flxat.nc  
     184#this is not needed anymore since bounds are included in flxat.py if they exist 
     185#[[ ${IsUnstructured} = yes ]] && ncks --fl_fmt=${FL_FMT} --history --append --variable bounds_lon,bounds_lat tmp_flxat.nc 
    185186ncks --fl_fmt=${FL_FMT} --append --history --variable COTAUXXU,COTAUYYU,COTAUZZU,COTAUXXV,COTAUYYV,COTAUZZV,COTOTRAI,COTOTSNO,COTOTEVA,COICEVAP,COQSRMIX,COQNSMIX,COSHFICE,CONSFICE,CODFLXDT,COCALVIN,COLIQRUN,COWINDSP,COTAUMOD tmp_flxat.nc flxat.nc 
    186187 
  • TOOLS/CPLRESTART/create_flxat.py

    r6229 r6327  
    179179COTAUXXV = COTAUXXU ; COTAUYYV = COTAUYYU ; COTAUZZV = COTAUZZU 
    180180 
     181## check if bounds for lon lat are present and add them to dataset or drop them 
     182ifbnds=True if ('bounds_lon' in d_In.data_vars) and ('bounds_lat' in d_In.data_vars) else False 
    181183 
    182184## Creates final Dataset 
     
    185187lon.attrs['long_name'] = 'Longitude' 
    186188lon.attrs['units']     = 'degrees_east' 
    187 lon.attrs['bounds']    = 'bounds_lon' 
     189if ifbnds: lon.attrs['bounds']    = 'bounds_lon' 
    188190 
    189191lat = xr.DataArray (lat, dims=('y', 'x')) 
     
    191193lat.attrs['long_name'] = 'Latitude' 
    192194lat.attrs['units']     = 'degrees_north' 
    193 lat.attrs['bounds']    = 'bounds_lat' 
    194  
    195 bounds_lon = d_In.bounds_lon.values.astype (np.float64) 
    196 bounds_lat = d_In.bounds_lat.values.astype (np.float64) 
    197 nvertex = bounds_lon.shape[-1] 
    198  
    199 bounds_lon = xr.DataArray ( np.reshape (bounds_lon, (ny,nx,nvertex)), dims=('y', 'x', 'nvertex')) 
    200 bounds_lat = xr.DataArray ( np.reshape (bounds_lat, (ny,nx,nvertex)), dims=('y', 'x', 'nvertex')) 
    201  
    202 bounds_lon.attrs['units'] = 'degrees_east' 
    203 bounds_lat.attrs['units'] = 'degrees_north' 
    204  
    205 d_Out = xr.Dataset ( {'lat':lat, 'lon':lon, 'bounds_lon':bounds_lon, 'bounds_lat':bounds_lat,  
    206     'COTOTRAI':COTOTRAI, 
     195if ifbnds: lat.attrs['bounds']    = 'bounds_lat' 
     196 
     197if ifbnds:  
     198    bounds_lon = d_In.bounds_lon.values.astype (np.float64) 
     199    bounds_lat = d_In.bounds_lat.values.astype (np.float64) 
     200    nvertex = bounds_lon.shape[-1] 
     201 
     202    bounds_lon = xr.DataArray ( np.reshape (bounds_lon, (ny,nx,nvertex)), dims=('y', 'x', 'nvertex')) 
     203    bounds_lat = xr.DataArray ( np.reshape (bounds_lat, (ny,nx,nvertex)), dims=('y', 'x', 'nvertex')) 
     204 
     205    bounds_lon.attrs['units'] = 'degrees_east' 
     206    bounds_lat.attrs['units'] = 'degrees_north' 
     207 
     208# prepare dictionnary to export dataset to netcdf file with or without bounds 
     209dictdataset = {'lat':lat, 'lon':lon } 
     210if ifbnds: dictdataset.update({'bounds_lon':bounds_lon, 'bounds_lat':bounds_lat}) 
     211dictdataset.update({'COTOTRAI':COTOTRAI, 
    207212    'COTOTSNO':COTOTSNO, 
    208213    'COTOTEVA':COTOTEVA, 
     
    224229    'COTAUZZV':COTAUZZV } ) 
    225230 
     231d_Out = xr.Dataset (dictdataset) 
     232 
    226233d_Out.attrs['Associated files'] = myargs.input 
    227234d_Out.attrs['Conventions']     = "CF-1.6" 
Note: See TracChangeset for help on using the changeset viewer.