Example #1
0
    def __init__(self, lambda1, lambda2, level=1.0):
        self.tmp_l1 = lambda1.deep_copy()
        self.tmp_l2 = lambda2.deep_copy()

        ## make sure we have amplitudes please
        if self.tmp_l1.is_xray_intensity_array():
            self.tmp_l1 = self.tmp_l1.f_sq_as_f()
        if self.tmp_l2.is_xray_intensity_array():
            self.tmp_l2 = self.tmp_l2.f_sq_as_f()

        ## Now this is done, swe have to set up a binner
        self.tmp_l1, self.tmp_l2 = self.tmp_l1.common_sets(self.tmp_l2)
        self.tmp_l1.setup_binner_d_star_sq_step(auto_binning=True)
        self.tmp_l2.use_binner_of(self.tmp_l1)

        self.tmp_l1_no_ano = self.tmp_l1.average_bijvoet_mates()
        self.tmp_l2_no_ano = self.tmp_l2.average_bijvoet_mates()
        self.tmp_l1_no_ano.setup_binner_d_star_sq_step(auto_binning=True)
        self.tmp_l2_no_ano.setup_binner_d_star_sq_step(auto_binning=True)

        self.plus2, self.minus2 = self.tmp_l2.hemispheres_acentrics()
        self.plus2.use_binning_of(self.tmp_l1_no_ano)
        self.minus2.use_binning_of(self.tmp_l1_no_ano)

        ## we assume that the data is properly scaled of course
        ## Loop over all bins, and in each bin,
        ## compute <diso>, <df> and their ratio
        estimates = flex.double()
        count = 0
        for bin in self.tmp_l1.binner().range_all():
            selection = self.tmp_l1_no_ano.binner().selection(bin).iselection()
            tmp1 = self.tmp_l1_no_ano.select(selection).data()
            tmp2 = self.tmp_l2_no_ano.select(selection).data()
            stmp1 = self.tmp_l1_no_ano.select(selection).sigmas()
            stmp2 = self.tmp_l2_no_ano.select(selection).sigmas()

            selection = self.plus2.binner().selection(bin).iselection()
            tmp3 = self.plus2.select(selection).data()
            tmp4 = self.minus2.select(selection).data()
            stmp3 = self.plus2.select(selection).sigmas()
            stmp4 = self.minus2.select(selection).sigmas()

            tmpiso = None
            tmpsiso = None
            tmpano = None
            tmpsano = None

            if tmp1.size() > 0:
                tmpiso = flex.mean((tmp1 - tmp2) * (tmp1 - tmp2))
                tmpsiso = flex.mean(stmp1 * stmp1 + stmp2 * stmp2)
            if tmp3.size() > 0:
                tmpano = flex.mean((tmp3 - tmp4) * (tmp3 - tmp4))
                tmpsano = flex.mean(stmp3 * stmp3 + stmp4 * stmp4)

            if tmp1.size() > 0:  ## make sure something is there
                if tmp3.size() > 0:  ## make sure something is there
                    if math.sqrt(tmpiso / tmpsiso) >= level:  ## s/n is okai
                        if math.sqrt(
                                tmpano / tmpsano) >= level:  ## s/n is okai
                            delta_iso_sq = math.sqrt(tmpiso)
                            delta_ano_sq = math.sqrt(tmpano)
                            tmp = 2.0 * delta_iso_sq / delta_ano_sq
                            print bin, tmp
                            estimates.append(tmp)
                            count += 1.0

        ## compute the trimean please
        self.ratio = None
        self.number = count
        if (self.number > 0):
            self.ratio = robust_statistics.trimean(estimates)
Example #2
0
def tst_trimean():
  n = 13
  x = flex.double(range(n))
  assert rs.trimean(x) == rs.median(x)
def tst_trimean():
    n = 13
    x = flex.double(range(n))
    assert rs.trimean(x) == rs.median(x)
Example #4
0
  def __init__(self,
               lambda1,
               lambda2,
               level=1.0):
    self.tmp_l1 = lambda1.deep_copy()
    self.tmp_l2 = lambda2.deep_copy()

    ## make sure we have amplitudes please
    if self.tmp_l1.is_xray_intensity_array():
      self.tmp_l1 = self.tmp_l1.f_sq_as_f()
    if self.tmp_l2.is_xray_intensity_array():
      self.tmp_l2 = self.tmp_l2.f_sq_as_f()

    ## Now this is done, swe have to set up a binner
    self.tmp_l1, self.tmp_l2 = self.tmp_l1.common_sets( self.tmp_l2 )
    self.tmp_l1.setup_binner_d_star_sq_step( auto_binning=True )
    self.tmp_l2.use_binner_of( self.tmp_l1 )

    self.tmp_l1_no_ano = self.tmp_l1.average_bijvoet_mates()
    self.tmp_l2_no_ano = self.tmp_l2.average_bijvoet_mates()
    self.tmp_l1_no_ano.setup_binner_d_star_sq_step( auto_binning=True )
    self.tmp_l2_no_ano.setup_binner_d_star_sq_step( auto_binning=True )

    self.plus2, self.minus2 = self.tmp_l2.hemispheres_acentrics()
    self.plus2.use_binning_of( self.tmp_l1_no_ano )
    self.minus2.use_binning_of( self.tmp_l1_no_ano )

    ## we assume that the data is properly scaled of course
    ## Loop over all bins, and in each bin,
    ## compute <diso>, <df> and their ratio
    estimates = flex.double()
    count = 0
    for bin in self.tmp_l1.binner().range_all():
      selection =  self.tmp_l1_no_ano.binner().selection( bin ).iselection()
      tmp1 = self.tmp_l1_no_ano.select( selection ).data()
      tmp2 = self.tmp_l2_no_ano.select( selection ).data()
      stmp1 = self.tmp_l1_no_ano.select( selection ).sigmas()
      stmp2 = self.tmp_l2_no_ano.select( selection ).sigmas()

      selection = self.plus2.binner().selection( bin ).iselection()
      tmp3 = self.plus2.select( selection ).data()
      tmp4 = self.minus2.select( selection ).data()
      stmp3 = self.plus2.select( selection ).sigmas()
      stmp4 = self.minus2.select( selection ).sigmas()

      tmpiso=None
      tmpsiso=None
      tmpano=None
      tmpsano=None

      if tmp1.size() > 0:
        tmpiso = flex.mean( (tmp1 - tmp2)*(tmp1 - tmp2) )
        tmpsiso = flex.mean( stmp1*stmp1 +  stmp2*stmp2  )
      if tmp3.size() > 0:
        tmpano = flex.mean( (tmp3 - tmp4)*(tmp3 - tmp4) )
        tmpsano = flex.mean( stmp3*stmp3 +  stmp4*stmp4  )

      if tmp1.size() > 0: ## make sure something is there
        if tmp3.size() > 0: ## make sure something is there
          if math.sqrt(tmpiso/tmpsiso)>=level:  ## s/n is okai
            if math.sqrt(tmpano/tmpsano)>=level: ## s/n is okai
              delta_iso_sq = math.sqrt( tmpiso  )
              delta_ano_sq = math.sqrt( tmpano  )
              tmp=2.0*delta_iso_sq/delta_ano_sq
              print bin, tmp
              estimates.append( tmp )
              count+=1.0

    ## compute the trimean please
    self.ratio = None
    self.number = count
    if (self.number>0):
      self.ratio=robust_statistics.trimean( estimates )