def CreateNewFile(self): get_lib_path('g.gui.tangible') dlg = wx.FileDialog(self, message="Create a new file with analyses", wildcard="Python source (*.py)|*.py", style=wx.SAVE | wx.FD_OVERWRITE_PROMPT) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() orig = os.path.join(get_lib_path('g.gui.tangible'), 'current_analyses.py') if not os.path.exists(orig): self.giface.WriteError("File with analyses not found: {}".format(orig)) else: copyfile(orig, path) self.selectAnalyses.SetValue(path) self.settings['analyses']['file'] = path dlg.Destroy()
def get_lib_path(modname, libname=None): """Return the path of the libname contained in the module. .. deprecated:: 7.1 Use :func:`grass.script.utils.get_lib_path` instead. """ from grass.script.utils import get_lib_path return get_lib_path(modname=modname, libname=libname)
#% type: integer #% label: Number of pixels to pass to the prediction method #% description: Number of pixels to pass to the prediction method. GRASS GIS reads raster by-row so chunksize is rounded down based on the number of columns #% answer: 100000 #% guisection: Optional #%end import sys import grass.script as gs import numpy as np import math from grass.script.utils import get_lib_path from grass.pygrass.gis.region import Region from grass.pygrass.modules.shortcuts import raster as r path = get_lib_path(modname="r.learn.ml2") if path is None: gs.fatal("Not able to find the r.learn.ml2 library directory") sys.path.append(path) from raster import RasterStack def string_to_rules(string): """Converts a string to a file for input as a GRASS Rules File""" tmp = gs.tempfile() f = open("%s" % (tmp), "wt") f.write(string) f.close() return tmp
#% label: Backbone architecture #% required: no #% multiple: no #% answer: resnet101 #% options: resnet50,resnet101 #% guisection: Training parameters #%end import grass.script as gscript from grass.script.utils import get_lib_path import os import sys from random import shuffle path = get_lib_path(modname="maskrcnn", libname="model") if path is None: grass.script.fatal("Not able to find the maskrcnn library directory.") sys.path.append(path) def main(options, flags): from config import ModelConfig import utils import model as modellib try: dataset = options["training_dataset"] initialWeights = options["model"] classes = options["classes"]
import os from shutil import copyfile import sys from io import BytesIO import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Polygon import grass.script as gscript from grass.script.utils import get_lib_path import grass.script.array as garray from osgeo import gdal, osr path = get_lib_path(modname='maskrcnn', libname='model') if path is None: gscript.fatal('Not able to find the maskrcnn library directory.') sys.path.append(path) def main(options, flags): import model as modellib from config import ModelConfig try: imagesDir = options['images_directory'] modelPath = options['model'] classes = options['classes'].split(',') if options['band1']:
def createPDF(self, save=True): self.story = self._parseMDOWS() self.doc = Pdf('Metadata file', 'GRASS GIS') self.doc.set_theme(MyTheme) lib_name = 'config' logo_path = get_lib_path("wx.metadata", lib_name) logo_path = os.path.join(logo_path, lib_name, 'logo_variant_bg.png') self.doc.add_image(logo_path, 57, 73, LEFT) if self.map is None: self.doc.add_header(self.filename, T1) else: self.doc.add_header(self.map, T1) self.doc.add_header(self.filename, T2) if self.type == 'vector': name = 'vector map' self.doc.add_header(name, T2) else: name = 'raster map' self.doc.add_header(name, T2) self.doc.add_header("%s metadata profile" % self.profile, T3) self.doc.add_spacer(2) if map is not None: mapPic = self.getMapPic() self.doc.add_image(mapPic, 200, 200, CENTER) self.textFactory(title="Keywords", name='Keywords', tag='identification', multiple=-1) self.textFactory(title="Abstract", name='Abstract', tag='identification') # #################### metadata ################################# self.doc.add_spacer(25) self.doc.add_header("Metadata on metadata", H1) head = ['Organization name', 'E-mail', 'Role'] # this is the header row self.tableFactory("Metadata point of contact", head, 'contact') self.textFactory(title="Metadata date", name='Datestamp', tag='datestamp') self.textFactory(title="Metadata language", name='Language', tag='languagecode') # #################### identification ################################# self.doc.add(PageBreak()) self.doc.add_header("Identification", H1) self.textFactory(title="Restource title", name='Title', tag='identification') self.textFactory(title="Identifier", name='Identifier', tag='identifier') # self.textFactory(title="Resource locator", name='Identifier',tag='identifier')#TODO linkage is missing self.tableFactory("Resource language", ['Language'], 'identification') # head = ['Organization name', 'E-mail','Role'] #.tableFactory("identifier",head,'contact') ##################### Keywords ################################## TODO ##################### Geographic ################################## self.doc.add_spacer(25) self.doc.add_header('Geographic Location', H1) maxy = float(self.findItem(self.story['identification'], 'maxy', 0)) maxx = float(self.findItem(self.story['identification'], 'maxx', 0)) miny = float(self.findItem(self.story['identification'], 'miny', 0)) minx = float(self.findItem(self.story['identification'], 'minx', 0)) head = [[ 'North Bound Latitude', 'East Bound Longitude', 'South Bound Latitude', 'West Bound Longitude' ]] head.append([maxx, maxy, minx, miny]) self.doc.add_table(head, self.TABLE_WIDTH) self.doc.add_spacer(25) mapPath = MapBBFactory([[maxx, minx], [maxy, miny]], ) ##################### Add google picture(extend) ################################## try: gmap = Image(mapPath.link1, 200, 200) gmap1 = Image(mapPath.link2, 200, 200) self.doc.add(Table([[gmap1, gmap]])) self.doc.add(PageBreak()) except: GWarning( "Cannot download metadata picture of extend provided by Google API. Please check internet connection." ) ##################### Temporal ################################## self.doc.add_spacer(25) self.doc.add_header('Temporal reference', H1) self.textFactory(title="Temporal extend start", name='Temporal extend start', tag='identification') self.textFactory(title="Temporal extend end", name='Temporal extend end', tag='identification') ##################### Quality ################################## self.doc.add_spacer(25) self.doc.add_header('Quality a validity', H1) self.textFactory(title="Lineage", name='Lineage', tag='dataquality') #self.textFactory(title="Temporal extend start", name='Temporal extend start',tag='identification') # TODO md.identification.denominators ######################Conformity ######################## self.doc.add_spacer(25) self.doc.add_header('Conformity', H1) head = ['Conformance date', "Conformance date type", 'Specification'] self.tableFactory("Conformity", head, 'dataquality') ###################### Constraints ######################## self.doc.add_spacer(25) self.doc.add_header('Constraints', H1) self.tableFactory("Condition applying to use", ["Use limitation"], 'identification') self.tableFactory("Condition applying to access", ["Access constraints"], 'identification') self.tableFactory("Limitation on public access", ["Other constraintrs"], 'identification') ###################### Responsible party ######################## self.doc.add_spacer(25) self.doc.add_header('Responsible party', H1) header = ["Organization name", "E-mail", "Role"] self.tableFactory( "Organisations responsible for the establishment, management, maintenance and distribution of spatial data sets and services", header, 'identification') text = self.doc.render() # http://www.reportlab.com/docs/reportlab-userguide.pdf if save and self.pdf_file is not None: path = self.savePDF(text) return path return text
from grass.script.utils import get_lib_path from grass.pygrass.raster import RasterRow from copy import deepcopy from grass.pygrass.gis.region import Region from grass.pygrass.modules.grid import split import multiprocessing as mltp from itertools import chain import time import numpy as np import sys path = get_lib_path('r.learn.ml') sys.path.append(path) from raster import RasterStack reg = Region() stack = RasterStack(rasters=["lsat5_1987_10", "lsat5_1987_20", "lsat5_1987_30", "lsat5_1987_40", "lsat5_1987_50", "lsat5_1987_70"]) X, y, crd = stack.extract_points(vect_name='landclass96_roi', fields=['value', 'cat']) df = stack.extract_points(vect_name='landclass96_roi', fields='value', as_df=True) df = stack.extract_pixels(response='landclass96_roi', as_df=True) X, y, crd = stack.extract_pixels(response='landclass96_roi') stack.head() stack.tail() df = stack.to_pandas() df = stack.to_pandas(res=500) df = df.melt(id_vars=['x', 'y'])
#% exclusive: load_training,save_training #%end from __future__ import absolute_import, print_function import atexit import os import sys import warnings import numpy as np from copy import deepcopy import grass.script as gs from grass.script.utils import get_lib_path path = get_lib_path(modname='r.learn.ml') if path is None: gs.fatal('Not able to find the r.learn library directory') sys.path.append(path) from model_selection import cross_val_scores from utils import (model_classifiers, load_training_data, save_training_data, option_to_list, scoring_metrics) from raster import RasterStack tmp_rast = [] def cleanup(): for rast in tmp_rast: