Skip to content
Snippets Groups Projects
Select Git revision
  • 0b631b81ca16e97f7679f047cbb8e624eae705e8
  • master default protected
  • replication_test
  • release-1.10 protected
  • dev protected
  • 556-usage-statistics
  • 553-semantic-recommendation-2
  • 553-semantic-recommendation
  • release-1.9 protected
  • 551-init-broker-service-permissions
  • 549-test-oai-pmh
  • 545-saving-multiple-times-breaks-pid-metadata
  • 499-standalone-compute-service-2
  • 539-load-tests
  • hotfix/helm-chart
  • luca_ba_new_interface
  • 534-bug-when-adding-access-to-user-that-is-not-registered-at-dashboard-service
  • release-1.8 protected
  • 533-integrate-semantic-recommendation
  • feature/openshift
  • 518-spark-doesn-t-map-the-headers-correct
  • v1.10.4 protected
  • v1.10.3 protected
  • v1.10.2 protected
  • v1.10.1 protected
  • v1.10.0-rc13 protected
  • v1.10.0-rc12 protected
  • v1.10.0-rc11 protected
  • v1.10.0-rc10 protected
  • v1.10.0-rc9 protected
  • v1.10.0-rc8 protected
  • v1.10.0-rc7 protected
  • v1.10.0-rc6 protected
  • v1.10.0-rc5 protected
  • v1.10.0-rc4 protected
  • v1.10.0-rc3 protected
  • v1.10.0-rc2 protected
  • v1.10.0rc1 protected
  • v1.10.0rc0 protected
  • v1.10.0 protected
  • v1.9.3 protected
41 results

coverage.txt

Blame
  • run_obs_diag.py 2.79 KiB
    import os, sys, shutil, glob
    from config.cfg import exp, cluster
    from utils import symlink, copy, sed_inplace, append_file
    
    rundir_program = '/home/fs71386/lkugler/data/run_DART/'
    
    
    def prepare(obserr_iszero='.true.'):
        copy(cluster.scriptsdir+'/../templates/input.eval.nml',
                rundir_program+'/input.nml')
        sed_inplace(rundir_program+'/input.nml', '<n_ens>', str(int(exp.n_ens)))
        sed_inplace(rundir_program+'/input.nml', '<zero_error_obs>', obserr_iszero)
        sed_inplace(rundir_program+'/input.nml', '<horiz_dist_only>', '.false.')  # dummy
        sed_inplace(rundir_program+'/input.nml', '<vert_norm_hgt>', '5000.0')  # dummy
        
        append_file(rundir_program+'/input.nml', cluster.scriptsdir+'/../templates/obs_def_rttov.VIS.nml')
    
    
    def write_input_filelist(filepaths):
        fpath = rundir_program+'/obsdiag_inputlist.txt'
        print('writing', fpath)
        if os.path.exists(fpath):
            os.remove(fpath)
    
        with open(fpath, 'w') as f:
            for fin in filepaths:
                f.write(fin)
                f.write('\n')
    
    
    def run_obsdiag(filepaths, f_out='./obsdiag.nc'):
        write_input_filelist(filepaths)
    
        for obserr_iszero in ['.true.', '.false.']:
            prepare(obserr_iszero=obserr_iszero)
    
            # run_allinoneplace obs_diag
            print('------ running obs_diag program')
            os.chdir(rundir_program)
            symlink(cluster.dart_srcdir+'/obs_diag', rundir_program+'/obs_diag')
            os.system('./obs_diag >& obs_diag.log')  # caution, this overwrites obs_seq_to_netcdf
    
            # move output to archive
            #outdir = os.path.dirname(f_out)  #'/'.join(folder_obs_seq_final.split('/')[:-1])
            if obserr_iszero == '.true.':
                fout = f_out[:-3]+'_wrt_truth.nc'   
            elif obserr_iszero == '.false.':
                fout = f_out[:-3]+'_wrt_obs.nc' 
            shutil.move(rundir_program+'/obs_diag_output.nc', fout)
            print(fout, 'saved.')
    
    
    def run_obs_seq_to_netcdf(filepaths, f_out='./obs_epoch.nc'):
    
        write_input_filelist(filepaths)
        print('------ running obs_seq_to_netcdf program')
        #shutil.copy(cluster.dart_srcdir+'/obs_seq_to_netcdf-bak', rundir_program+'/obs_seq_to_netcdf')
        os.chdir(rundir_program)
        os.system('./obs_seq_to_netcdf  >& obs_seq_to_netcdf.log')  # caution, overwrites its own binary?!
        shutil.move(rundir_program+'/obs_epoch_001.nc', f_out)
        print(f_out, 'saved.')
    
    
    if __name__ == '__main__':
        #folder_obs_seq_final = '/home/fs71386/lkugler/data/DART-WRF/rundir/test' 
        print('python run_obs_diag.py ')
        folder_obs_seq_final = str(sys.argv[1])
        files = sorted(glob.glob(folder_obs_seq_final+'/*.final'))  # input for obs_diag program
        
        run_obsdiag(files, f_out='./test.nc')  # input must be files with posterior data!!
        run_obs_seq_to_netcdf(files, outdir=folder_obs_seq_final)  # input can be files without posterior data