diff --git a/modules/WA/create_NC.py b/modules/WA/create_NC.py index af78f10..46b1a06 100644 --- a/modules/WA/create_NC.py +++ b/modules/WA/create_NC.py @@ -43,10 +43,15 @@ def main(nc_fn,basin,dataset,template,cutline,step='month',**kwargs): DTindex: object pandas DatetimeIndex range ''' - dims = {'time': None, 'latitude': None, 'longitude': None} - dims['latitude'], dims['longitude'], optionsProj, optionsClip = _get_lats_lons(template, cutline) - _init_nc(nc_fn, dims, dataset, attr = {"basin_name" : basin}) + overview=_make_overview(dataset, step) + if "invariant" in overview.keys(): + dims = {'latitude': None, 'longitude': None} + else: + dims = {'time': None, 'latitude': None, 'longitude': None} + + dims['latitude'], dims['longitude'], optionsProj, optionsClip = _get_lats_lons(template, cutline) + _init_nc(nc_fn, dims, dataset, attr = {"basin_name" : basin}) succes = _fill_data_to_nc(nc_fn, overview, optionsProj, optionsClip, cutline) return succes @@ -156,7 +161,9 @@ def _fill_data_to_nc(nc_file, overview, optionsProj, optionsClip, shape): sourceds = None os.remove(temp_file) os.remove(temp_fileP) - __fill_nc_one_timestep(nc_file, var, shape) + print(var) + print(shape) + __fill_nc_one_timestep(nc_file, var, shape,time_val = None) # Save time-variant data to nc-file. for date in tqdm(overview.keys()): @@ -292,7 +299,9 @@ def __fill_nc_one_timestep(nc_file, var, shape, time_val = None): # Add invariant data to nc-file. else: for name, data in var.items(): - out_nc.variables[name][...] = data + print(name) + print(data.shape) + out_nc.variables[name][0::] = data # Close nc-file. out_nc.close() diff --git a/modules/WA/model_SMBalance.py b/modules/WA/model_SMBalance.py index 4e46731..2ebd78a 100644 --- a/modules/WA/model_SMBalance.py +++ b/modules/WA/model_SMBalance.py @@ -17,7 +17,10 @@ def open_nc(nc,timechunk=1,chunksize=1000): dts=xr.open_dataset(nc) key=list(dts.keys())[0] - var=dts[key].chunk({"time": timechunk, "latitude": chunksize, "longitude": chunksize}) #.ffill("time") + if 'time' in list(dts.dims.keys()): + var=dts[key].chunk({"time": timechunk, "latitude": chunksize, "longitude": chunksize}) #.ffill("time") + else: + var=dts[key].chunk({"latitude": chunksize, "longitude": chunksize}) #.ffill("time") return var,key def SCS_calc_SRO(P,I,NRD,SMmax,SM, cf): @@ -245,7 +248,7 @@ def run_SMBalance(MAIN_FOLDER,p_in,e_in,i_in,nrd_in,lu_in,smsat_file, mask = xr.where(((lu==80) | (lu==81) | (lu==70) | (lu==200)|(lu==90)), 1,0) #include flooded shrub? Rd = root_depth(lu) - SMmax=thetasat[0]*Rd + SMmax=thetasat*Rd f_consumed = Consumed_fraction(lu) for t in range(t1,t2): print('time: ', t) diff --git a/notebooks/0_Collect_Prepare_data.ipynb b/notebooks/0_Collect_Prepare_data.ipynb index 794324b..333bb3c 100644 --- a/notebooks/0_Collect_Prepare_data.ipynb +++ b/notebooks/0_Collect_Prepare_data.ipynb @@ -37,9 +37,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loading WaPOR catalog...\n", + "\n", + "Download daily WaPOR precipitation data for the period 2009-01-01 till 2009-12-31\n", + "Loading WaPOR catalog...\n", + "Progress: |██████████████████████████████████████████████████| 100.0% Complete\n", + "\n", + "Download monthly WaPOR precipitation data for the period 2009-01-01 till 2009-12-31\n", + "Loading WaPOR catalog...\n", + "Progress: |██████████████████████████████████████████████████| 100.0% Complete\n", + "\n", + "Download monthly WaPOR Reference Evapotranspiration data for the period 2009-01-01 till 2009-12-31\n", + "Loading WaPOR catalog...\n", + "Progress: |██████████████████████████████████████████████████| 100.0% Complete\n", + "\n", + "Download monthly WaPOR Actual Evapotranspiration data for the period 2009-01-01 till 2009-12-31\n", + "Loading WaPOR catalog...\n", + "Progress: |██████████████████████████████████████████████████| 100.0% Complete\n", + "\n", + "Download yearly WaPOR Land Cover Class data for the period 2009-01-01 till 2009-12-31\n", + "Loading WaPOR catalog...\n", + "Progress: |██████████████████████████████████████████████████| 100.0% Complete\n", + "\n", + "Download dekadal WaPOR Interception data for the period 2009-01-01 till 2009-12-31\n", + "Loading WaPOR catalog...\n", + "Progress: |██████████████████████████████████████████████████| 100.0% Complete\n" + ] + } + ], "source": [ "WaPOR.API.version=2\n", "catalog=WaPOR.API.getCatalog()\n", diff --git a/notebooks/1_Create_NetCDF.ipynb b/notebooks/1_Create_NetCDF.ipynb index b184b43..153d83a 100644 --- a/notebooks/1_Create_NetCDF.ipynb +++ b/notebooks/1_Create_NetCDF.ipynb @@ -34,7 +34,7 @@ { "data": { "text/plain": [ - "'D:\\\\Github\\\\WAPORWA\\\\data\\\\Litani\\\\Main\\\\Info_20200204_16h38.pickle'" + "'D:\\\\Github\\\\WAPORWA\\\\data\\\\Litani\\\\Main\\\\Info_20200513_08h50.pickle'" ] }, "execution_count": 2, @@ -122,7 +122,9 @@ { "cell_type": "code", "execution_count": 4, - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [ { "name": "stdout", @@ -136,7 +138,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|█████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:07<00:00, 1.25it/s]\n" + "100%|██████████████████████████████████████████████████████████████████████████████████| 10/10 [00:06<00:00, 1.65it/s]\n" ] }, { @@ -152,7 +154,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|█████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:07<00:00, 1.29it/s]\n" + "100%|██████████████████████████████████████████████████████████████████████████████████| 10/10 [00:04<00:00, 2.14it/s]\n" ] }, { @@ -168,7 +170,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|███████████████████████████████████████████████████████████████████████████████████████████████| 120/120 [00:39<00:00, 3.34it/s]\n" + "100%|████████████████████████████████████████████████████████████████████████████████| 120/120 [00:36<00:00, 3.20it/s]\n" ] }, { @@ -184,7 +186,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|███████████████████████████████████████████████████████████████████████████████████████████████| 120/120 [01:22<00:00, 1.51it/s]\n" + "100%|████████████████████████████████████████████████████████████████████████████████| 120/120 [01:19<00:00, 1.34it/s]\n" ] }, { @@ -200,7 +202,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|███████████████████████████████████████████████████████████████████████████████████████████████| 120/120 [00:40<00:00, 3.25it/s]\n" + "100%|████████████████████████████████████████████████████████████████████████████████| 120/120 [00:38<00:00, 3.15it/s]\n" ] }, { @@ -216,7 +218,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|███████████████████████████████████████████████████████████████████████████████████████████████| 120/120 [01:20<00:00, 1.26it/s]\n" + "100%|████████████████████████████████████████████████████████████████████████████████| 120/120 [00:54<00:00, 1.49it/s]\n" ] }, { @@ -232,7 +234,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|███████████████████████████████████████████████████████████████████████████████████████████████| 120/120 [00:37<00:00, 3.34it/s]\n" + "100%|████████████████████████████████████████████████████████████████████████████████| 120/120 [00:41<00:00, 3.41it/s]\n" ] }, { @@ -241,7 +243,18 @@ "text": [ "Finished nRD_monthly.nc\n", "6.806621238863997e-16\n", - "-6.806621238863997e-16\n" + "-6.806621238863997e-16\n", + "{'Top-soil Saturated Water Content': array([[-9999., -9999., -9999., ..., -9999., -9999., -9999.],\n", + " [-9999., -9999., -9999., ..., -9999., -9999., -9999.],\n", + " [-9999., -9999., -9999., ..., -9999., -9999., -9999.],\n", + " ...,\n", + " [-9999., -9999., -9999., ..., -9999., -9999., -9999.],\n", + " [-9999., -9999., -9999., ..., -9999., -9999., -9999.],\n", + " [-9999., -9999., -9999., ..., -9999., -9999., -9999.]],\n", + " dtype=float32)}\n", + "D:\\Github\\WAPORWA\\data\\Global\\Basins\\BasinLitani.shp\n", + "Top-soil Saturated Water Content\n", + "(958, 1181)\n" ] }, { @@ -261,7 +274,7 @@ { "data": { "text/plain": [ - "'D:\\\\Github\\\\WAPORWA\\\\data\\\\Litani\\\\Main\\\\Info_20200204_16h45.pickle'" + "'D:\\\\Github\\\\WAPORWA\\\\data\\\\Litani\\\\Main\\\\Info_20200513_08h55.pickle'" ] }, "execution_count": 4, @@ -303,7 +316,7 @@ " if BASIN['input_data']['stat'][key] is not None: \n", " nc_fn=os.path.join(Dir_out,key+'_stat.nc') \n", " dataset={key:[BASIN['input_data']['stat'][key][0],\n", - " ('time','latitude', 'longitude'), \n", + " ('latitude', 'longitude'), \n", " {'units': BASIN['input_data']['stat'][key][1], \n", " 'quantity':BASIN['input_data']['stat'][key][2],\n", " 'source': 'WaPOR', 'period':'stat'}]}\n", diff --git a/notebooks/3_RunSMBalance.ipynb b/notebooks/3_RunSMBalance.ipynb index ed684b0..f0c0c4a 100644 --- a/notebooks/3_RunSMBalance.ipynb +++ b/notebooks/3_RunSMBalance.ipynb @@ -13,7 +13,7 @@ "