Exemplo n.º 1
0
def all_steps():
    print time.asctime()
    iterations = 20000
    sum_rc = 0
    for i in range(iterations):
        # Sampling Error
        bs1 = svmp.bootstrap(frw_sitedata)
        bs1m = svmp.bootstrap(frw_y1matchdata)
        bs2m = svmp.match_sites(bs1m,frw_y2matchdata)
        # Measurement Error
        me1 = svmp.measurement_error(bs1,i,"y1",outFileSiteMC)
        me1m = svmp.measurement_error(bs1m,i,"y1match",outFileSiteMC)
        me2m = svmp.measurement_error(bs2m,i,"y2match",outFileSiteMC)
        #me1 = svmp.measurement_error(bs1,i,"y1")
        #me1m = svmp.measurement_error(bs1m,i,"y1match")
        #me2m = svmp.measurement_error(bs2m,i,"y2match")
        # Calculate Change Analysis stats with Simulated Data
        yr1Samp  = svmp.SampleStats(me1,frwStratum,unit_convert)
        yr1mSamp = svmp.SampleStats(me1m,frwStratum,unit_convert)
        yr2mSamp = svmp.SampleStats(me2m,frwStratum,unit_convert)  
        frwChange = svmp.ChangeStats(yr1mSamp,yr2mSamp,yr1Samp)
        rc = frwChange.change_prop
        #print "Relative Change %r" % rc
        rcString = "%i,%r\n" % (i,rc)
        #print rcString
        rel_changes.append(rc)
        #sum_rc = sum_rc + rc
        outFileRC.write(rcString)
        
    mean_rc = sum(rel_changes)/ iterations
    print "Mean Relative Change %r" % mean_rc
    conf95pct = svmp.conf_int(rel_changes,0.95)
    print "95 percent confidence interval %r" % conf95pct
    print time.asctime()
Exemplo n.º 2
0
 def mc_stratum(y1_data,y1match_data,y2match_data,stratum,unit_convert=None):
     """ 
     Perform sampling error (bootstrap) and measurement error simulations
     to calculate area change statistics with simulated data from a single stratum
     """
     # Bootstrap Sample (Sampling Error)
     # Don't do bootstrap for core sites (non-subsampled) or strata with < 8 sites 
     if len(y1_data) < 8 or stratum.analysis == "core":
         y1 = y1_data[:]
         y1m = y1match_data[:]
         y2m = y2match_data[:]
     else:
         y1 = svmp.bootstrap(y1_data)
         y1m = svmp.bootstrap(y1match_data)
         y2m = svmp.match_sites(y1m,y2match_data)
     # Measurement Error - Simulated Zm area
     me1 = svmp.measurement_error(y1)
     me1m = svmp.measurement_error(y1m)
     me2m = svmp.measurement_error(y2m)
     # Printng for DEBUG only
     #for d in me1:
         #yr1_string = ','.join(["%s" % i for i in d[0:2]])
         #yr1_string = "%s,%s" % ("Y1",yr1_string)
         ## print yr1_string  # for debug only
     #for c,d in zip(me1m,me2m):
         #yr1m_string = ','.join(["%s" % i for i in c[0:2]])
         #yr1m_string = "%s,%s" % ("Y1m",yr1m_string)
         #yr2m_string = ','.join(["%s" % i for i in d[0:2]])
         #yr2m_string = "%s,%s" % ("Y2m",yr2m_string)
         #allmatch_string = "%s,%s" % (yr1m_string,yr2m_string)
         ## print allmatch_string # for debug only
         
      # Calculate Change Analysis stats with Simulated Data
     y1Samp  = svmp.SampleStats(me1,stratum,unit_convert)
     y1mSamp = svmp.SampleStats(me1m,stratum,unit_convert)
     y2mSamp = svmp.SampleStats(me2m,stratum,unit_convert)  
     change = svmp.ChangeStats(y1mSamp,y2mSamp,y1Samp)
     # Relative Change
     return (y1Samp,y1mSamp,y2mSamp,change)