1

I have created this bash file (.sh) while working on watershed analysis stochastic simulation in GRASS GIS 7.0.2RC1, which is running on Ubuntu. It worked perfectly and I received the correct results.

r.surf.random --overwrite output=frequency min=0 max=0
for (( n=1 ; n<21 ; n=$n+1 ))
do
    r.surf.random --overwrite output=mistakes min=-15 max=15
    r.mapcalc "fixed_terrain = terrain@exrcs1 + mistakes@exrcs1" --overwrite
    r.watershed --overwrite elevation=fixed_terrain@exrcs1 accumulation=accum$n
    r.reclass --overwrite input=accum$n@exrcs1 output=drain$n rules=C:\\Users\\Hynek\\exrcs1_reclass_rules
    r.mapcalc "frequency = drain$n + frequency" --o
done

The bash file is using reclassification rules that are set in the file exrcs1_reclass_rules. And this is my question - how to make this bash file work for Windows 7 located GRASS GIS 7.0.2RC1? I knew that there would be a problem in the directory containing the reclassification rules file. I tried to change the path file to rules=C:\\Users\\Hynek\\exrcs1_reclass_rules instead of Ubuntu path rules=/home/user/exrcs1_reclass_rules, and it was able to read this file, but then this error appeared in GRASS terminal:

WARNING: Unable to rename null file
        'C:\Users\Hynek\Documents\grassdata/utm/exrcs1/.tmp/unknown/34012.1'

        to
        'C:\Users\Hynek\Documents\grassdata/utm/exrcs1/cell_misc/frequency/nul
l':
        File exists
WARNING: Unable to rename cell file
        'C:\Users\Hynek\Documents\grassdata/utm/exrcs1/.tmp/unknown/34012.0'

        to
        'C:\Users\Hynek\Documents\grassdata/utm/exrcs1/fcell/frequency':
        File exists

So far this bash file created all twenty desired accumulation and drain rasters, that are fine, but desired frequency raster is completely yellow-coloured and with zero values. This is obviously wrong. Do you have any idea how could I fix this?

6
  • Welcome! Please take a moment to take the tour here: gis.stackexchange.com/tour. You may want to take a look at your formatting. Both of those warnings have a mixture of '/' and '\'.
    – MaryBeth
    Dec 17, 2015 at 14:21
  • @MaryBeth Hi, I already took a tour. Could you be more specific? I'm not sure if these slashes are the problem. I'm not experienced in GRASS.
    – Hynek G
    Dec 17, 2015 at 14:48
  • I'm not very versed in GRASS myself, but I believe there are problems using the mixed slashes and Ubuntu. stackoverflow.com/questions/25648256/… You can try echoing the pathnames for the prior paths that are able to save and see if they have the mixes of slashes as well.
    – MaryBeth
    Dec 17, 2015 at 14:58
  • I tried to use scriptPath = sys.path[0] in Python and print paths, but it just showed all of them correctly for Windows. So no mixes at all, only "\" slashes.
    – Hynek G
    Dec 17, 2015 at 16:10
  • Looking at Unable to rename null file I think you need to execute the commands one by one to see which one of them is doing that. Then ideally write this grass-user mailing list or even better open a ticket if you think that the issue is not on your site (so it seems as the error is quite low level). Reproducible example will be need in any case. Have you tried this on Ubuntu?
    – wenzeslaus
    Jan 12, 2016 at 15:05

1 Answer 1

0

So, I finally opened the ticket after a few years, and found the solution. The problem with renaming null and cell files is on Windows' side, nothing can be done about that. It is not possible to read and write to same file at the same time.

Therefore, a workaround using g.rename and g.remove is utilized. I used a new raster layer named "freqnew", which sums a drain raster and a frequency raster. Then, the old frequency raster is removed completely, and "freqnew" raster is renamed to "frequency" raster (removal is needed, since otherwise renaming would fail, because there would still be the "frequency" raster). With this approach, the simulation works as intended.

r.surf.random --overwrite output=frequency min=0 max=0
for (( n=1 ; n<21 ; n=$n+1 ))
do
    r.surf.random --overwrite output=mistakes min=-15 max=15
    r.mapcalc "fixed_terrain = terrain@exrcs1 + mistakes@exrcs1" --overwrite
    r.watershed --overwrite elevation=fixed_terrain@exrcs1 accumulation=accum$n
    r.reclass --overwrite input=accum$n@exrcs1 output=drain$n rules=C:\\Users\\Hynek\\exrcs1_reclass_rules
    r.mapcalc "freqnew = drain$n + frequency" --overwrite
    g.remove -f type=raster name=frequency
    g.rename raster=freqnew,frequency
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.