@@ -52,15 +52,15 @@ def generate_maps_for_scope(paths, param, multiprocessing):
5252 """
5353
5454 generate_land (paths , param ) # Subregions
55- generate_sea (paths , param ) # Sea
55+ # generate_sea(paths, param) # Sea
56+ generate_topography (paths , param )
5657 generate_weather_files (paths , param ) # MERRA Weather data for land
57- generate_weather_offshore_files (paths , param ) # MERRA Weather data for offshore # comment out if no offshore
58+ # generate_weather_offshore_files(paths, param) # MERRA Weather data for offshore # comment out if no offshore
5859
5960 if multiprocessing :
6061 processes = []
6162
6263 processes .append (mp .Process (target = generate_area , args = (paths , param )))
63- processes .append (mp .Process (target = generate_topography , args = (paths , param )))
6464 processes .append (mp .Process (target = generate_landuse , args = (paths , param )))
6565 processes .append (mp .Process (target = generate_protected_areas , args = (paths , param )))
6666 processes .append (mp .Process (target = generate_airports , args = (paths , param )))
@@ -244,8 +244,30 @@ def generate_weather_files(paths, param): #ToDo: Multiprocessing?
244244
245245 # Create the overall wind speed
246246 W50M = abs (U50M + (1j * V50M ))
247+ hdf5storage .writes ({"SWTDN" : SWTDN }, paths ["SWTDN" ], store_python_metadata = True ,
248+ matlab_compatible = True )
249+ hdf5storage .writes ({"SWGDN" : SWGDN }, paths ["SWGDN" ], store_python_metadata = True ,
250+ matlab_compatible = True )
247251 # Calculate the clearness index
248- CLEARNESS = np .divide (SWGDN , SWTDN , out = np .zeros_like (SWGDN ), where = SWTDN != 0 )
252+ # MERRA bias corrections
253+ TOPO_low = hdf5storage .read ("TOPO_low" , paths ["TOPO_low" ]).astype (float )
254+ TOPO_low = TOPO_low / 1000 #in km
255+ SWGDN = hdf5storage .read ("SWGDN" , paths ["SWGDN" ]).astype (float )
256+ SWTDN = hdf5storage .read ("SWTDN" , paths ["SWTDN" ]).astype (float )
257+ numfactor1 = 1 + 0.087 * np .multiply (TOPO_low , TOPO_low ) - 0.065 * TOPO_low - 0.51
258+ # numfactor2 = np.multiply(SWGDN, SWTDN)
259+ num = np .zeros ([param ["m_low" ],param ["n_low" ],8760 ])
260+ for hour in range (8760 ):
261+ num [:,:,hour ] = np .multiply (numfactor1 , SWGDN [:,:,hour ])
262+ den = - 0.82 * SWGDN + SWTDN
263+ CLEARNESS = np .divide (num , den , out = np .zeros_like (num ), where = den != 0 )
264+ for i in range (param ["m_low" ]):
265+ for j in range (param ["n_low" ]):
266+ for k in range (8760 ):
267+ if CLEARNESS [i ,j ,k ] > 0.7 :
268+ CLEARNESS [i ,j ,k ] = SWGDN [i ,j ,k ] / SWTDN [i ,j ,k ]
269+ # Clearness without corrections
270+ # CLEARNESS = np.divide(SWGDN, SWTDN, out=np.zeros_like(SWGDN), where=SWTDN != 0)
249271
250272 sys .stdout .write ("\n " )
251273 logger .info ("Writing Files: T2M, W50M, CLEARNESS" )
@@ -640,55 +662,27 @@ def generate_topography(paths, param):
640662 logger .info ('Skip' ) # Skip generation if files are already there
641663
642664 else :
665+ # if 1==1:
643666 logger .info ("Start" )
644667 Crd_all = param ["Crd_all" ]
645- # Ind = sf.ind_global(Crd_all, param["res_topography"])[0]
646668 Ind = sf .ind_global (Crd_all , param ["res_desired" ])[0 ]
647669 GeoRef = param ["GeoRef" ]
648- # Topo = np.zeros((int(180 / param["res_topography"][0]), int(360 / param["res_topography"][1])))
649- # tile_extents = np.zeros((24, 4), dtype=int)
650- # i = 1
651- # j = 1
652- # for letter in ul.char_range("A", "X"):
653- # north = (i - 1) * 45 / param["res_topography"][0] + 1
654- # east = j * 60 / param["res_topography"][1]
655- # south = i * 45 / param["res_topography"][0]
656- # west = (j - 1) * 60 / param["res_topography"][1] + 1
657- # tile_extents[ord(letter) - ord("A"), :] = [north, east, south, west]
658- # j = j + 1
659- # if j == 7:
660- # i = i + 1
661- # j = 1
662- # n_min = (Ind[0] // (45 * 240)) * 45 / param["res_topography"][0] + 1
663- # e_max = (Ind[1] // (60 * 240) + 1) * 60 / param["res_topography"][1]
664- # s_max = (Ind[2] // (45 * 240) + 1) * 45 / param["res_topography"][0]
665- # w_min = (Ind[3] // (60 * 240)) * 60 / param["res_topography"][1] + 1
666- #
667- # need = np.logical_and(
668- # (np.logical_and((tile_extents[:, 0] >= n_min), (tile_extents[:, 1] <= e_max))),
669- # np.logical_and((tile_extents[:, 2] <= s_max), (tile_extents[:, 3] >= w_min)),
670- # )
671- #
672- # for letter in ul.char_range("A", "X"):
673- # index = ord(letter) - ord("A")
674- # if need[index]:
675- # with rasterio.open(paths["Topo_tiles"] + "15-" + letter + ".tif") as src:
676- # tile = src.read()
677- # Topo[tile_extents[index, 0] - 1 : tile_extents[index, 2], tile_extents[index, 3] - 1 : tile_extents[index, 1]] = tile[0, 0:-1, 0:-1]
678- #
679- # A_TOPO = np.flipud(Topo[Ind[0] - 1 : Ind[2], Ind[3] - 1 : Ind[1]])
680- # A_TOPO = sf.adjust_resolution(A_TOPO, param["res_topography"], param["res_desired"], "mean")
681- # A_TOPO = sf.recalc_topo_resolution(A_TOPO, param["res_topography"], param["res_desired"])
670+ m_low = param ["m_low" ]
671+ n_low = param ["n_low" ]
682672
683673 with rasterio .open (paths ["Topo_global" ]) as src :
684674 A_TOPO = src .read (1 , window = rasterio .windows .Window .from_slices (slice (Ind [0 ] - 1 , Ind [2 ]),
685675 slice (Ind [3 ] - 1 , Ind [1 ])))
686676 A_TOPO = np .flipud (A_TOPO )
687677
678+ A_TOPO_low = np .zeros ([m_low ,n_low ])
679+ for i in range (m_low ):
680+ for j in range (n_low ):
681+ A_TOPO_low [i ,j ] = np .sum (A_TOPO [i :i + 200 ,j :j + 250 ])/ (200 * 250 )
688682
689683 hdf5storage .writes ({"TOPO" : A_TOPO }, paths ["TOPO" ], store_python_metadata = True , matlab_compatible = True )
684+ hdf5storage .writes ({"TOPO_low" : A_TOPO_low }, paths ["TOPO_low" ], store_python_metadata = True , matlab_compatible = True )
690685 logger .info ("files saved: " + paths ["TOPO" ])
691- # ul.create_json(paths["TOPO"], param, ["region_name", "Crd_all", "res_topography", "res_desired", "GeoRef"], paths, ["Topo_tiles", "TOPO"])
692686 ul .create_json (paths ["TOPO" ], param , ["region_name" , "Crd_all" , "res_desired" , "GeoRef" ],
693687 paths , ["Topo_global" , "TOPO" ])
694688 if param ["savetiff_inputmaps" ]:
@@ -1408,7 +1402,6 @@ def generate_livestock(paths, param):
14081402 :rtype: None
14091403 """
14101404 logger .info ("Start" )
1411- res_desired = param ["res_desired" ]
14121405 Crd_all = param ["Crd_all" ]
14131406 Ind = sf .ind_global (Crd_all , param ["res_livestock" ])[0 ]
14141407 GeoRef = param ["GeoRef" ]
@@ -1421,7 +1414,6 @@ def generate_livestock(paths, param):
14211414 slice (Ind [3 ] - 1 , Ind [1 ])))
14221415 A_LS = np .flipud (A_LS )
14231416 A_LS = sf .recalc_livestock_resolution (A_LS , param ["res_livestock" ], param ["res_desired" ])
1424- # print (np.size(A_LS))
14251417 A_LS [A_LS < 0 ] = float (0 )
14261418 A_LS = np .multiply (A_LS , A_area ) / (10 ** 6 )
14271419
0 commit comments