peckhams / topoflow36

TopoFlow is a component-based, spatial hydrologic model along with a large collection of utilities for data preparation, visualization and so on. Distributed as a Python package and version 3.6 has been updated to run in Python 3.*.
MIT License
26 stars 10 forks source link

Pedotransfer function doesn't check is the writable permissions #8

Open mosoriob opened 3 years ago

mosoriob commented 3 years ago
# Copy RTI file from topo to soil directory
topo_rti_file = topo_dir + site_prefix + '.rti'
soil_rti_file = soil_dir + site_prefix + '.rti'
if not Path(topo_rti_file).exists():
    print("error")
if not Path(soil_rti_file).exists():
    print("error")
print(topo_rti_file)
print(soil_rti_file)
print(out_bounds)
print(out_xres_sec)
print(out_yres_sec)
shutil.copyfile( topo_rti_file, soil_rti_file)
pedotransfer.save_soil_hydraulic_vars( site_prefix=site_prefix,
         in_dir=src_soil_dir, out_dir=soil_dir,
         out_bounds=out_bounds, REPORT=False,
         out_xres_sec=out_xres_sec, out_yres_sec=out_yres_sec,
         RESAMPLE_ALGO='bilinear')

The error is:

/home/jovyan/TF_Tests/Tana_120sec/__topo/Tana_120sec.rti
/home/jovyan/TF_Tests/Tana_120sec/__soil/Tana_120sec.rti
[36.4, -3.15, 40.75, 0.69]
120.0
120.0

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-25-005dc04f4761> in <module>
     12 print(out_yres_sec)
     13 shutil.copyfile( topo_rti_file, soil_rti_file)
---> 14 pedotransfer.save_soil_hydraulic_vars( site_prefix=site_prefix,
     15          in_dir=src_soil_dir, out_dir=soil_dir,
     16          out_bounds=out_bounds, REPORT=False,

~/topoflow/topoflow/utils/pedotransfer.py in save_soil_hydraulic_vars(site_prefix, in_dir, out_dir, out_bounds, REPORT, out_xres_sec, out_yres_sec, RESAMPLE_ALGO)
   1376     # Almost ready;  still need to create an RTI file
   1377     #----------------------------------------------------
-> 1378     transform_isric_soil_grid_files( site_prefix,
   1379            in_dir=in_dir, out_dir=out_dir,
   1380            out_bounds=out_bounds,

~/topoflow/topoflow/utils/pedotransfer.py in transform_isric_soil_grid_files(site_prefix, in_dir, out_dir, out_bounds, out_xres_sec, out_yres_sec, RESAMPLE_ALGO, IN_MEMORY, REPORT)
    722         #-------------------------------------------
    723         if not(BAD_BOX):
--> 724             grid2 = rg.gdal_regrid_to_dem_grid( ds_in, tmp_file,
    725                         out_bounds, out_xres_deg, out_yres_deg,
    726                         ### DEM_bounds, DEM_xres, DEM_yres,

~/topoflow/topoflow/utils/regrid.py in gdal_regrid_to_dem_grid(ds_in, tmp_file, DEM_bounds, DEM_xres_deg, DEM_yres_deg, nodata, RESAMPLE_ALGO, VERBOSE, IN_MEMORY)
    895         resampleAlg = resample_algo )
    896 
--> 897     grid = ds_tmp.ReadAsArray()
    898 
    899     ds_tmp = None   # Close tmp_file

AttributeError: 'NoneType' object has no attribute 'ReadAsArray'
mosoriob commented 3 years ago

Topoflow tries to write a temporal files in the src_soil_dir and doesn't check if it can write