Пример #1
0
def getEcfromWeightedKDE(lonOrMesh=None,latOrMesh=None,ZZpdfPframe=None,delta=None,
                         kt=None,populationClass=None,polygonClass=None,desval=0.0,boundsOption=1):
    areapop = delta**2.0

    if populationClass.keyDen ==None:
        popMatrix,xmatlocations,ymatlocations = SMF.agsgetdensity(populationClass.keyPop,populationClass.keyArea,
                                                                  populationClass.xllcorner,populationClass.yllcorner,
                                                                  populationClass.cellsize,lonOrMesh,latOrMesh,
                                                                  populationClass.xMax,populationClass.yMax,
                                                                  boundsOption,[populationClass.ncols,populationClass.nrows,xlen,ylen])
    else:
        popMatrix = SMF.agsgetvals(populationClass.keyDen,populationClass.xllcorner,populationClass.yllcorner,
                                   populationClass.cellsize,lonOrMesh,latOrMesh,populationClass.xMax,
                                   populationClass.yMax,boundsOption)
        
    
    if polygonClass!=None:
        
        xpol = polygonClass.xy[0]
        ypol = polygonClass.xy[1]
        matout = SMF.checkpolygon(lonOrMesh,latOrMesh,xpol,ypol)
        #print matout
        popMatrix = SMF.updatematpolygon(lonOrMesh,latOrMesh,xpol,ypol,popMatrix,desval)
        #print xpol,ypol
        #print popMatrix
        #print lonOrMesh.max(),lonOrMesh.min(),latOrMesh.min(),latOrMesh.max()
    Ec,Ecmatrix = getEc(popMatrix,ZZpdfPframe,areapop)
    Ec = Ec*kt
    Ecmatrix = Ecmatrix*kt
    return Ec,Ecmatrix
Пример #2
0
def calculateEc(lonlat,nSamples,delta,nsigma,key,xllcorner,yllcorner,cellsize,xMax,yMax,boundsOption,ncols,nrows,nPieces,arefMean,pdfoption):
    # this version uses the rotated pdf (actual lon lat coordinates). Gets pdf in regular frame, and integrates it. Inneficient for big ranges of lat lon (memory intensive)
    tempval = .3048 #1ft to meters
    PframeVals,OrFrameVals,transformDetails,areaInt = getPDF(lonlat,pdfoption=pdfoption,delta=delta)
    [lonPMesh,latPMesh,ZZpdf] = PframeVals
    [lonMesh,latMesh,ZZpdfN] = OrFrameVals
    popMatrix = SMF.agsgetvals(key,xllcorner,yllcorner,cellsize,lonMesh,latMesh,xMax,yMax,boundsOption)
    Ec = nPieces*(SMF.calculateec(ZZpdf,areaInt,arefMean,tempval,popMatrix))
    return (Ec,lonMesh,latMesh,ZZpdf)
Пример #3
0
def calculateEc(lonlat,nSamples,delta,nsigma,key,xllcorner,yllcorner,cellsize,xMax,yMax,boundsOption,ncols,nrows,nPieces,arefMean,pdfoption):


    # this version uses the rotated pdf (actual lon lat coordinates). Gets pdf in regular frame, and integrates it. Inneficient for big ranges of lat lon (memory intensive)
    areapop = delta*delta
    tempval = .3048 #1ft to meters
    lonMesh,latMesh,ZZpdf,XX,YY,xlen,ylen,transformDetails  = getPDF(lonlat,nSamples,delta,nsigma,pdfoption)
    popMatrix = SMF.agsgetvals(key,xllcorner,yllcorner,cellsize,lonMesh,latMesh,xMax,yMax,boundsOption,[ncols,nrows,ylen,xlen])
    Ec = nPieces*(SMF.calculateec(ZZpdf,areapop,arefMean,tempval,popMatrix,[ylen,xlen]))
    return (Ec,lonMesh,latMesh,ZZpdf)
Пример #4
0
def calculateEcRotatedFrame(lonlat,nSamples,delta,nsigma,key,xllcorner,yllcorner,cellsize,xMax,yMax,boundsOption,ncols,nrows,nPieces,arefMean,pdfoption):
    # calculates Ec by calculating pdf in P frame, then get corresponding population density for P frame.
    sys.path.append("../SafetyMetrics")
    import safetyMetrics as SMF
    
    # this version uses the rotated pdf (actual lon lat coordinates)
    areapop = delta*delta
    tempval = .3048 #1ft to meters
    lonPMesh,latPMesh,ZZpdfPframe,lonOrMesh,latOrMesh,xlen,ylen,transformDetails  = getPDF2(lonlat,nSamples,delta,nsigma,pdfoption)
    popMatrix = SMF.agsgetvals(key,xllcorner,yllcorner,cellsize,lonOrMesh,latOrMesh,xMax,yMax,boundsOption,[ncols,nrows,ylen,xlen])
    Ec = nPieces*(SMF.calculateec(ZZpdfPframe,areapop,arefMean,tempval,popMatrix,[ylen,xlen]))
    return (Ec,lonPMesh,latPMesh,ZZpdfPframe)
Пример #5
0
def calculateEc(lonlat, nSamples, delta, nsigma, key, xllcorner, yllcorner,
                cellsize, xMax, yMax, boundsOption, ncols, nrows, nPieces,
                arefMean, pdfoption):
    # this version uses the rotated pdf (actual lon lat coordinates). Gets pdf in regular frame, and integrates it. Inneficient for big ranges of lat lon (memory intensive)
    tempval = .3048  #1ft to meters
    PframeVals, OrFrameVals, transformDetails, areaInt = getPDF(
        lonlat, pdfoption=pdfoption, delta=delta)
    [lonPMesh, latPMesh, ZZpdf] = PframeVals
    [lonMesh, latMesh, ZZpdfN] = OrFrameVals
    popMatrix = SMF.agsgetvals(key, xllcorner, yllcorner, cellsize, lonMesh,
                               latMesh, xMax, yMax, boundsOption)
    Ec = nPieces * (SMF.calculateec(ZZpdf, areaInt, arefMean, tempval,
                                    popMatrix))
    return (Ec, lonMesh, latMesh, ZZpdf)
Пример #6
0
def checkStateVector(Vmag,gamma,beta,lat,long,alt,lonRef,latRef,mainVelRelOption,Vdebris,ballMin,ballMax,altitudeList,densitylist,key,xllcorner,yllcorner,cellsize,nrows, ncols,xMax,yMax):

    #################################################### MAIN CALL TO DEBRIS PROPAGATOR #############################################################################
     
    #print ballMax,ballMin
     
     
    initialposition = np.array([lat,long,alt,lonRef,latRef])
    mainVel = np.array([Vmag+Vdebris,gamma,beta])
    #mainVelRelOption = 1 # 0 for main Vehicle inertial velocity, 1 for main vehicle relative to rotating planet velocity
    debrisRelVel = np.array([0,0,0])
    loverd = 0
                     
     
    ## Debris Modeling Options
    cloption = 0# 1 =>using CL value instead of LoverD for computing Lift force, 0 => use LoverD value for lift calculation
    planetModel = 0#0 for spherical, 1 for oblate
    geoptions = 0# 
    atmosoption = -1# -1 Vacuum, 0 exp density, 1 gram density, 2 gram wind and density
    cl = 0.
    aref = 1.
    mass = 1.
    
    cd = mass/(ballMin*aref)
    
    minfcd = 1.
    minfcl = 1.
    #altitudeList = 1.
    #densitylist = 1.
    #ulist = 1.
    #vlist = 1.
    #wlist = 1.
    filename = 'piece1'
    #print ballMin,ballMax
    ncd = 1
    ncl = 1
    nlist = len(densitylist)
    zerolist = np.zeros((nlist))
    ulist = zerolist
    vlist = zerolist
    wlist = zerolist
    #print nlist
    finalConditions = DP.debrispropagation(initialposition, mainVel,mainVelRelOption,
                                            debrisRelVel, mass,aref, # debris piece state vector wrt to main vehicle
                                            minfcd,cd,cloption,minfcl,cl,loverd, # aerodynamic inputs
                                            atmosoption,altitudeList, # dt for RK4, angrate for tumbling debris. Atmospheric options
                                            densitylist,ulist,vlist,wlist, # atmospheric profile
                                            geoptions,filename,planetModel,[ncd,ncl,nlist]) # geoptions & filename used for Google Earth visualiation. ncd => length of CD array
     # ncl => length of CL array. nlist=> length of atmospheric data array (altitude)
     
    filename = 'piece2'

     
    altitudefinal = finalConditions[0]
    latitudefinal = finalConditions[1]
    longitudefinal = finalConditions[2]
    flag = finalConditions[8]
    vrelmag = finalConditions[3]
    mainVel = np.array([Vmag-Vdebris,gamma,beta])
    
    
    cd = mass/(ballMax*aref)
    atmosoption = 1# -1 Vacuum, 0 exp density, 1 gram density, 2 gram wind and density

    
    lowerConditions = DP.debrispropagation(initialposition, mainVel,mainVelRelOption,
                                               debrisRelVel, mass,aref, # debris piece state vector wrt to main vehicle
                                               minfcd,cd,cloption,minfcl,cl,loverd, # aerodynamic inputs
                                               atmosoption,altitudeList, # dt for RK4, angrate for tumbling debris. Atmospheric options
                                               densitylist,ulist,vlist,wlist, # atmospheric profile
                                               geoptions,filename,planetModel,[ncd,ncl,nlist]) # geoptions & filename used for Google Earth visualiation. ncd => length of CD array
    # ncl => length of CL array. nlist=> length of atmospheric data array (altitude)
    
    
    
    altitudeLower = lowerConditions[0]
    latitudeLower = lowerConditions[1]
    longitudeLower = lowerConditions[2]
    flagLower = lowerConditions[8]
    vrelmagLower = lowerConditions[3]
    
    
    
    
    if (altitudefinal<0)and(altitudeLower<0):
#   calculating radius
        
        
        thetaLength = 20
        rLength = 20
        deltaLon = longitudefinal - longitudeLower
        deltaLat = latitudefinal - latitudeLower
        rmax = max(1.,(deltaLat**2+deltaLat**2)**.5) #+ .5 # .5 added to be conservative
        rmin = 0.0
        centerLon = .5*(longitudefinal + longitudeLower) 
        centerLat = .5*(latitudefinal + latitudeLower)
        theta = np.linspace(0,2*np.pi,thetaLength)
        r = np.linspace(rmin,rmax,rLength)
        rMesh,thetaMesh = np.meshgrid(r,theta)
        xlon = rMesh*np.cos(thetaMesh) + centerLon
        ylat = rMesh*np.sin(theta) + centerLat
        boundsOption = 1
        popMatrix = SMF.agsgetvals(key,xllcorner,yllcorner,cellsize,xlon,ylat,xMax,yMax,boundsOption,[ncols,nrows,rLength,thetaLength])
        val = np.sum(popMatrix)
        if val < 1e-16:
            dangerZone = 0
        else :
            dangerZone = 1
    elif (altitudeLower>0)and(altitudefinal>0):
        dangerZone = 0 # debris will be in orbit
    elif altitudeLower<0 :
        thetaLength = 20
        rLength = 20
        rmax = 2.5 # conservative bound for upper level case
        rmin = 0.0
        centerLon =  longitudeLower 
        centerLat = latitudeLower
        theta = np.linspace(0,2*np.pi,thetaLength)
        r = np.linspace(rmin,rmax,rLength)
        rMesh,thetaMesh = np.meshgrid(r,theta)
        xlon = rMesh*np.cos(thetaMesh) + centerLon
        ylat = rMesh*np.sin(theta) + centerLat
        boundsOption = 1
        popMatrix = SMF.agsgetvals(key,xllcorner,yllcorner,cellsize,xlon,ylat,xMax,yMax,boundsOption,[ncols,nrows,rLength,thetaLength])
        val = np.sum(popMatrix)
        if val < 1e-16:
            dangerZone = 0
        else :
            dangerZone = 1
    print rmax,val,centerLon,centerLat
# print xlon
#   print ylat
    return dangerZone
        
    



        
Пример #7
0
def checkStateVector(Vmag, gamma, beta, lat, long, alt, lonRef, latRef,
                     mainVelRelOption, Vdebris, ballMin, ballMax, altitudeList,
                     densitylist, key, xllcorner, yllcorner, cellsize, nrows,
                     ncols, xMax, yMax):

    #################################################### MAIN CALL TO DEBRIS PROPAGATOR #############################################################################

    #print ballMax,ballMin

    initialposition = np.array([lat, long, alt, lonRef, latRef])
    mainVel = np.array([Vmag + Vdebris, gamma, beta])
    #mainVelRelOption = 1 # 0 for main Vehicle inertial velocity, 1 for main vehicle relative to rotating planet velocity
    debrisRelVel = np.array([0, 0, 0])
    loverd = 0

    ## Debris Modeling Options
    cloption = 0  # 1 =>using CL value instead of LoverD for computing Lift force, 0 => use LoverD value for lift calculation
    planetModel = 0  #0 for spherical, 1 for oblate
    geoptions = 0  #
    atmosoption = -1  # -1 Vacuum, 0 exp density, 1 gram density, 2 gram wind and density
    cl = 0.
    aref = 1.
    mass = 1.

    cd = mass / (ballMin * aref)

    minfcd = 1.
    minfcl = 1.
    #altitudeList = 1.
    #densitylist = 1.
    #ulist = 1.
    #vlist = 1.
    #wlist = 1.
    filename = 'piece1'
    #print ballMin,ballMax
    ncd = 1
    ncl = 1
    nlist = len(densitylist)
    zerolist = np.zeros((nlist))
    ulist = zerolist
    vlist = zerolist
    wlist = zerolist
    #print nlist
    finalConditions = DP.debrispropagation(
        initialposition,
        mainVel,
        mainVelRelOption,
        debrisRelVel,
        mass,
        aref,  # debris piece state vector wrt to main vehicle
        minfcd,
        cd,
        cloption,
        minfcl,
        cl,
        loverd,  # aerodynamic inputs
        atmosoption,
        altitudeList,  # dt for RK4, angrate for tumbling debris. Atmospheric options
        densitylist,
        ulist,
        vlist,
        wlist,  # atmospheric profile
        geoptions,
        filename,
        planetModel,
        [ncd, ncl, nlist]
    )  # geoptions & filename used for Google Earth visualiation. ncd => length of CD array
    # ncl => length of CL array. nlist=> length of atmospheric data array (altitude)

    filename = 'piece2'

    altitudefinal = finalConditions[0]
    latitudefinal = finalConditions[1]
    longitudefinal = finalConditions[2]
    flag = finalConditions[8]
    vrelmag = finalConditions[3]
    mainVel = np.array([Vmag - Vdebris, gamma, beta])

    cd = mass / (ballMax * aref)
    atmosoption = 1  # -1 Vacuum, 0 exp density, 1 gram density, 2 gram wind and density

    lowerConditions = DP.debrispropagation(
        initialposition,
        mainVel,
        mainVelRelOption,
        debrisRelVel,
        mass,
        aref,  # debris piece state vector wrt to main vehicle
        minfcd,
        cd,
        cloption,
        minfcl,
        cl,
        loverd,  # aerodynamic inputs
        atmosoption,
        altitudeList,  # dt for RK4, angrate for tumbling debris. Atmospheric options
        densitylist,
        ulist,
        vlist,
        wlist,  # atmospheric profile
        geoptions,
        filename,
        planetModel,
        [ncd, ncl, nlist]
    )  # geoptions & filename used for Google Earth visualiation. ncd => length of CD array
    # ncl => length of CL array. nlist=> length of atmospheric data array (altitude)

    altitudeLower = lowerConditions[0]
    latitudeLower = lowerConditions[1]
    longitudeLower = lowerConditions[2]
    flagLower = lowerConditions[8]
    vrelmagLower = lowerConditions[3]

    if (altitudefinal < 0) and (altitudeLower < 0):
        #   calculating radius

        thetaLength = 20
        rLength = 20
        deltaLon = longitudefinal - longitudeLower
        deltaLat = latitudefinal - latitudeLower
        rmax = max(1., (deltaLat**2 +
                        deltaLat**2)**.5)  #+ .5 # .5 added to be conservative
        rmin = 0.0
        centerLon = .5 * (longitudefinal + longitudeLower)
        centerLat = .5 * (latitudefinal + latitudeLower)
        theta = np.linspace(0, 2 * np.pi, thetaLength)
        r = np.linspace(rmin, rmax, rLength)
        rMesh, thetaMesh = np.meshgrid(r, theta)
        xlon = rMesh * np.cos(thetaMesh) + centerLon
        ylat = rMesh * np.sin(theta) + centerLat
        boundsOption = 1
        popMatrix = SMF.agsgetvals(key, xllcorner, yllcorner, cellsize, xlon,
                                   ylat, xMax, yMax, boundsOption,
                                   [ncols, nrows, rLength, thetaLength])
        val = np.sum(popMatrix)
        if val < 1e-16:
            dangerZone = 0
        else:
            dangerZone = 1
    elif (altitudeLower > 0) and (altitudefinal > 0):
        dangerZone = 0  # debris will be in orbit
    elif altitudeLower < 0:
        thetaLength = 20
        rLength = 20
        rmax = 2.5  # conservative bound for upper level case
        rmin = 0.0
        centerLon = longitudeLower
        centerLat = latitudeLower
        theta = np.linspace(0, 2 * np.pi, thetaLength)
        r = np.linspace(rmin, rmax, rLength)
        rMesh, thetaMesh = np.meshgrid(r, theta)
        xlon = rMesh * np.cos(thetaMesh) + centerLon
        ylat = rMesh * np.sin(theta) + centerLat
        boundsOption = 1
        popMatrix = SMF.agsgetvals(key, xllcorner, yllcorner, cellsize, xlon,
                                   ylat, xMax, yMax, boundsOption,
                                   [ncols, nrows, rLength, thetaLength])
        val = np.sum(popMatrix)
        if val < 1e-16:
            dangerZone = 0
        else:
            dangerZone = 1
    print rmax, val, centerLon, centerLat
    # print xlon
    #   print ylat
    return dangerZone
Пример #8
0
def calculateEcMatrixShelteringWeighted(lonlat,delta,populationClass,
                                        boundsOption,weightArray,massSum,massTotal,
                                        polygon=None,ArefList = None,massList=None,CDref = 1.0,debrisClass = None):
    # calculates Ec by calculating pdf in P frame, then get corresponding population density for P frame.
    #massSum is the added mass for all sampled debris pieces
    #massTotal is the actual physical mass for the debris group...constrained by the vehicle size
    # nSamplesModeled is not necessary equal to the number of samples in lonlat..because
    #some pieces might be in orbit, or would not cause a casualty. It is needed to calculate the weights in the KDE
    
    import safetyMetrics as SMF 
    # this version uses the rotated pdf (actual lon lat coordinates)
    nSamples,otherdim = np.shape(lonlat)
    
    if nSamples==0:
        return 0,[],[],[]
    
    popOrigArea = populationClass.cellsize**2
    areapop = delta*delta
    
    #mc = massSum/float(nSamplesModeled)
    #kt = massTotal/mc
    #print kt
    kt = (massTotal/massSum)*float(nSamples) # this takes into account that sometimes pieces of debris do not make it to the ground (e.g in orbit).
    # It adjusts the (1/n_pdf) term in the pdf calculation to 1/n_modeled

    #exit()
    
    
    print 'setting kde'
    
    
    lonlatPframe,lonOrMesh,latOrMesh,U,xMeshP,yMeshP,transformDetails,areaInt = pdfSetup(lonlat=lonlat,nSamples=nSamples,
                                                                                 delta=delta,pdfoption='kde')
    
    ylen,xlen = np.shape(xMeshP)
    
    if populationClass.keyDen ==None:
        popMatrix,xmatlocations,ymatlocations = SMF.agsgetdensity(populationClass.keyPop,populationClass.keyArea,
                                                              populationClass.xllcorner,populationClass.yllcorner,
                                                              populationClass.cellsize,lonOrMesh,latOrMesh,
                                                              populationClass.xMax,populationClass.yMax,
                                                              boundsOption,[populationClass.ncols,populationClass.nrows,xlen,ylen])
    else:
        popMatrix = SMF.agsgetvals(populationClass.keyDen,populationClass.xllcorner,populationClass.yllcorner,
                                   populationClass.cellsize,lonOrMesh,latOrMesh,populationClass.xMax,
                                   populationClass.yMax,boundsOption)
        
        xmatlocations = []
        ymatlocations = []
    if polygon!=None:
        xpol = polygon[0]
        ypol = polygon[1]
        matout = SMF.checkpolygon(lonOrMesh,latOrMesh,xpol,ypol)
        desval = 0.0
        popMatrix = SMF.updatematpolygon(lonOrMesh,latOrMesh,xpol,ypol,popMatrix,desval)


        '''
        print matout
        print lonOrMesh
        print latOrMesh

        plt.plot(lonlat[:,0],lonlat[:,1],'x')
        plt.plot(xpol,ypol)

        plt.show()
        '''




    # adjusting population density maps to account for exclusion zones
    # a 

    
    '''
    plt.figure()
    CS=plt.contourf(lonOrMesh,latOrMesh,popMatrix)

    locs,labels = plt.xticks()
    plt.xticks(locs, map(lambda x: "%.8f" % x, locs))
    locs,labels = plt.yticks()

    plt.yticks(locs, map(lambda x: "%.8f" % x, locs))
    plt.colorbar(CS)
    
    
    plt.show()
    '''
    print 'pop1Mat',np.sum(popMatrix)
    if np.sum(popMatrix)>0.0:
        
        
        '''
        pdfoption = 'kde'
        lonPMesh,latPMesh,ZZpdfPframe,lonOrMesh,latOrMesh = getPDFfromSetup(nSamples,pdfoption,lonlatPframe,lonOrMesh,latOrMesh,U,xMeshP,yMeshP)
        levels = np.linspace(np.min(ZZpdfPframe),np.max(ZZpdfPframe),30)
        plt.figure()
        plt.contourf(lonPMesh,latPMesh,ZZpdfPframe,50)
        plt.plot(lonlatPframe[:,0],lonlatPframe[:,1],'rx')
        '''
        
        # now divide into ballistic coefficient groups
        nAref,nmass,nlonlat,nweightArray =groupBallisticCoeff(ArefList=ArefList,massList=massList,lonlat=lonlat,weight=weightArray,CDref=CDref)
        nSamplesTotal  = 0.0
        ZZpdfPframe = 0.0
        for index in range(len(nAref)):
            lonlatPframe = originalFrame2Pframe(nlonlat[index],U)
            weightArray = nweightArray[index]
            nSamplesloc = len(weightArray)
            nSamplesTotal = nSamplesloc + nSamplesTotal
            print nSamplesloc
            if nSamplesloc<=10:
                print 'Error: Adjust debris catalog. Current samples for this subgroup (rearranged by ballistic coeff) <10 samples '
                print 'Try subdiviging this debris group or add more samples'
                print 'Check debris catalog',debrisClass.name
                exit(2)
            #print lonlatPframe
            lonPMesh,latPMesh,ZZpdfPframetemp,lonOrMesh,latOrMesh = getWeightedPDFfromSetup(nSamplesloc,lonlatPframe,lonOrMesh,latOrMesh,U,xMeshP,yMeshP,weightArray)
            print 'temp1PDF',np.sum(ZZpdfPframetemp)

            ZZpdfPframe = float(nSamplesloc)*ZZpdfPframetemp + ZZpdfPframe

        
        
        minDen = np.min(popMatrix[popMatrix>0])


        popMatrix[popMatrix<=0.] = 0.0#0.000000001*minDen

        ZZpdfPframe = (1./float(nSamplesTotal))*ZZpdfPframe
        Ec,Ecmatrix = getEc(popMatrix,ZZpdfPframe,areaInt)

        
        Ec = Ec*kt
        Ecmatrix = Ecmatrix*kt
       

    else:
        print 'No pdf calc',np.sum(popMatrix)
        Ec = 0.0
        #Ec2 = 0.0
        xmatlocations = [1]
        ymatlocations = [1]
        Ecmatrix = np.zeros((1,1))


    return Ec,Ecmatrix,xmatlocations,ymatlocations#,Ec2
Пример #9
0
def checkStateVector(stateVec, Vdeb, planetModel, dt, thetag, populationData):
    key, xllcorner, yllcorner, cellsize, xMax, yMax, ncols, nrows = populationData
    #    def checkStateVector(Vmag,gamma,beta,lat,long,alt,lonRef,latRef,mainVelRelOption,Vdebris,ballMin,ballMax,altitudeList,densitylist,key,xllcorner,yllcorner,cellsize,nrows, ncols,xMax,yMax):
    massval = 1.0
    arefval = 1.0
    minfcdval = 1.0
    CDval = 1.0
    minfclval = 1.0
    CLval = 0.0
    altitudeList = [1.0]
    densityList = 1.0
    uList = 1.0
    vList = 1.0
    wList = 1.0
    ncdval = 1
    nclval = 1
    nlist = 1

    finalConditions = dp.debrispropagation(initialstate=stateVec,
                                           debrisvel=Vdeb,
                                           mass=massval,
                                           sref=arefval,
                                           minfcd=minfcdval,
                                           cd=CDval,
                                           cloption=1,
                                           minfcl=minfclval,
                                           cl=CLval,
                                           loverd=0,
                                           atmosoption=-1,
                                           altitudelist=altitudeList,
                                           densitylist=densityList,
                                           ulist=uList,
                                           vlist=vList,
                                           wlist=wList,
                                           geoptions=0,
                                           filename='none',
                                           planetmodel=planetModel,
                                           dtinterval=dt,
                                           thetag0=thetag,
                                           ncd=ncdval,
                                           ncl=nclval,
                                           nlist=len(altitudeList))

    altitudefinal = finalConditions[0]
    latitudefinal = finalConditions[1]
    longitudefinal = finalConditions[2]

    ballMin = 0.1
    cd = massval / (ballMin * arefval)
    atmosoption = 1  # -1 Vacuum, 0 exp density, 1 gram density, 2 gram wind and density

    lowerConditions = dp.debrispropagation(initialstate=stateVec,
                                           debrisvel=Vdeb,
                                           mass=massval,
                                           sref=arefval,
                                           minfcd=minfcdval,
                                           cd=CDval,
                                           cloption=1,
                                           minfcl=minfclval,
                                           cl=CLval,
                                           loverd=0,
                                           atmosoption=0,
                                           altitudelist=altitudeList,
                                           densitylist=densityList,
                                           ulist=uList,
                                           vlist=vList,
                                           wlist=wList,
                                           geoptions=0,
                                           filename='none',
                                           planetmodel=planetModel,
                                           dtinterval=dt,
                                           thetag0=thetag,
                                           ncd=ncdval,
                                           ncl=nclval,
                                           nlist=len(altitudeList))

    altitudeLower = lowerConditions[0]
    latitudeLower = lowerConditions[1]
    longitudeLower = lowerConditions[2]

    if (altitudefinal < 0) and (altitudeLower < 0):
        #   calculating radius

        thetaLength = 20
        rLength = 20
        deltaLon = longitudefinal - longitudeLower
        deltaLat = latitudefinal - latitudeLower
        rmax = max(1., (deltaLon**2 +
                        deltaLat**2)**.5)  #+ .5 # .5 added to be conservative
        rmin = 0.0
        centerLon = .5 * (longitudefinal + longitudeLower)
        centerLat = .5 * (latitudefinal + latitudeLower)
        theta = np.linspace(0, 2 * np.pi, thetaLength)
        r = np.linspace(rmin, rmax, rLength)
        rMesh, thetaMesh = np.meshgrid(r, theta)
        xlon = rMesh * np.cos(thetaMesh) + centerLon
        ylat = rMesh * np.sin(theta) + centerLat
        boundsOption = 1
        popMatrix = SMF.agsgetvals(key, xllcorner, yllcorner, cellsize, xlon,
                                   ylat, xMax, yMax, boundsOption,
                                   [ncols, nrows, rLength, thetaLength])
        val = np.sum(popMatrix)
        if val < 1e-16:
            dangerZone = 0
        else:
            dangerZone = 1
    elif (altitudeLower > 0) and (altitudefinal > 0):
        dangerZone = 0  # debris will be in orbit
    elif altitudeLower < 0:
        thetaLength = 20
        rLength = 20
        rmax = 2.5  # conservative bound for upper level case
        rmin = 0.0
        centerLon = longitudeLower
        centerLat = latitudeLower
        theta = np.linspace(0, 2 * np.pi, thetaLength)
        r = np.linspace(rmin, rmax, rLength)
        rMesh, thetaMesh = np.meshgrid(r, theta)
        xlon = rMesh * np.cos(thetaMesh) + centerLon
        ylat = rMesh * np.sin(theta) + centerLat
        boundsOption = 1
        popMatrix = SMF.agsgetvals(key, xllcorner, yllcorner, cellsize, xlon,
                                   ylat, xMax, yMax, boundsOption,
                                   [ncols, nrows, rLength, thetaLength])
        val = np.sum(popMatrix)
        if val < 1e-16:
            dangerZone = 0
        else:
            dangerZone = 1
#print rmax,val,centerLon,centerLat
# print xlon
#   print ylat
    return dangerZone
Пример #10
0
def checkStateVector(stateVec,Vdeb,planetModel,dt,thetag,populationData):
    key,xllcorner,yllcorner,cellsize,xMax,yMax,ncols,nrows = populationData
    #    def checkStateVector(Vmag,gamma,beta,lat,long,alt,lonRef,latRef,mainVelRelOption,Vdebris,ballMin,ballMax,altitudeList,densitylist,key,xllcorner,yllcorner,cellsize,nrows, ncols,xMax,yMax):
    massval = 1.0
    arefval = 1.0
    minfcdval = 1.0
    CDval = 1.0
    minfclval = 1.0
    CLval = 0.0
    altitudeList = [1.0]
    densityList = 1.0
    uList = 1.0
    vList = 1.0
    wList = 1.0
    ncdval = 1
    nclval = 1
    nlist = 1
    

    finalConditions = dp.debrispropagation(initialstate = stateVec,
                                        debrisvel = Vdeb,
                                        mass=massval,sref=arefval,minfcd=minfcdval,cd=CDval,cloption=1,
                                        minfcl=minfclval,cl=CLval,loverd = 0,atmosoption=-1,altitudelist=altitudeList,
                                        densitylist=densityList,ulist=uList,vlist=vList,
                                        wlist=wList,geoptions=0,filename='none',planetmodel=planetModel,dtinterval = dt,thetag0=thetag,
                                        ncd=ncdval,
                                        ncl=nclval,
                                        nlist=len(altitudeList))
    
    
    
    

     

     
    altitudefinal = finalConditions[0]
    latitudefinal = finalConditions[1]
    longitudefinal = finalConditions[2]
    
    
    
    
    ballMin = 0.1
    cd = massval/(ballMin*arefval)
    atmosoption = 1# -1 Vacuum, 0 exp density, 1 gram density, 2 gram wind and density

    
    lowerConditions = dp.debrispropagation(initialstate = stateVec,
                                           debrisvel = Vdeb,
                                           mass=massval,sref=arefval,minfcd=minfcdval,cd=CDval,cloption=1,
                                           minfcl=minfclval,cl=CLval,loverd = 0,atmosoption=0,altitudelist=altitudeList,
                                           densitylist=densityList,ulist=uList,vlist=vList,
                                           wlist=wList,geoptions=0,filename='none',planetmodel=planetModel,dtinterval = dt,thetag0=thetag,
                                           ncd=ncdval,
                                           ncl=nclval,
                                           nlist=len(altitudeList))
    
    
    altitudeLower = lowerConditions[0]
    latitudeLower = lowerConditions[1]
    longitudeLower = lowerConditions[2]

    
    
    
    if (altitudefinal<0)and(altitudeLower<0):
#   calculating radius
        
        
        thetaLength = 20
        rLength = 20
        deltaLon = longitudefinal - longitudeLower
        deltaLat = latitudefinal - latitudeLower
        rmax = max(1.,(deltaLon**2+deltaLat**2)**.5) #+ .5 # .5 added to be conservative
        rmin = 0.0
        centerLon = .5*(longitudefinal + longitudeLower) 
        centerLat = .5*(latitudefinal + latitudeLower)
        theta = np.linspace(0,2*np.pi,thetaLength)
        r = np.linspace(rmin,rmax,rLength)
        rMesh,thetaMesh = np.meshgrid(r,theta)
        xlon = rMesh*np.cos(thetaMesh) + centerLon
        ylat = rMesh*np.sin(theta) + centerLat
        boundsOption = 1
        popMatrix = SMF.agsgetvals(key,xllcorner,yllcorner,cellsize,xlon,ylat,xMax,yMax,boundsOption,[ncols,nrows,rLength,thetaLength])
        val = np.sum(popMatrix)
        if val < 1e-16:
            dangerZone = 0
        else :
            dangerZone = 1
    elif (altitudeLower>0)and(altitudefinal>0):
        dangerZone = 0 # debris will be in orbit
    elif altitudeLower<0 :
        thetaLength = 20
        rLength = 20
        rmax = 2.5 # conservative bound for upper level case
        rmin = 0.0
        centerLon =  longitudeLower 
        centerLat = latitudeLower
        theta = np.linspace(0,2*np.pi,thetaLength)
        r = np.linspace(rmin,rmax,rLength)
        rMesh,thetaMesh = np.meshgrid(r,theta)
        xlon = rMesh*np.cos(thetaMesh) + centerLon
        ylat = rMesh*np.sin(theta) + centerLat
        boundsOption = 1
        popMatrix = SMF.agsgetvals(key,xllcorner,yllcorner,cellsize,xlon,ylat,xMax,yMax,boundsOption,[ncols,nrows,rLength,thetaLength])
        val = np.sum(popMatrix)
        if val < 1e-16:
            dangerZone = 0
        else :
            dangerZone = 1
#print rmax,val,centerLon,centerLat
# print xlon
#   print ylat
    return dangerZone
        
    



        
Пример #11
0
def calculateEcMatrixShelteringWeighted(lonlat,populationClass,weightArray,
                                        E_N_simulated,V_N_simulated,fractionOnGround=1.0,boundsOption=1,delta = None,nMesh = None,
                                        polygon=None,ArefList = None,massList=None,CDref = 1.0,
                                        debrisClass = None , variance = False):
    # calculates Ec by calculating pdf in P frame, then get corresponding population density for P frame.
    # E_N_simulated is the expected number of debris pieces from the debris group
    # V_N_simulated is the variance of the number of debris pieces from the debris group
    # fractionOnground is the fraction of the debris pieces that impact the ground (pieces could reach orbit)
    
    # this version uses the rotated pdf (actual lon lat coordinates)
    nSamples,otherdim = np.shape(lonlat)
    E_N_ground = fractionOnGround*E_N_simulated
    V_N_ground = (fractionOnGround**2.0) * V_N_simulated
    if nSamples==0 or np.sum(weightArray)==0:
        return 0,[],[],[],0
    ################################################################################################
    #making sure we have distributions and not just point landing in the same location
    #KDE cannot handle points landing in the same location
    lonCheck = lonlat[:,0]
    latCheck = lonlat[:,1]
    maxlon = lonCheck.max()
    minlon = lonCheck.min()
    maxlat = latCheck.max()
    minlat = latCheck.min()
    dlon = maxlon - minlon
    dlat = maxlat - minlat

    #special case....deterministic point.. KDE not necessary
    if (dlon*dlat<=10**-25):
        lonOrMesh = [lonCheck.mean()]
        latOrMesh = [latCheck.mean()]
        if populationClass.keyDen ==None:
            popMatrix,xmatlocations,ymatlocations = SMF.agsgetdensity(populationClass.keyPop,populationClass.keyArea,
                                                                      populationClass.xllcorner,populationClass.yllcorner,
                                                                      populationClass.cellsize,lonOrMesh,latOrMesh,
                                                                      populationClass.xMax,populationClass.yMax,
                                                                      boundsOption)#,[populationClass.ncols,populationClass.nrows,xlen,ylen])
        else:
            popMatrix = SMF.agsgetvals(populationClass.keyDen,populationClass.xllcorner,populationClass.yllcorner,
                                       populationClass.cellsize,lonOrMesh,latOrMesh,populationClass.xMax,
                                       populationClass.yMax,boundsOption)
            
            xmatlocations = []
            ymatlocations = []
        #popMatrix = SMF.agsgetvals(populationClass.keyDen,populationClass.xllcorner,populationClass.yllcorner,
        #                           populationClass.cellsize,lonOrMesh,latOrMesh,populationClass.xMax,
        #                           populationClass.yMax,boundsOption)
        if polygon!=None:
            xpol = polygon[0]
            ypol = polygon[1]
            matout = SMF.checkpolygon(lonOrMesh,latOrMesh,xpol,ypol)
            desval = 0.0
            popMatrix = SMF.updatematpolygon(lonOrMesh,latOrMesh,xpol,ypol,popMatrix,desval)
        km2_to_m_2 = (1000.0)**2.0   
        Ec = np.sum(weightArray)/nSamples *(popMatrix[0][0]/km2_to_m_2)*E_N_ground
        return Ec,[],[],[],0 
    ################################################################################################ 

   
    popOrigArea = populationClass.cellsize**2
    
    
    (PframeVals,OrFrameVals,rotVals) = pdfSetup(lonlat,pdfoption='kde',delta=delta,nMesh=nMesh)
    
    [xMeshP,yMeshP,lonlatPframe] = PframeVals
    [lonOrMesh,latOrMesh] = OrFrameVals
    [U,transformDetails,areaInt] = rotVals

    
    
    
    ylen,xlen = np.shape(xMeshP)
    
    if populationClass.keyDen ==None:
        popMatrix,xmatlocations,ymatlocations = SMF.agsgetdensity(populationClass.keyPop,populationClass.keyArea,
                                                                  populationClass.xllcorner,populationClass.yllcorner,
                                                                  populationClass.cellsize,lonOrMesh,latOrMesh,
                                                                  populationClass.xMax,populationClass.yMax,
                                                                  boundsOption)#,[populationClass.ncols,populationClass.nrows,xlen,ylen])
    else:
        popMatrix = SMF.agsgetvals(populationClass.keyDen,populationClass.xllcorner,populationClass.yllcorner,
                                   populationClass.cellsize,lonOrMesh,latOrMesh,populationClass.xMax,
                                   populationClass.yMax,boundsOption)
        
        xmatlocations = []
        ymatlocations = []
   
    if polygon!=None:
        xpol = polygon[0]
        ypol = polygon[1]
        matout = SMF.checkpolygon(lonOrMesh,latOrMesh,xpol,ypol)
        desval = 0.0
        popMatrix = SMF.updatematpolygon(lonOrMesh,latOrMesh,xpol,ypol,popMatrix,desval)
        
   
    if np.sum(popMatrix)>0.0:
        

        #print 'A0',len(ArefList)    
        # now divide into ballistic coefficient groups
        nAref,nmass,nlonlat,nweightArray =groupBallisticCoeff(ArefList=ArefList,massList=massList,lonlat=lonlat,weight=weightArray,CDref=CDref)
        nSamplesTotal  = 0.0
        ZZpdfPframe = 0.0
        ZZpdfPframe_sq = 0.0
        Vc = 0.0
        for index in range(len(nAref)):
            lonlatPframe = originalFrame2Pframe(nlonlat[index],U)
            weightArrayLocal = nweightArray[index]
            nSamplesloc = len(weightArrayLocal)
            nSamplesTotal = nSamplesloc + nSamplesTotal
            if nSamplesloc<=10:
                print 'Error: Adjust debris catalog. Current samples for this subgroup (rearranged by ballistic coeff) <10 samples '
                print 'Try subdiviging this debris group or add more samples'
                print 'Check debris catalog',debrisClass.name,nSamplesloc
                print 'Weight Array',weightArrayLocal
                exit(2)

            ZZpdfPframetemp = getWeightedPDFfromSetup(lonlatPframe,xMeshP,yMeshP,weightArrayLocal)
            percentPDF = float(nSamplesloc)/float(nSamples)
            assert (percentPDF<=1.0)
            ZZpdfPframe = percentPDF*ZZpdfPframetemp + ZZpdfPframe
          
            ZZpdfPframetemp_sq = getWeightedPDFfromSetup(lonlatPframe,xMeshP,yMeshP,weightArrayLocal**2.0)
            ZZpdfPframe_sq = percentPDF*ZZpdfPframetemp_sq + ZZpdfPframe_sq

        
       
        [[Ecsingle,Ecmatrixsingle],Vcsingle] = getEcVc(popMatrix,ZZpdfPframe,areaInt,ZZpdfPframe_sq)
        Ec = Ecsingle*E_N_ground
        Vc = (Vcsingle*E_N_ground) + (V_N_ground * Ecsingle**2.0) # variance computation
        Ecmatrix = Ecmatrixsingle*E_N_ground
    
      
    else:
        print 'No pdf calc',np.sum(popMatrix)
        Ec = 0.0
        Vc = 0.0
        #Ec2 = 0.0
        xmatlocations = [1]
        ymatlocations = [1]
        Ecmatrix = np.zeros((1,1))


    return Ec,Ecmatrix,xmatlocations,ymatlocations,Vc
Пример #12
0
def calculateEcBlast(lon,lat,populationClass,boundsOption,rad_Exp_Blast,angleDegBlast,polygon=None,desval=0.0 ):
    # TO DO...update to use classes instead of list for population
    import safetyMetrics as SMF
    import orbitTools
    #km2_to_m_2 = (1000.0)**2.0
    m2_to_km2 = 1/(1000.0)**2.0 
    #print lon,lat,angleDegBlast,rad_Exp_Blast
    # starting a mesh for blast overpressure
    lonVec = np.linspace(lon - 1.2*angleDegBlast,lon + 1.2*angleDegBlast,50)
    latVec = np.linspace(lat - 1.2*angleDegBlast,lat + 1.2*angleDegBlast,52)
    RplanetCirc = 6371000.8 # meters spherical Earth
    dlon = ( lonVec[1] - lonVec[0]) * np.pi/180.
    dlat = (latVec[1] - latVec[0]) * np.pi/180.

    lonMesh,latMesh = np.meshgrid(lonVec,latVec)


    try:

        popdensity,xMatLoc,yMatLoc = SMF.agsgetdensity(populationClass.keyPop,populationClass.keyArea,
                                                               populationClass.xllcorner,populationClass.yllcorner,
                                                               populationClass.cellsize,lonMesh,latMesh,
                                                               populationClass.xMax,populationClass.yMax,boundsOption)  
    except:
        popdensity = SMF.agsgetvals(populationClass.keyDen,populationClass.xllcorner,populationClass.yllcorner,
                                   populationClass.cellsize,lonMesh,latMesh,populationClass.xMax,
                                   populationClass.yMax,boundsOption)

    if polygon!=None:
        xpol = polygon[0]
        ypol = polygon[1]
        matout = SMF.checkpolygon(lonMesh,latMesh,xpol,ypol)
        popdensity = SMF.updatematpolygon(lonMesh,latMesh,xpol,ypol,popdensity,desval)

    

    Ac = (dlon*dlat)*( RplanetCirc**2) * np.cos(latMesh*np.pi/180.)  
    r0= orbitTools.latlonalt2ECEF(lat,lon,0,0)
    rX,rY,rZ = orbitTools.latlonalt2ECEF(latMesh,lonMesh,0.,0)

    distMat = ((rX-r0[0])**2 + (rY-r0[1])**2 + (rZ-r0[2])**2)**.5
  
    indexSphere =  distMat > rad_Exp_Blast
    Ac[indexSphere] = 0.0

    casualties = popdensity  * (Ac*m2_to_km2)
    #print np.sum(Ac)*m2_to_km2
    #currPopulation = np.asarray(deepcopy(populationClass.keyPop),order='F') # making sure it is Fortran ordered
    #print 'P1',populationClass.keyPop[xMatLoc,yMatLoc]
    #row,col = np.shape(xMatLoc)

    # population was being updated every single time
    #for i in range(row):
    #    for j in range(col):
    #        populationClass.keyPop[xMatLoc[i,j],yMatLoc[i,j]] = max(populationClass.keyPop[xMatLoc[i,j],yMatLoc[i,j]]- casualties[i,j],0.0) # updating population counts

    #print 'P2',populationClass.keyPop[xMatLoc,yMatLoc]

    #print 'Popden',popdensity
    #print np.sum(casualties),np.sum(Ac),rad_Exp_Blast**2*np.pi
    return np.sum(casualties) , populationClass
Пример #13
0
def calculateEcMatrixShelteringWeighted(lonlat,
                                        populationClass,
                                        weightArray,
                                        E_N_simulated,
                                        V_N_simulated,
                                        fractionOnGround=1.0,
                                        boundsOption=1,
                                        delta=None,
                                        nMesh=None,
                                        polygon=None,
                                        ArefList=None,
                                        massList=None,
                                        CDref=1.0,
                                        debrisClass=None,
                                        variance=False):
    # calculates Ec by calculating pdf in P frame, then get corresponding population density for P frame.
    # E_N_simulated is the expected number of debris pieces from the debris group
    # V_N_simulated is the variance of the number of debris pieces from the debris group
    # fractionOnground is the fraction of the debris pieces that impact the ground (pieces could reach orbit)

    # this version uses the rotated pdf (actual lon lat coordinates)
    nSamples, otherdim = np.shape(lonlat)
    E_N_ground = fractionOnGround * E_N_simulated
    V_N_ground = (fractionOnGround**2.0) * V_N_simulated
    if nSamples == 0 or np.sum(weightArray) == 0:
        return 0, [], [], [], 0
    ################################################################################################
    #making sure we have distributions and not just point landing in the same location
    #KDE cannot handle points landing in the same location
    lonCheck = lonlat[:, 0]
    latCheck = lonlat[:, 1]
    maxlon = lonCheck.max()
    minlon = lonCheck.min()
    maxlat = latCheck.max()
    minlat = latCheck.min()
    dlon = maxlon - minlon
    dlat = maxlat - minlat

    #special case....deterministic point.. KDE not necessary
    if (dlon * dlat <= 10**-25):
        lonOrMesh = [lonCheck.mean()]
        latOrMesh = [latCheck.mean()]
        if populationClass.keyDen == None:
            popMatrix, xmatlocations, ymatlocations = SMF.agsgetdensity(
                populationClass.keyPop, populationClass.keyArea,
                populationClass.xllcorner, populationClass.yllcorner,
                populationClass.cellsize, lonOrMesh, latOrMesh,
                populationClass.xMax, populationClass.yMax, boundsOption
            )  #,[populationClass.ncols,populationClass.nrows,xlen,ylen])
        else:
            popMatrix = SMF.agsgetvals(populationClass.keyDen,
                                       populationClass.xllcorner,
                                       populationClass.yllcorner,
                                       populationClass.cellsize, lonOrMesh,
                                       latOrMesh, populationClass.xMax,
                                       populationClass.yMax, boundsOption)

            xmatlocations = []
            ymatlocations = []
        #popMatrix = SMF.agsgetvals(populationClass.keyDen,populationClass.xllcorner,populationClass.yllcorner,
        #                           populationClass.cellsize,lonOrMesh,latOrMesh,populationClass.xMax,
        #                           populationClass.yMax,boundsOption)
        if polygon != None:
            xpol = polygon[0]
            ypol = polygon[1]
            matout = SMF.checkpolygon(lonOrMesh, latOrMesh, xpol, ypol)
            desval = 0.0
            popMatrix = SMF.updatematpolygon(lonOrMesh, latOrMesh, xpol, ypol,
                                             popMatrix, desval)
        km2_to_m_2 = (1000.0)**2.0
        Ec = np.sum(weightArray) / nSamples * (popMatrix[0][0] /
                                               km2_to_m_2) * E_N_ground
        return Ec, [], [], [], 0
    ################################################################################################

    popOrigArea = populationClass.cellsize**2

    (PframeVals, OrFrameVals, rotVals) = pdfSetup(lonlat,
                                                  pdfoption='kde',
                                                  delta=delta,
                                                  nMesh=nMesh)

    [xMeshP, yMeshP, lonlatPframe] = PframeVals
    [lonOrMesh, latOrMesh] = OrFrameVals
    [U, transformDetails, areaInt] = rotVals

    ylen, xlen = np.shape(xMeshP)

    if populationClass.keyDen == None:
        popMatrix, xmatlocations, ymatlocations = SMF.agsgetdensity(
            populationClass.keyPop, populationClass.keyArea,
            populationClass.xllcorner, populationClass.yllcorner,
            populationClass.cellsize, lonOrMesh, latOrMesh,
            populationClass.xMax, populationClass.yMax, boundsOption
        )  #,[populationClass.ncols,populationClass.nrows,xlen,ylen])
    else:
        popMatrix = SMF.agsgetvals(populationClass.keyDen,
                                   populationClass.xllcorner,
                                   populationClass.yllcorner,
                                   populationClass.cellsize, lonOrMesh,
                                   latOrMesh, populationClass.xMax,
                                   populationClass.yMax, boundsOption)

        xmatlocations = []
        ymatlocations = []

    if polygon != None:
        xpol = polygon[0]
        ypol = polygon[1]
        matout = SMF.checkpolygon(lonOrMesh, latOrMesh, xpol, ypol)
        desval = 0.0
        popMatrix = SMF.updatematpolygon(lonOrMesh, latOrMesh, xpol, ypol,
                                         popMatrix, desval)

    if np.sum(popMatrix) > 0.0:

        #print 'A0',len(ArefList)
        # now divide into ballistic coefficient groups
        nAref, nmass, nlonlat, nweightArray = groupBallisticCoeff(
            ArefList=ArefList,
            massList=massList,
            lonlat=lonlat,
            weight=weightArray,
            CDref=CDref)
        nSamplesTotal = 0.0
        ZZpdfPframe = 0.0
        ZZpdfPframe_sq = 0.0
        Vc = 0.0
        for index in range(len(nAref)):
            lonlatPframe = originalFrame2Pframe(nlonlat[index], U)
            weightArrayLocal = nweightArray[index]
            nSamplesloc = len(weightArrayLocal)
            nSamplesTotal = nSamplesloc + nSamplesTotal
            if nSamplesloc <= 10:
                print 'Error: Adjust debris catalog. Current samples for this subgroup (rearranged by ballistic coeff) <10 samples '
                print 'Try subdiviging this debris group or add more samples'
                print 'Check debris catalog', debrisClass.name, nSamplesloc
                print 'Weight Array', weightArrayLocal
                exit(2)

            ZZpdfPframetemp = getWeightedPDFfromSetup(lonlatPframe, xMeshP,
                                                      yMeshP, weightArrayLocal)
            percentPDF = float(nSamplesloc) / float(nSamples)
            assert (percentPDF <= 1.0)
            ZZpdfPframe = percentPDF * ZZpdfPframetemp + ZZpdfPframe

            ZZpdfPframetemp_sq = getWeightedPDFfromSetup(
                lonlatPframe, xMeshP, yMeshP, weightArrayLocal**2.0)
            ZZpdfPframe_sq = percentPDF * ZZpdfPframetemp_sq + ZZpdfPframe_sq

        [[Ecsingle, Ecmatrixsingle],
         Vcsingle] = getEcVc(popMatrix, ZZpdfPframe, areaInt, ZZpdfPframe_sq)
        Ec = Ecsingle * E_N_ground
        Vc = (Vcsingle * E_N_ground) + (V_N_ground * Ecsingle**2.0
                                        )  # variance computation
        Ecmatrix = Ecmatrixsingle * E_N_ground

    else:
        print 'No pdf calc', np.sum(popMatrix)
        Ec = 0.0
        Vc = 0.0
        #Ec2 = 0.0
        xmatlocations = [1]
        ymatlocations = [1]
        Ecmatrix = np.zeros((1, 1))

    return Ec, Ecmatrix, xmatlocations, ymatlocations, Vc
Пример #14
0
def calculateEcBlast(lon,
                     lat,
                     populationClass,
                     boundsOption,
                     rad_Exp_Blast,
                     angleDegBlast,
                     polygon=None,
                     desval=0.0):
    # TO DO...update to use classes instead of list for population
    import safetyMetrics as SMF
    import orbitTools
    #km2_to_m_2 = (1000.0)**2.0
    m2_to_km2 = 1 / (1000.0)**2.0
    #print lon,lat,angleDegBlast,rad_Exp_Blast
    # starting a mesh for blast overpressure
    lonVec = np.linspace(lon - 1.2 * angleDegBlast, lon + 1.2 * angleDegBlast,
                         50)
    latVec = np.linspace(lat - 1.2 * angleDegBlast, lat + 1.2 * angleDegBlast,
                         52)
    RplanetCirc = 6371000.8  # meters spherical Earth
    dlon = (lonVec[1] - lonVec[0]) * np.pi / 180.
    dlat = (latVec[1] - latVec[0]) * np.pi / 180.

    lonMesh, latMesh = np.meshgrid(lonVec, latVec)

    try:

        popdensity, xMatLoc, yMatLoc = SMF.agsgetdensity(
            populationClass.keyPop, populationClass.keyArea,
            populationClass.xllcorner, populationClass.yllcorner,
            populationClass.cellsize, lonMesh, latMesh, populationClass.xMax,
            populationClass.yMax, boundsOption)
    except:
        popdensity = SMF.agsgetvals(populationClass.keyDen,
                                    populationClass.xllcorner,
                                    populationClass.yllcorner,
                                    populationClass.cellsize, lonMesh, latMesh,
                                    populationClass.xMax, populationClass.yMax,
                                    boundsOption)

    if polygon != None:
        xpol = polygon[0]
        ypol = polygon[1]
        matout = SMF.checkpolygon(lonMesh, latMesh, xpol, ypol)
        popdensity = SMF.updatematpolygon(lonMesh, latMesh, xpol, ypol,
                                          popdensity, desval)

    Ac = (dlon * dlat) * (RplanetCirc**2) * np.cos(latMesh * np.pi / 180.)
    r0 = orbitTools.latlonalt2ECEF(lat, lon, 0, 0)
    rX, rY, rZ = orbitTools.latlonalt2ECEF(latMesh, lonMesh, 0., 0)

    distMat = ((rX - r0[0])**2 + (rY - r0[1])**2 + (rZ - r0[2])**2)**.5

    indexSphere = distMat > rad_Exp_Blast
    Ac[indexSphere] = 0.0

    casualties = popdensity * (Ac * m2_to_km2)
    #print np.sum(Ac)*m2_to_km2
    #currPopulation = np.asarray(deepcopy(populationClass.keyPop),order='F') # making sure it is Fortran ordered
    #print 'P1',populationClass.keyPop[xMatLoc,yMatLoc]
    #row,col = np.shape(xMatLoc)

    # population was being updated every single time
    #for i in range(row):
    #    for j in range(col):
    #        populationClass.keyPop[xMatLoc[i,j],yMatLoc[i,j]] = max(populationClass.keyPop[xMatLoc[i,j],yMatLoc[i,j]]- casualties[i,j],0.0) # updating population counts

    #print 'P2',populationClass.keyPop[xMatLoc,yMatLoc]

    #print 'Popden',popdensity
    #print np.sum(casualties),np.sum(Ac),rad_Exp_Blast**2*np.pi
    return np.sum(casualties), populationClass