Exemple #1
0
    def execute(self):
        ncfiles = self.getInputValues(identifier='resource')
        var = self.variableIn.getValue()

        self.status.set('plotting variable %s' % var, 10)

        plotout_spagetti_file = vs.spaghetti(ncfiles,
                                             variable=var,
                                             title='Fieldmean of %s ' % (var),
                                             dir_out=None)

        self.status.set(
            'Spagetti plot for %s %s files done' % (len(ncfiles), var), 50)

        plotout_uncertainty_file = vs.uncertainty(
            ncfiles,
            variable=var,
            title='Ensemble uncertainty for %s ' % (var),
            dir_out=None)

        self.status.set(
            'Uncertainty plot for %s %s files done' % (len(ncfiles), var), 90)

        self.plotout_spagetti.setValue(plotout_spagetti_file)
        self.plotout_uncertainty.setValue(plotout_uncertainty_file)

        self.status.set('visualisation done', 100)
    def execute(self):
        from flyingpigeon.utils import archive, archiveextract
        from tempfile import mkstemp

        init_process_logger('log.txt')
        self.output_log.setValue('log.txt')

        ncs = archiveextract(self.getInputValues(identifier='resource'))
        # mosaic = self.mosaic.getValue()
        regions = self.region.getValue()

        self.status.set('Arguments set for subset process', 0)
        logger.debug('starting: regions=%s, num_files=%s' % (len(regions), len(ncs)))

        try:
            from flyingpigeon.visualisation import plot_polygons
            png_country = plot_polygons(regions)
        except:
            logger.exception('failed to plot the polygon to world map')
            o1, factsheet_plot = mkstemp(dir='.', suffix='.png')

        # clip the demanded polygons
        from flyingpigeon.subset import clipping
        subsets = clipping(resource=ncs, variable=None,
                           dimension_map=None,
                           calc=None,
                           output_format='nc',
                           calc_grouping=None,
                           time_range=None,
                           time_region=None,
                           historical_concatination=True,
                           prefix=None,
                           spatial_wrapping='wrap',
                           polygons=regions,
                           mosaic=True
                           )
        try:
            from flyingpigeon.visualisation import uncertainty
            png_uncertainty = uncertainty(subsets)
        except:
            logger.exception('failed to generate the uncertainty plot')
            _, png_uncertainty = mkstemp(dir='.', suffix='.png')

        try:
            from flyingpigeon.visualisation import spaghetti
            png_spaghetti = spaghetti(subsets)
        except:
            logger.exception('failed to generate the spaghetti plot')
            _, png_spaghetti = mkstemp(dir='.', suffix='.png')

        from flyingpigeon.visualisation import factsheetbrewer
        factsheet = factsheetbrewer(png_country=png_country,
                                    png_uncertainty=png_uncertainty,
                                    png_spaghetti=png_spaghetti)

        self.output_factsheet.setValue(factsheet)
        self.status.set('done', 100)
Exemple #3
0
    def _handler(self, request, response):
        init_process_logger('log.txt')
        response.outputs['output_log'].file = 'log.txt'

        ncfiles = archiveextract(
            resource=rename_complexinputs(request.inputs['resource']))

        if 'variable' in request.inputs:
            var = request.inputs['variable'][0].data
        else:
            var = get_variable(ncfiles[0])
            #  var = ncfiles[0].split("_")[0]

        response.update_status('plotting variable {}'.format(var), 10)

        try:
            plotout_spagetti_file = vs.spaghetti(
                ncfiles,
                variable=var,
                title='Field mean of {}'.format(var),
            )
            LOGGER.info("spagetti plot done")
            response.update_status(
                'Spagetti plot for %s %s files done' % (len(ncfiles), var), 50)
            response.outputs['plotout_spagetti'].file = plotout_spagetti_file
        except Exception as e:
            raise Exception("spagetti plot failed : {}".format(e))

        try:
            plotout_uncertainty_file = vs.uncertainty(
                ncfiles,
                variable=var,
                title='Ensemble uncertainty for {}'.format(var),
            )

            response.update_status(
                'Uncertainty plot for {} {} files done'.format(
                    len(ncfiles), var), 90)
            response.outputs[
                'plotout_uncertainty'].file = plotout_uncertainty_file
            LOGGER.info("uncertainty plot done")
        except Exception as err:
            raise Exception("uncertainty plot failed {}".format(err.message))

        response.update_status('visualisation done', 100)
        return response
    def execute(self):
        ncfiles = self.getInputValues(identifier='resource')
        var = self.variableIn.getValue()

        self.status.set('plotting variable %s' % var, 10)

        plotout_spagetti_file = vs.spaghetti(ncfiles , variable=var, title=var, dir_out=None)
        
        self.status.set('Spagetti plot for %s %s files done' % (len(ncfiles), var), 50)
        
        plotout_uncertainty_file = vs.uncertainty(ncfiles , variable=var, title=var, dir_out=None)

        self.status.set('Uncertainty plot for %s %s files done' % (len(ncfiles), var), 90)
        
        self.plotout_spagetti.setValue( plotout_spagetti_file )
        self.plotout_uncertainty.setValue( plotout_uncertainty_file )
        
        self.status.set('visualisation done', 100)
Exemple #5
0
    def _handler(self, request, response):
        init_process_logger('log.txt')
        response.outputs['output_log'].file = 'log.txt'

        ncfiles = archiveextract(
            resource=rename_complexinputs(request.inputs['resource']))
        var = request.inputs['variableIn']

        if var is None:
            from flyingpigeon.utils import get_variable
            var = get_variable(ncfiles[0])

        response.update_status('plotting variable %s' % var, 10)

        try:
            plotout_spagetti_file = vs.spaghetti(ncfiles,
                                                 variable=var,
                                                 title='Fieldmean of %s ' %
                                                 (var),
                                                 dir_out=None)
            LOGGER.info("spagetti plot done")
            response.update_status(
                'Spagetti plot for %s %s files done' % (len(ncfiles), var), 50)
        except:
            LOGGER.exception("spagetti plot failed")

        try:
            plotout_uncertainty_file = vs.uncertainty(
                ncfiles,
                variable=var,
                title='Ensemble uncertainty for %s ' % (var),
                dir_out=None)

            response.update_status(
                'Uncertainty plot for %s %s files done' % (len(ncfiles), var),
                90)
            LOGGER.info("uncertainty plot done")
        except:
            LOGGER.exception("uncertainty plot failed")

        response.outputs['plotout_spagetti'].file = plotout_spagetti_file
        response.outputs['plotout_uncertainty'].file = plotout_uncertainty_file
        response.update_status('visualisation done', 100)
        return response
    def execute(self):

        init_process_logger('log.txt')
        self.output_log.setValue('log.txt')
        from flyingpigeon.utils import archiveextract

        ncfiles = archiveextract(self.getInputValues(identifier='resource'))
        var = self.variableIn.getValue()

        if var is None:
            from flyingpigeon.utils import get_variable
            var = get_variable(ncfiles[0])

        self.status.set('plotting variable %s' % var, 10)

        try:
            plotout_spagetti_file = vs.spaghetti(
                                             ncfiles,
                                             variable=var,
                                             title='Fieldmean of %s ' % (var),
                                             dir_out=None
                                             )
            logger.info("spagetti plot done")
            self.status.set('Spagetti plot for %s %s files done' % (len(ncfiles), var), 50)
        except:
            logger.exception("spagetti plot failed")

        try:
            plotout_uncertainty_file = vs.uncertainty(
                                                  ncfiles,
                                                  variable=var,
                                                  title='Ensemble uncertainty for %s ' % (var),
                                                  dir_out=None
                                                  )

            self.status.set('Uncertainty plot for %s %s files done' % (len(ncfiles), var), 90)
            logger.info("uncertainty plot done")
        except:
            logger.exception("uncertainty plot failed")

        self.plotout_spagetti.setValue(plotout_spagetti_file)
        self.plotout_uncertainty.setValue(plotout_uncertainty_file)
        self.status.set('visualisation done', 100)
    def _handler(self, request, response):

        init_process_logger('log.txt')
        response.outputs['output_log'].file = 'log.txt'

        ncs = archiveextract(
            resource=rename_complexinputs(request.inputs['resource']))

        var = get_variable(ncs[0])
        LOGGER.info('variable to be plotted: {}'.format(var))

        # mosaic = self.mosaic.getValue()
        if 'region' in request.inputs:
            regions = [inp.data for inp in request.inputs['region']]
            try:
                png_region = vs.plot_polygons(regions)
            except Exception as ex:
                msg = 'failed to plot the polygon to world map: {}'.format(
                    str(ex))
                LOGGER.exception(msg)
                raise Exception(msg)
                o1, png_region = mkstemp(dir='.', suffix='.png')

            # clip the demanded polygons
            subsets = clipping(
                resource=ncs,
                variable=var,
                polygons=regions,
                mosaic=True,
                spatial_wrapping='wrap',
            )
        else:
            subsets = ncs
            png_region = vs.plot_extend(ncs[0])

        response.update_status('Arguments set for subset process', 0)

        try:
            tar_subsets = archive(subsets)
        except Exception as ex:
            msg = 'failed to archive subsets: {}'.format(ex)
            LOGGER.exception(msg)
            raise Exception(msg)
            _, tar_subsets = mkstemp(dir='.', suffix='.tar')

        try:
            png_uncertainty = vs.uncertainty(subsets, variable=var)
        except Exception as ex:
            msg = 'failed to generate the uncertainty plot: {}'.format(ex)
            LOGGER.exception(msg)
            raise Exception(msg)
            _, png_uncertainty = mkstemp(dir='.', suffix='.png')

        try:
            png_spaghetti = vs.spaghetti(
                subsets,
                variable=var,
            )

        except Exception as ex:
            msg = 'failed to generate the spaghetti plot: {}'.format(str(ex))
            LOGGER.exception(msg)
            raise Exception(msg)
            _, png_spaghetti = mkstemp(dir='.', suffix='.png')

        try:
            from flyingpigeon import robustness as ro
            signal, low_agreement_mask, high_agreement_mask, text_src = ro.signal_noise_ratio(
                resource=subsets,
                # start=None, end=None,
                # timeslice=None,
                # variable=var
            )
            # if title is None:
            title = 'signal robustness of %s ' % (
                var)  # , end1, end2, start1, start2
            png_robustness = vs.map_robustness(
                signal,
                high_agreement_mask,
                low_agreement_mask,
                # cmap=cmap,
                #    title=title
            )
            LOGGER.info('robustness graphic generated')
        except Exception as ex:
            msg = 'failed to generate the robustness plot: {}'.format(ex)
            LOGGER.exception(msg)
            raise Exception(msg)
            _, png_robustness = mkstemp(dir='.', suffix='.png')

        factsheet = vs.factsheetbrewer(png_region=png_region,
                                       png_uncertainty=png_uncertainty,
                                       png_spaghetti=png_spaghetti,
                                       png_robustness=png_robustness)

        response.outputs['output_nc'].file = tar_subsets
        response.outputs['output_factsheet'].file = factsheet
        response.update_status("done", 100)
        return response
    def _handler(self, request, response):
        from flyingpigeon.utils import archive, archiveextract
        from tempfile import mkstemp

        init_process_logger('log.txt')
        response.outputs['output_log'].file = 'log.txt'

        ncs = archiveextract(
            resource=rename_complexinputs(request.inputs['resource']))

        # mosaic = self.mosaic.getValue()
        regions = [inp.data for inp in request.inputs['region']]

        response.update_status('Arguments set for subset process', 0)
        LOGGER.debug('starting: regions=%s, num_files=%s' % (len(regions), len(ncs)))

        try:
            from flyingpigeon.visualisation import plot_polygons
            png_country = plot_polygons(regions)
        except:
            LOGGER.exception('failed to plot the polygon to world map')
            o1, png_country = mkstemp(dir='.', suffix='.png')

        # clip the demanded polygons
        from flyingpigeon.subset import clipping
        subsets = clipping(resource=ncs, variable=None,
                           dimension_map=None,
                           calc=None,
                           output_format='nc',
                           calc_grouping=None,
                           time_range=None,
                           time_region=None,
                           historical_concatination=True,
                           prefix=None,
                           spatial_wrapping='wrap',
                           polygons=regions,
                           mosaic=True
                           )

        try:
            tar_subsets = archive(subsets)
        except:
            LOGGER.exception('failed to archive subsets')
            _, tar_subsets = mkstemp(dir='.', suffix='.tar')

        try:
            from flyingpigeon.visualisation import uncertainty
            png_uncertainty = uncertainty(subsets)
        except:
            LOGGER.exception('failed to generate the uncertainty plot')
            _, png_uncertainty = mkstemp(dir='.', suffix='.png')

        try:
            from flyingpigeon.visualisation import spaghetti
            png_spaghetti = spaghetti(subsets)
        except:
            LOGGER.exception('failed to generate the spaghetti plot')
            _, png_spaghetti = mkstemp(dir='.', suffix='.png')

        try:
            from flyingpigeon import robustness as erob
            from flyingpigeon.utils import get_variable
            variable = get_variable(ncs[0])

            signal, low_agreement_mask, high_agreement_mask, text_src = erob.method_A(resource=subsets,
                                                                                      # start=None, end=None,
                                                                                      # timeslice=None,
                                                                                      variable=variable
                                                                                      )
            LOGGER.info('variable to be plotted: %s' % variable)
            from flyingpigeon.visualisation import map_robustness
            # if title is None:
            title = 'signal robustness of %s ' % (variable)  # , end1, end2, start1, start2
            png_robustness = map_robustness(signal,
                                            high_agreement_mask,
                                            low_agreement_mask,
                                            # cmap=cmap,
                                            title=title)
            LOGGER.info('graphic generated')

        except:
            LOGGER.exception('failed to generate the robustness plot')
            _, png_robustness = mkstemp(dir='.', suffix='.png')

        from flyingpigeon.visualisation import factsheetbrewer
        factsheet = factsheetbrewer(png_country=png_country,
                                    png_uncertainty=png_uncertainty,
                                    png_spaghetti=png_spaghetti,
                                    png_robustness=png_robustness)

        response.outputs['output_nc'].file = tar_subsets
        response.outputs['output_factsheet'].file = factsheet
        response.update_status("done", 100)
        return response