Beispiel #1
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
Beispiel #2
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 = prologue.product_id
    md.channel = prologue.product_name[:4]
    ssp = float(im.product_name[5:-1].replace('_','.'))
    if im.product_name[-1].lower() == 'w':            
        ssp *= -1
    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
    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])

    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))))

    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.coff = im.navigation.coff

    return md
Beispiel #3
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)

    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
Beispiel #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
Beispiel #5
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
Beispiel #6
0
def _get_metadata(hdr, ftr, channel_name):
    
    md = Metadata()
    md.calibrate = _Calibrator(hdr, channel_name)

    if channel_name == "HRV":
        md.pixel_size = (1000.134348869, 1000.134348869)
    else:
        md.pixel_size = (3000.403165817, 3000.403165817)

    md.sublon = hdr["ProjectionDescription"]["LongitudeOfSSP"]
    md.channel = channel_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()
        del ns_
        md.boundaries = np.array([[
            ftr["LowerSouthLineActual"],
            ftr["LowerNorthLineActual"],
            ftr["LowerEastColumnActual"],
            ftr["LowerWestColumnActual"]],
           [ftr["UpperSouthLineActual"],
            ftr["UpperNorthLineActual"],
            ftr["UpperEastColumnActual"],
            ftr["UpperWestColumnActual"]]])

        hcoff = 1856 * 3
        hloff = 1856 * 3
        md.coff = (ftr["Lower"+ew_.capitalize()+"ColumnActual"]
                   + hcoff - 1)
        md.loff = hloff

    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"]]])
        lcoff = 1856
        lloff = 1856
        md.coff = lcoff
        md.loff = lloff

    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
Beispiel #7
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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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)

    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
Beispiel #11
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