Пример #1
0
def load(scene, *args, **kwargs):
    """Loads the *channels* into the satellite *scene*.
    A possible *calibrate* keyword argument is passed to the AAPP reader
    Should be 0 for off, 1 for default, and 2 for radiances only.
    However, as the AAPP-lvl1b file contains radiances this reader cannot
    return counts, so calibrate=0 is not allowed/supported. The radiance to
    counts conversion is not possible.
    """

    del args
    calibrate = kwargs.get("calibrate", True)
    if calibrate == 0:
        raise ValueError('calibrate=0 is not supported! ' +
                         'This reader cannot return counts')

    filename = (kwargs.get("filename", None) or
                get_filename(scene, "level2"))
    LOG.debug("Using file " + filename)
    reader = EpsAvhrrL1bReader(filename)
    for chname, arr in reader.get_channels(scene.channels_to_load, 
                                           calibrate).items():
        scene[chname] = arr

    scene.orbit = str(int(reader["ORBIT_START"]))

    lons, lats = reader.get_full_lonlats()
    try:
        scene.area = geometry.SwathDefinition(lons, lats)
    except NameError:
        scene.lons, scene.lats = lons, lats
Пример #2
0
def load_generic(satscene, options, calibrate=True):
    """Read sar data from file and load it into *satscene*.
    """
    os.environ["PPP_CONFIG_DIR"] = CONFIG_PATH

    LOG.debug("Channels to load from %s: %s"%(satscene.instrument_name,
                                              satscene.channels_to_load))
    
    # Compulsory global attribudes
    satscene.info["title"] = (satscene.satname.capitalize() + satscene.number +
                              " satellite, " +
                              satscene.instrument_name.capitalize() +
                              " instrument.")
    satscene.info["institution"] = "No institution."
    satscene.add_to_history("SAR data read by mipp/mpop.")
    satscene.info["references"] = "No reference."
    satscene.info["comments"] = "No comment."
    
    for chn in satscene.channels_to_load:
        try:
            metadata, data = xsar.sat.load(satscene.fullname,
                                           satscene.time_slot,
                                           chn,
                                           mask=True,
                                           calibrate=calibrate)
        except CalibrationError:
            LOG.warning("Loading non calibrated data since calibration failed.")
            metadata, data = xsar.sat.load(satscene.fullname,
                                           satscene.time_slot,
                                           chn,
                                           mask=True,
                                           calibrate=False)
        except ReaderError:
            # if channel can't be found, go on with next channel
            continue

        satscene[chn] = data
        satscene[chn].info['units'] = metadata.calibration_unit
        
        if is_pyresample_loaded:
            # Build an area on the fly from the mipp metadata
            proj_params = getattr(metadata, "proj4_params").split()
            proj_dict = {}
            for param in proj_params:
                key, val = [i.strip() for i in param.split("=")]
                proj_dict[key] = val
            
            # Build area_def on-the-fly
            satscene[chn].area = geometry.AreaDefinition(
                satscene.satname + satscene.instrument_name +
                str(metadata.area_extent) +
                str(data.shape),
                "On-the-fly area",
                proj_dict["proj"],
                proj_dict,
                data.shape[1],
                data.shape[0],
                metadata.area_extent)
        else:
            LOG.info("Could not build area, pyresample missing...")
Пример #3
0
def load_avhrr(satscene, options):
    """Read avhrr data from file and load it into *satscene*.
    """
    
    if "filename" not in options:
        raise IOError("No filename given, cannot load.")
    values = {"INSTRUMENT": satscene.instrument_name[:4].upper(),
              "FNAME": satscene.satname[0].upper() + satscene.number
              }
    filename = os.path.join(
        options["dir"],
        (satscene.time_slot.strftime(options["filename"])%values))
    LOG.debug("Looking for file %s"%satscene.time_slot.strftime(filename))
    file_list = glob.glob(satscene.time_slot.strftime(filename))

    if len(file_list) > 1:
        raise IOError("More than one l1b file matching!")
    elif len(file_list) == 0:
        raise IOError("No l1b file matching!")

    try:
        fdes = open(file_list[0])
        channels, lats, lons, g3a, g3b, orbit = read(fdes)
    
    finally:
        fdes.close()

    channels = np.ma.masked_invalid(channels)
    
    satscene["1"] = channels[0, :, :]
    satscene["2"] = channels[1, :, :]
    satscene["4"] = channels[4, :, :]
    satscene["5"] = channels[5, :, :]
    if g3a:
        satscene["3A"] = channels[2, :, :]
    if g3b:
        satscene["3B"] = channels[3, :, :]

    print "Inside eps_avhrr.load_avhrr: orbit = ", orbit
    #satscene.orbit = str(int(orbit) + 1)
    satscene.orbit = str(int(orbit))

    try:
        from pyresample import geometry
        satscene.area = geometry.SwathDefinition(lons=lons, lats=lats)
    except ImportError:
        satscene.area = None
        satscene.lat = lats
        satscene.lon = lons
Пример #4
0
def get_filename(satscene, level):
    """Get the filename.
    """
    conf = ConfigParser()
    conf.read(os.path.join(CONFIG_PATH, satscene.fullname + ".cfg"))
    options = {}
    for option, value in conf.items(satscene.instrument_name + "-" + level,
                                    raw = True):
        options[option] = value
    values = {"INSTRUMENT": satscene.instrument_name[:4].upper(),
              "FNAME": satscene.satname[0].upper() + satscene.number
              }
    filename = os.path.join(
        options["dir"],
        (satscene.time_slot.strftime(options["filename"])%values))
    LOG.debug("Looking for file %s"%satscene.time_slot.strftime(filename))
    file_list = glob.glob(satscene.time_slot.strftime(filename))

    if len(file_list) > 1:
        raise IOError("More than one l1b file matching!")
    elif len(file_list) == 0:
        raise IOError("No l1b file matching!")
    return file_list[0]
Пример #5
0
def load_avhrr(satscene, options):
    """Read avhrr data from file and load it into *satscene*.
    """
    
    if "filename" not in options:
        raise IOError("No filename given, cannot load.")


    chns = satscene.channels_to_load & set(["1", "2", "3A", "3B", "4", "5"])
    if len(chns) == 0:
        return

    values = {"orbit": satscene.orbit,
              "satname": satscene.satname,
              "number": satscene.number,
              "instrument": satscene.instrument_name,
              "satellite": satscene.fullname
              }

    filename = os.path.join(satscene.time_slot.strftime(options["dir"])%values,
                            satscene.time_slot.strftime(options["filename"])
                            %values)

    file_list = glob.glob(filename)

    if len(file_list) > 1:
        raise IOError("More than one l1b file matching!")
    elif len(file_list) == 0:
        raise IOError("No l1b file matching!: "+
                      filename)

    
    filename = file_list[0]

    LOG.debug("Loading from " + filename)

    import avhrr # AHAMAP module

    avh = avhrr.avhrr(filename)
    avh.get_unprojected()
    instrument_data = avh.build_raw()

    available_channels = set([])
    data_channels = {}

    for chn in instrument_data.data:
        channel_name = chn.info.info["channel_id"][3:].upper()
        available_channels |= set([channel_name])
        data_channels[channel_name] = chn.data

    for chn in satscene.channels_to_load:
        if chn in available_channels:
            if chn in ["1", "2", "3A"]:
                gain = instrument_data.info["vis_gain"]
                intercept = instrument_data.info["vis_intercept"]
                units = "%"
            else:
                gain = instrument_data.info["ir_gain"]
                intercept = instrument_data.info["ir_intercept"]
                units = "K"

            chn_array = np.ma.array(data_channels[chn])
            missing_data = instrument_data.info["missing_data"]
            chn_array = np.ma.masked_inside(chn_array,
                                            missing_data - EPSILON,
                                            missing_data + EPSILON)
            no_data = instrument_data.info["nodata"]
            chn_array = np.ma.masked_inside(chn_array,
                                            no_data - EPSILON,
                                            no_data + EPSILON)

            satscene[chn] = chn_array
            satscene[chn].data =  np.ma.masked_less(satscene[chn].data *
                                                    gain +
                                                    intercept,
                                                    0)

            satscene[chn].info['units'] = units
        else:
            LOG.warning("Channel "+str(chn)+" not available, not loaded.")

    # Compulsory global attribudes
    satscene.info["title"] = (satscene.satname.capitalize() + satscene.number +
                              " satellite, " +
                              satscene.instrument_name.capitalize() +
                              " instrument.")
    satscene.info["institution"] = "Original data disseminated by EumetCast."
    satscene.add_to_history("HRIT/LRIT data read by mipp/mpop.")
    satscene.info["references"] = "No reference."
    satscene.info["comments"] = "No comment."

    lons = instrument_data.londata / math.pi * 180
    lats = instrument_data.latdata / math.pi * 180

    try:
        from pyresample import geometry
        satscene.area = geometry.SwathDefinition(lons=lons, lats=lats)
    except ImportError:
        satscene.area = None
        satscene.lat = lats
        satscene.lon = lons
Пример #6
0
def load_generic(satscene, options, calibrate=True, area_extent=None):
    """Read seviri data from file and load it into *satscene*.
    """
    os.environ["PPP_CONFIG_DIR"] = CONFIG_PATH

    LOG.debug("Channels to load from %s: %s" % (satscene.instrument_name, satscene.channels_to_load))

    # Compulsory global attribudes
    satscene.info["title"] = (
        satscene.satname.capitalize()
        + satscene.number
        + " satellite, "
        + satscene.instrument_name.capitalize()
        + " instrument."
    )
    satscene.info["institution"] = "Original data disseminated by EumetCast."
    satscene.add_to_history("HRIT/LRIT data read by mipp/mpop.")
    satscene.info["references"] = "No reference."
    satscene.info["comments"] = "No comment."

    from_area = False

    if area_extent is None and satscene.area is not None:
        if not satscene.area_def:
            satscene.area = get_area_def(satscene.area_id)
        area_extent = satscene.area.area_extent
        from_area = True

    for chn in satscene.channels_to_load:
        if from_area:
            try:
                metadata = xrit.sat.load(satscene.fullname, satscene.time_slot, chn, only_metadata=True)
                if (
                    satscene.area_def.proj_dict["proj"] != "geos"
                    or float(satscene.area_def.proj_dict["lon_0"]) != metadata.sublon
                ):
                    raise ValueError(
                        "Slicing area must be in "
                        "geos projection, and lon_0 should match the"
                        " satellite's position."
                    )
            except SatReaderError:
                # if channel can't be found, go on with next channel
                continue
        try:
            image = xrit.sat.load(satscene.fullname, satscene.time_slot, chn, mask=True, calibrate=calibrate)
            if area_extent:
                metadata, data = image(area_extent)
            else:
                metadata, data = image()
        except CalibrationError:
            LOG.warning("Loading non calibrated data since calibration failed.")
            image = xrit.sat.load(satscene.fullname, satscene.time_slot, chn, mask=True, calibrate=False)
            if area_extent:
                metadata, data = image(area_extent)
            else:
                metadata, data = image()

        except SatReaderError:
            # if channel can't be found, go on with next channel
            continue

        satscene[chn] = data

        satscene[chn].info["units"] = metadata.calibration_unit

        # Build an area on the fly from the mipp metadata
        proj_params = getattr(metadata, "proj4_params").split(" ")
        proj_dict = {}
        for param in proj_params:
            key, val = param.split("=")
            proj_dict[key] = val

        if is_pyresample_loaded:
            # Build area_def on-the-fly
            satscene[chn].area = geometry.AreaDefinition(
                satscene.satname + satscene.instrument_name + str(metadata.area_extent) + str(data.shape),
                "On-the-fly area",
                proj_dict["proj"],
                proj_dict,
                data.shape[1],
                data.shape[0],
                metadata.area_extent,
            )
        else:
            LOG.info("Could not build area, pyresample missing...")