示例#1
0
文件: TSX.py 项目: pytroll/mipp
def read_metadata(xmlbuffer):

    # Speciel decoders
    def dec_isoformat(rts):
        return datetime.strptime(rts, "%Y-%m-%dT%H:%M:%S.%fZ")
    def dec_orbit_number(rts):
        return int(rts[:5])    
    def dec_satellite_name(rts):
        return rts.replace('-', '')
    def dec_calibration_unit(rts):
        _trans = {'radar brightness': 'nrcs'}
        rts = rts.replace(' ', '-').lower()
        return rts

    attributes = {
        'product_level':  ('generalHeader/itemName', str),
        'satellite_name': ('productInfo/missionInfo/mission', dec_satellite_name),
        'orbit_number': ('productInfo/missionInfo/absOrbit', dec_orbit_number),
        'sensor_type': ('productInfo/acquisitionInfo/sensor', str),
        'beam_mode': ('productInfo/acquisitionInfo/imagingMode', str),
        'polarisation': ('productInfo/acquisitionInfo/polarisationList/polLayer', str),
        'beamid': ('productInfo/acquisitionInfo/elevationBeamConfiguration', str),
        'calibrated': ('productInfo/productVariantInfo/radiometricCorrection', str),
        'calibration_factor': ('calibration/calibrationConstant/calFactor', float),
        'calibration_beamid': ('calibration/calibrationConstant/beamID', str),
        'calibration_unit': ('productInfo/imageDataInfo/pixelValueID', dec_calibration_unit),
        'image_data_path': ('productComponents/imageData/file/location/path', str),
        'image_data_filename': ('productComponents/imageData/file/location/filename', str),
        'time_start': ('productInfo/sceneInfo/start/timeUTC', dec_isoformat),        
        'center_coor_lat': ('productInfo/sceneInfo/sceneCenterCoord/lat', float),
        'center_coor_lon': ('productInfo/sceneInfo/sceneCenterCoord/lon', float)
        }

    check_attributes = {'product_level': 'level 1b product',
                        'satellite_name': 'tsx',
                        'sensor_type': 'sar'}

    tree = etree.fromstring(xmlbuffer)
    
    # Check satellite, sensor and product level
    for key, val in check_attributes.items():
        try:
            path = attributes[key][0]
            attr = tree.xpath(path)[0].text.lower()
            if not attr.startswith(val):
                raise mipp.ReaderError("This does not look like a TSX SAR " +
                                       "Level 1B Product, %s is '%s' expected '%s'" %
                                       (key, attr, val))
        except IndexError:
            raise mipp.ReaderError("This does not look like a TSX SAR " +
                                   "Level 1B Product, could not find attribute '%s' (%s)" %
                                   (key, path))

    mda = Metadata()
    for key, val in attributes.items():
        setattr(mda, key, val[1](tree.xpath(val[0])[0].text))
    mda.image_filename = (mda.image_data_path + '/' + mda.image_data_filename)
    delattr(mda, 'image_data_path')
    delattr(mda, 'image_data_filename')
    return mda
示例#2
0
文件: CSK.py 项目: pytroll/mipp
def read_metadata(xmlbuffer):
    mda = Metadata()    

    # Speciel decoders
    def dec_timeformat(strn):
        strn = strn.split('.')        
        return (datetime.strptime(strn[0], "%Y-%m-%d %H:%M:%S") + 
                timedelta(seconds=float('.' + strn[1])))
    def dec_orbit_number(strn):
        return int(strn[:5])

    attributes = (
        ('_ROOT_/Attribute', {
                'Satellite ID': ('satellite_name', str),
                'Product Filename': ('image_filename', str),
                'Product Type': ('product_type', str),
                'Acquisition Station ID': ('facility_id', str),
                'Scene Sensing Start UTC': ('time_start', dec_timeformat),
                'Scene Sensing Stop UTC': ('time_stop', dec_timeformat),
                'Orbit Number': ('orbit_number', dec_orbit_number),
                'Sample Format': ('product_format', str),
                'Image Scale': ('image_scale', str),
                'Image Layers': ('layers', int),
                'Bits per Sample': ('bits_per_sample', int),
                'Samples per Pixel': ('samples_per_pixel', int),
                }),
        
        ('MBI/Attribute', {
                'Column Spacing': ('sample_spacing', float),
                'Line Spacing': ('line_spacing', float)
                }),

        ('S01/Attribute', {            
                'Polarisation': ('polarisation', str),
                }),
        )

    tree = etree.fromstring(xmlbuffer)

    #
    # Get Atrributes
    #
    for path, attr in attributes:
        names = attr.keys()
        path = tree.xpath(path)
        for i in path:
            name = i.attrib['Name']
            if name in names:
                names.remove(name)
                val = i.text
                setattr(mda, attr[name][0], attr[name][1](val))

    

    satid = 'CSK'
    if not mda.satellite_name.upper().startswith(satid):
        raise mipp.ReaderError(
            "This does not look like a CosmoSkymed product, " + 
            "satellite ID does now start with '%s'"%satid)

    mda.image_filename = os.path.splitext(mda.image_filename)[0] + '.MBI.tif'

    mda.no_data_value = 0
    mda.calibrated = 'NOTCALIBRATED'

    return mda
示例#3
0
文件: TSX.py 项目: jferencik/mipp
def read_metadata(xmlbuffer):

    # Speciel decoders
    def dec_isoformat(rts):
        return datetime.strptime(rts, "%Y-%m-%dT%H:%M:%S.%fZ")

    def dec_orbit_number(rts):
        return int(rts[:5])

    def dec_satellite_name(rts):
        return rts.replace('-', '')

    def dec_calibration_unit(rts):
        _trans = {'radar brightness': 'nrcs'}
        rts = rts.replace(' ', '-').lower()
        return rts

    attributes = {
        'product_level': ('generalHeader/itemName', str),
        'satellite_name':
        ('productInfo/missionInfo/mission', dec_satellite_name),
        'orbit_number': ('productInfo/missionInfo/absOrbit', dec_orbit_number),
        'sensor_type': ('productInfo/acquisitionInfo/sensor', str),
        'beam_mode': ('productInfo/acquisitionInfo/imagingMode', str),
        'polarisation':
        ('productInfo/acquisitionInfo/polarisationList/polLayer', str),
        'beamid':
        ('productInfo/acquisitionInfo/elevationBeamConfiguration', str),
        'calibrated': ('productInfo/productVariantInfo/radiometricCorrection',
                       str),
        'calibration_factor': ('calibration/calibrationConstant/calFactor',
                               float),
        'calibration_beamid': ('calibration/calibrationConstant/beamID', str),
        'calibration_unit': ('productInfo/imageDataInfo/pixelValueID',
                             dec_calibration_unit),
        'image_data_path': ('productComponents/imageData/file/location/path',
                            str),
        'image_data_filename':
        ('productComponents/imageData/file/location/filename', str),
        'time_start': ('productInfo/sceneInfo/start/timeUTC', dec_isoformat),
        'center_coor_lat': ('productInfo/sceneInfo/sceneCenterCoord/lat',
                            float),
        'center_coor_lon': ('productInfo/sceneInfo/sceneCenterCoord/lon',
                            float)
    }

    check_attributes = {
        'product_level': 'level 1b product',
        'satellite_name': 'tsx',
        'sensor_type': 'sar'
    }

    tree = etree.fromstring(xmlbuffer)

    # Check satellite, sensor and product level
    for key, val in check_attributes.items():
        try:
            path = attributes[key][0]
            attr = tree.xpath(path)[0].text.lower()
            if not attr.startswith(val):
                raise mipp.ReaderError(
                    "This does not look like a TSX SAR " +
                    "Level 1B Product, %s is '%s' expected '%s'" %
                    (key, attr, val))
        except IndexError:
            raise mipp.ReaderError(
                "This does not look like a TSX SAR " +
                "Level 1B Product, could not find attribute '%s' (%s)" %
                (key, path))

    mda = Metadata()
    for key, val in attributes.items():
        setattr(mda, key, val[1](tree.xpath(val[0])[0].text))
    mda.image_filename = (mda.image_data_path + '/' + mda.image_data_filename)
    delattr(mda, 'image_data_path')
    delattr(mda, 'image_data_filename')
    return mda
示例#4
0
文件: CSK.py 项目: jferencik/mipp
def read_metadata(xmlbuffer):
    mda = Metadata()

    # Speciel decoders
    def dec_timeformat(strn):
        strn = strn.split('.')
        return (datetime.strptime(strn[0], "%Y-%m-%d %H:%M:%S") +
                timedelta(seconds=float('.' + strn[1])))

    def dec_orbit_number(strn):
        return int(strn[:5])

    attributes = (
        ('_ROOT_/Attribute', {
            'Satellite ID': ('satellite_name', str),
            'Product Filename': ('image_filename', str),
            'Product Type': ('product_type', str),
            'Acquisition Station ID': ('facility_id', str),
            'Scene Sensing Start UTC': ('time_start', dec_timeformat),
            'Scene Sensing Stop UTC': ('time_stop', dec_timeformat),
            'Orbit Number': ('orbit_number', dec_orbit_number),
            'Sample Format': ('product_format', str),
            'Image Scale': ('image_scale', str),
            'Image Layers': ('layers', int),
            'Bits per Sample': ('bits_per_sample', int),
            'Samples per Pixel': ('samples_per_pixel', int),
        }),
        ('MBI/Attribute', {
            'Column Spacing': ('sample_spacing', float),
            'Line Spacing': ('line_spacing', float)
        }),
        ('S01/Attribute', {
            'Polarisation': ('polarisation', str),
        }),
    )

    tree = etree.fromstring(xmlbuffer)

    #
    # Get Atrributes
    #
    for path, attr in attributes:
        names = attr.keys()
        path = tree.xpath(path)
        for i in path:
            name = i.attrib['Name']
            if name in names:
                names.remove(name)
                val = i.text
                setattr(mda, attr[name][0], attr[name][1](val))

    satid = 'CSK'
    if not mda.satellite_name.upper().startswith(satid):
        raise mipp.ReaderError(
            "This does not look like a CosmoSkymed product, " +
            "satellite ID does now start with '%s'" % satid)

    mda.image_filename = os.path.splitext(mda.image_filename)[0] + '.MBI.tif'

    mda.no_data_value = 0
    mda.calibrated = 'NOTCALIBRATED'

    return mda