Changeset 12273


Ignore:
Timestamp:
05/22/12 10:54:55 (13 years ago)
Author:
Mathieu Morlighem
Message:

Added observation averaging

Location:
issm/trunk-jpl/src/c
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/Container/Observations.cpp

    r12231 r12273  
    7878                }
    7979                else{
    80                         //We need to average with the current observations (not done yet)
     80                        /*We need to average with the current observations*/
     81                        this->quadtree->AddAndAverage(x[i],y[i],observations_list[i]);
    8182                }
    8283        }
  • issm/trunk-jpl/src/c/objects/Kriging/Observation.cpp

    r12229 r12273  
    1515Observation::Observation(double x_in,double y_in,int xi_in,int yi_in,int index_in,double value_in){
    1616
    17         this->x     = x_in;
    18         this->y     = y_in;
    19         this->xi    = xi_in;
    20         this->yi    = yi_in;
    21         this->index = index_in;
    22         this->value = value_in;
     17        this->x      = x_in;
     18        this->y      = y_in;
     19        this->xi     = xi_in;
     20        this->yi     = yi_in;
     21        this->index  = index_in;
     22        this->value  = value_in;
     23        this->weight = 1.;
    2324
    2425}
     
    4243        printf("   xi    : "); printbinary(this->xi); printf("\n");
    4344        printf("   yi    : "); printbinary(this->yi); printf("\n");
     45        printf("   weight: %g\n",this->weight);
    4446        printf("   value : %g\n",this->value);
    4547}
  • issm/trunk-jpl/src/c/objects/Kriging/Observation.h

    r12229 r12273  
    1414                int    xi,yi;
    1515                int    index;
     16                double weight;
    1617                double value;
    1718
  • issm/trunk-jpl/src/c/objects/Kriging/Quadtree.cpp

    r12230 r12273  
    198198
    199199}/*}}}*/
     200/*FUNCTION Quadtree::AddAndAverage{{{1*/
     201void Quadtree::AddAndAverage(double x,double y,double value){
     202
     203        QuadtreeBox **pbox = NULL;
     204        QuadtreeBox  *box  = NULL;
     205        int           xi,yi;
     206        int           level,levelbin;
     207        int           index;
     208        double        length,length2;
     209
     210        /*Get integer coodinates*/
     211        this->IntergerCoordinates(&xi,&yi,x,y);
     212
     213        /*Initialize levels*/
     214        level    = 0;
     215        levelbin = (1L<<this->MaxDepth);// = 2^30
     216
     217        /*Get inital box (the largest)*/
     218        pbox=&root;
     219
     220        /*Find the smallest box where this point is located*/
     221        while((box=*pbox) && (box->nbitems<0)){
     222
     223                levelbin>>=1; level+=1;
     224
     225                pbox = &box->box[IJ(xi,yi,levelbin)];
     226        }
     227
     228        /*Add obervation in this box (should be full)*/
     229        if(box && box->nbitems==4){
     230                index  = 0;
     231                length = pow(box->obs[0]->x - x,2.) + pow(box->obs[0]->y - y,2.);
     232                for(int i=1;i<4;i++){
     233                        length2 = pow(box->obs[i]->x - x,2.) + pow(box->obs[i]->y - y,2.);
     234                        if(length2<length){
     235                                index  = i;
     236                                length = length2;
     237                        }
     238                }
     239
     240                /*We found the closest observation, now average observation (do not change xi and yi to avoid round off errors*/
     241                box->obs[index]->x = (box->obs[index]->weight*box->obs[index]->x + x)/(box->obs[index]->weight+1);
     242                box->obs[index]->y = (box->obs[index]->weight*box->obs[index]->y + y)/(box->obs[index]->weight+1);
     243                box->obs[index]->xi= int((box->obs[index]->weight*double(box->obs[index]->xi) + double(xi))/(box->obs[index]->weight+1));
     244                box->obs[index]->yi= int((box->obs[index]->weight*double(box->obs[index]->yi) + double(yi))/(box->obs[index]->weight+1));
     245                box->obs[index]->value   = (box->obs[index]->weight*box->obs[index]->value + value)/(box->obs[index]->weight+1);
     246                box->obs[index]->weight += 1;
     247        }
     248        else{
     249                _error_("Box is not full");
     250        }
     251}/*}}}*/
    200252/*FUNCTION Quadtree::Echo{{{1*/
    201253void  Quadtree::Echo(void){
  • issm/trunk-jpl/src/c/objects/Kriging/Quadtree.h

    r12229 r12273  
    5353                ~Quadtree();
    5454                void         Add(Observation *observation);
     55                void         AddAndAverage(double x,double y,double value);
    5556                void         DeepEcho(void);
    5657                void         Echo(void);
Note: See TracChangeset for help on using the changeset viewer.