def show_info(self): """Show usage text to the user.""" header = html_header() footer = html_footer() string = header heading = m.Heading(self.tr('Shakemap Grid Importer'), **INFO_STYLE) body = self.tr( 'This tool will convert an earthquake \'shakemap\' that is in ' 'grid xml format to a GeoTIFF file. The imported file can be used ' 'in InaSAFE as an input for impact functions that require and ' 'earthquake layer. To use this tool effectively:') tips = m.BulletedList() tips.add(self.tr('Select a grid.xml for the input layer.')) tips.add(self.tr('Choose where to write the output layer to.')) tips.add( self. tr('Choose the interpolation algorithm that should be used when ' 'converting the xml grid to a raster. If unsure keep the default.' )) tips.add( self. tr('If you want to obtain shake data you can get it for free from ' 'the USGS shakemap site: ' 'http://earthquake.usgs.gov/earthquakes/shakemap/list.php?y=2013' )) message = m.Message() message.add(heading) message.add(body) message.add(tips) string += message.to_html() string += footer self.webView.setHtml(string)
def show_info(self): """Show usage info to the user.""" # Read the header and footer html snippets header = html_header() footer = html_footer() string = header heading = m.Heading(self.tr('Impact Layer Merge Tool'), **INFO_STYLE) body = self.tr( 'This tool will merge the outputs from two impact maps for the ' 'same area. The maps must be created using the same aggregation ' 'areas and same hazard. To use:') tips = m.BulletedList() tips.add( self.tr( 'Run an impact assessment for an area using aggregation. e.g.' 'Flood Impact on Buildings aggregated by municipal boundaries.' )) tips.add( self. tr('Run a second impact assessment for the same area using the same ' 'aggregation. e.g. Flood Impact on People aggregated by ' 'municipal boundaries.')) tips.add( self. tr('Open this tool and select each impact layer from the pick lists ' 'provided below.')) tips.add( self.tr( 'Select the aggregation layer that was used to generate the ' 'first and second impact layer.')) tips.add(self.tr('Select an output directory.')) tips.add( self. tr('Check "Use customized report template" checkbox and select the ' 'report template file if you want to use your own template. Note ' 'that all the map composer components that are needed must be ' 'fulfilled.')) tips.add( self.tr('Click OK to generate the per aggregation area combined ' 'summaries.')) message = m.Message() message.add(heading) message.add(body) message.add(tips) string += message.to_html() string += footer self.web_view.setHtml(string)
def show_info(self): """Show usage info to the user.""" # Read the header and footer html snippets header = html_header() footer = html_footer() string = header heading = m.Heading(self.tr('OSM Downloader'), **INFO_STYLE) body = self.tr( 'This tool will fetch building (\'structure\') data from the ' 'OpenStreetMap project for you. The downloaded data will have ' 'InaSAFE keywords defined and a default QGIS style applied. To ' 'use this tool effectively:') tips = m.BulletedList() tips.add( self. tr('Use QGIS to zoom in to the area for which you want building data ' 'to be retrieved.')) tips.add( self. tr('Check the output directory is correct. Note that the saved ' 'dataset will be called buildings.shp (and its associated files).' )) tips.add( self. tr('If a dataset already exists in the output directory it will be ' 'overwritten.')) tips.add( self. tr('This tool requires a working internet connection and fetching ' 'buildings will consume your bandwidth.')) tips.add( m.Link( 'http://www.openstreetmap.org/copyright', text=self.tr( 'Downloaded data is copyright OpenStreetMap contributors' ' (click for more info).'))) message = m.Message() message.add(heading) message.add(body) message.add(tips) string += message.to_html() string += footer self.webView.setHtml(string)
def update_warning(self): """Update warning message and enable/disable Ok button.""" if len(self.warning_text) == 0: self.button_box.button(QDialogButtonBox.Ok).setEnabled(True) return header = html_header() footer = html_footer() string = header heading = m.Heading(self.tr('Shakemap Grid Importer'), **INFO_STYLE) tips = m.BulletedList() self.button_box.button(QDialogButtonBox.Ok).setEnabled(False) message = m.Message() message.add(heading) for warning in self.warning_text: tips.add(warning) message.add(tips) string += message.to_html() string += footer self.webView.setHtml(string)
def show_info(self): """Show basic usage instructions.""" header = html_header() footer = html_footer() string = header heading = m.Heading(self.tr('Minimum Needs Calculator'), **INFO_STYLE) body = self.tr( 'This tool will calculated minimum needs for evacuated people. To ' 'use this tool effectively:') tips = m.BulletedList() tips.add( self. tr('Load a polygon layer in QGIS. Typically the layer will ' 'represent administrative districts where people have gone to an ' 'evacuation center.')) tips.add( self. tr('Ensure that the layer has an INTEGER attribute for the number of ' 'displaced people associated with each feature.')) tips.add( self. tr('Use the pick lists below to select the layer and the population ' 'field and then press \'OK\'.')) tips.add( self. tr('A new layer will be added to QGIS after the calculation is ' 'complete. The layer will contain the minimum needs per district ' '/ administrative boundary.')) message = m.Message() message.add(heading) message.add(body) message.add(tips) string += message.to_html() string += footer self.webView.setHtml(string)
def check_memory_usage(buffered_geo_extent, cell_size): """Helper to check if analysis is feasible when extents change. For simplicity, we will do all our calculations in geocrs. :param buffered_geo_extent: An extent in the for [xmin, ymin, xmax, ymax] :type buffered_geo_extent: list :param cell_size: The size of a cell (assumes in the X direction). :type cell_size: float :returns: True if it appears we have enough memory (or we can't compute it), False if it appears we do not have enough. :rtype: bool :raises: A Message containing notes about how much memory is needed for a single raster and if this is likely to result in an error. :returns: True if it is supposed that there is sufficient memory, False if it is supposed that too little memory exists. :rtype: bool """ message = m.Message() check_heading = m.Heading(tr('Checking available memory'), **PROGRESS_UPDATE_STYLE) message.add(check_heading) width = buffered_geo_extent[2] - buffered_geo_extent[0] height = buffered_geo_extent[3] - buffered_geo_extent[1] try: # noinspection PyAugmentAssignment width = width / cell_size # noinspection PyAugmentAssignment height = height / cell_size except TypeError: # Could have been a vector layer for example reason = tr( 'Computed cellsize was None. Memory check currently only works ' 'for raster input layers.') message.add(reason) send_message(message) return True # assume enough mem since we have no vector check logic bullet_list = m.BulletedList() bullet = m.Paragraph(m.ImportantText(tr('Width: ')), str(width)) bullet_list.add(bullet) bullet = m.Paragraph(m.ImportantText(tr('Height: ')), str(height)) bullet_list.add(bullet) bullet = m.Paragraph(m.ImportantText(tr('Cell Size: ')), str(cell_size)) bullet_list.add(bullet) message.add(bullet_list) # Compute mem requirement in MB (assuming numpy uses 8 bytes by per # cell) see this link: # http://stackoverflow.com/questions/11784329/ # python-memory-usage-of-numpy-arrays # Also note that the on-disk requirement of the clipped tifs is about # half this since the tifs as in single precision, # whereas numpy arrays are in double precision. requirement = ((width * height * 8) / 1024 / 1024) try: free_memory = get_free_memory() except ValueError: error_heading = m.Heading(tr('Memory check error'), **WARNING_STYLE) error_message = tr('Could not determine free memory') message.add(error_heading) message.add(error_message) send_message(message) LOGGER.exception(message) return True # still let the user try to run their analysis # We work on the assumption that if more than 10% of the available # memory is occupied by a single layer we could run out of memory # (depending on the impact function). This is because multiple # in memory copies of the layer are often made during processing. warning_limit = 10 usage_indicator = (float(requirement) / float(free_memory)) * 100 counts_message = tr('Memory requirement: about %d mb per raster layer (' '%d mb available)') % (requirement, free_memory) usage_message = tr('Memory used / available: %d/%d') % (usage_indicator, warning_limit) message.add(counts_message) message.add(usage_message) if warning_limit <= usage_indicator: warning_heading = m.Heading(tr('Potential memory issue'), **WARNING_STYLE) warning_message = tr( 'There may not be enough free memory to run this analysis. You can' ' attempt to run the analysis anyway, but note that your computer ' 'may become unresponsive during execution, and / or the analysis ' 'may fail due to insufficient memory. Proceed at your own risk.') suggestion_heading = m.Heading(tr('Suggestion'), **INFO_STYLE) suggestion = tr( 'Try zooming in to a smaller area or using a raster layer with a ' 'coarser resolution to speed up execution and reduce memory ' 'requirements. You could also try adding more RAM to your ' 'computer.') message.add(warning_heading) message.add(warning_message) message.add(suggestion_heading) message.add(suggestion) send_message(message) LOGGER.info(message.to_text()) return False send_message(message) LOGGER.info(message.to_text()) return True