zjf014 / hydro-gistools

GIS tools for hydro-data
MIT License
0 stars 1 forks source link

TypeError: type DataArray doesn't define __round__ method #1

Open silencesoup opened 10 months ago

silencesoup commented 10 months ago

在docs/examples/mean/mask.ipynb下

使用wis_s3api,或者opendata下的s3api,都会报错:

TypeError Traceback (most recent call last) Cell In[7], line 1 ----> 1 data = gpm.open_dataset(start_time=start_time, end_time=end_time, bbox=bbox, time_chunks=720) 2 data

File ~/flood_data_preprocess/GPM_data_preprocess/hydro_opendata/s3api/gpm.py:318, in open_dataset(start_time, end_time, bbox, time_chunks) 315 for year in years: 316 if year == year_start: 317 dss.append( --> 318 get_dataset_year( 319 start_time=start_time, 320 end_time=np.datetime64(f"{year}-12-31T23:30:00.000000000"), 321 bbox=bbox, 322 time_chunks=time_chunks, 323 ) 324 ) 326 elif year == year_end: 327 dss.append( 328 get_dataset_year( 329 start_time=np.datetime64( (...) 335 ) 336 )

File ~/flood_data_preprocess/GPM_data_preprocess/hydro_opendata/s3api/gpm.py:85, in get_dataset_year(start_time, end_time, bbox, time_chunks) 82 times = slice(start_time, end_time) 83 ds = ds.sel(time=times) ---> 85 bbox = regen_box(bbox, 0.1, 0.05) 87 if bbox[0] < box[0]: 88 left = box[0]

File ~/flood_data_preprocess/GPM_data_preprocess/hydro_opendata/utils.py:79, in regen_box(bbox, resolution, offset) 77 lx = bbox[0] 78 rx = bbox[2] ---> 79 LLON = round( 80 int(lx) 81 + resolution int((lx - int(lx)) / resolution + 0.5) 82 + offset 83 (int(lx 10) / 10 + offset - lx) 84 / abs(int(lx 10) // 10 + offset - lx + 0.0000001), 85 3, 86 ) 87 RLON = round( 88 int(rx) 89 + resolution * int((rx - int(rx)) / resolution + 0.5) (...) 93 3, 94 ) 96 by = bbox[1]

TypeError: type DataArray doesn't define round method

silencesoup commented 10 months ago

试过用era5,也是报错同样问题

silencesoup commented 10 months ago

我不确定自己理解的对不对 image 这一部分的代码,是不是就是根据bbox的范围,去获取这个bbox矩形下的所有gpm/gfs/era5数据,那是不是如果我们已经下好了数据,只需要根据bbox的值,去把这个数据切割一下,效果是一样的 里面目前我唯一不太理解的参数是time_chunks是用来做什么的

zjf014 commented 10 months ago

额,这部分文档是老的,读数据还是参照opendata的文档,time_chunks是dask分块,可以并行提高读取速度?

zjf014 commented 10 months ago

有问题的代码贴出来看一下

silencesoup commented 10 months ago

报错的代码就是上面贴图的那部分代码,跑到[In]13时会报错,还是想知道我理解的那部分有没有问题,如果没问题的话,和后面的工作没有影响

silencesoup commented 10 months ago

今天在gfs的gen_mask上遇到了同样的问题

ZeroDivisionError Traceback (most recent call last) Cell In[3], line 1 ----> 1 gen_mask(watershed, "STAID", "gfs", save_dir="./mask_GFS")

File ~/flood_data_preprocess/GPM_data_preprocess/mean.py:241, in gen_mask(watershed, filedname, dataname, save_dir) 238 # print(geo.bounds) 239 res, offset = get_para(dataname) --> 241 grid = gen_grids(bbox, res, offset) 242 grid = grid.to_crs(epsg=3857) 243 grid["GRID_AREA"] = grid.area

File ~/flood_data_preprocess/GPM_data_preprocess/mean.py:117, in gen_grids(bbox, resolution, offset) 112 lx = bbox[0] 113 rx = bbox[2] 114 LLON = round( 115 int(lx) 116 + resolution int((lx - int(lx)) / resolution + 0.5) --> 117 + offset 118 (int(lx 10) / 10 + offset - lx) 119 / abs(int(lx 10) / 10 + offset - lx), 120 3, 121 ) 122 RLON = round( 123 int(rx) 124 + resolution * int((rx - int(rx)) / resolution + 0.5) (...) 128 3, 129 ) 131 by = bbox[1]

ZeroDivisionError: float division by zero