Changeset 3668 for palm/trunk/SCRIPTS/palm_csd
- Timestamp:
- Jan 14, 2019 12:49:24 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/SCRIPTS/palm_csd
r3629 r3668 25 25 # ----------------- 26 26 # $Id$ 27 # Various improvements and bugfixes 28 # 29 # 3629 2018-12-13 12:18:54Z maronga 27 30 # Added canopy generator calls. Some improvements 28 31 # … … 72 75 73 76 # Definition of settings 74 global settings_filename_out 77 75 78 global settings_bridge_width 76 79 global settings_lai_roof_intensive … … 100 103 global global_site 101 104 global global_source 102 global global_version 105 106 global path_out 107 global filename_out 108 global version_out 103 109 104 110 … … 158 164 global zt_min 159 165 160 settings_filename_out = "default"161 166 settings_bridge_width = 3.0 162 167 settings_lai_roof_intensive = 0.5 … … 185 190 global_site = "" 186 191 global_source = "" 187 global_version = 1 188 192 193 path_out = "" 194 version_out = 1 195 filename_out = "default" 196 189 197 domain_names = [] 190 198 domain_px = [] … … 260 268 global_site = config.get(read_tmp, 'site') 261 269 global_source = config.get(read_tmp, 'source') 262 global_version = float(config.get(read_tmp, 'version')) 270 263 271 264 272 if ( read_tmp == 'settings' ): 265 settings_filename_out = config.get(read_tmp, 'filename_out')266 273 settings_lai_roof_intensive = config.get(read_tmp, 'lai_roof_intensive') 267 274 settings_lai_roof_extensive = config.get(read_tmp, 'lai_roof_extensive') … … 273 280 settings_lai_alpha = float(config.get(read_tmp, 'lai_alpha')) 274 281 settings_lai_beta = float(config.get(read_tmp, 'lai_beta')) 282 283 if ( read_tmp == 'output' ): 284 path_out = config.get(read_tmp, 'path') 285 filename_out = config.get(read_tmp, 'file_out') 286 version_out = float(config.get(read_tmp, 'version')) 275 287 276 288 if ( read_tmp.split("_")[0] == 'domain' ): … … 322 334 input_file_street_crossings.append(config.get(read_tmp, 'path') + "/" + config.get(read_tmp, 'file_street_crossings')) 323 335 input_file_patch_height.append(config.get(read_tmp, 'path') + "/" + config.get(read_tmp, 'file_patch_height')) 324 input_file_tree_crown_diameter.append(config.get(read_tmp, 'path') + "/" + config.get(read_tmp, 'file_tree_crown_diameter')) 336 337 tmp = config.get(read_tmp, 'file_tree_crown_diameter') 338 if tmp is not None: 339 input_file_tree_crown_diameter.append(config.get(read_tmp, 'path') + "/" + tmp) 340 else: 341 input_file_tree_crown_diameter.append(None) 325 342 input_file_tree_height.append(config.get(read_tmp, 'path') + "/" + config.get(read_tmp, 'file_tree_height')) 326 343 input_file_tree_trunk_diameter.append(config.get(read_tmp, 'path') + "/" + config.get(read_tmp, 'file_tree_trunk_diameter')) … … 433 450 # Calculate indices and input files 434 451 ii.append(input_px.index(domain_px[i])) 435 filename.append( settings_filename_out + "_" + domain_names[i])452 filename.append(path_out + "/" + filename_out + "_" + domain_names[i]) 436 453 if domain_parent[i] is not None: 437 454 ii_parent.append(domain_names.index(domain_parent[i])) … … 447 464 # Create NetCDF output file and set global attributes 448 465 nc_create_file(filename[i]) 449 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, global_version)466 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) 450 467 451 468 … … 468 485 del zt_all[:] 469 486 487 print( "Shift terrain height by -" + str(zt_min)) 470 488 for i in range(0,ndomains): 471 489 … … 475 493 y = nc_read_from_file_1d(input_file_y[ii[i]], "y", domain_y0[i], domain_y1[i]) 476 494 477 print( "Shift terrain height by -" + str(zt_min))478 495 zt = zt - zt_min 496 497 nc_write_global_attribute(filename[i], 'origin_z', float(zt_min)) 479 498 480 499 # If necessary, interpolate parent domain terrain height on child domain grid and blend the two … … 494 513 495 514 # Interpolate array and bring to PALM grid of child domain 515 496 516 zt_ip = interpolate_2d(zt_parent,tmp_x,tmp_y,x,y) 497 517 zt_ip = bring_to_palm_grid(zt_ip,x,y,domain_dz[ii_parent[i]]) … … 580 600 581 601 building_type = nc_read_from_file_2d(input_file_building_type[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 582 building_type[building_type == 255] = fillvalues["building_type"]602 building_type[building_type >= 254] = fillvalues["building_type"] 583 603 building_type = np.where(building_type < 1,defaultvalues["building_type"],building_type) 584 604 … … 594 614 building_type = np.where((building_type == fillvalues["building_type"]) & (buildings_2d != fillvalues["buildings_2d"]),defaultvalues["building_type"],building_type) 595 615 print("Data check #2 " + str(check_arrays_2(buildings_2d,building_type,fillvalues["buildings_2d"],fillvalues["building_type"]))) 616 596 617 597 618 nc_write_to_file_2d(filename[i], 'buildings_2d', buildings_2d, datatypes["buildings_2d"],'y','x',fillvalues["buildings_2d"]) … … 606 627 nc_write_attribute(filename[i], 'building_id', 'long_name', 'building id') 607 628 nc_write_attribute(filename[i], 'building_id', 'units', '') 608 nc_write_attribute(filename[i], 'building_id', 'res _orig', domain_px[i])629 nc_write_attribute(filename[i], 'building_id', 'res _orig', domain_px[i]) 609 630 nc_write_attribute(filename[i], 'building_id', 'coordinates', 'E_UTM N_UTM lon lat') 610 631 nc_write_attribute(filename[i], 'building_id', 'grid_mapping', 'E_UTM N_UTM lon lat') … … 616 637 nc_write_attribute(filename[i], 'building_type', 'coordinates', 'E_UTM N_UTM lon lat') 617 638 nc_write_attribute(filename[i], 'building_type', 'grid_mapping', 'E_UTM N_UTM lon lat') 639 640 print("out_1: " + str(np.any(building_type == -2))) 618 641 619 642 del buildings_2d … … 705 728 # #6 Remove water for pixels with buildings 706 729 water_type = np.where((water_type != fillvalues["water_type"]) & (building_type != fillvalues["building_type"]),fillvalues["water_type"],water_type) 707 708 709 # #7 to be removed: set default soil type everywhere 710 soil_type = np.where((vegetation_type != fillvalues["vegetation_type"]) | (pavement_type != fillvalues["pavement_type"]),defaultvalues["soil_type"],fillvalues["soil_type"]) 711 730 731 732 # Correct vegetation_type when a vegetation height is available and is indicative of low vegeetation 733 vegetation_height = nc_read_from_file_2d(input_file_vegetation_height[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 734 735 vegetation_type = np.where((vegetation_height != fillvalues["vegetation_height"]) & (vegetation_height == 0.0) & ((vegetation_type == 4) | (vegetation_type == 5) | (vegetation_type == 6) |(vegetation_type == 7) | (vegetation_type == 17) | (vegetation_type == 18)), 3, vegetation_type) 736 vegetation_height = np.where((vegetation_height != fillvalues["vegetation_height"]) & (vegetation_height == 0.0) & ((vegetation_type == 4) | (vegetation_type == 5) | (vegetation_type == 6) |(vegetation_type == 7) | (vegetation_type == 17) | (vegetation_type == 18)), fillvalues["vegetation_height"],vegetation_height) 712 737 713 738 # Check for consistency and fill empty fields with default vegetation type … … 717 742 vegetation_type = np.where(consistency_array == 0,defaultvalues["vegetation_type"],vegetation_type) 718 743 consistency_array, test = check_consistency_4(vegetation_type,building_type,pavement_type,water_type,fillvalues["vegetation_type"],fillvalues["building_type"],fillvalues["pavement_type"],fillvalues["water_type"]) 719 744 745 # #7 to be removed: set default soil type everywhere 746 soil_type = np.where((vegetation_type != fillvalues["vegetation_type"]) | (pavement_type != fillvalues["pavement_type"]),defaultvalues["soil_type"],fillvalues["soil_type"]) 747 748 749 # Check for consistency and fill empty fields with default vegetation type 750 consistency_array, test = check_consistency_3(vegetation_type,pavement_type,soil_type,fillvalues["vegetation_type"],fillvalues["pavement_type"],fillvalues["soil_type"]) 751 720 752 # Create surface_fraction array 721 753 x = nc_read_from_file_2d_all(filename[i], 'x') … … 734 766 nc_write_attribute(filename[i], 'surface_fraction', 'res_orig', domain_px[i]) 735 767 del surface_fraction 736 737 738 # Correct vegetation_type when a vegetation height is available and is indicative of low vegeetation739 vegetation_height = nc_read_from_file_2d(input_file_vegetation_height[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i])740 741 vegetation_type = np.where((vegetation_height != fillvalues["vegetation_height"]) & (vegetation_height == 0.0) & ((vegetation_type == 4) | (vegetation_type == 5) | (vegetation_type == 6) |(vegetation_type == 7) | (vegetation_type == 17) | (vegetation_type == 18)), 3, vegetation_type)742 vegetation_height = np.where((vegetation_height != fillvalues["vegetation_height"]) & (vegetation_height == 0.0) & ((vegetation_type == 4) | (vegetation_type == 5) | (vegetation_type == 6) |(vegetation_type == 7) | (vegetation_type == 17) | (vegetation_type == 18)), fillvalues["vegetation_height"],vegetation_height)743 744 768 745 769 nc_write_to_file_2d(filename[i], 'vegetation_type', vegetation_type, datatypes["vegetation_type"],'y','x',fillvalues["vegetation_type"]) … … 779 803 780 804 # pixels with bridges get building_type = 7 = bridge. This does not change the _type setting for the under-bridge 781 # area 805 # area NOTE: when bridges are present the consistency check will fail at the moment 782 806 if domain_3d[i]: 783 807 if np.any(building_type != fillvalues["building_type"]): … … 853 877 # Read tree data and create LAD and BAD arrays using the canopy generator 854 878 for i in range(0,ndomains): 879 lai = nc_read_from_file_2d(input_file_lai[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 880 881 vegetation_type = nc_read_from_file_2d_all(filename[i], 'vegetation_type') 882 883 lai = np.where(vegetation_type == fillvalues["vegetation_type"],fillvalues["vegetation_pars"],lai) 884 885 886 x = nc_read_from_file_2d_all(filename[i], 'x') 887 y = nc_read_from_file_2d_all(filename[i], 'y') 888 nvegetation_pars = np.arange(0,12) 889 vegetation_pars = np.ones((len(nvegetation_pars),len(y),len(x))) 890 vegetation_pars[:,:,:] = fillvalues["vegetation_pars"] 891 892 vegetation_pars[1,:,:] = lai 893 894 895 # Write out first version of LAI. Will later be overwritten. 896 nc_write_dimension(filename[i], 'nvegetation_pars', nvegetation_pars, datatypes["nvegetation_pars"]) 897 nc_write_to_file_3d(filename[i], 'vegetation_pars', vegetation_pars, datatypes["vegetation_pars"],'nvegetation_pars','y','x',fillvalues["vegetation_pars"]) 898 nc_write_attribute(filename[i], 'vegetation_pars', 'long_name', 'vegetation_pars') 899 nc_write_attribute(filename[i], 'vegetation_pars', 'units', '') 900 nc_write_attribute(filename[i], 'vegetation_pars', 'res_orig', domain_px[i]) 901 nc_write_attribute(filename[i], 'vegetation_pars', 'coordinates', 'E_UTM N_UTM lon lat') 902 nc_write_attribute(filename[i], 'vegetation_pars', 'grid_mapping', 'E_UTM N_UTM lon lat') 903 904 del lai, vegetation_pars, vegetation_type 905 906 # Read tree data and create LAD and BAD arrays using the canopy generator 907 for i in range(0,ndomains): 855 908 if domain_street_trees[i]: 856 lai = nc_read_from_file_2d(input_file_lai[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 857 858 909 910 vegetation_pars = nc_read_from_file_2d_all(filename[i], 'vegetation_pars') 911 912 lai = np.copy(vegetation_pars[1,:,:]) 913 914 x = nc_read_from_file_2d_all(filename[i], 'x') 915 y = nc_read_from_file_2d_all(filename[i], 'y') 916 859 917 # Save lai data as default for low and high vegetation 860 918 lai_low = lai 861 919 lai_high = lai 862 863 x = nc_read_from_file_2d_all(filename[i], 'x') 864 y = nc_read_from_file_2d_all(filename[i], 'y') 865 nvegetation_pars = np.arange(0,11) 866 vegetation_pars = np.ones((len(nvegetation_pars),len(y),len(x))) 867 vegetation_pars[:,:,:] = fillvalues["vegetation_pars"] 868 869 vegetation_pars[1,:,:] = lai 870 871 872 # Write out first version of LAI. Will later be overwritten. 873 nc_write_dimension(filename[i], 'nvegetation_pars', nvegetation_pars, datatypes["nvegetation_pars"]) 874 nc_write_to_file_3d(filename[i], 'vegetation_pars', vegetation_pars, datatypes["vegetation_pars"],'nvegetation_pars','y','x',fillvalues["vegetation_pars"]) 875 nc_write_attribute(filename[i], 'vegetation_pars', 'long_name', 'vegetation_pars') 876 nc_write_attribute(filename[i], 'vegetation_pars', 'units', '') 877 nc_write_attribute(filename[i], 'vegetation_pars', 'res_orig', domain_px[i]) 878 nc_write_attribute(filename[i], 'vegetation_pars', 'coordinates', 'E_UTM N_UTM lon lat') 879 nc_write_attribute(filename[i], 'vegetation_pars', 'grid_mapping', 'E_UTM N_UTM lon lat') 880 881 920 882 921 # Read all tree parameters from file 883 922 tree_height = nc_read_from_file_2d(input_file_tree_height[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 884 tree_crown_diameter = nc_read_from_file_2d(input_file_tree_crown_diameter[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 923 924 if (input_file_tree_crown_diameter[ii[i]] is not None): 925 tree_crown_diameter = nc_read_from_file_2d(input_file_tree_crown_diameter[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 926 tree_crown_diameter = np.where( (tree_crown_diameter == 0.0) | (tree_crown_diameter == -1.0) ,fillvalues["tree_data"],tree_crown_diameter) 927 else: 928 tree_crown_diameter = np.ones((len(y),len(x))) 929 tree_crown_diameter[:,:] = fillvalues["tree_data"] 930 931 885 932 tree_trunk_diameter = nc_read_from_file_2d(input_file_tree_trunk_diameter[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 886 933 tree_type = nc_read_from_file_2d(input_file_tree_type[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) … … 889 936 # Remove missing values from the data. Reasonable values will be set by the tree generator 890 937 tree_height = np.where( (tree_height == 0.0) | (tree_height == -1.0) ,fillvalues["tree_data"],tree_height) 891 tree_crown_diameter = np.where( (tree_crown_diameter == 0.0) | (tree_crown_diameter == -1.0) ,fillvalues["tree_data"],tree_crown_diameter)892 938 tree_trunk_diameter = np.where( (tree_trunk_diameter == 0.0) | (tree_trunk_diameter == -1.0) ,fillvalues["tree_data"],tree_trunk_diameter) 893 939 tree_type = np.where( (tree_type == 0.0) | (tree_type == -1.0) ,fillvalues["tree_data"],tree_type) … … 907 953 # For zero-height patches, set vegetation_type to short grass and remove these pixels from the patch height array 908 954 vegetation_type = np.where( (patch_height == 0.0) & ( (vegetation_type == 4) | (vegetation_type == 5) | (vegetation_type == 6) |(vegetation_type == 7) | (vegetation_type == 17) | (vegetation_type == 18) ),3,vegetation_type) 909 patch_type = np.where( (patch_height == 0.0) & ( (vegetation_type == 4) | (vegetation_type == 5) | (vegetation_type == 6) |(vegetation_type == 7) | (vegetation_type == 17) | (vegetation_type == 18) ),fillvalues["tree_data"],patch_height) 910 nc_overwrite_to_file_2d(filename[i], 'vegetation_type', vegetation_type)955 patch_type = np.where( (patch_height == 0.0) & ( (vegetation_type == 4) | (vegetation_type == 5) | (vegetation_type == 6) |(vegetation_type == 7) | (vegetation_type == 17) | (vegetation_type == 18) ),fillvalues["tree_data"],patch_height) 956 911 957 912 958 max_tree_height = max(tree_height.flatten()) … … 914 960 915 961 if ( (max_tree_height != fillvalues["tree_data"]) | (max_patch_height == fillvalues["tree_data"]) ): 916 962 917 963 lad, bad, tree_ids, zlad = generate_single_tree_lad(x,y,domain_dz[i],max_tree_height,max_patch_height,tree_type,tree_height,tree_crown_diameter,tree_trunk_diameter,lai,settings_season,fillvalues["tree_data"]) 918 964 … … 925 971 bad[k,:,:] = np.where(buildings_2d == fillvalues["buildings_2d"],bad[k,:,:],fillvalues["tree_data"]) 926 972 tree_ids[k,:,:] = np.where(buildings_2d == fillvalues["buildings_2d"],tree_ids[k,:,:],fillvalues["tree_data"]) 927 973 974 del buildings_2d 928 975 929 976 nc_write_dimension(filename[i], 'zlad', zlad, datatypes["tree_data"]) … … 949 996 nc_write_attribute(filename[i], 'tree_id', 'grid_mapping', 'E_UTM N_UTM lon lat') 950 997 951 del buildings_2d,lai, lad, bad, tree_ids, zlad952 953 del vegetation_pars, tree_height, tree_crown_diameter, tree_trunk_diameter, tree_type, patch_height, vegetation_type,x, y998 del lai, lad, bad, tree_ids, zlad 999 1000 del vegetation_pars, tree_height, tree_crown_diameter, tree_trunk_diameter, tree_type, patch_height, x, y 954 1001 955 1002 … … 961 1008 vegetation_type = nc_read_from_file_2d_all(filename[i], 'vegetation_type') 962 1009 lad = nc_read_from_file_3d_all(filename[i], 'lad') 1010 zlad = nc_read_from_file_1d_all(filename[i], 'zlad') 963 1011 patch_height = nc_read_from_file_2d(input_file_patch_height[ii[i]], 'Band1', domain_x0[i], domain_x1[i], domain_y0[i], domain_y1[i]) 964 1012 vegetation_pars = nc_read_from_file_3d_all(filename[i], 'vegetation_pars') 965 1013 lai = vegetation_pars[1,:,:] 966 1014 967 # For all pixels where the LAD array does not contains a street tree and for which a high vegetation was set and for which a patch height is either missing of larger than one grid spacing 968 # the lai_high is reset to a low vegetation value969 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])) ), settings_lai_low_default,fillvalues["tree_data"])970 971 # For all pixels where lai_high is set but no lai is available, set the default high vegetation lai TODO: check if this makes sense bacauce lai_high = lai anway?!972 lai_high = np.where( (lai_high != fillvalues["tree_data"]) & (lai == fillvalues["tree_data"]), settings_lai_high_default, lai _high)973 974 # Define a patch height where ever it is missing, but where a high vegetation LAI was set1015 1016 # 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 1017 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"]) 1018 1019 # Now, assign either the default LAI for high vegetation or the value stored in the LAI array. 1020 lai_high = np.where( (lai_high != fillvalues["tree_data"]) & (lai == fillvalues["tree_data"]), settings_lai_high_default, lai) 1021 1022 # Define a patch height wherever it is missing, but where a high vegetation LAI was set 975 1023 patch_height = np.where ( (lai_high != fillvalues["tree_data"]) & (patch_height == fillvalues["tree_data"]), settings_patch_height_default, patch_height) 976 1024 … … 978 1026 patch_height = np.where ( (lad[0,:,:] != fillvalues["tree_data"]), fillvalues["tree_data"], patch_height) 979 1027 1028 # Remove patch heights that have no lai_high value 1029 patch_height = np.where ( (lai_high == fillvalues["tree_data"]), fillvalues["tree_data"], patch_height) 1030 980 1031 # For missing LAI values, set either the high vegetation default or the low vegetation default 981 lai_high = np.where( (patch_height > 2.0) & (lai_high == fillvalues["tree_data"]),settings_lai_high_default,lai_high) 982 lai_high = np.where( (patch_height <= 2.0) & (lai_high == fillvalues["tree_data"]),settings_lai_low_default,lai_high) 983 984 1032 lai_high = np.where( (patch_height > 2.0) & (patch_height != fillvalues["tree_data"]) & (lai_high == fillvalues["tree_data"]),settings_lai_high_default,lai_high) 1033 lai_high = np.where( (patch_height <= 2.0) & (patch_height != fillvalues["tree_data"]) & (lai_high == fillvalues["tree_data"]),settings_lai_low_default,lai_high) 1034 985 1035 if ( max(patch_height.flatten()) >= (2.0 * domain_dz[i]) ): 986 1036 print(" start calculating LAD (this might take some time)") 987 lad_patch, patch_nz, status = process_patch(domain_dz[i],patch_height, lai_high,settings_lai_alpha,settings_lai_beta)1037 lad_patch, patch_nz, status = process_patch(domain_dz[i],patch_height,max(zlad),lai_high,settings_lai_alpha,settings_lai_beta) 988 1038 989 1039 lad[0:patch_nz+1,:,:] = np.where( (lad[0:patch_nz+1,:,:] == fillvalues["tree_data"]),lad_patch[0:patch_nz+1,:,:], lad[0:patch_nz+1,:,:] ) … … 991 1041 # Remove high vegetation wherever it is replaced by a leaf area density. This should effectively remove all high vegetation pixels 992 1042 vegetation_type = np.where((lad[0,:,:] != fillvalues["tree_data"]) & (vegetation_type != fillvalues["vegetation_type"]),3,vegetation_type) 993 994 1043 995 1044 # If desired, remove all high vegetation. TODO: check if this is still necessary 996 1045 if domain_high_vegetation[i]: … … 998 1047 999 1048 1000 # Remove LAI from pixels where a LAD was set1001 lai_low = np.where( (lad[0,:,:] == fillvalues["tree_data"]), lai, fillvalues["tree_data"])1049 # Set default low LAI for pixels with an LAD (short grass below trees) 1050 lai_low = np.where( (lad[0,:,:] == fillvalues["tree_data"]), lai, settings_lai_low_default) 1002 1051 1003 # Fill low vegetation pixels without LAI set with default value 1004 lai_low = np.where( (lai == fillvalues["tree_data"]) & (vegetation_type != fillvalues["vegetation_type"] ), settings_lai_low_default, lai) 1005 1006 1052 # Fill low vegetation pixels without LAI set or with LAI = 0 with default value 1053 lai_low = np.where( ( (lai_low == fillvalues["tree_data"]) | (lai_low == 0.0) ) & (vegetation_type != fillvalues["vegetation_type"] ), settings_lai_low_default, lai_low) 1054 1055 # Remove lai for pixels that have no vegetation_type 1056 lai_low = np.where( vegetation_type != fillvalues["vegetation_type"], lai_low, fillvalues["tree_data"]) 1057 1007 1058 # Overwrite lai in vegetation_parameters 1008 1009 vegetation_pars[1,:,:] = lai_low 1059 vegetation_pars[1,:,:] = np.copy(lai_low) 1010 1060 nc_overwrite_to_file_3d(filename[i], 'vegetation_pars', vegetation_pars) 1011 1061 1012 1062 # Overwrite lad array 1013 1063 nc_overwrite_to_file_3d(filename[i], 'lad', lad) 1014 1015 # Overwrite vegetation_type 1016 nc_overwrite_to_file_2d(filename[i], 'vegetation_type', vegetation_type) 1017 1018 1019 del vegetation_type, lad, lai, patch_height, vegetation_pars 1064 1065 nc_overwrite_to_file_2d(filename[i], 'vegetation_type', vegetation_type) 1066 1067 1068 del vegetation_type, lad, lai, patch_height, vegetation_pars, zlad 1069 1070 # Final consistency check 1071 for i in range(0,ndomains): 1072 vegetation_type = nc_read_from_file_2d_all(filename[i], 'vegetation_type') 1073 pavement_type = nc_read_from_file_2d_all(filename[i], 'pavement_type') 1074 building_type = nc_read_from_file_2d_all(filename[i], 'building_type') 1075 water_type = nc_read_from_file_2d_all(filename[i], 'water_type') 1076 soil_type = nc_read_from_file_2d_all(filename[i], 'soil_type') 1077 1078 # Check for consistency and fill empty fields with default vegetation type 1079 consistency_array, test = check_consistency_4(vegetation_type,building_type,pavement_type,water_type,fillvalues["vegetation_type"],fillvalues["building_type"],fillvalues["pavement_type"],fillvalues["water_type"]) 1080 1081 # Check for consistency and fill empty fields with default vegetation type 1082 consistency_array, test = check_consistency_3(vegetation_type,pavement_type,soil_type,fillvalues["vegetation_type"],fillvalues["pavement_type"],fillvalues["soil_type"]) 1083 1084 surface_fraction = nc_read_from_file_3d_all(filename[i], 'surface_fraction') 1085 surface_fraction[0,:,:] = np.where(vegetation_type != fillvalues["vegetation_type"], 1.0, 0.0) 1086 surface_fraction[1,:,:] = np.where(pavement_type != fillvalues["pavement_type"], 1.0, 0.0) 1087 surface_fraction[2,:,:] = np.where(water_type != fillvalues["water_type"], 1.0, 0.0) 1088 nc_overwrite_to_file_3d(filename[i], 'surface_fraction', surface_fraction) 1089 1090 del vegetation_type, pavement_type, building_type, water_type, soil_type
Note: See TracChangeset
for help on using the changeset viewer.