Example #1
0
    def _read_metadata(self, prologue, image_files, epilogue=None):
        if epilogue:
            mda = self._metadata_reader(prologue,
                                        image_files,
                                        epilogue=epilogue)
        else:
            mda = self._metadata_reader(prologue, image_files)
        if "%.2f" % mda.sublon != "%.2f" % self.sublon:
            if CHECK_CONFIG_SUBLON:
                raise mipp.ReaderError(
                    "Sub satellite point in config file (%.2f) don't match data (%.2f)"
                    % (self.sublon, mda.sublon))
            else:
                logger.warning(
                    "Modifying sub satellite point from %.2f to %.2f" %
                    (self.sublon, mda.sublon))
                self.sublon = mda.sublon

        chn = self._config_reader.get_channel(mda.channel)
        if mda.image_size[0] != chn.size[0]:
            raise mipp.ReaderError(
                "unknown image width for %s, %s: %d" %
                (self.satname, mda.channel, mda.image_size[0]))

        mda.pixel_size = numpy.array([chn.resolution, chn.resolution],
                                     dtype=numpy.float64)
        for k, v in self.__dict__.items():
            if k[0] != '_' and type(v) != types.FunctionType:
                setattr(mda, k, v)

        img = _xrit.read_imagedata(image_files[0])

        return mda
Example #2
0
File: sat.py Project: 3Geo/mipp
 def _read_metadata(self, prologue, image_files, epilogue=None):
     if epilogue:
         mda = self._metadata_reader(prologue, image_files, epilogue=epilogue)
     else:
         mda = self._metadata_reader(prologue, image_files)
     if "%.2f"%mda.sublon != "%.2f"%self.sublon:
         if CHECK_CONFIG_SUBLON:
             raise mipp.ReaderError("Sub satellite point in config file (%.2f) don't match data (%.2f)"%
                                       (self.sublon, mda.sublon))
         else:
             self.sublon = mda.sublon
             logger.warning("Modifying sub satellite point from %.2f to %.2f"%
                            (self.sublon, mda.sublon))
             
     
     chn = self._config_reader.get_channel(mda.channel)
     if mda.image_size[0] != chn.size[0]:
         raise mipp.ReaderError("unknown image width for %s, %s: %d"%
                                (self.satname, mda.channel, mda.image_size[0]))
                             
     mda.pixel_size = numpy.array([chn.resolution, chn.resolution], dtype=numpy.float64)
     for k, v in self.__dict__.items():
         if k[0] != '_' and type(v) != types.FunctionType:
             setattr(mda, k, v)
             
     img = _xrit.read_imagedata(image_files[0])
     
     return mda
Example #3
0
def read_metadata(prologue, image_files):
    """ Selected items from the GOES image data files (not much information in prologue).
    """
    im = _xrit.read_imagedata(image_files[0])
    hdr = im.data_function.data_definition
    md = Metadata()
    md.calibrate = _Calibrator(hdr)
    md.satname = im.platform.lower()
    md.product_type = 'full disc'
    md.region_name = 'full disc'
    #md.product_name = im.product_id
    md.channel = im.product_name
    #ssp = float(im.product_name[5:-1].replace('_','.'))
    #if im.product_name[-1].lower() == 'w':
    #    ssp *= -1
    ssp = im.navigation.ssp
    md.sublon = ssp
    md.first_pixel = 'north west'
    md.data_type = -im.structure.nb
    nseg = im.segment.planned_end_seg_no - im.segment.planned_start_seg_no + 1
    #nseg = im.segment.total_seg_no
    md.image_size = (im.structure.nc, im.structure.nl * nseg)  # !!!
    md.line_offset = 0
    #md.time_stamp = im.time_stamp
    md.production_time = im.production_time
    md.calibration_unit = ""

    # Calibration table
    dd = []
    for k in sorted(hdr.keys()):
        if isinstance(k, int):
            v = hdr[k]
            dd.append([float(k), v])

    try:
        md.calibration_table = dict(
            (('name', im.data_function.data_definition['_NAME']),
             ('unit', im.data_function.data_definition['_UNIT']),
             ('table', numpy.array(dd, dtype=numpy.float32))))
    except KeyError:
        md.calibration_table = dict(
            (('unit', im.data_function.data_definition['_UNIT']),
             ('table', numpy.array(dd, dtype=numpy.float32))))
    md.no_data_value = no_data_value

    segment_size = im.structure.nl

    #md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)
    md.loff = im.navigation.loff
    md.coff = im.navigation.coff

    return md
Example #4
0
File: MSG.py Project: EBarbera/mipp
def read_scanline_quality(segment_filename):
    """Get the line quality data from the segment file. This is from the
    ImageSegmentLineQuality class of the _xrit module, which maps the Header
    Type 129 - Image Segment Line Quality as decribed in the 'MSG Ground
    Segment LRIT/HRIT Mission Specific Implementation, EUM/MSG/SPE/057'
    document, see reference below.
    
    This record contains the scan line mean acquisition times
    
    http://www.eumetsat.int/website/wcm/idc/idcplg?IdcService=GET_FILE&dDocName=PDF_TEN_05057_SPE_MSG_LRIT_HRI&RevisionSelectionMethod=LatestReleased&Rendition=Web

    """
    imgdata = _xrit.read_imagedata(segment_filename)
    return imgdata.image_quality.line_quality
Example #5
0
File: MSG.py Project: lorehov/mipp
def read_scanline_quality(segment_filename):
    """Get the line quality data from the segment file. This is from the
    ImageSegmentLineQuality class of the _xrit module, which maps the Header
    Type 129 - Image Segment Line Quality as decribed in the 'MSG Ground
    Segment LRIT/HRIT Mission Specific Implementation, EUM/MSG/SPE/057'
    document, see reference below.

    This record contains the scan line mean acquisition times

    http://www.eumetsat.int/website/wcm/idc/idcplg?IdcService=GET_FILE&dDocName=PDF_TEN_05057_SPE_MSG_LRIT_HRI&RevisionSelectionMethod=LatestReleased&Rendition=Web

    """
    imgdata = _xrit.read_imagedata(segment_filename)
    return imgdata.image_quality.line_quality
Example #6
0
File: H8.py Project: pytroll/mipp
def read_metadata(prologue, image_files):
    """ Selected items from the GOES image data files (not much information in prologue).
    """
    im = _xrit.read_imagedata(image_files[0])
    hdr = im.data_function.data_definition
    md = Metadata()
    md.calibrate = _Calibrator(hdr)
    md.satname = im.platform.lower()
    md.product_type = 'full disc'
    md.region_name = 'full disc'
    #md.product_name = im.product_id
    md.channel = im.product_name
    #ssp = float(im.product_name[5:-1].replace('_','.'))
    #if im.product_name[-1].lower() == 'w':
    #    ssp *= -1
    ssp = im.navigation.ssp
    md.sublon = ssp
    md.first_pixel = 'north west'
    md.data_type = -im.structure.nb
    nseg = im.segment.planned_end_seg_no - im.segment.planned_start_seg_no + 1
    #nseg = im.segment.total_seg_no
    md.image_size = (im.structure.nc, im.structure.nl*nseg) # !!!
    md.line_offset = 0
    #md.time_stamp = im.time_stamp
    md.production_time = im.production_time
    md.calibration_unit = ""

    # Calibration table
    dd = []
    for k in sorted(hdr.keys()):
        if isinstance(k, int):
            v = hdr[k]
            dd.append([float(k), v])

    try:
        md.calibration_table = dict((('name', im.data_function.data_definition['_NAME']),
                                     ('unit', im.data_function.data_definition['_UNIT']),
                                     ('table', numpy.array(dd, dtype=numpy.float32))))
    except KeyError:
        md.calibration_table = dict((('unit', im.data_function.data_definition['_UNIT']),
                                     ('table', numpy.array(dd, dtype=numpy.float32))))
    md.no_data_value = no_data_value

    segment_size = im.structure.nl

    #md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)
    md.loff = im.navigation.loff
    md.coff = im.navigation.coff

    return md
Example #7
0
def read_metadata(prologue, image_files):
    """ Selected items from the Meteosat-7 prolog file.
    """
    im = _xrit.read_imagedata(image_files[0])
    fp = StringIO(prologue.data)
    asc_hdr = _read_ascii_header(fp)
    bin_hdr = _read_binary_header(fp, asc_hdr['ProductType'])
    md = Metadata()
    md.calibrate = _Calibrator(bin_hdr)
    md.product_name = prologue.product_id
    pf = asc_hdr['Platform']
    if pf == 'M7':
        pf = 'MET7'
    md.satname = pf.lower()
    md.channel = prologue.product_name[:4]
    md.product_type = asc_hdr['ProductType']
    md.region_name = 'full disc'
    md.sublon = bin_hdr['ssp']
    md.first_pixel = asc_hdr['FirstPixelOri']
    md.data_type = bin_hdr['dtype']*8
    md.no_data_value = 0
    md.image_size = (int(asc_hdr['NumberOfPixels']), int(asc_hdr['NumberOfLines']))
    md.line_offset = int(asc_hdr['LineOffset'])
    # handle 24 hour clock
    d, t = strptime(asc_hdr['Date'], "%y%m%d"), int(asc_hdr['Time'])
    md.time_stamp = d + timedelta(hours=t//100, minutes=t%100)
    md.production_time = strptime(asc_hdr['ProdDate'] + asc_hdr['ProdTime'], "%y%m%d%H:%M:%S")
    md.calibration_unit = 'counts'

    # Calibration table
    md.calibration_table = dict((('name', ''),
                                 ('unit', ''),
                                 ('table', None)))

    segment_size = im.structure.nl
    md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)
    md.coff = im.navigation.coff

    return md
Example #8
0
def read_metadata(prologue, image_files):
    """ Selected items from the Meteosat-7 prolog file.
    """
    im = _xrit.read_imagedata(image_files[0])
    fp = StringIO(prologue.data)
    asc_hdr = _read_ascii_header(fp)
    bin_hdr = _read_binary_header(fp, asc_hdr['ProductType'])
    md = Metadata()
    md.calibrate = _Calibrator(bin_hdr)
    md.product_name = prologue.product_id
    pf = asc_hdr['Platform']
    if pf == 'M7':
        pf = 'MET7'
    md.satname = pf.lower()
    md.channel = prologue.product_name[:4]
    md.product_type = asc_hdr['ProductType']
    md.region_name = 'full disc'
    md.sublon = bin_hdr['ssp']
    md.first_pixel = asc_hdr['FirstPixelOri']
    md.data_type = bin_hdr['dtype'] * 8
    md.no_data_value = 0
    md.image_size = (int(asc_hdr['NumberOfPixels']),
                     int(asc_hdr['NumberOfLines']))
    md.line_offset = int(asc_hdr['LineOffset'])
    # handle 24 hour clock
    d, t = strptime(asc_hdr['Date'], "%y%m%d"), int(asc_hdr['Time'])
    md.time_stamp = d + timedelta(hours=t // 100, minutes=t % 100)
    md.production_time = strptime(asc_hdr['ProdDate'] + asc_hdr['ProdTime'],
                                  "%y%m%d%H:%M:%S")
    md.calibration_unit = 'counts'

    # Calibration table
    md.calibration_table = dict((('name', ''), ('unit', ''), ('table', None)))

    segment_size = im.structure.nl
    md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)
    md.coff = im.navigation.coff

    return md
Example #9
0
def read_metadata(prologue, image_files, epilogue):
    """ Selected items from the Electro L N1 prolog file.
    """

    segment_size = 464 # number of lines in a segment

    hdr = {}

    fp = StringIO(prologue.data)
    phdr = read_proheader(fp)
    fp = StringIO(epilogue.data)
    ehdr = read_epiheader(fp)

    hdr.update(phdr)
    hdr.update(ehdr)

    im = _xrit.read_imagedata(image_files[0])

    md = Metadata()

    md.sublon = np.rad2deg(hdr["SatelliteStatus"]["NominalLongitude"])

    md.image_size = (im.structure.nc, im.structure.nc)

    md.channel = im.product_name[:4]
    md.satname = im.platform.lower()
    md.line_offset = 0
    md.data_type = im.structure.nb
    md.no_data_value = 0
    md.first_pixel = "north west"
    md.calibrate = _Calibrator(hdr, md.channel)

    segment_size = im.structure.nl
    md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)
    md.coff = im.navigation.coff
    return md
Example #10
0
def read_metadata(prologue, image_files, epilogue):
    """ Selected items from the Electro L N1 prolog file.
    """

    segment_size = 464  # number of lines in a segment

    hdr = {}

    fp = StringIO(prologue.data)
    phdr = read_proheader(fp)
    fp = StringIO(epilogue.data)
    ehdr = read_epiheader(fp)

    hdr.update(phdr)
    hdr.update(ehdr)

    im = _xrit.read_imagedata(image_files[0])

    md = Metadata()

    md.sublon = np.rad2deg(hdr["SatelliteStatus"]["NominalLongitude"])

    md.image_size = (im.structure.nc, im.structure.nc)

    md.channel = im.product_name[:4]
    md.satname = im.platform.lower()
    md.line_offset = 0
    md.data_type = im.structure.nb
    md.no_data_value = 0
    md.first_pixel = "north west"
    md.calibrate = _Calibrator(hdr, md.channel)

    segment_size = im.structure.nl
    md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)
    md.coff = im.navigation.coff
    return md
Example #11
0
File: MSG.py Project: EBarbera/mipp
def read_metadata(prologue, image_files, epilogue):
    """ Selected items from the MSG prologue file.
    """
    segment_size = 464 # number of lines in a segment

    fp = StringIO(prologue.data)
    hdr = read_proheader(fp)

    fp = StringIO(epilogue.data)
    ftr = read_epiheader(fp)
    
    im = _xrit.read_imagedata(image_files[0])

    md = Metadata()
    md.calibrate = _Calibrator(hdr, im.product_name)

    md.sublon = hdr["ProjectionDescription"]["LongitudeOfSSP"]
    md.product_name = im.product_id
    md.channel = im.product_name
    if md.channel == "HRV":
        md.image_size = np.array((hdr["ReferenceGridHRV"]["NumberOfLines"],
                                  hdr["ReferenceGridHRV"]["NumberOfColumns"]))
    else:
        md.image_size = np.array((hdr["ReferenceGridVIS_IR"]["NumberOfLines"],
                                  hdr["ReferenceGridVIS_IR"]["NumberOfColumns"]))
        
    md.satname = im.platform.lower()
    md.product_type = 'full disc'
    md.region_name = 'full disc'
    if md.channel == "HRV":
        md.first_pixel = hdr["ReferenceGridHRV"]["GridOrigin"]
        ns_, ew_ = md.first_pixel.split()
        md.boundaries = np.array([[
            ftr["LowerSouthLineActual"],
            ftr["LowerNorthLineActual"],
            ftr["LowerEastColumnActual"],
            ftr["LowerWestColumnActual"]],
           [ftr["UpperSouthLineActual"],
            ftr["UpperNorthLineActual"],
            ftr["UpperEastColumnActual"],
            ftr["UpperWestColumnActual"]]])

        md.coff = (ftr["Lower"+ew_.capitalize()+"ColumnActual"]
                   + im.navigation.coff - 1)
        md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)

    else:
        md.first_pixel = hdr["ReferenceGridVIS_IR"]["GridOrigin"]
        ns_, ew_ = md.first_pixel.split()
        md.boundaries = np.array([[
            ftr["SouthernLineActual"],
            ftr["NorthernLineActual"],
            ftr["EasternColumnActual"],
            ftr["WesternColumnActual"]]])

        md.coff = im.navigation.coff
        md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)

    md.data_type = im.structure.nb
    md.no_data_value = no_data_value
    md.line_offset = 0
    md.time_stamp = im.time_stamp
    md.production_time = im.production_time
    md.calibration_unit = 'counts'

    return md
Example #12
0
File: MSG.py Project: lorehov/mipp
def read_metadata(prologue, image_files, epilogue):
    """ Selected items from the MSG prologue file.
    """
    segment_size = 464  # number of lines in a segment

    fp = StringIO(prologue.data)
    hdr = read_proheader(fp)

    fp = StringIO(epilogue.data)
    ftr = read_epiheader(fp)

    try:
        im = _xrit.read_imagedata(image_files[0])
    except IndexError:
        raise ReaderError("No image segments available")

    md = Metadata()
    md.calibrate = _Calibrator(hdr,
                               im.product_name,
                               bits_per_pixel=im.structure.nb)

    md.sublon = hdr["ProjectionDescription"]["LongitudeOfSSP"]
    md.product_name = im.product_id
    md.channel = im.product_name
    if md.channel == "HRV":
        md.image_size = np.array((hdr["ReferenceGridHRV"]["NumberOfLines"],
                                  hdr["ReferenceGridHRV"]["NumberOfColumns"]))
    else:
        md.image_size = np.array(
            (hdr["ReferenceGridVIS_IR"]["NumberOfLines"],
             hdr["ReferenceGridVIS_IR"]["NumberOfColumns"]))

    md.satname = im.platform.lower()
    md.satnumber = SATNUM[hdr["SatelliteDefinition"]["SatelliteId"]]
    logger.debug("%s %s", md.satname, md.satnumber)
    md.product_type = 'full disc'
    md.region_name = 'full disc'
    if md.channel == "HRV":
        md.first_pixel = hdr["ReferenceGridHRV"]["GridOrigin"]
        ns_, ew_ = md.first_pixel.split()
        md.boundaries = np.array([[
            ftr["LowerSouthLineActual"], ftr["LowerNorthLineActual"],
            ftr["LowerEastColumnActual"], ftr["LowerWestColumnActual"]
        ],
                                  [
                                      ftr["UpperSouthLineActual"],
                                      ftr["UpperNorthLineActual"],
                                      ftr["UpperEastColumnActual"],
                                      ftr["UpperWestColumnActual"]
                                  ]])

        md.coff = (ftr["Lower" + ew_.capitalize() + "ColumnActual"] - 1 +
                   im.navigation.coff - 1)
        md.loff = im.navigation.loff + \
            segment_size * (im.segment.seg_no - 1) - 1
        if (hdr["GeometricProcessing"]["EarthModel"]["TypeOfEarthModel"] < 2):
            md.coff += 1.5
            md.loff += 1.5

    else:
        md.first_pixel = hdr["ReferenceGridVIS_IR"]["GridOrigin"]
        ns_, ew_ = md.first_pixel.split()
        md.boundaries = np.array([[
            ftr["SouthernLineActual"], ftr["NorthernLineActual"],
            ftr["EasternColumnActual"], ftr["WesternColumnActual"]
        ]])

        md.coff = im.navigation.coff - 1
        md.loff = im.navigation.loff + \
            segment_size * (im.segment.seg_no - 1) - 1

        if (hdr["GeometricProcessing"]["EarthModel"]["TypeOfEarthModel"] < 2):
            md.coff += .5
            md.loff += .5

    md.x_pixel_size = np.deg2rad(2.**16 / im.navigation.cfac) * MSG_HEIGHT * -1
    md.y_pixel_size = np.deg2rad(2.**16 / im.navigation.lfac) * MSG_HEIGHT * -1

    md.data_type = im.structure.nb
    md.no_data_value = no_data_value
    md.line_offset = 0
    md.time_stamp = im.time_stamp
    md.production_time = im.production_time
    md.calibration_unit = ""

    return md
Example #13
0
    def _read(self, rows, columns, mda):
        shape = (rows.stop - rows.start, columns.stop - columns.start)
        if (columns.start < 0 or
                columns.stop > mda.image_size[0] or
                rows.start < 0 or
                rows.stop > mda.image_size[1]):
            raise IndexError, "index out of range"

        image_files = self.image_files

        #
        # Order segments
        #
        segments = {}
        for f in image_files:
            s = _xrit.read_imagedata(f)
            segments[s.segment.seg_no] = f
        start_seg_no = s.segment.planned_start_seg_no
        end_seg_no = s.segment.planned_end_seg_no
        ncols = s.structure.nc
        segment_nlines = s.structure.nl

        #
        # Data type
        #
        converter = _null_converter
        if mda.data_type == 8:
            data_type = numpy.uint8
            data_type_len = 8
        elif mda.data_type == 10:
            converter = convert.dec10216
            data_type = numpy.uint16
            data_type_len = 16
        elif mda.data_type == 16:
            data_type = numpy.uint16
            data_type_len = 16
        elif mda.data_type == -16:
            data_type = '>u2'
            data_type_len = 16
        else:
            raise mipp.ReaderError, "unknown data type: %d bit per pixel"\
                % mda.data_type

        #
        # Calculate initial and final line and column.
        # The interface 'load(..., center, size)' will produce
        # correct values relative to the image orientation.
        # line_init, line_end : 1-based
        #
        line_init = rows.start + 1
        line_end = line_init + rows.stop - rows.start - 1
        col_count = shape[1]
        col_offset = (columns.start) * data_type_len // 8

        #
        # Calculate initial and final segments
        # depending on the image orientation.
        # seg_init, seg_end : 1-based.
        #
        seg_init = ((line_init - 1) // segment_nlines) + 1
        seg_end = ((line_end - 1) // segment_nlines) + 1

        #
        # Calculate initial line in image, line increment
        # offset for columns and factor for columns,
        # and factor for columns, depending on the image
        # orientation
        #
        if mda.first_pixel == 'north west':
            first_line = 0
            increment_line = 1
            factor_col = 1
        elif mda.first_pixel == 'north east':
            first_line = 0
            increment_line = 1
            factor_col = -1
        elif mda.first_pixel == 'south west':
            first_line = shape[0] - 1
            increment_line = -1
            factor_col = 1
        elif mda.first_pixel == 'south east':
            first_line = shape[0] - 1
            increment_line = -1
            factor_col = -1
        else:
            raise mipp.ReaderError, "unknown geographical orientation of " + \
                "first pixel: '%s'" % mda.first_pixel

        #
        # Generate final image with no data
        #
        image = numpy.zeros(shape, dtype=data_type) + mda.no_data_value

        #
        # Begin the segment processing.
        #
        seg_no = seg_init
        line_in_image = first_line
        while seg_no <= seg_end:
            line_in_segment = 1

            #
            # Calculate initial line in actual segment.
            #
            if seg_no == seg_init:
                init_line_in_segment = (line_init
                                        - (segment_nlines * (seg_init - 1)))
            else:
                init_line_in_segment = 1

            #
            # Calculate final line in actual segment.
            #
            if seg_no == seg_end:
                end_line_in_segment = line_end - \
                    (segment_nlines * (seg_end - 1))
            else:
                end_line_in_segment = segment_nlines

            #
            # Open segment file.
            #
            seg_file = segments.get(seg_no, None)
            if not seg_file:
                #
                # No data for this segment.
                #
                logger.warning("Segment number %d not found" % seg_no)

                # all image lines are already set to no-data count.
                line_in_segment = init_line_in_segment
                while line_in_segment <= end_line_in_segment:
                    line_in_segment += 1
                    line_in_image += increment_line
            else:
                #
                # Data for this segment.
                #
                logger.info("Read %s" % seg_file)
                seg = _xrit.read_imagedata(seg_file)

                #
                # Skip lines not processed.
                #
                while line_in_segment < init_line_in_segment:
                    line = seg.readline()
                    line_in_segment += 1

                #
                # Reading and processing segment lines.
                #
                while line_in_segment <= end_line_in_segment:
                    line = seg.readline()[mda.line_offset:]
                    line = converter(line)

                    line = (numpy.frombuffer(line,
                                             dtype=data_type,
                                             count=col_count,
                                             offset=col_offset)[::factor_col])

                    #
                    # Insert image data.
                    #
                    image[line_in_image] = line

                    line_in_segment += 1
                    line_in_image += increment_line

                seg.close()

            seg_no += 1

        #
        # Compute mask before calibration
        #

        mask = (image == mda.no_data_value)

        #
        # Calibrate ?
        #
        mda.is_calibrated = False
        if self.do_calibrate:
            # do this before masking.
            calibrate = self.do_calibrate
            if isinstance(calibrate, bool):
                # allow boolean True/False for 1/0
                calibrate = int(calibrate)
            image, mda.calibration_unit = mda.calibrate(
                image, calibrate=calibrate)
            mda.is_calibrated = True
        else:
            mda.calibration_unit = ""

        #
        # With or without mask ?
        #
        if self.do_mask and not isinstance(image, numpy.ma.core.MaskedArray):
            image = numpy.ma.array(image, mask=mask, copy=False)
        elif ((not self.do_mask) and
                isinstance(image, numpy.ma.core.MaskedArray)):
            image = image.filled(mda.no_data_value)

        return image
Example #14
0
def read_metadata(prologue, image_files, epilogue):
    """ Selected items from the MSG prologue file.
    """
    segment_size = 464  # number of lines in a segment

    fp = StringIO(prologue.data)
    hdr = read_proheader(fp)

    fp = StringIO(epilogue.data)
    ftr = read_epiheader(fp)

    im = _xrit.read_imagedata(image_files[0])

    md = Metadata()
    md.calibrate = _Calibrator(hdr, im.product_name)

    md.sublon = hdr["ProjectionDescription"]["LongitudeOfSSP"]
    md.product_name = im.product_id
    md.channel = im.product_name
    if md.channel == "HRV":
        md.image_size = np.array((hdr["ReferenceGridHRV"]["NumberOfLines"],
                                  hdr["ReferenceGridHRV"]["NumberOfColumns"]))
    else:
        md.image_size = np.array(
            (hdr["ReferenceGridVIS_IR"]["NumberOfLines"],
             hdr["ReferenceGridVIS_IR"]["NumberOfColumns"]))

    md.satname = im.platform.lower()
    md.product_type = 'full disc'
    md.region_name = 'full disc'
    if md.channel == "HRV":
        md.first_pixel = hdr["ReferenceGridHRV"]["GridOrigin"]
        ns_, ew_ = md.first_pixel.split()
        md.boundaries = np.array([[
            ftr["LowerSouthLineActual"], ftr["LowerNorthLineActual"],
            ftr["LowerEastColumnActual"], ftr["LowerWestColumnActual"]
        ],
                                  [
                                      ftr["UpperSouthLineActual"],
                                      ftr["UpperNorthLineActual"],
                                      ftr["UpperEastColumnActual"],
                                      ftr["UpperWestColumnActual"]
                                  ]])

        md.coff = (ftr["Lower" + ew_.capitalize() + "ColumnActual"] +
                   im.navigation.coff - 1)
        md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)

    else:
        md.first_pixel = hdr["ReferenceGridVIS_IR"]["GridOrigin"]
        ns_, ew_ = md.first_pixel.split()
        md.boundaries = np.array([[
            ftr["SouthernLineActual"], ftr["NorthernLineActual"],
            ftr["EasternColumnActual"], ftr["WesternColumnActual"]
        ]])

        md.coff = im.navigation.coff
        md.loff = im.navigation.loff + segment_size * (im.segment.seg_no - 1)

    md.data_type = im.structure.nb
    md.no_data_value = no_data_value
    md.line_offset = 0
    md.time_stamp = im.time_stamp
    md.production_time = im.production_time
    md.calibration_unit = 'counts'

    return md
Example #15
0
File: MSG.py Project: pytroll/mipp
def read_metadata(prologue, image_files, epilogue):
    """ Selected items from the MSG prologue file.
    """
    segment_size = 464  # number of lines in a segment

    fp = StringIO(prologue.data)
    hdr = read_proheader(fp)

    fp = StringIO(epilogue.data)
    ftr = read_epiheader(fp)

    try:
        im = _xrit.read_imagedata(image_files[0])
    except IndexError:
        raise ReaderError("No image segments available")

    md = Metadata()
    md.calibrate = _Calibrator(
        hdr, im.product_name, bits_per_pixel=im.structure.nb)

    md.sublon = hdr["ProjectionDescription"]["LongitudeOfSSP"]
    md.product_name = im.product_id
    md.channel = im.product_name
    if md.channel == "HRV":
        md.image_size = np.array((hdr["ReferenceGridHRV"]["NumberOfLines"],
                                  hdr["ReferenceGridHRV"]["NumberOfColumns"]))
    else:
        md.image_size = np.array((hdr["ReferenceGridVIS_IR"]["NumberOfLines"],
                                  hdr["ReferenceGridVIS_IR"]["NumberOfColumns"]))

    md.satname = im.platform.lower()
    md.satnumber = SATNUM[hdr["SatelliteDefinition"]["SatelliteId"]]
    logger.debug("%s %s", md.satname, md.satnumber)
    md.product_type = 'full disc'
    md.region_name = 'full disc'
    if md.channel == "HRV":
        md.first_pixel = hdr["ReferenceGridHRV"]["GridOrigin"]
        ns_, ew_ = md.first_pixel.split()
        md.boundaries = np.array([[
            ftr["LowerSouthLineActual"],
            ftr["LowerNorthLineActual"],
            ftr["LowerEastColumnActual"],
            ftr["LowerWestColumnActual"]],
            [ftr["UpperSouthLineActual"],
             ftr["UpperNorthLineActual"],
             ftr["UpperEastColumnActual"],
             ftr["UpperWestColumnActual"]]])

        md.coff = (ftr["Lower" + ew_.capitalize() + "ColumnActual"] - 1
                   + im.navigation.coff - 1)
        md.loff = im.navigation.loff + \
            segment_size * (im.segment.seg_no - 1) - 1
        if (hdr["GeometricProcessing"]["EarthModel"]["TypeOfEarthModel"] < 2):
            md.coff += 1.5
            md.loff += 1.5

    else:
        md.first_pixel = hdr["ReferenceGridVIS_IR"]["GridOrigin"]
        ns_, ew_ = md.first_pixel.split()
        md.boundaries = np.array([[
            ftr["SouthernLineActual"],
            ftr["NorthernLineActual"],
            ftr["EasternColumnActual"],
            ftr["WesternColumnActual"]]])

        md.coff = im.navigation.coff - 1
        md.loff = im.navigation.loff + \
            segment_size * (im.segment.seg_no - 1) - 1

        if (hdr["GeometricProcessing"]["EarthModel"]["TypeOfEarthModel"] < 2):
            md.coff += .5
            md.loff += .5

    md.x_pixel_size = np.deg2rad(2.**16 / im.navigation.cfac) * MSG_HEIGHT * -1
    md.y_pixel_size = np.deg2rad(2.**16 / im.navigation.lfac) * MSG_HEIGHT * -1

    md.data_type = im.structure.nb
    md.no_data_value = no_data_value
    md.line_offset = 0
    md.time_stamp = im.time_stamp
    md.production_time = im.production_time
    md.calibration_unit = ""

    return md