<p dir="ltr">Hi Sören,</p>
<p dir="ltr">Thanks for your answer. I did something similar and it works well under Linux.<br>
Making those hacks works with Windows seems to be a bit more complex, though.</p>
<p dir="ltr">Regards,<br>
Laurent</p>
<p dir="ltr">2016-09-24 4:35 GMT-05:00 Sören Gebbert <<a href="mailto:soerengebbert@googlemail.com">soerengebbert@googlemail.com</a>>:<br>
> Hi Laurent,<br>
> i have attached a Python script that shows the handling of tgis.init() in a<br>
> subprocess in case location and mapsets change using grass72.<br>
> The following output was generated with this script, it seems to work on my<br>
> system:<br>
><br>
> soeren@knecht:~$ python test_tgis.py <br>
> New envrionment: {u'MAPSET': u'PERMANENT', u'GISDBASE':<br>
> u'/home/soeren/grassdata', u'LOCATION_NAME': u'nc_spm_08_grass7'}<br>
> TGIS init: <br>
> database: /home/soeren/grassdata <br>
> location: nc_spm_08_grass7 <br>
> mapset: PERMANENT<br>
> New envrionment: {u'MAPSET': u'user1', u'GISDBASE':<br>
> u'/home/soeren/grassdata', u'LOCATION_NAME': u'nc_spm_08_grass7'}<br>
> TGIS init: <br>
> database: /home/soeren/grassdata <br>
> location: nc_spm_08_grass7 <br>
> mapset: user1<br>
> New envrionment: {u'MAPSET': u'PERMANENT', u'GISDBASE':<br>
> u'/home/soeren/grassdata', u'LOCATION_NAME': u'nc_spm_08'}<br>
> TGIS init: <br>
> database: /home/soeren/grassdata <br>
> location: nc_spm_08 <br>
> mapset: PERMANENT<br>
> New envrionment: {u'MAPSET': u'user1', u'GISDBASE':<br>
> u'/home/soeren/grassdata', u'LOCATION_NAME': u'nc_spm_08'}<br>
> TGIS init: <br>
> database: /home/soeren/grassdata <br>
> location: nc_spm_08 <br>
> mapset: user1<br>
><br>
><br>
> Best regards<br>
> Soeren<br>
><br>
><br>
> 2016-09-24 5:32 GMT+02:00 Laurent C. <<a href="mailto:lrntct@gmail.com">lrntct@gmail.com</a>>:<br>
>><br>
>> Hi Sören,<br>
>><br>
>> I followed you suggestion and now each simulation run in its own process<br>
>> using the multiprocessing library. It works well, thanks.<br>
>> However, there was indeed something strange going on:<br>
>> The new mapset, location and accessible mapsets were set properly, as seen<br>
>> by the output of g.mapset and g.mapsets<br>
>> However, the output of ciface.available_mapsets() and therefore<br>
>> core.get_available_temporal_mapsets() were not updated after the first<br>
>> simulation, so tgis.init() were failing, not seeing the new current mapset<br>
>> in its own list of available mapsets.<br>
>><br>
>> Below was the output of the software:<br>
>><br>
>> g.mapset -p<br>
>> swashes_1d_1000m<br>
>> g.mapsets -p<br>
>> Accessible mapsets:<br>
>> swashes_1d_1000m PERMANENT<br>
>> ciface.available_mapsets()<br>
>> ['swashes_1d_1000m', 'PERMANENT']<br>
>> get_available_temporal_mapsets()<br>
>> {'swashes_1d_1000m': ('sqlite',<br>
>> '/home/laurent/grassdata/flood_test/swashes_1d_1000m/tgis/sqlite.db')}<br>
>> Starting simulation for configuration file macdo1000.ini...<br>
>> [...]<br>
>> g.mapset -p<br>
>> hull<br>
>> g.mapsets -p<br>
>> Accessible mapsets:<br>
>> hull PERMANENT hull_rain<br>
>> ciface.available_mapsets()<br>
>> ['swashes_1d_1000m', 'PERMANENT']<br>
>> get_available_temporal_mapsets()<br>
>> {'swashes_1d_1000m': ('sqlite',<br>
>> '/home/laurent/grassdata/flood_test/swashes_1d_1000m/tgis/sqlite.db')}<br>
>> ERROR: Unable to execute sql statement. There is no temporal database<br>
>> connection defined for mapset <hull><br>
>><br>
>> It seems that tgis.init() is not doing what it is supposed to, according<br>
>> to the documentation:<br>
>><br>
>> "Re-run this function in case the following GRASS variables change while<br>
>> the process runs:<br>
>> - MAPSET<br>
>> - LOCATION_NAME<br>
>> - GISDBASE<br>
>> - TGIS_DISABLE_MAPSET_CHECK<br>
>> - TGIS_DISABLE_TIMESTAMP_WRITE<br>
>> "<br>
>><br>
>> Thanks again.<br>
>><br>
>> Regards,<br>
>> Laurent<br>
>><br>
>> 2016-09-22 13:52 GMT-05:00 Sören Gebbert <<a href="mailto:soerengebbert@googlemail.com">soerengebbert@googlemail.com</a>>:<br>
>> > Hi Laurent,<br>
>> > the temporal framework was neither tested nor designed to work in a<br>
>> > script<br>
>> > that changes the location while running. I would suggest to run the<br>
>> > temporal<br>
>> > framework related code in a subprocess that is created each time the<br>
>> > location or mapset changes. Unfortunately i have no other suggestion.<br>
>> ><br>
>> > However, have you tested your code with grass 7.2 or 7.3? Many<br>
>> > improvements<br>
>> > have been implement in the recent version that would be beneficial to<br>
>> > use.<br>
>> ><br>
>> > Best regards<br>
>> > Soeren<br>
>> ><br>
>> > 2016-09-22 2:47 GMT+02:00 Laurent C. <<a href="mailto:lrntct@gmail.com">lrntct@gmail.com</a>>:<br>
>> >><br>
>> >> Hello all,<br>
>> >><br>
>> >> I've ran into another related issue.<br>
>> >> One of the goal of running the software outside of GRASS shell is to<br>
>> >> batch process simulations in various Locations/mapsets.<br>
>> >><br>
>> >> I set the GRASS session for each case. The simulation works well for<br>
>> >> the first case.<br>
>> >> However when starting the second case, tgis.init() fails with the<br>
>> >> following error:<br>
>> >><br>
>> >> ERROR: Unable to execute sql statement. There is no temporal database<br>
>> >> connection defined for mapset <hull><br>
>> >><br>
>> >> The mapset and location are properly set.<br>
>> >> If this case is run first, it works well and it's the second one that<br>
>> >> fail.<br>
>> >> Running t.connect -c between two cases does not solve the problem.<br>
>> >> Actually, t.connect -p shows the correct connection parameters, but<br>
>> >> tgis.init() still fails.<br>
>> >><br>
>> >> Regards,<br>
>> >> Laurent<br>
>> >><br>
>> >><br>
>> >> 2016-09-21 18:27 GMT-05:00 Laurent C. <<a href="mailto:lrntct@gmail.com">lrntct@gmail.com</a>>:<br>
>> >> > Hi Sören,<br>
>> >> ><br>
>> >> > Setting LD_LIBRARY_PATH is working, thanks. But it cannot be set at<br>
>> >> > run-time, which is not very user-friendly.<br>
>> >> > I guess this issue is related to the ticket 2424 [1].<br>
>> >> ><br>
>> >> > I managed to get it work at run-time by restarting the program with<br>
>> >> > sys.execv() after setting the path [2], but I find it a bit ugly and<br>
>> >> > quite verbose to be multi-platform.<br>
>> >> ><br>
>> >> > It would be great if an easier option was possible.<br>
>> >> ><br>
>> >> > Regards,<br>
>> >> > Laurent<br>
>> >> ><br>
>> >> > [1] <a href="https://trac.osgeo.org/grass/ticket/2424">https://trac.osgeo.org/grass/ticket/2424</a><br>
>> >> > [2]<br>
>> >> ><br>
>> >> > <a href="http://stackoverflow.com/questions/6543847/setting-ld-library-path-from-inside-python">http://stackoverflow.com/questions/6543847/setting-ld-library-path-from-inside-python</a><br>
>> >> ><br>
>> >> ><br>
>> >> > 2016-09-21 15:40 GMT-05:00 Sören Gebbert<br>
>> >> > <<a href="mailto:soerengebbert@googlemail.com">soerengebbert@googlemail.com</a>>:<br>
>> >> >> Hi,<br>
>> >> >> i think you have to put the GRASS libraries into your<br>
>> >> >> LD_LIBRARY_PATH<br>
>> >> >> so<br>
>> >> >> that the python wrapper can access them.<br>
>> >> >><br>
>> >> >> Best regards<br>
>> >> >> Soeren<br>
>> >> >><br>
>> >> >> 2016-09-21 20:37 GMT+02:00 Laurent C. <<a href="mailto:lrntct@gmail.com">lrntct@gmail.com</a>>:<br>
>> >> >>><br>
>> >> >>> Hello all,<br>
>> >> >>><br>
>> >> >>> I'm trying to adapt a python module in order for it to be run<br>
>> >> >>> outside<br>
>> >> >>> of<br>
>> >> >>> GRASS.<br>
>> >> >>> I followed the instructions from the wiki and<br>
>> >> >>> lib/python/script/setup.py<br>
>> >> >>><br>
>> >> >>> gsetup.init() run without error and I can list maps like in the<br>
>> >> >>> example.<br>
>> >> >>><br>
>> >> >>> However, when I try to import the temporal module, I receive this<br>
>> >> >>> error:<br>
>> >> >>><br>
>> >> >>> import grass.temporal as tgis<br>
>> >> >>> File "/usr/lib/grass70/etc/python/grass/temporal/__init__.py", line<br>
>> >> >>> 1, in <module><br>
>> >> >>> from core import *<br>
>> >> >>> File "/usr/lib/grass70/etc/python/grass/temporal/core.py", line 38,<br>
>> >> >>> in <module><br>
>> >> >>> from c_libraries_interface import *<br>
>> >> >>> File<br>
>> >> >>><br>
>> >> >>> "/usr/lib/grass70/etc/python/grass/temporal/c_libraries_interface.py",<br>
>> >> >>> line 19, in <module><br>
>> >> >>> import grass.lib.gis as libgis<br>
>> >> >>> File "/usr/lib/grass70/etc/python/grass/lib/gis.py", line 23, in<br>
>> >> >>> <module><br>
>> >> >>> _libs["grass_gis.7.0.4"] = load_library("grass_gis.7.0.4")<br>
>> >> >>> File "/usr/lib/grass70/etc/python/grass/lib/ctypes_loader.py", line<br>
>> >> >>> 55, in load_library<br>
>> >> >>> return self.load(path)<br>
>> >> >>> File "/usr/lib/grass70/etc/python/grass/lib/ctypes_loader.py", line<br>
>> >> >>> 71, in load<br>
>> >> >>> raise ImportError,e<br>
>> >> >>> ImportError: <a href="http://libgrass_datetime.7.0.4.so">libgrass_datetime.7.0.4.so</a>: cannot open shared object<br>
>> >> >>> file: No such file or directory<br>
>> >> >>><br>
>> >> >>><br>
>> >> >>> Did I forgot to set-up something or this is a bug?<br>
>> >> >>><br>
>> >> >>> Cheers,<br>
>> >> >>> Laurent<br>
>> >> >>> _______________________________________________<br>
>> >> >>> grass-dev mailing list<br>
>> >> >>> <a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br>
>> >> >>> <a href="http://lists.osgeo.org/mailman/listinfo/grass-dev">http://lists.osgeo.org/mailman/listinfo/grass-dev</a><br>
>> >> >><br>
>> >> >><br>
>> ><br>
>> ><br>
><br>
><br>
</p>