示例#1
0
def save_passes(allpasses,
                poly,
                output_dir,
                plot_parameters=None,
                plot_title=None):
    """Save overpass plots to png and store in directory *output_dir*
    """
    from trollsched.drawing import save_fig
    for overpass in allpasses:
        save_fig(overpass,
                 poly=poly,
                 directory=output_dir,
                 plot_parameters=plot_parameters,
                 plot_title=plot_title)
def process_xmlrequest(filename, plotdir, output_file, excluded_satellites):

    tree = ET.parse(filename)
    root = tree.getroot()

    for child in root:
        if child.tag == 'pass':
            LOG.debug("Pass: %s", str(child.attrib))
            platform_name = SATELLITE_NAMES.get(child.attrib['satellite'],
                                                child.attrib['satellite'])
            instrument = INSTRUMENT.get(platform_name)
            if not instrument:
                LOG.error('Instrument unknown! Platform = %s', platform_name)
                continue

            if platform_name in excluded_satellites:
                LOG.debug('Platform name excluded: %s', platform_name)
                continue
            try:
                overpass = Pass(platform_name,
                                datetime.strptime(child.attrib['start-time'],
                                                  '%Y-%m-%d-%H:%M:%S'),
                                datetime.strptime(child.attrib['end-time'],
                                                  '%Y-%m-%d-%H:%M:%S'),
                                instrument=instrument)
            except KeyError as err:
                LOG.warning('Failed on satellite %s: %s', platform_name,
                            str(err))
                continue

            save_fig(overpass, directory=plotdir)
            child.set('img', overpass.fig)
            child.set('rec', 'True')
            LOG.debug("Plot saved - plotdir = %s, platform_name = %s", plotdir,
                      platform_name)

    tree.write(output_file, encoding='utf-8', xml_declaration=True)

    with open(output_file) as fpt:
        lines = fpt.readlines()
        lines.insert(
            1, "<?xml-stylesheet type='text/xsl' href='reqreader.xsl'?>")

    with open(output_file, 'w') as fpt:
        fpt.writelines(lines)
def granule_inside_area(start_time,
                        end_time,
                        platform_name,
                        instrument,
                        area_def,
                        thr_area_coverage,
                        tle_file=None):
    """Check if a satellite data granule is over area interest, using the start and
    end times from the filename

    """

    try:
        metop = Orbital(platform_name, tle_file)
    except KeyError:
        LOG.exception(
            'Failed getting orbital data for {0}'.format(platform_name))
        LOG.critical(
            'Cannot determine orbit! Probably TLE file problems...\n' +
            'Granule will be set to be inside area of interest disregarding')
        return True

    tle1 = metop.tle.line1
    tle2 = metop.tle.line2

    mypass = Pass(platform_name,
                  start_time,
                  end_time,
                  instrument=instrument,
                  tle1=tle1,
                  tle2=tle2)
    acov = mypass.area_coverage(area_def)
    LOG.debug("Granule coverage of area %s: %f", area_def.area_id, acov)

    is_inside = (acov > thr_area_coverage)

    if is_inside:
        from pyresample.boundary import AreaDefBoundary
        from trollsched.drawing import save_fig
        area_boundary = AreaDefBoundary(area_def, frequency=100)
        area_boundary = area_boundary.contour_poly
        save_fig(mypass, poly=area_boundary, directory='/tmp')

    return
def process_xmlrequest(filename, plotdir, output_file, excluded_satellites):

    tree = ET.parse(filename)
    root = tree.getroot()

    for child in root:
        if child.tag == 'pass':
            LOG.debug("Pass: %s", str(child.attrib))
            platform_name = SATELLITE_NAMES.get(child.attrib['satellite'], child.attrib['satellite'])
            instrument = INSTRUMENT.get(platform_name)
            if not instrument:
                LOG.error('Instrument unknown! Platform = %s', platform_name)
                continue

            if platform_name in excluded_satellites:
                LOG.debug('Platform name excluded: %s', platform_name)
                continue
            try:
                overpass = Pass(platform_name,
                                datetime.strptime(child.attrib['start-time'],
                                                  '%Y-%m-%d-%H:%M:%S'),
                                datetime.strptime(child.attrib['end-time'],
                                                  '%Y-%m-%d-%H:%M:%S'),
                                instrument=instrument)
            except KeyError as err:
                LOG.warning('Failed on satellite %s: %s', platform_name, str(err))
                continue

            save_fig(overpass, directory=plotdir)
            child.set('img', overpass.fig)
            child.set('rec', 'True')
            LOG.debug("Plot saved - plotdir = %s, platform_name = %s", plotdir, platform_name)

    tree.write(output_file, encoding='utf-8', xml_declaration=True)

    with open(output_file) as fpt:
        lines = fpt.readlines()
        lines.insert(
            1, "<?xml-stylesheet type='text/xsl' href='reqreader.xsl'?>")

    with open(output_file, 'w') as fpt:
        fpt.writelines(lines)
示例#5
0
def save_passes(allpasses, poly, output_dir):
    """Save overpass plots to png and store in directory *output_dir*
    """
    from trollsched.drawing import save_fig
    for overpass in allpasses:
        save_fig(overpass, poly=poly, directory=output_dir)