def add_python_modules_to_path_if_needed(): """If modules cannot be imported, add them to the path.""" # Importing here because it is for test and than for a fallback. # pylint: disable=import-outside-toplevel try: # If it imports, no action is needed. # pylint: disable=unused-import import grasssession # noqa: F401 except ImportError: # Not on path, try to add them to the path now. # (Module fails if the path can't be set up.) from grass.script.utils import set_path set_path("g.remote")
def set_path(modulename, dirname=None, path='.'): """Set sys.path looking in the the local directory GRASS directories. :param modulename: string with the name of the GRASS module :param dirname: string with the directory name containing the python libraries, default None :param path: string with the path to reach the dirname locally. .. deprecated:: 7.1 Use :func:`grass.script.utils.set_path` instead. """ from grass.script.utils import set_path return set_path(modulename=modulename, dirname=dirname, path=path)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Created on Wed Nov 20 14:44:32 2013 @author: anna """ import os import wx import wx.lib.newevent import wx.lib.filebrowsebutton as filebrowse from shutil import copyfile from grass.script.utils import set_path, get_lib_path set_path(modulename='g.gui.tangible') from grass.script.setup import set_gui_path set_gui_path() from gui_core.gselect import Select from core.settings import UserSettings import grass.script as gscript from grass.pydispatch.signal import Signal from tangible_utils import run_analyses updateGUIEvt, EVT_UPDATE_GUI = wx.lib.newevent.NewCommandEvent()
from __future__ import print_function import atexit # import system libraries import os import sys from grass.pygrass.messages import get_msgr from grass.script import core as gcore from grass.script.utils import set_path try: # set python path to the shared r.green libraries set_path("r.green", "libhydro", "..") set_path("r.green", "libgreen", os.path.join("..", "..")) from libgreen.utils import cleanup from libhydro.basin import dtm_corr from libhydro.plant import power2energy from libhydro import basin from libgreen.utils import check_overlay_rr # from libgreen.utils import check_overlay_rv from libgreen.utils import raster2numpy from libgreen.utils import remove_pixel_from_raster except ImportError: try: set_path("r.green", "libhydro", os.path.join("..", "etc", "r.green")) set_path("r.green", "libgreen", os.path.join("..", "etc", "r.green")) from libgreen.utils import cleanup
import datetime import os import subprocess import sys import time from pprint import pprint as pp if "GISBASE" not in os.environ: sys.exit("Exiting: You must be in GRASS GIS to run this program.") import grass.script as grass from grass.script.utils import set_path try: # set python path to the shared libraries set_path('r.estimap.recreation', 'estimap_recreation', '..') # constants from estimap_recreation.colors import * from estimap_recreation.constants import * from estimap_recreation.labels import * # main from estimap_recreation.main import main as main_estimap except ImportError: try: set_path('r.estimap.recreation', 'estimap_recreation', os.path.join('..', 'etc', 'r.estimap.recreation')) # constants from estimap_recreation.colors import * from estimap_recreation.constants import * from estimap_recreation.labels import * # main
from grass.script.core import overwrite, parser, run_command, warning from grass.script.utils import set_path #from grass.script import mapcalc version = 70 # 71 try: import numexpr as ne except ImportError: ne = None warning('You should install numexpr to use this module: ' 'pip install numexpr') try: # set python path to the shared r.green libraries set_path('r.green', 'libhydro', '..') set_path('r.green', 'libgreen', os.path.join('..', '..')) from libgreen.utils import cleanup except ImportError: try: set_path('r.green', 'libhydro', os.path.join('..', 'etc', 'r.green')) set_path('r.green', 'libgreen', os.path.join('..', 'etc', 'r.green')) from libgreen.utils import cleanup except ImportError: warning('libgreen and libhydro not in the python path!') def rname(base): return 'tmprgreen_%i_%s' % (os.getpid(), base)
PURPOSE: Test of r.learn.ml for dropping RasterRow objects from an internal RasterStack object COPYRIGHT: (C) 2020 by Steven Pawley and the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details. """ import unittest from grass.script.utils import set_path set_path("r.learn.ml2", "rlearnlib") from rlearnlib.raster import RasterStack class MyTestCase(unittest.TestCase): @classmethod def setUpClass(cls) -> None: """Setup that is run once for the entire test module""" cls.predictors = [ "lsat7_2002_10@PERMANENT", "lsat7_2002_20@PERMANENT", "lsat7_2002_30@PERMANENT", "lsat7_2002_40@PERMANENT", "lsat7_2002_50@PERMANENT", "lsat7_2002_70@PERMANENT", ]
#% description: INSPIRE profile is not filled properly (unknown values are filled with '$NULL') #% options: basic, inspire #% answer: basic #%end #%option G_OPT_F_OUTPUT #% required: no #%end import os import sys from grass.script import parser from grass.script.utils import set_path set_path(modulename="wx.metadata", dirname="mdlib") def main(): # Load metadata library from mdlib.mdgrass import GrassMD if not options["output"]: destination = None name = None else: destination, name = os.path.split(options["output"]) md = GrassMD(options["map"], "raster") if options["profile"] == "inspire": md.createGrassInspireISO()
# -*- coding: utf-8 -*- """ Created on Wed Nov 20 14:44:32 2013 @author: anna """ import os import wx import wx.lib.filebrowsebutton as filebrowse from shutil import copyfile from subprocess import PIPE import signal from grass.script.utils import set_path, get_lib_path set_path(modulename='g.gui.tangible') from grass.script.setup import set_gui_path set_gui_path() from gui_core.gselect import Select from core.settings import UserSettings import grass.script as gscript from grass.pydispatch.signal import Signal from tangible_utils import run_analyses, updateGUIEvt, EVT_UPDATE_GUI from tangible_utils import EVT_ADD_LAYERS, EVT_REMOVE_LAYERS, EVT_CHECK_LAYERS from drawing import DrawingPanel from export import ExportPanel from color_interaction import ColorInteractionPanel
#% description: INSPIRE profile is not filled properly (unknown values are filled with '$NULL') #% options: basic, inspire #% answer: basic #%end #%option G_OPT_F_OUTPUT #% required: no #%end import os import sys from grass.script import parser from grass.script.utils import set_path set_path(modulename='wx.metadata', dirname='mdlib') def main(): # Load metadata library from mdlib.mdgrass import GrassMD if not options['output']: destination = None name = None else: destination, name = os.path.split(options['output']) md = GrassMD(options['map'], 'raster') if options['profile'] == 'inspire': md.createGrassInspireISO()
#% key_desc: name #% description: Name of raster map with the financial potential of bioenergy for coppices[Mwh/year] #% required: no #% guisection: Output maps #%end import atexit import os from grass.pygrass.modules.shortcuts import raster as r from grass.script.core import parser, run_command, warning from grass.script.utils import set_path try: # set python path to the shared r.green libraries set_path('r.green', 'libforest', '..') set_path('r.green', 'libgreen', os.path.join('..', '..')) from libforest.harvesting import combination from libforest.harvesting import slope_computation, yield_pix_process from libgreen.utils import cleanup from libgreen.utils import sel_columns #TODO: check the required column # from libgreen.checkparameter import check_required_columns, # exception2error from libforest.financial import revenues, productivity from libforest.financial import costs, net_revenues except ImportError: warning('libgreen and libforest not in the python path!') def main(opts, flgs):
# % key_desc: name # % description: Name of raster map with the financial potential of bioenergy for coppices[Mwh/year] # % required: no # % guisection: Output maps # %end import atexit import os from grass.pygrass.modules.shortcuts import raster as r from grass.script.core import parser, run_command, warning from grass.script.utils import set_path try: # set python path to the shared r.green libraries set_path("r.green", "libforest", "..") set_path("r.green", "libgreen", os.path.join("..", "..")) from libforest.harvesting import combination from libforest.harvesting import slope_computation, yield_pix_process from libgreen.utils import cleanup from libgreen.utils import sel_columns # TODO: check the required column # from libgreen.checkparameter import check_required_columns, # exception2error from libforest.financial import revenues, productivity from libforest.financial import costs, net_revenues except ImportError: warning("libgreen and libforest not in the python path!")
#%end """ Created on Fri Oct 4 17:17:49 2013 @author: Vaclav Petras <wenzeslaus gmail.com> """ import os import sys import grass.script as gs from grass.script.utils import set_path set_path(modulename='r.out.png.proj', dirname='routleaflet', path=os.path.join(os.path.dirname(__file__), '..')) from routleaflet.pngproj import export_png_in_projection def main(): options, flags = gs.parser() # main options map_name = options['input'] output_file = options['output'] # TODO: other options of g.proj are not supported epsg_code = int(options['epsg']) # r.out.png options compression = int(options['compression'])