- Timestamp:
- 08/09/22 09:31:27 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/CPLRESTART/create_flxat.py
r6228 r6229 54 54 d_In = xr.open_dataset (myargs.input) 55 55 56 lon = d_In.lon.astype(np.float64) 57 lat = d_In.lat.astype(np.float64) 58 evap_oce = d_In.evap_oce.astype(np.float64) 59 evap_sic = d_In.evap_sic.astype(np.float64) 60 fract_oce = d_In.fract_oce.astype(np.float64) 61 fract_sic = d_In.fract_sic.astype(np.float64) 62 precip = d_In.precip.astype(np.float64) 63 snow = d_In.snow.astype(np.float64) 64 soll = d_In.soll.astype(np.float64) 65 sols = d_In.sols.astype(np.float64) 66 taux_oce = d_In.taux_oce.astype(np.float64) 67 taux_sic = d_In.taux_sic.astype(np.float64) 68 tauy_oce = d_In.tauy_oce.astype(np.float64) 69 tauy_sic = d_In.tauy_sic.astype(np.float64) 70 wind10m = d_In.wind10m.astype(np.float64) 56 lon = d_In.lon.astype(np.float64).values 57 lat = d_In.lat.astype(np.float64).values 58 evap_oce = d_In.evap_oce.astype(np.float64).values 59 evap_sic = d_In.evap_sic.astype(np.float64).values 60 fract_oce = d_In.fract_oce.astype(np.float64).values 61 fract_sic = d_In.fract_sic.astype(np.float64).values 62 precip = d_In.precip.astype(np.float64).values 63 snow = d_In.snow.astype(np.float64).values 64 soll = d_In.soll.astype(np.float64).values 65 sols = d_In.sols.astype(np.float64).values 66 taux_oce = d_In.taux_oce.astype(np.float64).values 67 taux_sic = d_In.taux_sic.astype(np.float64).values 68 tauy_oce = d_In.tauy_oce.astype(np.float64).values 69 tauy_sic = d_In.tauy_sic.astype(np.float64).values 70 wind10m = d_In.wind10m.astype(np.float64).values 71 72 ## 73 yxshape = lat.shape 74 ny, nx = yxshape 71 75 72 76 ## Computations 73 77 np.seterr (divide='ignore', invalid='ignore') 74 78 fract_oce_plus_sic = (fract_oce + fract_sic) ; ## ocean fraction 75 fract_oce_norm = xr.where (fract_oce_plus_sic > 0.0, (fract_oce)/fract_oce_plus_sic, 0.0) # free ocean vs. total ocen fraction 76 fract_sic_norm = xr.where (fract_oce_plus_sic > 0.0, (fract_sic)/fract_oce_plus_sic, 0.0) # sea ice vs. total ocean fraction 77 ## 78 COTOTRAI = precip-snow ## Liquid precip 79 COTOTSNO = snow ## Solid precipitation 80 COTOTEVA = evap_oce*fract_oce_norm + evap_sic*fract_sic_norm 81 COICEVAP = evap_sic ## Evaporation on sea ice 82 COQSRMIX = sols ## Heat flux short wave 83 COQNSMIX = soll ## Heat flux minus short wave 84 COSHFICE = sols ## Heat flux short wave over sea ice 85 CONSFICE = soll ## Heat flux minus short wave over sea ice 86 CODFLXDT = -20.0 ## W/m2 - dQ/dt 87 COCALVIN = 0.0 ## Calving of icebergs, solid 88 COLIQRUN = 0.0 ## River run-off , liquid 89 COWINDSP = wind10m ## Wind speed at 10m high 90 COTAUMOD = 0.0 ## Wind stress modulus 79 fract_oce_norm = np.where (fract_oce_plus_sic > 0.0, fract_oce/fract_oce_plus_sic, 0.0) # free ocean vs. total ocen fraction 80 fract_sic_norm = np.where (fract_oce_plus_sic > 0.0, fract_sic/fract_oce_plus_sic, 0.0) # sea ice vs. total ocean fraction 81 ## 82 COTOTRAI = xr.DataArray (precip-snow, dims=('y', 'x')) 83 COTOTRAI.attrs['long_name'] = 'Liquid precip' 84 COTOTRAI.attrs['coordinates'] = "lat lon" 85 86 COTOTSNO = xr.DataArray (snow , dims=('y', 'x')) 87 COTOTSNO.attrs['long_name'] ='Solid precipitation' 88 COTOTSNO.attrs['coordinates'] = "lat lon" 89 90 COTOTEVA = xr.DataArray (evap_oce*fract_oce_norm + evap_sic*fract_sic_norm, dims=('y', 'x')) 91 COTOTEVA.attrs['coordinates'] = "lat lon" 92 93 COICEVAP = xr.DataArray (evap_sic , dims=('y', 'x')) 94 COICEVAP.attrs['long_name'] = 'Evaporation on sea ice' 95 COICEVAP.attrs['coordinates'] = "lat lon" 96 97 COQSRMIX = xr.DataArray (sols , dims=('y', 'x')) 98 COQSRMIX.attrs['long_name'] = 'Heat flux short wave' 99 COQSRMIX.attrs['units'] = 'W/m2' 100 COQSRMIX.attrs['coordinates'] = "lat lon" 101 102 COQNSMIX = xr.DataArray (soll , dims=('y', 'x')) 103 COQNSMIX.attrs['long_name'] = 'Heat flux minus short wave' 104 COQNSMIX.attrs['units'] = 'W/m2' 105 COQNSMIX.attrs['coordinates'] = "lat lon" 106 107 COSHFICE = xr.DataArray (sols , dims=('y', 'x')) 108 COSHFICE.attrs['long_name'] = 'Heat flux short wave over sea ice' 109 COSHFICE.attrs['units'] = 'W/m2' 110 COSHFICE.attrs['coordinates'] = "lat lon" 111 112 CONSFICE = xr.DataArray (soll , dims=('y', 'x')) 113 CONSFICE.attrs['long_name'] = 'Heat flux minus short wave over sea ice' 114 CONSFICE.attrs['units'] = 'W/m2' 115 CONSFICE.attrs['coordinates'] = "lat lon" 116 117 COWINDSP = xr.DataArray (wind10m , dims=('y', 'x')) 118 COWINDSP.attrs['long_name'] = 'Wind speed at 10m high' 119 COWINDSP.attrs['units'] = 'm/s' 120 COWINDSP.attrs['coordinates'] = "lat lon" 121 122 CODFLXDT = xr.DataArray (-20.0*np.ones(yxshape), dims=('y', 'x')) 123 CODFLXDT.attrs['long_name'] = 'dQ/dT - Derivative over temperatue of turbulent heat fluxes' 124 CODFLXDT.attrs['units'] = 'W/m2/K' 125 CODFLXDT.attrs['coordinates'] = "lat lon" 126 127 COCALVIN = xr.DataArray ( 0.0*np.ones(yxshape), dims=('y', 'x')) 128 COCALVIN.attrs['long_name'] = 'Calving of icebergs, solid' 129 COCALVIN.attrs['coordinates'] = "lat lon" 130 131 COLIQRUN = xr.DataArray ( 0.0*np.ones(yxshape), dims=('y', 'x')) 132 COLIQRUN.attrs['long_name'] = 'River run-off, liquid' 133 COLIQRUN.attrs['coordinates'] = "lat lon" 91 134 92 135 ## Wind stress 93 tau_x = (taux_oce*fract_oce_norm + taux_sic*fract_sic_norm) ; 94 tau_y = (tauy_oce*fract_oce_norm + tauy_sic*fract_sic_norm) ; 95 COTAUMOD = np.sqrt ( (tau_x*tau_x + tau_y*tau_y) ) ; 136 tau_x = (taux_oce*fract_oce_norm + taux_sic*fract_sic_norm) 137 tau_y = (tauy_oce*fract_oce_norm + tauy_sic*fract_sic_norm) 138 COTAUMOD = xr.DataArray (np.sqrt ( (tau_x*tau_x + tau_y*tau_y) ) , dims=('y', 'x')) 139 COTAUMOD.attrs['long_name'] = 'Wind stress modulus' 140 COTAUMOD.attrs['units'] = 'Pa' 141 COTAUMOD.attrs['coordinates'] = "lat lon" 96 142 97 143 ## Wind stress, from east/north components to geocentric 98 rad = np.deg2rad(1.0) 99 COTAUXXU = -tau_x * np.sin(rad * lon) - tau_y * np.sin(rad * lat) * np.cos(rad * lon) 100 COTAUYYU = tau_x * np.cos(rad * lon) - tau_y * np.sin(rad * lat) * np.sin(rad * lon) 101 COTAUZZU = tau_y * np.cos(rad * lat) 144 rad = np.deg2rad (1.0) 145 COTAUXXU = xr.DataArray (-tau_x * np.sin(rad * lon) - tau_y * np.sin(rad * lat) * np.cos(rad * lon) , dims=('y', 'x')) 146 COTAUYYU = xr.DataArray ( tau_x * np.cos(rad * lon) - tau_y * np.sin(rad * lat) * np.sin(rad * lon) , dims=('y', 'x')) 147 COTAUZZU = xr.DataArray ( tau_y * np.cos(rad * lat) , dims=('y', 'x')) 148 102 149 103 150 ## Value at North Pole 104 105 151 if myargs.IsUnstructured == 'yes' : 106 152 ## Value at North Pole for DYNAMICO grid … … 119 165 120 166 ## 167 COTAUXXU.attrs['long_name'] = 'Wind stress in geocentric referential - x-component' 168 COTAUYYU.attrs['long_name'] = 'Wind stress in geocentric referential - y-component' 169 COTAUZZU.attrs['long_name'] = 'Wind stress in geocentric referential - z-component' 170 171 COTAUXXU.attrs['units'] = 'Pa' 172 COTAUYYU.attrs['units'] = 'Pa' 173 COTAUZZU.attrs['units'] = 'Pa' 174 175 COTAUXXU.attrs['coordinates'] = "lat lon" 176 COTAUYYU.attrs['coordinates'] = "lat lon" 177 COTAUZZU.attrs['coordinates'] = "lat lon" 178 121 179 COTAUXXV = COTAUXXU ; COTAUYYV = COTAUYYU ; COTAUZZV = COTAUZZU 122 ## 180 123 181 124 182 ## Creates final Dataset 125 126 d_Out = xr.Dataset ( { 183 lon = xr.DataArray (lon, dims=('y', 'x')) 184 lon.attrs['name'] = 'longitude' 185 lon.attrs['long_name'] = 'Longitude' 186 lon.attrs['units'] = 'degrees_east' 187 lon.attrs['bounds'] = 'bounds_lon' 188 189 lat = xr.DataArray (lat, dims=('y', 'x')) 190 lat.attrs['name'] = 'latitude' 191 lat.attrs['long_name'] = 'Latitude' 192 lat.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, 127 206 'COTOTRAI':COTOTRAI, 128 207 'COTOTSNO':COTOTSNO, … … 145 224 'COTAUZZV':COTAUZZV } ) 146 225 226 d_Out.attrs['Associated files'] = myargs.input 227 d_Out.attrs['Conventions'] = "CF-1.6" 228 d_Out.attrs['source'] = "IPSL Earth system model" 229 d_Out.attrs['group'] = "ICMC IPSL Climate Modelling Center" 230 d_Out.attrs['Institution'] = "IPSL https.//www.ipsl.fr" 231 try : d_Out.attrs['directory'] = os.getcwd () 232 except : pass 233 try : d_Out.attrs['HOSTNAME'] = platform.node () 234 except : pass 235 try : d_Out.attrs['LOGNAME'] = os.getlogin () 236 except : pass 237 try : d_Out.attrs['Python'] = "Python version " + platform.python_version () 238 except : pass 239 try : d_Out.attrs['OS'] = platform.system () 240 except : pass 241 try : d_Out.attrs['release'] = platform.release () 242 except : pass 243 try : d_Out.attrs['hardware'] = platform.machine () 244 except : pass 245 d_Out.attrs['conventions'] = "SCRIP" 246 d_Out.attrs['dest_grid'] = "curvilinear" 247 d_Out.attrs['Model'] = "IPSL CM6" 248 d_Out.attrs['SVN_Author'] = "$Author: omamce $" 249 d_Out.attrs['SVN_Date'] = "$Date: 2022-07-06 11:06:07 +0200 (Wed, 06 Jul 2022) $" 250 d_Out.attrs['SVN_Revision'] = "$Revision: 6190 $" 251 d_Out.attrs['SVN_Id'] = "$Id: CalvingWeights.py 6190 2022-07-06 09:06:07Z omamce $" 252 d_Out.attrs['SVN_HeadURL'] = "$HeadURL: svn+ssh://omamce@forge.ipsl.jussieu.fr/ipsl/forge/projets/igcmg/svn/TOOLS/MOSAIX/CalvingWeights.py $" 253 254 147 255 d_Out.to_netcdf ( myargs.output, format=NcFormat ) 148 256 d_Out.close() 149 257 ## =========================================================================== 150 258 ##
Note: See TracChangeset
for help on using the changeset viewer.