Changeset 3726 for palm/trunk/SCRIPTS
- Timestamp:
- Feb 7, 2019 6:22:49 PM (6 years ago)
- Location:
- palm/trunk/SCRIPTS
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/SCRIPTS/palm_csd
r3688 r3726 25 25 # ----------------- 26 26 # $Id$ 27 # Removed some more bugs 28 # 29 # 3688 2019-01-22 10:44:20Z maronga 27 30 # Some unspecified bugfixes 28 31 # … … 458 461 filename.append(path_out + "/" + filename_out + "_" + domain_names[i]) 459 462 if domain_parent[i] is not None: 460 ii_parent.append( domain_names.index(domain_parent[i]))463 ii_parent.append(input_px.index(domain_px[domain_names.index(domain_parent[i])])) 461 464 else: 462 465 ii_parent.append(None) 463 466 464 467 465 x_UTM = nc_read_from_file_2d(input_file_x[ii[i]], "Band1", domain_x0[i], domain_x0[i], domain_y0[i], domain_y0[i]) - 0.5 * domain_px[i] 466 y_UTM = nc_read_from_file_2d(input_file_y[ii[i]], "Band1", domain_x0[i], domain_x0[i], domain_y0[i], domain_y0[i]) - 0.5 * domain_px[i] 467 lat = nc_read_from_file_2d(input_file_lat[ii[i]], "Band1", domain_x0[i], domain_x0[i], domain_y0[i], domain_y0[i]) 468 lon = nc_read_from_file_2d(input_file_lon[ii[i]], "Band1", domain_x0[i], domain_x0[i], domain_y0[i], domain_y0[i]) 468 x_UTM = nc_read_from_file_2d(input_file_x[ii[i]], "Band1", domain_x0[i], domain_x0[i]+1, domain_y0[i], domain_y0[i]+1) 469 y_UTM = nc_read_from_file_2d(input_file_y[ii[i]], "Band1", domain_x0[i], domain_x0[i]+1, domain_y0[i], domain_y0[i]+1) 470 lat = nc_read_from_file_2d(input_file_lat[ii[i]], "Band1", domain_x0[i], domain_x0[i]+1, domain_y0[i], domain_y0[i]+1) 471 lon = nc_read_from_file_2d(input_file_lon[ii[i]], "Band1", domain_x0[i], domain_x0[i]+1, domain_y0[i], domain_y0[i]+1) 472 473 # Calculate position of origin 474 x_UTM_origin = float(x_UTM[0,0]) - 0.5 * (float(x_UTM[0,1]) - float(x_UTM[0,0])) 475 y_UTM_origin = float(y_UTM[0,0]) - 0.5 * (float(y_UTM[1,0]) - float(y_UTM[0,0])) 476 x_origin = float(lon[0,0]) - 0.5 * (float(lon[0,1]) - float(lon[0,0])) 477 y_origin = float(lat[0,0]) - 0.5 * (float(lat[1,0]) - float(lat[0,0])) 469 478 470 479 # Create NetCDF output file and set global attributes 471 480 nc_create_file(filename[i]) 472 nc_write_global_attributes(filename[i], float(x_UTM[0,0]),float(y_UTM[0,0]),float(lat[0,0]),float(lon[0,0]),"",global_acronym,global_angle,global_author,global_campaign,global_comment,global_contact,global_data_content,global_dependencies,global_institution,global_keywords,global_location,global_palm_version,global_references,global_site,global_source,version_out)481 nc_write_global_attributes(filename[i],x_UTM_origin,y_UTM_origin,y_origin,x_origin,"",global_acronym,global_angle,global_author,global_campaign,global_comment,global_contact,global_data_content,global_dependencies,global_institution,global_keywords,global_location,global_palm_version,global_references,global_site,global_source,version_out) 473 482 474 483 del x_UTM, y_UTM, lat, lon … … 492 501 del zt_all[:] 493 502 494 print( "Shift terrain height by -" + str(zt_min))503 print( "Shift terrain heights by -" + str(zt_min)) 495 504 for i in range(0,ndomains): 496 505 … … 500 509 y = nc_read_from_file_1d(input_file_y[ii[i]], "y", domain_y0[i], domain_y1[i]) 501 510 511 502 512 zt = zt - zt_min 503 513 … … 506 516 # If necessary, interpolate parent domain terrain height on child domain grid and blend the two 507 517 if domain_ip[i]: 508 tmp_x0 = int( domain_x0[i] * domain_px[i] / domain_px[ii_parent[i]] ) - 1 509 tmp_y0 = int( domain_y0[i] * domain_px[i] / domain_px[ii_parent[i]] ) - 1 510 tmp_x1 = int( domain_x1[i] * domain_px[i] / domain_px[ii_parent[i]] ) + 1 511 tmp_y1 = int( domain_y1[i] * domain_px[i] / domain_px[ii_parent[i]] ) + 1 512 518 parent_id = domain_names.index(domain_parent[i]) 519 tmp_x0 = int( domain_x0[i] * domain_px[i] / domain_px[parent_id] ) - 1 520 tmp_y0 = int( domain_y0[i] * domain_px[i] / domain_px[parent_id] ) - 1 521 tmp_x1 = int( domain_x1[i] * domain_px[i] / domain_px[parent_id] ) + 1 522 tmp_y1 = int( domain_y1[i] * domain_px[i] / domain_px[parent_id] ) + 1 523 print(tmp_x0) 524 print(tmp_x1) 525 print(tmp_y0) 526 print(tmp_y1) 527 513 528 tmp_x = nc_read_from_file_1d(input_file_x[ii_parent[i]], "x", tmp_x0, tmp_x1) 514 529 tmp_y = nc_read_from_file_1d(input_file_y[ii_parent[i]], "y", tmp_y0, tmp_y1) … … 516 531 zt_parent = nc_read_from_file_2d(input_file_zt[ii_parent[i]], 'Band1', tmp_x0, tmp_x1, tmp_y0, tmp_y1) 517 532 518 print( "Shift terrain height by -" + str(zt_min))519 533 zt_parent = zt_parent - zt_min 520 534 521 535 # Interpolate array and bring to PALM grid of child domain 522 523 536 zt_ip = interpolate_2d(zt_parent,tmp_x,tmp_y,x,y) 524 zt_ip = bring_to_palm_grid(zt_ip,x,y,domain_dz[ii_parent[i]]) 525 526 # Shift the child terrain height according to the parent mean terrain height 527 zt = zt - np.mean(zt) + np.mean(zt_ip) 537 zt_ip = bring_to_palm_grid(zt_ip,x,y,domain_dz[parent_id]) 538 539 540 # Shift the child terrain height according to the parent mean terrain height 541 zt = zt - np.mean(zt) + np.mean(zt_ip) 528 542 529 543 … … 532 546 533 547 # Final step: add zt array to the global array 548 534 549 zt_all.append(zt) 535 550 del zt … … 569 584 x_UTM = nc_read_from_file_2d(input_file_x_UTM[ii[i]], "Band1", domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 570 585 y_UTM = nc_read_from_file_2d(input_file_y_UTM[ii[i]], "Band1", domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 586 571 587 572 588 nc_write_to_file_2d(filename[i], 'E_UTM', x_UTM, datatypes["E_UTM"],'y','x',fillvalues["E_UTM"]) … … 664 680 building_id = np.where(bridges_2d == fillvalues["bridges_2d"],building_id,bridges_id) 665 681 666 667 682 if np.any(buildings_2d != fillvalues["buildings_2d"]): 668 683 buildings_3d, z = make_3d_from_2d(buildings_2d,x,y,domain_dz[i]) … … 676 691 nc_write_attribute(filename[i], 'z', 'long_name', 'z') 677 692 nc_write_attribute(filename[i], 'z', 'units', 'm') 693 694 nc_overwrite_to_file_2d(filename[i], 'building_id', building_id) 678 695 679 696 nc_write_to_file_3d(filename[i], 'buildings_3d', buildings_3d, datatypes["buildings_3d"],'z','y','x',fillvalues["buildings_3d"]) … … 839 856 street_crossings = np.where((street_crossings < 1) & (street_crossings != fillvalues["street_crossings"]),defaultvalues["street_crossings"],street_crossings) 840 857 841 nc_write_to_file_2d(filename[i], 'street_crossing s', street_crossings, datatypes["street_crossings"],'y','x',fillvalues["street_crossings"])842 nc_write_attribute(filename[i], 'street_crossing s', 'long_name', 'street crossings')843 nc_write_attribute(filename[i], 'street_crossing s', 'units', '')844 nc_write_attribute(filename[i], 'street_crossing s', 'res_orig', domain_px[i])845 nc_write_attribute(filename[i], 'street_crossing s', 'coordinates', 'E_UTM N_UTM lon lat')846 nc_write_attribute(filename[i], 'street_crossing s', 'grid_mapping', 'E_UTM N_UTM lon lat')858 nc_write_to_file_2d(filename[i], 'street_crossing', street_crossings, datatypes["street_crossings"],'y','x',fillvalues["street_crossings"]) 859 nc_write_attribute(filename[i], 'street_crossing', 'long_name', 'street crossings') 860 nc_write_attribute(filename[i], 'street_crossing', 'units', '') 861 nc_write_attribute(filename[i], 'street_crossing', 'res_orig', domain_px[i]) 862 nc_write_attribute(filename[i], 'street_crossing', 'coordinates', 'E_UTM N_UTM lon lat') 863 nc_write_attribute(filename[i], 'street_crossing', 'grid_mapping', 'E_UTM N_UTM lon lat') 847 864 del street_crossings 848 865 … … 1017 1034 vegetation_pars = nc_read_from_file_3d_all(filename[i], 'vegetation_pars') 1018 1035 lai = vegetation_pars[1,:,:] 1019 1020 # Determine all pixels that do not already have and LAD but which are high vegetation to a dummy value of 1.0 and remove all other pixels 1036 1037 1038 # Determine all pixels that do not already have an LAD but which are high vegetation to a dummy value of 1.0 and remove all other pixels 1021 1039 lai_high = np.where( (lad[0,:,:] == fillvalues["tree_data"]) & ( ( (vegetation_type == 4) | (vegetation_type == 5) | (vegetation_type == 6) |(vegetation_type == 7) | (vegetation_type == 17) | (vegetation_type == 18) ) & ( (patch_height == fillvalues["tree_data"]) | (patch_height >= domain_dz[i])) ),1.0,fillvalues["tree_data"]) 1022 1040 1023 # Now, assign either the default LAI for high vegetation or the value stored in the LAI array. 1024 lai_high = np.where( (lai_high != fillvalues["tree_data"]) & (lai == fillvalues["tree_data"]), settings_lai_high_default, lai) 1041 # Now, assign either the default LAI for high vegetation or keep 1.0 from the lai_high array. 1042 lai_high = np.where( (lai_high != fillvalues["tree_data"]) & (lai == fillvalues["tree_data"]), settings_lai_high_default, lai_high) 1043 1044 # If lai values are available in the lai array, write them on the lai_high array 1045 lai_high = np.where( (lai_high != fillvalues["tree_data"]) & (lai != fillvalues["tree_data"]), lai, lai_high) 1025 1046 1026 1047 # Define a patch height wherever it is missing, but where a high vegetation LAI was set … … 1038 1059 1039 1060 if ( max(patch_height.flatten()) >= (2.0 * domain_dz[i]) ): 1040 print(" start calculating LAD (this might take some time)") 1061 print(" start calculating LAD (this might take some time)") 1062 1063 1041 1064 lad_patch, patch_nz, status = process_patch(domain_dz[i],patch_height,max(zlad),lai_high,settings_lai_alpha,settings_lai_beta) 1042 1065 -
palm/trunk/SCRIPTS/palm_csd_files/palm_csd_tools.py
r3668 r3726 25 25 # ----------------- 26 26 # $Id$ 27 # Index bound bugfix 28 # 29 # 3668 2019-01-14 12:49:24Z maronga 27 30 # Minor changes 28 31 # … … 90 93 for l in range(0,len(x)): 91 94 for m in range(0,len(y)): 92 for k in range( 0,len(k_tmp+1)):95 for k in range(1,len(k_tmp+1)): 93 96 if k_tmp[k] > array[m,l]: 94 array[m,l] = k_tmp[k ]-0.5*dz97 array[m,l] = k_tmp[k-1] 95 98 break 96 99 … … 105 108 array_3d = np.ones((len(k_tmp),len(y),len(x))) 106 109 107 for l in range(0,len(x) -1):108 for m in range(0,len(y) -1):109 for k in range(0,len(k_tmp) -1):110 for l in range(0,len(x)): 111 for m in range(0,len(y)): 112 for k in range(0,len(k_tmp)): 110 113 if k_tmp[k] > array_2d[m,l]: 111 114 array_3d[k,m,l] = 0
Note: See TracChangeset
for help on using the changeset viewer.