my_file=basedir + '/' + my_exp + '/' + ctime.strftime("%Y%m%d%H%M%S") + '/' + filetype + '/update_comp_meandiff_vobs_' + var_obs + '_upd_obs_' + var_upd + '_ens_size_' + str(nbv) + '_obs_inc_' + str(obs_increment[iv]) + '.grd'

         print('Reading update comparisson for ',var_obs,' and ',var_upd)

         #Read all the variables and levels at once
         tmp_parameter[:,:,:,it] = np.squeeze( ctlr.read_data(  my_file , ctl_dict , undef2nan = True ) )

         #print( np.nanmin(tmp_parameter[:,:,:,it]) , np.nanmax( tmp_parameter[:,:,:,it] ) )

         ctime = ctime + delta
 
         it = it + 1

      print ( "Finish time loop" )

      rmse = np.sqrt( np.squeeze( np.nanmean( np.power( tmp_parameter , 2) , 3 ) ) )
      bias = np.squeeze( np.nanmean( tmp_parameter , 3 ) )

      print('RMSE ', np.nanmin(rmse) , np.nanmax(rmse) )
      print('BIAS ', np.nanmin(bias) , np.nanmax(bias) )

      my_file=outputdir + '/update_comp_meandiff_vobs_' + var_obs + '_upd_obs_' + var_upd + '_ens_size_' + str(nbv) + '_obs_inc_' + str(obs_increment[iv]) + '_rmse' + '.grd'
      comm.write_data(outfile=my_file,mydata=rmse,nx=nx,ny=ny,nz=nlev,ie=endian,acc=access)

      my_file=outputdir + '/update_comp_meandiff_vobs_' + var_obs + '_upd_obs_' + var_upd + '_ens_size_' + str(nbv) + '_obs_inc_' + str(obs_increment[iv]) + '_bias' + '.grd'
      comm.write_data(outfile=my_file,mydata=bias,nx=nx,ny=ny,nz=nlev,ie=endian,acc=access)



Esempio n. 2
0
            #Read all the variables and levels at once
            tmp_parameter[:, :, :, it] = np.squeeze(
                ctlr.read_data(my_file, ctl_dict, undef2nan=True))

            print(np.nanmin(tmp_parameter[:, :, :, it]),
                  np.nanmax(tmp_parameter[:, :, :, it]))

            ctime = ctime + delta

            it = it + 1

        print("Finish time loop")

        frequency = np.zeros(np.shape(tmp_parameter))
        frequency[tmp_parameter > threshold] = 1.0
        frequency[np.isnan(tmp_parameter)] = np.nan

        frequency = np.squeeze(np.nanmean(frequency, 3))

        print(np.nanmin(frequency), np.nanmax(frequency))

        my_file = outputdir + '/' + file_name + '_freq' + '.grd'
        comm.write_data(outfile=my_file,
                        mydata=frequency,
                        nx=nx,
                        ny=ny,
                        nz=nlev,
                        ie=endian,
                        acc=access)
Esempio n. 3
0
            my_file = basedir + my_exp + '/' + ctime.strftime(
                "%Y%m%d%H%M%S"
            ) + '/' + my_file_type + '/' + '/' + file_name + '.grd'

            #Read all the variables and levels at once
            tmp_parameter[:, :, :, it] = np.squeeze(
                ctlr.read_data(my_file, ctl_dict, undef2nan=True))

            print(np.nanmin(tmp_parameter[:, :, :, it]),
                  np.nanmax(tmp_parameter[:, :, :, it]))

            ctime = ctime + delta

            it = it + 1

        print("Finish time loop")

        parameter = np.squeeze(np.nanmean(tmp_parameter, 3))

        print(np.nanmin(parameter), np.nanmax(parameter))

        my_file = outputdir + '/' + file_name + '_mean' + '.grd'
        comm.write_data(outfile=my_file,
                        mydata=parameter,
                        nx=nx,
                        ny=ny,
                        nz=nlev,
                        ie=endian,
                        acc=access)
                        nx=nx,
                        ny=ny,
                        nz=nz,
                        nbv=nbv,
                        nmoments=nmoments,
                        undef=undef)

                    for imoment in range(0, nmoments):
                        momentstr = "%04d" % (imoment + 1)
                        my_file = basedir + '/' + my_exp_name + '/' + ctime.strftime(
                            "%Y%m%d%H%M%S"
                        ) + '/' + my_file_type + '/moment' + momentstr + '.grd'
                        comm.write_data(outfile=my_file,
                                        mydata=my_moments[:, :, :, imoment],
                                        nx=nx,
                                        ny=ny,
                                        nz=nz,
                                        ie=endian,
                                        acc=access)

                if get_kldistance:
                    print("Computing kl divergence" +
                          ctime.strftime("%Y%m%d%H%M%S"))
                    kldist = comm.compute_kld(my_ensemble=my_ensemble,
                                              my_undefmask=my_undefmask,
                                              nx=nx,
                                              ny=ny,
                                              nz=nz,
                                              nbv=nbv,
                                              undef=undef,
                                              nbins=nbins)
      #Compute tot cond 
      tot_cond_f = xf[:,:,:,:,iqr] + xf[:,:,:,:,iqs] + xf[:,:,:,:,iqg] 
      tot_cond_a = xa[:,:,:,:,iqr] + xa[:,:,:,:,iqs] + xa[:,:,:,:,iqg]

      tot_cond_f[ tot_cond_f < np.min(tot_cond_f) ] = np.min(tot_cond_f)
      tot_cond_a[ tot_cond_a < np.min(tot_cond_f) ] = np.min(tot_cond_f) 
      
      tot_cond_fcero_freq = np.sum( ( tot_cond_f == np.min(tot_cond_f) ).astype('int'),3)/nbv
      tot_cond_acero_freq = np.sum( ( tot_cond_a == np.min(tot_cond_f) ).astype('int'),3)/nbv


      #Write the analysis for the update variables
      print('Writing data')
      for ivar,my_var in enumerate(updated_variables)  :
          my_file=basedir + '/' + expname + '/' + ctime.strftime("%Y%m%d%H%M%S") + '/' + file_type + '/update_dbz_' + my_var + '_obs_inc_' + str(obs_increment) + '_obserr_' + str(obs_error) + '.grd'
          comm.write_data(outfile=my_file,mydata=xa_mean[:,:,:,ivar],nx=nx,ny=ny,nz=nlev,ie=endian,acc=access)

      #Write the analysis reflectivity (reflectivity of the ensemble mean)
      my_file=basedir + '/' + expname + '/' + ctime.strftime("%Y%m%d%H%M%S") + '/' + file_type + '/update_dbz_dbz_obs_inc_' + str(obs_increment) + '_obserr_' + str(obs_error) + '.grd'
      comm.write_data(outfile=my_file,mydata=xao_mean,nx=nx,ny=ny,nz=nlev,ie=endian,acc=access)

     #Write the tot cond cero frec
      my_file=basedir + '/' + expname + '/' + ctime.strftime("%Y%m%d%H%M%S") + '/' + file_type + '/posterior_tot_cond_' + str(obs_increment) + '_obserr_' + str(obs_error) + '.grd'
      comm.write_data(outfile=my_file,mydata=np.mean(tot_cond_a,3),nx=nx,ny=ny,nz=nlev,ie=endian,acc=access)

     #Write the analysis tot cond cero frec
      my_file=basedir + '/' + expname + '/' + ctime.strftime("%Y%m%d%H%M%S") + '/' + file_type + '/posterior_tot_cond_cero_frec_' + str(obs_increment) + '_obserr_' + str(obs_error) + '.grd'
      comm.write_data(outfile=my_file,mydata=tot_cond_acero_freq,nx=nx,ny=ny,nz=nlev,ie=endian,acc=access)


      #Write the gues for the update variables
Esempio n. 6
0
                        undefmask=my_undefmask[:, :, obs_record_list],
                        nens=nbv,
                        nx=nx,
                        ny=ny,
                        nz=local_nz,
                        obs_increment=obs_increment[iv],
                        obs_error=obs_error[iv])

                    my_file = basedir + '/' + my_exp_name + '/' + ctime.strftime(
                        "%Y%m%d%H%M%S"
                    ) + '/' + my_file_type + '/update_comp_meandiff_vobs_' + var_obs + '_upd_obs_' + var_upd + '_ens_size_' + str(
                        nbv) + '_obs_inc_' + str(obs_increment[iv]) + '.grd'
                    comm.write_data(outfile=my_file,
                                    mydata=mean_diff,
                                    nx=nx,
                                    ny=ny,
                                    nz=local_nz,
                                    ie=endian,
                                    acc=access)

                    my_file = basedir + '/' + my_exp_name + '/' + ctime.strftime(
                        "%Y%m%d%H%M%S"
                    ) + '/' + my_file_type + '/update_comp_modediff_vobs_' + var_obs + '_upd_obs_' + var_upd + '_ens_size_' + str(
                        nbv) + '_obs_inc_' + str(obs_increment[iv]) + '.grd'
                    comm.write_data(outfile=my_file,
                                    mydata=mode_diff,
                                    nx=nx,
                                    ny=ny,
                                    nz=local_nz,
                                    ie=endian,
                                    acc=access)
Esempio n. 7
0
            ) + '/' + filetype + '/update_comp_kld_vobs_' + var_obs + '_upd_obs_' + var_upd + '_ens_size_' + str(
                nbv) + '_obs_inc_' + str(obs_increment[iv]) + '.grd'

            print('Reading update comparisson for ', var_obs, ' and ', var_upd)

            #Read all the variables and levels at once
            tmp_parameter[:, :, :, it] = np.squeeze(
                ctlr.read_data(my_file, ctl_dict, undef2nan=True))

            #print( np.nanmin(tmp_parameter[:,:,:,it]) , np.nanmax( tmp_parameter[:,:,:,it] ) )

            ctime = ctime + delta

            it = it + 1

        print("Finish time loop")

        meankld = np.squeeze(np.nanmean(tmp_parameter, 3))

        print('Mean KLD ', np.nanmin(meankld), np.nanmax(meankld))

        my_file = outputdir + '/update_comp_vobs_' + var_obs + '_upd_obs_' + var_upd + '_ens_size_' + str(
            nbv) + '_obs_inc_' + str(obs_increment[iv]) + '_kld' + '.grd'
        comm.write_data(outfile=my_file,
                        mydata=meankld,
                        nx=nx,
                        ny=ny,
                        nz=nlev,
                        ie=endian,
                        acc=access)
Esempio n. 8
0
          for iobs , my_obs_var in enumerate( obs_variables ) :
 
             print('Computing single obs update for variable ',my_var 
             [i_ind,e_ind]=get_var_start_end( ctl , my_var )  #Get start and end index.

             hxf = my_ensemble[obs_location[0],obs_location[1],obs_location[2]+i_ind,:]
             yo  = np.mean( hxf ) + obs_increment[iobs]
             
             #EnKF update
             [umean,ustd,umode]compute_single_obs_update(hxf=hxf,ens=my_ensemble,mask=my_undefmask,nx=nx,ny=ny,nz=nz,nens=nbv,yo=yo,obs_error=obs_error[iobs]
                                                         ,undef=undef,update_type=1]
             prefix=basedir + '/' + my_exp_name + '/' + ctime.strftime("%Y%m%d%H%M%S") + '/' + my_file_type + '/updateEnKF_' + my_obs_var + '_'
             sufix = '_obsloc_x'+str(obs_location[0])+'_y'+str(obs_location[1])+'_z'+str(obs_location[2])+'.grd'
             my_file= prefix + 'mean' + sufix 
             comm.write_data(outfile=my_file,mydata=umean,nx=nx,ny=ny,nz=nz,ie=endian,acc=access)
             my_file= prefix + 'std' + sufix
             comm.write_data(outfile=my_file,mydata=ustd,nx=nx,ny=ny,nz=nz,ie=endian,acc=access)
             my_file= prefix + 'mode' + sufix
             comm.write_data(outfile=my_file,mydata=umode,nx=nx,ny=ny,nz=nz,ie=endian,acc=access)

             #ISPF update
             [umean,ustd,umode]compute_single_obs_update(hxf=hxf,ens=my_ensemble,mask=my_undefmask,nx=nx,ny=ny,nz=nz,nens=nbv,yo=yo,obs_error=obs_error[iobs]
                                                         ,undef=undef,update_type=2]
             prefix=basedir + '/' + my_exp_name + '/' + ctime.strftime("%Y%m%d%H%M%S") + '/' + my_file_type + '/updateISPF_' + my_obs_var + '_'
             sufix = '_obsloc_x'+str(obs_location[0])+'_y'+str(obs_location[1])+'_z'+str(obs_location[2])+'.grd'
             my_file= prefix + 'mean' + sufix
             comm.write_data(outfile=my_file,mydata=umean,nx=nx,ny=ny,nz=nz,ie=endian,acc=access)
             my_file= prefix + 'std' + sufix
             comm.write_data(outfile=my_file,mydata=ustd,nx=nx,ny=ny,nz=nz,ie=endian,acc=access)
             my_file= prefix + 'mode' + sufix