Geographic Information Systems Asked on June 12, 2021
I am new in PCRaster, so I made a primitive model to test the functionality. I need to read input from precipitation data maps for each day. My code is:
class Model(DynamicModel):
def __init__(self):
DynamicModel.__init__(self)
setclone(src.RasterYSize,src.RasterXSize,src.GetGeoTransform()[1],src.GetGeoTransform()[0],src.GetGeoTransform()[3])
def initial(self):
self.dem=self.readmap('dem')
self.snowmaxTss=TimeoutputTimeseries("snowmax", self, None, noHeader=False)
def dynamic(self):
self.snow=self.readmap('/snowdata/snow')
maxsnow=max(self.snow)
self.snowmaxTss.sample(maxsnow)
myModel=Model()
dynModel = DynamicFramework(myModel, lastTimeStep=16, firstTimestep=1)
dynModel.run()
My snow maps stack is correct and corresponds to setclone. But I get an error:
RuntimeError Traceback (most recent call last)
<ipython-input-188-c7810b190e43> in <module>
14 myModel=Model()
15 dynModel = DynamicFramework(myModel, lastTimeStep=16, firstTimestep=1)
---> 16 dynModel.run()
/opt/conda/lib/python3.7/site-packages/pcraster/framework/dynamicFramework.py in run(self)
63 self._runInitial()
64
---> 65 self._runDynamic()
66
67 # Only execute this section while running filter frameworks.
/opt/conda/lib/python3.7/site-packages/pcraster/framework/frameworkBase.py in _runDynamic(self)
369 self._incrementIndentLevel()
370 self._traceIn("dynamic")
--> 371 self._userModel().dynamic()
372 self._traceOut("dynamic")
373 self._decrementIndentLevel()
<ipython-input-188-c7810b190e43> in dynamic(self)
9 self.snowmaxTss=TimeoutputTimeseries("snowmax", self, None, noHeader=False)
10 def dynamic(self):
---> 11 self.snow=self.readmap('/snowdata/snow')
12 maxsnow=max(self.snow)
13 self.snowmaxTss.sample(maxsnow)
/opt/conda/lib/python3.7/site-packages/pcraster/framework/dynamicPCRasterBase.py in readmap(self, name, style)
78 `style` argument is not used.
79 """
---> 80 return self._readmapNew(name)
81
82 def _setNrTimeSteps(self,
/opt/conda/lib/python3.7/site-packages/pcraster/framework/frameworkBase.py in __call__(self, *args, **kwargs)
35 if obj:
36 attr = getattr(obj, self.callback_attr)
---> 37 result = attr(*args, **kwargs)
38 else:
39 result = self.default_callback(*args, **kwargs)
/opt/conda/lib/python3.7/site-packages/pcraster/framework/frameworkBase.py in _readmapNew(self, name, style)
564 assert path is not ""
565 import pcraster
--> 566 return pcraster.readmap(path)
567
568 def _assertAndThrow(self,
RuntimeError: Raster /snowdata/snow0000.001: can not be opened
I tried different formats of file names: 0000.001, 0000.001.map etc – but result is the same. What’s the problem with my code? I know, that readmap() method must read stacks by time.
Is an xml file read when reading a map file? I convert from nc layers to map by GDAL and my xml files may contain odd information from the whole nc file.
It was a problem with path format. PCRaster for unknown reason doesn't understand the relative path.
self.readmap(os.getcwd()+'/snowdata/'+'snow')
completely solves this problem.
Answered by Nikolay Yasinskiy on June 12, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP