How to clip temporal precipitation (as per SPHY generated Basin.Map), and export it in to SPHY forcing data format and save it with naming convention used by SPHY for forcing (i.e., prec0000.001, prec0000.002) using batch mode.

85 views
Skip to first unread message

Mritunjay Kumar Singh

unread,
Oct 21, 2019, 4:30:09 AM10/21/19
to SPHY-model-user

Hi

 

I have precipitation (modeled) in 500 m spatial resolution can i use that in the forcing. If yes than how to clip (as per SPHY generated Basin.map), and export it in to SPHY forcing data format and give the naming convention used by SPHY for forcing (i.e., prec0000.001, prec0000.002) using batch mode. Can you please provide me a python code for this?

 

My files naming convention is 01-01-2000.tif, 02-01-2000.tif, 03-01-2000.tif...........21-12-2018.tif



Regards



WilcoTerink

unread,
Nov 2, 2019, 12:32:24 AM11/2/19
to SPHY-model-user
Hi,

I suggest you use gdal_translate in combination with python subprocess in a code that looks something like this:


cnt = 0

while condition is True:
    cnt+=1
    pcrstr = '%08.3f' %(cnt/1000.0)
    output = 'prec' + pcrstr
subprocess.Popen('gdal_translate -of PCRaster input.tif output', shell=True).wait()

The condition can be while the current date of the file is lower or equal to the end date of the time-series to be processed; i.e. it does the loop until all files are processed. You also need to make input.tif a variable, so that for each iteration it picks the correct *.tif file.

Of course you need to have gdal installed and make it availble through the Environmental Settings. Hope this helps.


Reply all
Reply to author
Forward
0 new messages