Esempio n. 1
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
Esempio n. 2
0
File: H8.py Progetto: 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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
0
File: MSG.py Progetto: 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
Esempio n. 6
0
File: MSG.py Progetto: 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
Esempio n. 7
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
Esempio n. 8
0
File: MSG.py Progetto: 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