[14021] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
| 3 | import os,sys |
---|
| 4 | from netCDF4 import Dataset as netcdf |
---|
| 5 | import numpy as np |
---|
| 6 | |
---|
| 7 | resname='' |
---|
| 8 | |
---|
| 9 | # input file |
---|
| 10 | fcoord='mesh_mask.nc' |
---|
| 11 | |
---|
| 12 | # output file |
---|
| 13 | fflx='initice.nc' |
---|
| 14 | |
---|
| 15 | print ' creating init ice file ' +fflx |
---|
| 16 | |
---|
| 17 | # Reading coordinates file |
---|
| 18 | nccoord=netcdf(fcoord,'r') |
---|
| 19 | nav_lon=nccoord.variables['glamt'][0,:,:] |
---|
| 20 | nav_lat=nccoord.variables['gphit'][0,:,:] |
---|
| 21 | time_counter=1 |
---|
| 22 | LON1= nav_lon.shape[1] |
---|
| 23 | LAT1= nav_lon.shape[0] |
---|
| 24 | print 'nav_lon.shape[1]' ,nav_lon.shape[1] |
---|
| 25 | print 'LON1 ', LON1 |
---|
| 26 | print 'LAT1 ', LAT1 |
---|
| 27 | |
---|
| 28 | # Creating INITICE netcdf file |
---|
| 29 | nc=netcdf(fflx,'w') |
---|
| 30 | nc.createDimension('y',LAT1) |
---|
| 31 | nc.createDimension('x',LON1) |
---|
| 32 | nc.createDimension('time_counter',None) # Setting dimension size to 0 or None makes it unlimited. |
---|
| 33 | |
---|
| 34 | cdflon=nc.createVariable('nav_lon','f',('y','x')) |
---|
| 35 | cdflat=nc.createVariable('nav_lat','f',('y','x')) |
---|
| 36 | cdftimecounter=nc.createVariable('time_counter','f',('time_counter')) |
---|
| 37 | |
---|
| 38 | # ati : Fraction of open waters in sea ice - units % |
---|
| 39 | # hti : Sea ice thickness - units m |
---|
| 40 | # hts : Snow thickness - units m |
---|
| 41 | # smi : Sea ice salinity: |
---|
| 42 | # tmi : Sea ice internal temperature - units K |
---|
| 43 | # tsu : Sea ice surface temperature - units K |
---|
| 44 | # |
---|
| 45 | # Take constant values from namelist &namiceini of NEMO |
---|
| 46 | rn_hti_ini=2.0 |
---|
| 47 | rn_hts_ini=0.1 # initial real snow thickness (m) |
---|
| 48 | rn_ati_ini=0.99 # initial ice concentration (-) |
---|
| 49 | rn_smi_ini=6.3 # initial ice salinity (g/kg) |
---|
| 50 | rn_tmi_ini=270. # initial ice/snw temperature (K) |
---|
| 51 | rn_tsu_ini=270. # initial sea ice temperature (K) |
---|
| 52 | # |
---|
| 53 | cdfati=nc.createVariable('ati','f',('time_counter','y','x')) |
---|
| 54 | cdfati.units='Percentage' |
---|
| 55 | cdfati.long_name='Sea ice concentration' |
---|
| 56 | cdfhti=nc.createVariable('hti','f',('time_counter','y','x')) |
---|
| 57 | cdfhti.long_name='Sea ice thickness' |
---|
| 58 | cdfhti.units='m' |
---|
| 59 | cdfhts=nc.createVariable('hts','f',('time_counter','y','x')) |
---|
| 60 | cdfhts.long_name='Snow thickness' |
---|
| 61 | cdfhts.units='m' |
---|
| 62 | cdfsmi=nc.createVariable('smi','f',('time_counter','y','x')) |
---|
| 63 | cdfsmi.long_name='Sea ice salinity' |
---|
| 64 | cdfsmi.units='pss' |
---|
| 65 | cdftmi=nc.createVariable('tmi','f',('time_counter','y','x')) |
---|
| 66 | cdftmi.long_name='Sea ice internal temperature' |
---|
| 67 | cdftmi.units='Kelvin' |
---|
| 68 | cdftsu=nc.createVariable('tsu','f',('time_counter','y','x')) |
---|
| 69 | cdftsu.long_name='Sea ice surface temperature' |
---|
| 70 | cdftsu.units='Kelvin' |
---|
| 71 | |
---|
| 72 | cdflon[:,:]=nav_lon[:,:] |
---|
| 73 | cdflat[:,:]=nav_lat[:,:] |
---|
| 74 | cdftimecounter[0]=1 |
---|
| 75 | |
---|
| 76 | cdfati[:,:,:]=rn_ati_ini |
---|
| 77 | cdfhts[:,:,:]=rn_hts_ini |
---|
| 78 | cdfsmi[:,:,:]=rn_smi_ini |
---|
| 79 | cdftmi[:,:,:]=rn_tmi_ini |
---|
| 80 | cdftsu[:,:,:]=rn_tsu_ini |
---|
| 81 | |
---|
| 82 | # --- add noise in initial thickness to help nucleation of deformation --- |
---|
| 83 | #for y in np.arange(1,1000,1) : |
---|
| 84 | # for x in np.arange(1,1000,1) : |
---|
| 85 | # cdfhti[:,y,x] = rn_hti_ini+0.02*rn_hti_ini*np.random.uniform(-1,1) |
---|
| 86 | cdfhti[:,:,:]=rn_hti_ini |
---|
| 87 | |
---|
| 88 | nc.close() |
---|
| 89 | nccoord.close() |
---|
| 90 | |
---|
| 91 | #sys.exit() |
---|