Minimalistic SimFit example

From Remeis-Wiki
Revision as of 16:38, 12 April 2018 by Falkner (talk | contribs) (Created page with "=== Minimalistic SimFit example === The aim of this example is to demonstrate the functionality of the SimFit routines with a minimalistic Example. <code> require("isisscri...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Minimalistic SimFit example

The aim of this example is to demonstrate the functionality of the SimFit routines with a minimalistic Example.


require("isisscripts");

% Define Data Minimum_Stat_Err = 1e-20; seed_random(1);

variable N = 30; variable bin_lo = [1:2:#N+1]-2; variable bin_hi = [1:2:#N+1]1:;

variable data1 = struct{

 bin_lo = bin_lo,
 bin_hi = bin_hi,
 value  = (30+5*sin(2*PI*bin_lo) + grand(N)-0.5) * (bin_hi-bin_lo),
 err  = (9e-1*[1.:1.:#N]) * (bin_hi-bin_lo)

}; variable data2 = struct{

 bin_lo = bin_lo,
 bin_hi = bin_hi,
 value  = (35+10*sin(2*PI*bin_lo) + grand(N)-0.5) * (bin_hi-bin_lo),
 err    = (10e-1*[1.:1.:#N]) * (bin_hi-bin_lo)

}; variable data3 = struct{

 bin_lo = bin_lo,
 bin_hi = bin_hi,
 value  = (35+10*sin(2*PI*bin_lo) + grand(N)-0.5) * (bin_hi-bin_lo),
 err    = (10e-1*[1.:1.:#N]) * (bin_hi-bin_lo)

}; fancy_plot_unit("A"); % Nur zum plotten, falls Daten kein Spektrum sind! % % Initialize sim fit variable sfit = simultaneous_fit(); % Add data () = sfit.add_data(data1); () = sfit.add_data([data2,data3]);


% Set fit function sfit.fit_fun("sinwave2(%)");

% Define global Parameter: Tie parameter sinwave2(%).c of all groups to % that of group 1 sfit.set_global("sinwave2(%).b"); sfit.set_global("sinwave2(%).c"); sfit.set_par("sinwave2(%).d",1,0,0,1e6);

% load Parameter: variable file_org = "simpi"; variable file_new = "simpi_new";

variable file; if( wherefirst(__argv == "org") != NULL ){

 file = file_org;

} else{

 file = file_new;

} vmessage("\n Loading %s.par & %s.model.",file,file); load_par(file+".par"); sfit.load_model(file+".model");


define save_newpar(){

 vmessage("\n SAVING %s.par & %s.model.\n",file_new,file_new);
 save_par(file_new+".par");
 %sfit.save_model(file_new+".model");

};

if( wherefirst(__argv == "run") != NULL ){

 variable runjob = sfit.fit_pars_run_job("simpi_0000.job", ["simpi_0001.job", "simpi_0002.job"],
                                         "simpi_fitpars/*.fits", &save_newpar;
                                         agree,maxiter=3,wait=10);

}

  1. !/bin/bash
  2. PBS -S /bin/bash -V
  3. PBS -l nodes=2
  4. PBS -l arch=x86_64
  5. PBS -l walltime=00:01:00
  6. PBS -N simpi_fitpars_0000
  7. PBS -o /home/falkner/Public/simpi_fitpars/simpi_fitpars/simpi_fitpars_0000.out
  8. PBS -e /home/falkner/Public/simpi_fitpars/simpi_fitpars/simpi_fitpars_0000.err

cd /home/falkner/Public/simpi_fitpars COMMAND="mpiexec isis-script simpi_fitpars.sl 0" /usr/bin/nice -n +15 ${COMMAND}

  1. !/bin/bash
  2. PBS -S /bin/bash -V
  3. PBS -l nodes=2
  4. PBS -l arch=x86_64
  5. PBS -l walltime=00:01:00
  6. PBS -N simpi_fitpars_0001
  7. PBS -o /home/falkner/Public/simpi_fitpars/simpi_fitpars/simpi_fitpars_0001.out
  8. PBS -e /home/falkner/Public/simpi_fitpars/simpi_fitpars/simpi_fitpars_0001.err

cd /home/falkner/Public/simpi_fitpars COMMAND="mpiexec isis-script simpi_fitpars.sl 1" /usr/bin/nice -n +15 ${COMMAND}

  1. !/bin/bash
  2. PBS -S /bin/bash -V
  3. PBS -l nodes=2
  4. PBS -l arch=x86_64
  5. PBS -l walltime=00:01:00
  6. PBS -N simpi_fitpars_0002
  7. PBS -o /home/falkner/Public/simpi_fitpars/simpi_fitpars/simpi_fitpars_0002.out
  8. PBS -e /home/falkner/Public/simpi_fitpars/simpi_fitpars/simpi_fitpars_0002.err

cd /home/falkner/Public/simpi_fitpars COMMAND="mpiexec isis-script simpi_fitpars.sl 2" /usr/bin/nice -n +15 ${COMMAND}

require("isisscripts"); _traceback=1;

% TIME LOG tic;vmessage("%s : Calling: '%s'",time,strjoin(__argv," "));

%%% initialize the simultaneous fit, adding the %%% %%% data and defining/loading the model here %%%

()=evalfile ("simpi.sl");

% get command line arguments (last argument has to be the group index!) variable grp = atoi(__argv[-1]);

%%% set the directory for the output fits-files here %%% %%% make sure that this directory exists! %%% variable parpath = "/home/falkner/Public/simpi_fitpars/simpi_fitpars"; % check on existence of parpath if (access(parpath, F_OK) != 0) {

 vmessage("error: directory %s does not exist, aborting...", parpath);
 exit;

}

% calculate uncertainties %%% replace 'simfit' by the name of your simultaneous-fit-structure %%% variable fpars = sfit.mpi_fit_pars( grp ;

                                   dir=parpath,
                                   basefilename = sprintf("simpi_fitpars_%04d", grp)
                                 );

% TIME LOG variable elaptime = toc; vmessage("%s : Finished '%s' after %d s < %d %s", time,strjoin(__argv," "),nint(elaptime),time_array(elaptime)[-1]+1, ["sec","min","h","d","y"][length(time_array(elaptime))-1] );