Пример #1
0
def findFrame():
    totFound = 0
    for dire in ['asc', 'dsc']:
        for sc in ['CSKS1', 'CSKS2', 'CSKS3', 'CSKS4']:
            params = {
                'spacecraftName': sc,
                'direction': dire,
                'responseGroups': 'Medium'
            }
            resp, cnt = requester.request("%s?%s" %
                                          (rest_url, urlencode(params)))
            metList = []
            if (resp['status'] == PegRegionChecker.STATUS_QUERY_OK):
                results = json.loads(cnt)
                if results['result']:
                    for result in results['result']:
                        fm = FrameMetadata()
                        fm.load(result)
                        tbp, peg = checkPegRegion(sc, fm)
                        if (not tbp):
                            exit = 10
                        else:
                            tbpNew, pegNew = checkCoherence(tbp, peg)
                            if (not tbpNew):
                                exit = 10
                            else:
                                return fm.url
Пример #2
0
def createMetaObjects(metaList):
    retList = []
    for meta in metaList:
        fm = FrameMetadata()
        fm.load(meta)
        retList.append(fm)
    return retList
Пример #3
0
def main():
    import pdb
    pdb.set_trace()
    PR = PegRegionChecker()
    PR.initPegList('pegfile_alos.txt_test')
    PR._sensorType = "ALOS"
    #list1 = PR.mockRestCall()
    #list2 = PR.mockRestCall()
    FM = FrameMetadata()
    FM.load(sys.argv[1])
    tbp, peg = PR.runNominalMode(FM)
    print('dummy')
    '''
Пример #4
0
 def createMetadata(self, filename):
     fp = open(filename)
     listMeta = json.load(fp)
     fp.close()
     ret = []
     for listFrame in listMeta:
         frames = []
         for frame in listFrame:
             fm = FrameMetadata()
             fm.load(frame)
             frames.append(fm)
         ret.append(frames)
     return ret
Пример #5
0
def main():
    import json
    inputs = json.load(open(sys.argv[1]))
    '''
    parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('-i','--input',dest='input',type=str,help='Input json filename containing metadata')
    parser.add_argument('-o','--output',dest='output',type=str,help='Output prefix name for the results') 
    parser.add_argument('-p','--project',dest='project',type=str,help='Project that belongs too')                                                                    
    args = parser.parse_args()
    '''
    process = 'networkSelector'
    message = ''

    exitv = 0
    try:
        outputFile = inputs['networkSelector']['outputFile']
        with open(inputs['networkSelector']['inputFile']) as fp:
            meta = json.load(fp)
        fm = FrameMetadata()
        fm.load(meta)
        sensor = fm.getSpacecraftName()
        tbp, peg = checkPegRegion(fm, inputs['project'])
        message = 'Found complete PEG region'
        if (not tbp):
            exitv = 10
            message = 'Not found complete PEG region'

        else:
            tbpNew, pegNew = checkCoherence(tbp, peg, inputs['project'])
            if (not tbpNew):
                exitv = 11
                message = 'Coherence below threshold'
            else:
                for i in range(len(tbpNew)):
                    with open(outputFile + '_' + str(i), 'w') as fp:
                        json.dump(toDict(tbpNew[i]), fp, indent=4)
    except Exception as e:
        exitv = 255
        message = 'Failed with exception %s: %s' % (str(e),
                                                    traceback.format_exc())
        toContext(process, exitv, message)

    toContext(process, exitv, message)
    return exitv
Пример #6
0
def check_reference(dataset, md):
    """Check reference of this metadata against what's in GRQ."""

    # get config
    uu = UrlUtils()
    rest_url = uu.rest_url

    # is this scene a reference?
    fm_md = copy.deepcopy(md)
    fm = FrameMetadata()
    fm.load(fm_md)

    #sys.stderr.write("fm.reference: %s\n" % fm.reference)
    #sys.stderr.write("fm.trackNumber: %s\n" % fm.trackNumber)
    #sys.stderr.write("fm.beamID: %s\n" % fm.beamID)
    #sys.stderr.write("fm.latitudeIndexMin: %s\n" % fm.latitudeIndexMin)
    #sys.stderr.write("fm.latitudeIndexMax: %s\n" % fm.latitudeIndexMax)

    # if not a reference, save
    if fm.reference == False:
        return {
            'ok_to_save': True,
            'suspicious_flag': False,
            'suspicious_code': ''
        }

    # check if reference exists already
    extremes = fm.getExtremes(fm.bbox)
    latMin = extremes[0]
    latMax = extremes[1]
    lonMin = extremes[2]
    lonMax = extremes[3]
    latDelta = (latMax - latMin) / 3.
    latitudeResolution = .1
    params = {
        'sensor':
        fm.platform,
        'dataset_type':
        dataset,
        'trackNumber':
        fm.trackNumber,
        'latitudeIndexMin':
        int(math.floor((latMin - latDelta) / latitudeResolution)),
        'latitudeIndexMax':
        int(math.ceil((latMax + latDelta) / latitudeResolution)),
        'system_version':
        uu.version,
        'direction':
        fm.direction,
        'lookDirection':
        fm.lookDirection,
        'reference':
        True,
    }
    if fm.beamID:
        params['beamID'] = fm.beamID
    metList, status = postQuery(buildQuery(params, ['within']))
    metObj = createMetaObjects(metList)

    # if none found, save
    if len(metObj) == 0:
        return {
            'ok_to_save': True,
            'suspicious_flag': False,
            'suspicious_code': ''
        }

    # loop over frames and check if in this frame's bbox
    inbbox_count = 0
    frames = []
    for met_idx, tmp_fm in enumerate(metObj):
        inbbox = fm.isInBbox(tmp_fm.refbbox)
        if inbbox: inbbox_count += 1
        frames.append({
            'id':
            os.path.splitext(metList[met_idx]['dfdn']['ProductName'])[0],
            'archive_filename':
            metList[met_idx]['archive_filename'],
            'inbbox':
            inbbox,
        })

    #print "true_count:", true_count

    # if all not in bbox, okay to save but flag suspicious
    if inbbox_count == 0:
        return {
            'ok_to_save': True,
            'frames': frames,
            'suspicious_flag': True,
            'suspicious_code': 'no_frames_in_bbox'
        }

    # if one is in bbox, not okay to update
    elif inbbox_count == 1:
        #return { 'ok_to_save': False, 'reprocess': True, 'suspicious_flag': True, 'suspicious_code': 'one_frame_in_bbox' }
        # fail for now; it can be eventually reprocessed after the initial re-ingest
        return {
            'ok_to_save': False,
            'frames': frames,
            'reprocess': False,
            'suspicious_flag': True,
            'suspicious_code': 'one_frame_in_bbox'
        }

    # if more than one is in bbox, not okay to update and flag
    else:
        return {
            'ok_to_save': False,
            'frames': frames,
            'reprocess': False,
            'suspicious_flag': True,
            'suspicious_code': 'more_than_one_frame_in_bbox'
        }
Пример #7
0
 def createMeta(self, metaDict):
     fm = FrameMetadata()
     fm.load(metaDict)
     return fm