Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: t.sentinel.mask: Add postgresql option #14

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions i.sentinel.mask.worker/i.sentinel.mask.worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@
#% description: Name of new mapset to run i.sentinel.mask
#% guisection: Required
#%end
#%option
#% key: pg_database
#% type: string
#% required: no
#% multiple: no
#% description: Name of optional PostgreSQL database to use as vector attribute connection
#%end
#%option
#% key: pg_user
#% type: string
#% required: no
#% multiple: no
#% description: Name of the PostgreSQL user
#% answer: postgres
#%end
#%option G_OPT_F_INPUT
#% key: input_file
#% description: Name of the .txt file containing the list of input bands
Expand Down Expand Up @@ -175,6 +190,7 @@
#% excludes: -c,shadow_mask,shadow_raster
#% required: input_file,blue,green,red,nir,nir8a,swir11,swir12,mtd_file
#% excludes: input_file,blue,green,red,nir,nir8a,swir11,swir12,mtd_file
#% collective: pg_database,pg_user
#%end

import sys
Expand Down Expand Up @@ -213,11 +229,18 @@ def main():
shutil.copyfile(gisrc, newgisrc)
os.environ['GISRC'] = newgisrc

### change mapset
# change mapset
grass.message("GISRC: <%s>" % os.environ['GISRC'])
grass.run_command('g.mapset', flags='c', mapset=new_mapset)

### import data
# define new database connection
if options["pg_database"] is not None:
grass.run_command("db.connect", driver="pg",
database=options["pg_database"], quiet=True)
grass.run_command("db.login", database=options["pg_database"],
user=options["pg_user"], quiet=True, overwrite=True)

# import data
grass.message(_("Running i.sentinel.mask ..."))
kwargs = dict()
for opt,val in options.items():
Expand All @@ -229,12 +252,12 @@ def main():
else:
kwargs[opt] = val
flagstr = ''
for flag,val in flags.items():
for flag, val in flags.items():
if val:
flagstr += flag
grass.run_command('g.region', raster=kwargs['nir'])
grass.run_command('g.region', raster=kwargs['nir'], zoom=kwargs["nir"])
grass.run_command('i.sentinel.mask', quiet=True,
flags=flagstr, **kwargs)
flags=flagstr, **kwargs)

grass.utils.try_remove(newgisrc)
return 0
Expand Down
25 changes: 23 additions & 2 deletions t.sentinel.mask/t.sentinel.mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,27 @@
#% answer: 1
#%end

#%option
#% key: pg_database
#% type: string
#% required: no
#% multiple: no
#% description: Name of optional PostgreSQL database to use as vector attribute connection
#%end

#%option
#% key: pg_user
#% type: string
#% required: no
#% multiple: no
#% description: Name of the PostgreSQL user
#% answer: postgres
#%end

#%rules
#% requires_all: output_shadows,metadata
#% requires_all: threshold,metadata
#% collective: pg_database,pg_user
#%end

import atexit
Expand Down Expand Up @@ -247,9 +265,12 @@ def main():
kwargs['shadow_raster'] = s2_scene['shadows']
kwargs['metadata'] = s2_scene['metadata']
kwargs['shadow_threshold'] = 1000
flags='s'
flags = 's'
else:
flags='sc'
flags = 'sc'
if options["pg_database"]:
kwargs["pg_database"] = options["pg_database"]
kwargs["pg_user"] = options["pg_user"]
newmapset = s2_scene['clouds']
# grass.run_command(
i_sentinel_mask = Module(
Expand Down