def test_polygons(): from flyingpigeon.visualisation import plot_polygons from os.path import exists from os import remove png = plot_polygons(['DEU', 'ESP']) assert exists(png) is True remove(png)
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)
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