from earthdiagnostics import Utils, cdftools, cdo, TempFile from earthdiagnostics.basins import Basins from autosubmit.config.log import Log import shutil class Ice(object): @staticmethod def siasiesiv(thickness_file, fraction_file, output_file, basin): """ Compute the sea ice extent (1000km2), area (1000km2), volume (km3) and mean thickness (m) in both hemispheres or a specified region. Created in April 2012 Author : vguemas@ic3.cat Modified in June 2014 Author : neven.fuckar@ic3.cat Computation of the properties in various selected regions according to mask.regions.${NEMOVERSION}.nc (mask_regions.nc) is based on modification of mask.regions.ORCA1.noverticalinfo.Matt.nc from Matthieu Chevallier. :param input_file: input ice file name :param output_file: output file name :param basin: region of interest :return: """ nco = Utils.nco input_scratch = TempFile.get() shutil.copy(thickness_file, input_scratch) nco.ncks(input=fraction_file, output=input_scratch, options='-A -v sic') ntime = int(cdo.ntime(input=input_scratch)[0]) files = list() for time in range(ntime): Log.info('Running time {0}', time) temp = TempFile.get() nco.ncks(input=input_scratch, output=temp, options='-O -d time,{0}'.format(time)) Log.info('Computing salt content') cdftools.run('cdficediags', input=temp) Utils.move_file('icediags.nc', temp) files.append(temp) temp = TempFile.get() cdo.cat(input=' '.join(files), output=temp,) nco.ncks(input=input_scratch, output=temp, options='-A -v time') Utils.move_file(temp, output_file) # # for jt in $(seq 1 $ntime) ; do # cdo seltimestep,$jt $1 tmpice.nc # cdficediags tmpice.nc>ice.txt # for d in N S;do # ncdump toto_${d}.nc > ice_template.cdl # sia=`grep ${d}Area ice.txt |awk '{print $4}'` # sie=`grep ${d}Exnsidc ice.txt|awk '{print $4}'` # siv=`grep ${d}Volume ice.txt|awk '{print $4}'` # sed -e "s/sia =.*/sia = $sia ;/" ice_template.cdl > ice_template2.cdl # sed -e "s/sie =.*/sie = $sie ;/" ice_template2.cdl > ice_template3.cdl # sed -e "s/siv =.*/siv = $siv ;/" ice_template3.cdl > ice_template.cdl # ncgen -o ice_${d}_${jt}.nc ice_template.cdl # rm -f ice_template.cdl ice_template2.cdl ice_template3.cdl # done # list1=$list1" "ice_N_${jt}.nc # list2=$list2" "ice_S_${jt}.nc # rm -f ice.txt tmpice.nc icediags.nc # done # cdo cat $list1 ice_N_${2} # cdo cat $list2 ice_S_${2} # ncks -A -v time $1 ice_N_${2} # ncks -A -v time $1 ice_S_${2} # rm -f $list1 $list2 toto_N.nc toto_S.nc # # for d in N S;do # ncatted -O -a units,sia,m,c,1000km2 ice_${d}_${2} # ncatted -O -a units,sie,m,c,1000km2 ice_${d}_${2} # # ncks -O -v siv ice_${d}_${2} siv_${d}_${2}1 # ncks -O -v sia ice_${d}_${2} sia_${d}_${2}1 # ncrename -h -v sia,siv sia_${d}_${2}1 # ncbo -O --op_typ=dvd siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} # ncatted -O -a standard_name,siv,m,c,Mean_sea_ice_thickness sit_${d}_${2} # ncatted -O -a long_name,siv,m,c,"Mean sea ice thickness" sit_${d}_${2} # ncatted -O -a units,siv,m,c,m sit_${d}_${2} # cdo ltc,100 sit_${d}_${2} sit_${d}_${2}1 # cdo ifthenelse sit_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 # ncrename -h -v siv,sit sit_${d}_${2}2 # ncks -A sit_${d}_${2}2 ice_${d}_${2} # # rm siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 # done # # setminmax ice_N_${2} sia sie siv sit # setminmax ice_S_${2} sia sie siv sit # # if [ ! -z "$3" ] ; then # ncrename -h -v tmask,$3 mask.nc # mv mask.nc mask_regions.nc # mv mask_tmp.nc mask.nc # fi # # }