def handle(self, *args, **kwargs):
        results_dir = (Setting.objects.get(
            key='DESTINATION_DIR').value.replace('\\', '/'))

        logger = Log()

        for scenario in scenarios():
            mwgeotransform = (
                calculate_export_maps.maxwaterdepth_geotransform(scenario))
            needs_conversion = False
            for result in scenario.result_set.all():
                if not result.resultloc:
                    continue
                result_location = os.path.join(
                    results_dir, result.resultloc.replace('\\', '/'))
                if not os.path.basename(result_location).startswith('fls'):
                    continue

                try:
                    fls = Flsh(result_location,
                               helper_geotransform=mwgeotransform)
                    needs_conversion = fls.uses_old_y0()
                    break
                except ValueError:
                    # Happens if there is more than one file in an fls.zip
                    continue

            if needs_conversion:
                convert_scenario(scenario, logger)
def common_generation(scenario_id, source_programs, tmp_dir):
    """
    loop on all results computed for the given scenario_id, unpack
    them into a temporary directory, save as a pyramid, set in the
    results record.
    """

    scenario = Scenario.objects.get(pk=scenario_id)

    maxwaterdepth_geotransform = (
        calculate_export_maps.maxwaterdepth_geotransform(scenario))

    logger.debug("select results relative to scenario %s" % scenario_id)

    # The Generation for some results creates new results. In
    # particular, creating animations for max water depth generates
    # results for arrival time maps. So first we generate the results
    # that generate others, then the rest.

    all_results = (scenario.result_set.filter(
        resulttype__program__in=source_programs,
        resulttype__color_mapping_name__isnull=False).exclude(
            resulttype__color_mapping_name=""))

    generate_for_result_queryset(
        scenario,
        all_results.filter(resulttype__use_to_compute_arrival_times=True),
        tmp_dir, maxwaterdepth_geotransform)

    generate_for_result_queryset(
        scenario,
        all_results.filter(resulttype__use_to_compute_arrival_times=False),
        tmp_dir, maxwaterdepth_geotransform)

    return True
    def handle(self, *args, **kwargs):
        results_dir = Setting.objects.get(key="DESTINATION_DIR").value.replace("\\", "/")

        logger = Log()

        for scenario in scenarios():
            mwgeotransform = calculate_export_maps.maxwaterdepth_geotransform(scenario)
            needs_conversion = False
            for result in scenario.result_set.all():
                if not result.resultloc:
                    continue
                result_location = os.path.join(results_dir, result.resultloc.replace("\\", "/"))
                if not os.path.basename(result_location).startswith("fls"):
                    continue

                try:
                    fls = Flsh(result_location, helper_geotransform=mwgeotransform)
                    needs_conversion = fls.uses_old_y0()
                    break
                except ValueError:
                    # Happens if there is more than one file in an fls.zip
                    continue

            if needs_conversion:
                convert_scenario(scenario, logger)
示例#4
0
def standalone_generation_for_result(result):
    """Call this function from scripts and so on."""
    scenario = result.scenario
    maxwaterdepth_geotransform = (
        calculate_export_maps.maxwaterdepth_geotransform(scenario))
    results_dir = settings.EXTERNAL_RESULT_MOUNTED_DIR
    # Destination dir -- same as the old PNGs were saved to
    destination_dir = settings.EXTERNAL_RESULT_MOUNTED_DIR
    base_output_dir = os.path.join(destination_dir, scenario.get_rel_destdir())
    base_output_dir = base_output_dir.encode('utf8')  # Gdal wants byte strings

    return generate_for_result(
        result, results_dir, base_output_dir, settings.TMP_DIR,
        maxwaterdepth_geotransform)
def standalone_generation_for_result(result):
    """Call this function from scripts and so on."""
    scenario = result.scenario
    maxwaterdepth_geotransform = (
        calculate_export_maps.maxwaterdepth_geotransform(scenario))
    results_dir = (Setting.objects.get(key='DESTINATION_DIR').value.replace(
        '\\', '/'))
    # Destination dir -- same as the old PNGs were saved to
    destination_dir = (Setting.objects.get(
        key='DESTINATION_DIR').value.replace('\\', '/'))
    base_output_dir = os.path.join(destination_dir, scenario.get_rel_destdir())
    base_output_dir = base_output_dir.encode('utf8')  # Gdal wants byte strings

    return generate_for_result(result, results_dir, base_output_dir,
                               settings.TMP_DIR, maxwaterdepth_geotransform)
示例#6
0
def standalone_generation_for_result(result):
    """Call this function from scripts and so on."""
    scenario = result.scenario
    maxwaterdepth_geotransform = (
        calculate_export_maps.maxwaterdepth_geotransform(scenario))
    results_dir = (
        Setting.objects.get(key='DESTINATION_DIR').value.replace('\\', '/'))
    # Destination dir -- same as the old PNGs were saved to
    destination_dir = (
        Setting.objects.get(key='DESTINATION_DIR').value.replace('\\', '/'))
    base_output_dir = os.path.join(destination_dir, scenario.get_rel_destdir())
    base_output_dir = base_output_dir.encode('utf8')  # Gdal wants byte strings

    return generate_for_result(
        result, results_dir, base_output_dir, settings.TMP_DIR,
        maxwaterdepth_geotransform)
示例#7
0
def common_generation(scenario_id, source_programs, tmp_dir):
    """
    loop on all results computed for the given scenario_id, unpack
    them into a temporary directory, save as a pyramid, set in the
    results record.
    """

    scenario = Scenario.objects.get(pk=scenario_id)

    maxwaterdepth_geotransform = (
        calculate_export_maps.maxwaterdepth_geotransform(scenario))

    logger.debug("select results relative to scenario %s" % scenario_id)

    # The Generation for some results creates new results. In
    # particular, creating animations for max water depth generates
    # results for arrival time maps. So first we generate the results
    # that generate others, then the rest.

    all_results = (
        scenario.result_set.filter(
            resulttype__program__in=source_programs,
            resulttype__color_mapping_name__isnull=False)
        .exclude(resulttype__color_mapping_name=""))

    generate_for_result_queryset(
        scenario, all_results.filter(
            resulttype__use_to_compute_arrival_times=True),
        tmp_dir, maxwaterdepth_geotransform)

    generate_for_result_queryset(
        scenario, all_results.filter(
            resulttype__use_to_compute_arrival_times=False),
        tmp_dir, maxwaterdepth_geotransform)

    return True