From 0bd2561c88850c98352e57a1998d81ce12e14737 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Tue, 5 May 2020 23:38:19 +0200 Subject: [PATCH 01/30] back to gcc11 --- drawbicyc/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drawbicyc/CMakeLists.txt b/drawbicyc/CMakeLists.txt index 5014572..5be15e3 100644 --- a/drawbicyc/CMakeLists.txt +++ b/drawbicyc/CMakeLists.txt @@ -46,9 +46,9 @@ foreach(exe drawbicyc plot_series_compare average) $ ) # enabling c++14 - target_compile_features(${exe} PUBLIC cxx_std_14) - # enabling c++11 - # target_compile_features(${exe} PUBLIC cxx_std_11) + #target_compile_features(${exe} PUBLIC cxx_std_14) + #enabling c++11 + target_compile_features(${exe} PUBLIC cxx_std_11) target_link_libraries(${exe} PRIVATE uwlcm::uwlcm_includes) target_link_libraries(${exe} PRIVATE ${HDF5_LIBRARIES}) target_include_directories(${exe} PUBLIC ${HDF5_INCLUDE_DIRS}) From 2d9567dbd6526606643753159ce48278f60f1f66 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 23 Jul 2020 10:32:49 +0200 Subject: [PATCH 02/30] Cloud Top Height --- Matplotlib_common/latex_labels.py | 2 ++ .../Lasher_Trapp_series_comparison.py | 3 +- cases/Lasher_Trapp/plot_ranges.py | 16 +++++++++ drawbicyc/include/drawbicyc/Plotter3d.hpp | 2 +- drawbicyc/include/drawbicyc/PlotterCommon.hpp | 2 +- drawbicyc/include/drawbicyc/PlotterMicro.hpp | 11 +++++- .../drawbicyc/cases/Lasher_Trapp/plots.hpp | 31 ++++++++-------- drawbicyc/include/drawbicyc/plot_series.hpp | 36 ++++++++++++++++++- 8 files changed, 84 insertions(+), 19 deletions(-) diff --git a/Matplotlib_common/latex_labels.py b/Matplotlib_common/latex_labels.py index 11caf22..33ad9d8 100644 --- a/Matplotlib_common/latex_labels.py +++ b/Matplotlib_common/latex_labels.py @@ -3,6 +3,7 @@ "rwp" : 'RWP [g m$^{-2}$]', "surf_precip" : 'Surface precip. [mm/day]', "acc_precip" : 'Accumulated precip. [mm]', + "acc_vol_precip" : 'Accumulated volume precipitation [m^3]', "cl_nc" : '$N_c$ [cm$^{-3}$] (cloudy cells)', "cl_nr" : '$N_{r>25\mu m}$ [cm$^{-3}$]', "cl_gccn_conc" : '$N_{GCCN}$ [cm$^{-3}$] (cloudy cells)', @@ -21,6 +22,7 @@ "er" : 'Entrainment rate [cm s$^{-1}$]', "wvarmax" : 'Max. $w$ variance [m$^{2}$ s$^{-2}$]', "cloud_base" : 'Cloud base height [m]', + "cloud_top_height" : 'Cloud top height [m]', "gccn_rw_cl" : '$$ of GCCN droplets (cloudy cells) [um]', "non_gccn_rw_cl" : '$$ of CCN droplets (cloudy cells) [um]', "clb_bigrain_mean_rd" : '$$ of (r$>$40um) @ clbase [m]', diff --git a/cases/Lasher_Trapp/Lasher_Trapp_series_comparison.py b/cases/Lasher_Trapp/Lasher_Trapp_series_comparison.py index 876bf10..eba3b6d 100644 --- a/cases/Lasher_Trapp/Lasher_Trapp_series_comparison.py +++ b/cases/Lasher_Trapp/Lasher_Trapp_series_comparison.py @@ -12,7 +12,8 @@ # activate latex text rendering rc('text', usetex=True) -Lasher_Trapp_vars = ["lwp", "rwp", "surf_precip", "acc_precip", "cl_nc"] +##Lasher_Trapp_vars = ["lwp", "rwp", "surf_precip", "acc_precip", "cl_nc"] +Lasher_Trapp_vars = ["RH_max", "cloud_top_height", "surf_precip", "acc_precip", "acc_vol_precip"] # init the plot nplotx = 2 diff --git a/cases/Lasher_Trapp/plot_ranges.py b/cases/Lasher_Trapp/plot_ranges.py index 6dc3ccc..aa8f136 100644 --- a/cases/Lasher_Trapp/plot_ranges.py +++ b/cases/Lasher_Trapp/plot_ranges.py @@ -10,6 +10,9 @@ "sat_RH" : "linear", "rad_flx" : "linear", "lwp" : "linear", + "RH_max" : "linear", + "cloud_top_height" : "linear", + "acc_vol_precip" : "linear", "rwp" : "linear", "er" : "linear", "wvarmax" : "linear", @@ -34,6 +37,9 @@ "sat_RH" : "linear", "rad_flx" : "linear", "lwp" : "linear", + "RH_max" : "linear", + "cloud_top_height" : "linear", + "acc_vol_precip" : "linear", "rwp" : "linear", "er" : "linear", "wvarmax" : "linear", @@ -56,6 +62,8 @@ "wvar" : None, "w3rd" : None, "sat_RH" : None, + ##"RH_max" : None, + ##"cloud_top_height" : None, "rad_flx" : None, "gccn_rw_cl" : (0,90), "non_gccn_rw_cl" : (0,12), @@ -72,6 +80,8 @@ "w3rd" : (0,3000), "sat_RH" : (0,3000), "rad_flx" : (0,3000), + "RH_max" : (0,3000), + "cloud_top_height" : (0,3000), "gccn_rw_cl" : (0,3000), "non_gccn_rw_cl" : (0,3000), "base_prflux_vs_clhght" : (0,2500) @@ -81,11 +91,14 @@ "clfrac" : None, "cl_nc" : None, "lwp" : None, + "RH_max" : None, + "cloud_top_height" : None, "rwp" : None, "er" : None, "wvarmax" : None, "surf_precip" : None, "acc_precip" : None, + "acc_vol_precip" : None, "cl_gccn_conc" : None, "cloud_base" : None } @@ -94,6 +107,9 @@ "clfrac" : None, "cl_nc" : None, "lwp" : None, + "RH_max" : None, + "cloud_top_height" : None, + "acc_vol_precip" : None, "rwp" : None, "er" : None, "wvarmax" : None, diff --git a/drawbicyc/include/drawbicyc/Plotter3d.hpp b/drawbicyc/include/drawbicyc/Plotter3d.hpp index b850f9c..557fc31 100644 --- a/drawbicyc/include/drawbicyc/Plotter3d.hpp +++ b/drawbicyc/include/drawbicyc/Plotter3d.hpp @@ -189,7 +189,7 @@ class Plotter_t<3> : public PlotterCommon this->map["dz"] = tmp(0,0,1) - tmp(0,0,0); this->CellVol = this->map["dx"] * this->map["dy"] * this->map["dz"]; this->DomainSurf = this->map["dx"] * this->map["dy"] * this->map["x"] * this->map["y"]; - + this->DomainVolume = this->map["dx"] * this->map["dy"] * this->map["dz"] * this->map["x"] * this->map["y"] * this->map["z"]; // other dataset are of the size x*z, resize tmp tmp.resize(n[0]-1, n[1]-1, n[2]-1); diff --git a/drawbicyc/include/drawbicyc/PlotterCommon.hpp b/drawbicyc/include/drawbicyc/PlotterCommon.hpp index 01c0555..6d9ace9 100644 --- a/drawbicyc/include/drawbicyc/PlotterCommon.hpp +++ b/drawbicyc/include/drawbicyc/PlotterCommon.hpp @@ -10,7 +10,7 @@ class PlotterCommon const string file; std::map map; blitz::Array timesteps, p_e; - double CellVol, DomainSurf; + double CellVol, DomainSurf, DomainVolume; protected: H5::H5File h5f; diff --git a/drawbicyc/include/drawbicyc/PlotterMicro.hpp b/drawbicyc/include/drawbicyc/PlotterMicro.hpp index 811a7f6..ace3e9c 100644 --- a/drawbicyc/include/drawbicyc/PlotterMicro.hpp +++ b/drawbicyc/include/drawbicyc/PlotterMicro.hpp @@ -307,7 +307,16 @@ class PlotterMicro_t : public Plotter_t / 1e3 // to m^3 of water * 1e3; // to mm } - + // accumulated volume precipitation [m^3] + double calc_acc_volume_precip(double prec_vol) + { + if(this->micro == "lgrngn") + return prec_vol / this->DomainVolume; + if(this->micro == "blk_1m") + return prec_vol * this->map["dt"] + / (this->map["x"] * this->map["y"] * this->map["z"]) + / 1e3; // to m^3 of water + } //ctor PlotterMicro_t(const string &file, const string µ): parent_t(file), diff --git a/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp b/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp index 5ce831f..c444706 100644 --- a/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp @@ -2,22 +2,25 @@ const std::vector series_Lasher_Trapp({ - "clfrac", - "lwp", - "rwp", - "surf_precip", - "acc_precip", - "cl_nc", + //"clfrac", + //"lwp", + //"rwp", + //"surf_precip", + //"acc_precip", + //"acc_vol_precip", + //"cl_nc", "cloud_base", - "surf_flux_latent", - "surf_flux_sensible", - "sd_conc_avg", + //"RH_max", + "cloud_top_height", + //"surf_flux_latent", + //"surf_flux_sensible", + //"sd_conc_avg", //"mass_dry", - "cl_gccn_conc", - "gccn_conc", - "cl_non_gccn_conc", - "non_gccn_conc", - "cl_gccn_to_non_gccn_conc_ratio" + //"cl_gccn_conc", + //"gccn_conc", + //"cl_non_gccn_conc", + //"non_gccn_conc", + //"cl_gccn_to_non_gccn_conc_ratio" //, "cl_gccn_meanr" //,"cl_avg_cloud_rad" // "sd_conc_std_dev", diff --git a/drawbicyc/include/drawbicyc/plot_series.hpp b/drawbicyc/include/drawbicyc/plot_series.hpp index 6f9172c..a24ad3d 100644 --- a/drawbicyc/include/drawbicyc/plot_series.hpp +++ b/drawbicyc/include/drawbicyc/plot_series.hpp @@ -82,7 +82,7 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) for (int at = first_timestep; at <= last_timestep; ++at) // TODO: mark what time does it actually mean! { - res_pos(at) = at * n["outfreq"] * n["dt"] / 3600.; + res_pos(at) = at * n["outfreq"] * n["dt"] /3600.; // store accumulated precip volume prec_vol_prev = prec_vol; try @@ -150,6 +150,27 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) } catch(...) {;} } + // cloud top height + else if (plt =="cloud_top_height") + { + try + { + // cloud fraction (cloudy if ql > 1e-4)) + auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]); + typename Plotter_t::arr_t snap(tmp); + snap = iscloudy_rc(snap); + plotter.k_i = blitz::last((snap == 1), plotter.LastIndex); + auto cloudy_column = plotter.k_i.copy(); + cloudy_column = blitz::sum(snap, plotter.LastIndex); + cloudy_column = where(cloudy_column > 0, 1, 0); + plotter.k_i = where(cloudy_column == 0, 0, plotter.k_i); + if(blitz::sum(cloudy_column) > 0) + res_prof(at) = blitz::max(plotter.k_i)*n["dz"]; + else + res_prof(at) = 0; + } + catch(...) {;} + } // average sd_conc else if (plt == "sd_conc") { @@ -572,6 +593,15 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) } catch(...) {;} } + else if (plt == "acc_vol_precip") + { + // accumulated volume precipitation[m^3] + try + { + res_prof(at) = plotter.calc_acc_volume_precip(prec_vol); + } + catch(...) {;} + } else if (plt == "lwp") { // liquid water path @@ -1187,6 +1217,10 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { res_pos *= 60.; } + else if (plt == "cloud_top_height") + { + res_pos *= 60.; + } else if (plt == "tot_tke" || plt == "tot_tke_nowall" || plt == "sgs_tke" || plt == "uw_resolved_tke") { res_pos *= 60.; From a89401014752bc9c8f71b3f586053eecf1077b20 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 23 Jul 2020 10:54:20 +0200 Subject: [PATCH 03/30] Python3 update --- Matplotlib_common/read_UWLCM_arrays.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Matplotlib_common/read_UWLCM_arrays.py b/Matplotlib_common/read_UWLCM_arrays.py index 5c828cf..29b76b4 100644 --- a/Matplotlib_common/read_UWLCM_arrays.py +++ b/Matplotlib_common/read_UWLCM_arrays.py @@ -7,7 +7,7 @@ def read_my_array(file_obj): line = line.split(" ") del line[0] del line[len(line)-1] - arr = map(float,line) + arr =list( map(float,line)) return np.array(arr), arr_name def read_my_var(file_obj, var_name): From bdfc97affc4c29fce9696ec9743949392473892e Mon Sep 17 00:00:00 2001 From: ryba183 Date: Wed, 5 Aug 2020 20:41:09 +0200 Subject: [PATCH 04/30] Lasher_Trapp_ICMW --- Matplotlib_common/latex_labels.py | 9 +- Matplotlib_common/plot_profs.py | 3 +- Matplotlib_common/plot_series.py | 6 +- cases/Lasher_Trapp/plot_ranges.py | 6 +- .../drawbicyc/cases/Lasher_Trapp/plots.hpp | 19 ++-- drawbicyc/include/drawbicyc/plot_prof.hpp | 3 +- drawbicyc/include/drawbicyc/plot_series.hpp | 105 ++++++++++++++++-- 7 files changed, 130 insertions(+), 21 deletions(-) diff --git a/Matplotlib_common/latex_labels.py b/Matplotlib_common/latex_labels.py index 33ad9d8..dc1b88a 100644 --- a/Matplotlib_common/latex_labels.py +++ b/Matplotlib_common/latex_labels.py @@ -1,6 +1,10 @@ var_labels = { - "lwp" : 'LWP [g m$^{-2}$]', - "rwp" : 'RWP [g m$^{-2}$]', + "lwp" : 'LWP [kg m$^{-2}$]', + "rwp" : 'RWP [kg m$^{-2}$]', + "cwp" : 'CWP [kg m$^{-2}$]', + "lwm" : 'LWM [kg]', + "cwm" : 'CWM [kg]', + "rwm" : 'RWM [kg]', "surf_precip" : 'Surface precip. [mm/day]', "acc_precip" : 'Accumulated precip. [mm]', "acc_vol_precip" : 'Accumulated volume precipitation [m^3]', @@ -23,6 +27,7 @@ "wvarmax" : 'Max. $w$ variance [m$^{2}$ s$^{-2}$]', "cloud_base" : 'Cloud base height [m]', "cloud_top_height" : 'Cloud top height [m]', + "total_droplets_number" : 'Total Number of Cloud and Rain Droplets [#]', "gccn_rw_cl" : '$$ of GCCN droplets (cloudy cells) [um]', "non_gccn_rw_cl" : '$$ of CCN droplets (cloudy cells) [um]', "clb_bigrain_mean_rd" : '$$ of (r$>$40um) @ clbase [m]', diff --git a/Matplotlib_common/plot_profs.py b/Matplotlib_common/plot_profs.py index d2c0a0c..c77b629 100644 --- a/Matplotlib_common/plot_profs.py +++ b/Matplotlib_common/plot_profs.py @@ -19,7 +19,8 @@ def plot_profiles(var_list, plot_iter, nplotx, nploty, axarr, xscaledict, yscale print file_name # try: profiles_file = open(file_name, "r") - my_pos = read_my_var(profiles_file, "position") + ## my_pos = read_my_var(profiles_file, "position") + my_pos = read_my_var(profiles_file, "time") my_res = read_my_var(profiles_file, var) profiles_file.close() diff --git a/Matplotlib_common/plot_series.py b/Matplotlib_common/plot_series.py index f7580dc..946c645 100644 --- a/Matplotlib_common/plot_series.py +++ b/Matplotlib_common/plot_series.py @@ -17,11 +17,13 @@ def plot_series(var_list, plot_iter, nplotx, nploty, axarr, xscaledict, yscaledi for file_name in file_names: print file_name, var series_file = open(file_name, "r") - my_times = read_my_var(series_file, "position") + #my_times = read_my_var(series_file, "position") + my_time = read_my_var(series_file, "time") my_res = read_my_var(series_file, var) # rescale time to hours - my_times = my_times / 3600. + #my_times = my_times / 3600. ##H + my_times = my__times / 60. ##Minutes series_file.close() diff --git a/cases/Lasher_Trapp/plot_ranges.py b/cases/Lasher_Trapp/plot_ranges.py index aa8f136..49a74f1 100644 --- a/cases/Lasher_Trapp/plot_ranges.py +++ b/cases/Lasher_Trapp/plot_ranges.py @@ -12,6 +12,7 @@ "lwp" : "linear", "RH_max" : "linear", "cloud_top_height" : "linear", + "total_droplets_number" : "linear", "acc_vol_precip" : "linear", "rwp" : "linear", "er" : "linear", @@ -39,6 +40,7 @@ "lwp" : "linear", "RH_max" : "linear", "cloud_top_height" : "linear", + "total_droplets_number" : "linear", "acc_vol_precip" : "linear", "rwp" : "linear", "er" : "linear", @@ -92,7 +94,8 @@ "cl_nc" : None, "lwp" : None, "RH_max" : None, - "cloud_top_height" : None, + "cloud_top_height" : None, + "total_droplets_number" : None, "rwp" : None, "er" : None, "wvarmax" : None, @@ -109,6 +112,7 @@ "lwp" : None, "RH_max" : None, "cloud_top_height" : None, + "total_droplets_number" : None, "acc_vol_precip" : None, "rwp" : None, "er" : None, diff --git a/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp b/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp index c444706..42e7900 100644 --- a/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp @@ -3,15 +3,20 @@ const std::vector series_Lasher_Trapp({ //"clfrac", - //"lwp", - //"rwp", - //"surf_precip", - //"acc_precip", - //"acc_vol_precip", + "lwp", + "rwp", + "cwp", + "lwm", + "cwm", + "rwm", + "surf_precip", + "acc_precip", + "acc_vol_precip", //"cl_nc", "cloud_base", - //"RH_max", + "RH_max", "cloud_top_height", + "total_droplets_number", //"surf_flux_latent", //"surf_flux_sensible", //"sd_conc_avg", @@ -24,7 +29,7 @@ const std::vector series_Lasher_Trapp({ //, "cl_gccn_meanr" //,"cl_avg_cloud_rad" // "sd_conc_std_dev", - // // "tot_water" + // "tot_water" }); std::vector profs_Lasher_Trapp({ diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index c1b25f9..005a37f 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -785,7 +785,8 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool // res_pos = i * n["dz"] / z_i; if(!res_pos_out_done) { - oprof_file << "position" << endl; + //oprof_file << "position" << endl; + oprof_file << "time" << endl; oprof_file << res_pos; res_pos_out_done = true; } diff --git a/drawbicyc/include/drawbicyc/plot_series.hpp b/drawbicyc/include/drawbicyc/plot_series.hpp index a24ad3d..7c9b30b 100644 --- a/drawbicyc/include/drawbicyc/plot_series.hpp +++ b/drawbicyc/include/drawbicyc/plot_series.hpp @@ -64,7 +64,8 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) com_x_idx(last_timestep - first_timestep + 1); // index of the center of mass cell // save time steps to the series file - oprof_file << "position" << endl; + //oprof_file << "position" << endl; + oprof_file << "time" << endl; oprof_file << plotter.timesteps; @@ -155,10 +156,10 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { try { - // cloud fraction (cloudy if ql > 1e-4)) + // cloud fraction (cloudy if ql > 1e-5)) auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]); typename Plotter_t::arr_t snap(tmp); - snap = iscloudy_rc(snap); + snap = iscloudy_rc_rico(snap); plotter.k_i = blitz::last((snap == 1), plotter.LastIndex); auto cloudy_column = plotter.k_i.copy(); cloudy_column = blitz::sum(snap, plotter.LastIndex); @@ -495,6 +496,24 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) } catch(...){;} } + else if (plt == "total_droplets_number") + { + // Total number of Cloud and Rain Droplets + try + { + // cloud fraction (cloudy if ql > 1e-5)) + auto tmp = plotter.h5load_timestep("cloud_rw_mom0", at *n["outfreq"]); + typename Plotter_t::arr_t snap(tmp); + snap *= rhod * plotter.CellVol; + auto tmp2 = plotter.h5load_timestep("rain_rw_mom0", at *n["outfreq"]); + typename Plotter_t::arr_t snap2(tmp2); + snap2 *= rhod * plotter.CellVol; + auto tmp3 = plotter.h5load_timestep("all_rw_mom0", at *n["outfreq"]); + typename Plotter_t::arr_t snap3(tmp3); + res_prof(at) = blitz::sum(snap3);// + blitz::sum(snap2); + } + catch(...){;} + } else if (plt == "cloud_base") { try @@ -608,9 +627,9 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) try { { - auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]) * 1e3; //g/kg + auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]);// kg/kg * 1e3; //g/kg typename Plotter_t::arr_t snap(tmp); - snap += plotter.h5load_rr_timestep(at * n["outfreq"]) * 1e3; //g/kg + snap += plotter.h5load_rr_timestep(at * n["outfreq"]);// kg/kg * 1e3; //g/kg snap *= rhod; // water per cubic metre (should be wet density...) res_prof(at) = blitz::mean(snap); } @@ -624,12 +643,68 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { { typename Plotter_t::arr_t snap(plotter.h5load_rr_timestep(at * n["outfreq"])); - snap *= rhod * 1e3; // water per cubic metre (should be wet density...) & g/kg + snap *= rhod; //kg/kg * 1e3; // water per cubic metre (should be wet density...) & g/kg res_prof(at) = blitz::mean(snap); } } catch(...) {;} - } + } + else if (plt == "cwp") + { + // cloud water path + try + { + { + typename Plotter_t::arr_t snap(plotter.h5load_rc_timestep(at * n["outfreq"])); + snap *= rhod; //kg/kg *1e3; // water per cubic metre (should be wet density ...) & g/kg + res_prof(at) = blitz::mean(snap); + } + } + catch(...) {;} + } + else if (plt == "lwm") + { + //liquid water mass + try + { + { + auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]); + typename Plotter_t::arr_t snap(tmp); + snap += plotter.h5load_rr_timestep(at * n["outfreq"]); + snap *= rhod; + res_prof(at) = blitz::sum(snap) * plotter.DomainSurf; + } + } + catch(...) {;} + } + else if (plt == "cwm") + { + //cloud water mass + try + { + { + auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]); + typename Plotter_t::arr_t snap(tmp); + snap *= rhod; + res_prof(at) = blitz::sum(snap) * plotter.DomainSurf; + } + } + catch(...) {;} + } + else if (plt == "rwm") + { + //liquid water mass + try + { + { + auto tmp = plotter.h5load_rr_timestep(at * n["outfreq"]); + typename Plotter_t::arr_t snap(tmp); + snap *= rhod; + res_prof(at) = blitz::sum(snap) * plotter.DomainSurf; + } + } + catch(...) {;} + } else if (plt == "surf_flux_latent") { try @@ -1238,6 +1313,22 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller } + else if (plt == "cwp") + { + res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller + } + else if (plt == "lwm") + { + res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller + } + else if (plt == "cwm") + { + res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller + } + else if (plt == "rwm") + { + res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller + } else if (plt == "er") { // central difference, in cm From ed62eef45e9a85c2d74b1b141f913b26cef5a866 Mon Sep 17 00:00:00 2001 From: Piotr <40355493+ryba183@users.noreply.github.com> Date: Thu, 6 Aug 2020 13:45:04 +0200 Subject: [PATCH 05/30] Update latex_labels.py --- Matplotlib_common/latex_labels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Matplotlib_common/latex_labels.py b/Matplotlib_common/latex_labels.py index f2425fe..fb204c1 100644 --- a/Matplotlib_common/latex_labels.py +++ b/Matplotlib_common/latex_labels.py @@ -10,7 +10,7 @@ "sgs_tke_sd" : 'SGS TKE (Super-droplets) [m$^{2}$ s$^{-2}$]', "surf_precip" : 'Surface precip. [mm/day]', "acc_precip" : 'Accumulated precip. [mm]', - "acc_vol_precip" : 'Accumulated volume precipitation [m^3]', + "acc_precip_vol" : 'Accumulated precip. [m^3]', "cl_nc" : '$N_c$ [cm$^{-3}$] (cloudy cells)', "cl_nr" : '$N_{r>25\mu m}$ [cm$^{-3}$]', "cl_gccn_conc" : '$N_{GCCN}$ [cm$^{-3}$] (cloudy cells)', From d0f3ba562c8e49e81dfb41259bce91869ec55e9c Mon Sep 17 00:00:00 2001 From: ryba183 Date: Wed, 12 Aug 2020 18:29:54 +0200 Subject: [PATCH 06/30] looking for error --- Matplotlib_common/latex_labels.py | 2 +- Matplotlib_common/plot_profs.py | 3 +- Matplotlib_common/plot_series.py | 4 +- ...020_cumulus_congestus_series_comparison.py | 74 +++++++++++ .../ICMW2020_cumulus_congestus/plot_ranges.py | 124 ++++++++++++++++++ .../Lasher_Trapp_series_comparison.py | 3 +- cases/Lasher_Trapp/plot_ranges.py | 12 +- drawbicyc/average.cpp | 8 +- drawbicyc/drawbicyc.cpp | 7 +- drawbicyc/include/drawbicyc/Plotter3d.hpp | 2 +- drawbicyc/include/drawbicyc/PlotterMicro.hpp | 4 +- .../ICMW2020_cumulus_congestus/plots.hpp | 56 ++++++++ .../drawbicyc/cases/Lasher_Trapp/plots.hpp | 33 ++--- drawbicyc/include/drawbicyc/plot_prof.hpp | 3 +- drawbicyc/include/drawbicyc/plot_series.hpp | 23 ++-- drawbicyc/include/drawbicyc/plots.hpp | 6 + 16 files changed, 304 insertions(+), 60 deletions(-) create mode 100644 cases/ICMW2020_cumulus_congestus/ICMW2020_cumulus_congestus_series_comparison.py create mode 100644 cases/ICMW2020_cumulus_congestus/plot_ranges.py create mode 100644 drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp diff --git a/Matplotlib_common/latex_labels.py b/Matplotlib_common/latex_labels.py index dc1b88a..a8339c9 100644 --- a/Matplotlib_common/latex_labels.py +++ b/Matplotlib_common/latex_labels.py @@ -7,7 +7,7 @@ "rwm" : 'RWM [kg]', "surf_precip" : 'Surface precip. [mm/day]', "acc_precip" : 'Accumulated precip. [mm]', - "acc_vol_precip" : 'Accumulated volume precipitation [m^3]', + "acc_precip_vol" : 'Accumulated precip. [m^3]', "cl_nc" : '$N_c$ [cm$^{-3}$] (cloudy cells)', "cl_nr" : '$N_{r>25\mu m}$ [cm$^{-3}$]', "cl_gccn_conc" : '$N_{GCCN}$ [cm$^{-3}$] (cloudy cells)', diff --git a/Matplotlib_common/plot_profs.py b/Matplotlib_common/plot_profs.py index c77b629..d2c0a0c 100644 --- a/Matplotlib_common/plot_profs.py +++ b/Matplotlib_common/plot_profs.py @@ -19,8 +19,7 @@ def plot_profiles(var_list, plot_iter, nplotx, nploty, axarr, xscaledict, yscale print file_name # try: profiles_file = open(file_name, "r") - ## my_pos = read_my_var(profiles_file, "position") - my_pos = read_my_var(profiles_file, "time") + my_pos = read_my_var(profiles_file, "position") my_res = read_my_var(profiles_file, var) profiles_file.close() diff --git a/Matplotlib_common/plot_series.py b/Matplotlib_common/plot_series.py index 946c645..73a4236 100644 --- a/Matplotlib_common/plot_series.py +++ b/Matplotlib_common/plot_series.py @@ -22,9 +22,7 @@ def plot_series(var_list, plot_iter, nplotx, nploty, axarr, xscaledict, yscaledi my_res = read_my_var(series_file, var) # rescale time to hours - #my_times = my_times / 3600. ##H - my_times = my__times / 60. ##Minutes - + my_times = my_times / 3600. ##H series_file.close() linestyles = ['--', '-.', ':'] diff --git a/cases/ICMW2020_cumulus_congestus/ICMW2020_cumulus_congestus_series_comparison.py b/cases/ICMW2020_cumulus_congestus/ICMW2020_cumulus_congestus_series_comparison.py new file mode 100644 index 0000000..8bc45b0 --- /dev/null +++ b/cases/ICMW2020_cumulus_congestus/ICMW2020_cumulus_congestus_series_comparison.py @@ -0,0 +1,74 @@ +from matplotlib import rc +import matplotlib.pyplot as plt +from matplotlib.ticker import AutoMinorLocator, MultipleLocator + +import os +import sys +sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../Matplotlib_common/") + +from plot_ranges import xscaledict, yscaledict, xlimdict_series, ylimdict_series +from plot_series import * + +# activate latex text rendering +rc('text', usetex=True) + +Lasher_Trapp_vars = ["RH_max", "cloud_top_height", "surf_precip", "acc_precip", "acc_vol_precip"] + +# init the plot +nplotx = 2 +nploty= 3 +fig, axarr = plt.subplots(nplotx,nploty) + +plot_series( Lasher_Trapp_vars, 0, nplotx, nploty, axarr, xscaledict, yscaledict, xlimdict_series, ylimdict_series, xlabel='Time [h]') + +# legend font size +plt.rcParams.update({'font.size': 8}) + +# hide axes on empty plots +if len( Lasher_Trapp_vars) % nploty == 0: + nemptyplots = 0 +else: + nemptyplots = nploty - len( ICMW2020_vars) % nploty + emptyplots = np.arange(nploty - nemptyplots, nploty) +for empty in emptyplots: + axarr[nplotx-1, empty].axis('off') + +# hide hrzntl tic labels +x_empty_label = np.arange(0, nplotx-1) +y_empty_label = np.arange(nploty) +for x in x_empty_label: + for y in y_empty_label: + axarr[x,y].set_xticklabels([]) + +#axes = plt.gca() +#axes.tick_params(direction='in') +x_arr = np.arange(nplotx) +y_arr = np.arange(nploty) +for x in x_arr: + for y in y_arr: + #tics inside + axarr[x,y].tick_params(direction='in', which='both', top=1, right=1) + #minor tics + axarr[x,y].xaxis.set_minor_locator(AutoMinorLocator()) + axarr[x,y].yaxis.set_minor_locator(AutoMinorLocator()) + #labels and tics font size + for item in ([axarr[x,y].xaxis.label, axarr[x,y].yaxis.label] + axarr[x,y].get_xticklabels() + axarr[x,y].get_yticklabels()): + item.set_fontsize(8) + # subplot numbering + if y < nploty - nemptyplots or x < (nplotx - 1): + axarr[x,y].text(0.2, 0.9, labeldict[y + x*nploty], fontsize=8, transform=axarr[x,y].transAxes) + +#single legend for the whole figure +handles, labels = axarr[0,0].get_legend_handles_labels() + +lgd = fig.legend(handles, labels, handlelength=4, loc='lower center', bbox_to_anchor=(0.45,0)) + +#figure size +fig.set_size_inches(7.874, 5. + (len(labels) - 2) * 0.2)# 5.214)#20.75,13.74) +#distances between subplots and from bottom of the plot +fig.subplots_adjust(bottom=0.18 + (len(labels) - 2) * 0.03, hspace=0.1, wspace=0.4) + +#fig.tight_layout(pad=0, w_pad=0, h_pad=0) + +#plt.show() +fig.savefig(argv[len(sys.argv)-1], bbox_inches='tight', dpi=300)#, bbox_extra_artists=(lgd,)) diff --git a/cases/ICMW2020_cumulus_congestus/plot_ranges.py b/cases/ICMW2020_cumulus_congestus/plot_ranges.py new file mode 100644 index 0000000..26c572f --- /dev/null +++ b/cases/ICMW2020_cumulus_congestus/plot_ranges.py @@ -0,0 +1,124 @@ +xscaledict = { + "thl" : "linear", + "00rtot" : "linear", + "rliq" : "linear", + "prflux" : "linear", + "cl_nc" : "linear", + "clfrac" : "linear", + "wvar" : "linear", + "w3rd" : "linear", + "sat_RH" : "linear", + "rad_flx" : "linear", + "lwp" : "linear", + "RH_max" : "linear", + "cloud_top_height" : "linear", + "total_droplets_number" : "linear", + "acc_precip_vol" : "linear", + "rwp" : "linear", + "er" : "linear", + "wvarmax" : "linear", + "surf_precip" : "linear", + "acc_precip" : "linear", + "cloud_base" : "linear", + "gccn_rw_cl" : "linear", + "non_gccn_rw_cl" : "linear", + "base_prflux_vs_clhght" : "log", + "cl_gccn_conc" : "linear" + } + +yscaledict = { + "thl" : "linear", + "00rtot" : "linear", + "rliq" : "linear", + "prflux" : "linear", + "cl_nc" : "linear", + "clfrac" : "linear", + "wvar" : "linear", + "w3rd" : "linear", + "sat_RH" : "linear", + "rad_flx" : "linear", + "lwp" : "linear", + "RH_max" : "linear", + "cloud_top_height" : "linear", + "total_droplets_number" : "linear", + "acc_precip_vol" : "linear", + "rwp" : "linear", + "er" : "linear", + "wvarmax" : "linear", + "surf_precip" : "linear", + "acc_precip" : "linear", + "cloud_base" : "linear", + "gccn_rw_cl" : "linear", + "non_gccn_rw_cl" : "linear", + "base_prflux_vs_clhght" : "linear", + "cl_gccn_conc" : "log" + } + +xlimdict_profs = { + "thl" : None, + "00rtot" : None, + "rliq" : None, + "prflux" : (0,20), + "cl_nc" : (0,90), + "clfrac" : None, + "wvar" : None, + "w3rd" : None, + "sat_RH" : None, + "RH_max" : None, + "cloud_top_height" : None, + "rad_flx" : None, + "gccn_rw_cl" : (0,90), + "non_gccn_rw_cl" : (0,12), + "base_prflux_vs_clhght" : (1,10000) + } +ylimdict_profs = { + "thl" : (0,3000), + "00rtot" : (0,3000), + "rliq" : (0,3000), + "prflux" : (0,3000), + "cl_nc" : (0,3000), + "clfrac" : (0,3000), + "wvar" : (0,3000), + "w3rd" : (0,3000), + "sat_RH" : (0,3000), + "rad_flx" : (0,3000), + "RH_max" : (0,3000), + "cloud_top_height" : (0,3000), + "gccn_rw_cl" : (0,3000), + "non_gccn_rw_cl" : (0,3000), + "base_prflux_vs_clhght" : (0,2500) + } + +xlimdict_series = { + "clfrac" : None, + "cl_nc" : None, + "lwp" : None, + "RH_max" : None, + "cloud_top_height" : None, + "total_droplets_number" : None, + "rwp" : None, + "er" : None, + "wvarmax" : None, + "surf_precip" : None, + "acc_precip" : None, + "acc_precip_vol" : None, + "cl_gccn_conc" : None, + "cloud_base" : None + } + +ylimdict_series = { + "clfrac" : None, + "cl_nc" : None, + "lwp" : None, + "RH_max" : None, + "cloud_top_height" : None, + "total_droplets_number" : None, + "acc_precip_vol" : None, + "rwp" : None, + "er" : None, + "wvarmax" : None, + "surf_precip" : None, + "acc_precip" : None,#(0,0.07), + "cl_gccn_conc" : (1e-6, 1), + "cloud_base" : None + } diff --git a/cases/Lasher_Trapp/Lasher_Trapp_series_comparison.py b/cases/Lasher_Trapp/Lasher_Trapp_series_comparison.py index eba3b6d..876bf10 100644 --- a/cases/Lasher_Trapp/Lasher_Trapp_series_comparison.py +++ b/cases/Lasher_Trapp/Lasher_Trapp_series_comparison.py @@ -12,8 +12,7 @@ # activate latex text rendering rc('text', usetex=True) -##Lasher_Trapp_vars = ["lwp", "rwp", "surf_precip", "acc_precip", "cl_nc"] -Lasher_Trapp_vars = ["RH_max", "cloud_top_height", "surf_precip", "acc_precip", "acc_vol_precip"] +Lasher_Trapp_vars = ["lwp", "rwp", "surf_precip", "acc_precip", "cl_nc"] # init the plot nplotx = 2 diff --git a/cases/Lasher_Trapp/plot_ranges.py b/cases/Lasher_Trapp/plot_ranges.py index 49a74f1..26c572f 100644 --- a/cases/Lasher_Trapp/plot_ranges.py +++ b/cases/Lasher_Trapp/plot_ranges.py @@ -13,7 +13,7 @@ "RH_max" : "linear", "cloud_top_height" : "linear", "total_droplets_number" : "linear", - "acc_vol_precip" : "linear", + "acc_precip_vol" : "linear", "rwp" : "linear", "er" : "linear", "wvarmax" : "linear", @@ -41,7 +41,7 @@ "RH_max" : "linear", "cloud_top_height" : "linear", "total_droplets_number" : "linear", - "acc_vol_precip" : "linear", + "acc_precip_vol" : "linear", "rwp" : "linear", "er" : "linear", "wvarmax" : "linear", @@ -64,8 +64,8 @@ "wvar" : None, "w3rd" : None, "sat_RH" : None, - ##"RH_max" : None, - ##"cloud_top_height" : None, + "RH_max" : None, + "cloud_top_height" : None, "rad_flx" : None, "gccn_rw_cl" : (0,90), "non_gccn_rw_cl" : (0,12), @@ -101,7 +101,7 @@ "wvarmax" : None, "surf_precip" : None, "acc_precip" : None, - "acc_vol_precip" : None, + "acc_precip_vol" : None, "cl_gccn_conc" : None, "cloud_base" : None } @@ -113,7 +113,7 @@ "RH_max" : None, "cloud_top_height" : None, "total_droplets_number" : None, - "acc_vol_precip" : None, + "acc_precip_vol" : None, "rwp" : None, "er" : None, "wvarmax" : None, diff --git a/drawbicyc/average.cpp b/drawbicyc/average.cpp index 5a8446a..af3646a 100644 --- a/drawbicyc/average.cpp +++ b/drawbicyc/average.cpp @@ -49,7 +49,8 @@ void average(int argc, char* argv[], int wtp, std::vector types, st int ver = double(types.size()) / 4. + 0.99999; init_prof(gp, ofile + string(".svg"), ver, hor); - types.insert(types.begin(), "position"); + // types.insert(types.begin(), "position"); + types.insert(types.begin(), "time"); int prof_ctr = 0; @@ -115,8 +116,9 @@ void average(int argc, char* argv[], int wtp, std::vector types, st avg = where(weight > 0, avg / weight, 0); //std_dev = where(weight > 0, sqrt(std_dev / weight - avg * avg), 0); // without the Bessel correction std_dev = where(weight > 0, sqrt(weight / (weight - 1) * (std_dev / weight - avg * avg)), 0); // with the Bessel correction - if(plt == "position") - pos = avg; + //if(plt == "position") + if(plt == "time") + pos = avg; else { gp << "plot '-' with l \n"; diff --git a/drawbicyc/drawbicyc.cpp b/drawbicyc/drawbicyc.cpp index 565b036..f9c6d33 100644 --- a/drawbicyc/drawbicyc.cpp +++ b/drawbicyc/drawbicyc.cpp @@ -19,8 +19,7 @@ int main(int argc, char** argv) ("qv_qc_2_6_10_min", po::value()->default_value(false) , "plot comparison of qv and qc fields at 2, 6 and 10 min?") ("dir", po::value()->required() , "directory containing out_lgrngn") ("micro", po::value()->required(), "one of: blk_1m, blk_2m, lgrngn") - ("type", po::value()->required(), "one of: dycoms, moist_thermal, rico, Lasher_Trapp")//, base_prflux_vs_clhght") - ; + ("type", po::value()->required(), "one of: dycoms, moist_thermal, rico, Lasher_Trapp, ICMW2020");//, base_prflux_vs_clhght") po::variables_map vm; po::store(po::command_line_parser(ac, av).options(opts_main).allow_unregistered().run(), vm); // ignores unknown @@ -33,8 +32,8 @@ int main(int argc, char** argv) // handling the "type" option std::string type = vm["type"].as(); - if(type != "dycoms" && type != "moist_thermal" && type != "rico" && type != "pi_chamber" && type != "Lasher_Trapp") - throw std::runtime_error("Unrecognized 'type' option, only dycoms, rico, moist_thermal, pi_chamber, Lasher_Trapp available now");//, base_prflux_vs_clhght available now"); + if(type != "dycoms" && type != "moist_thermal" && type != "rico" && type != "pi_chamber" && type != "Lasher_Trapp") && type != "ICMW2020"); + throw std::runtime_error("Unrecognized 'type' option, only dycoms, rico, moist_thermal, pi_chamber, Lasher_Trapp, ICMW2020 available now");//, base_prflux_vs_clhght available now"); // should profiles be normalized by inversion height const bool normalize_prof = type == "dycoms"; diff --git a/drawbicyc/include/drawbicyc/Plotter3d.hpp b/drawbicyc/include/drawbicyc/Plotter3d.hpp index 557fc31..7167d32 100644 --- a/drawbicyc/include/drawbicyc/Plotter3d.hpp +++ b/drawbicyc/include/drawbicyc/Plotter3d.hpp @@ -25,7 +25,7 @@ class Plotter_t<3> : public PlotterCommon auto h5load( const string &file, const string &dataset, - bool srfc = false // load a horiznotal slice + bool srfc = false // load a horizontal slice ) -> decltype(blitz::safeToReturn(arr_t() + 0)) { parent_t::h5load(file, dataset); diff --git a/drawbicyc/include/drawbicyc/PlotterMicro.hpp b/drawbicyc/include/drawbicyc/PlotterMicro.hpp index ace3e9c..fed3e40 100644 --- a/drawbicyc/include/drawbicyc/PlotterMicro.hpp +++ b/drawbicyc/include/drawbicyc/PlotterMicro.hpp @@ -308,10 +308,10 @@ class PlotterMicro_t : public Plotter_t * 1e3; // to mm } // accumulated volume precipitation [m^3] - double calc_acc_volume_precip(double prec_vol) + double calc_acc_surf_precip_volume(double prec_vol) { if(this->micro == "lgrngn") - return prec_vol / this->DomainVolume; + return prec_vol / this->DomainSurf * calc_acc_surf_precip(prec_vol); //DomainVolume; if(this->micro == "blk_1m") return prec_vol * this->map["dt"] / (this->map["x"] * this->map["y"] * this->map["z"]) diff --git a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp new file mode 100644 index 0000000..cdfbb40 --- /dev/null +++ b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp @@ -0,0 +1,56 @@ +#pragma once + + +const std::vector series_ICMW2020({ + "lwp", + "rwp", + "cwp", + "lwm", + "cwm", + "rwm", + "surf_precip", + "acc_precip", + "acc_precip_vol", + "cloud_base", + "RH_max", + "cloud_top_height", + "total_droplets_number" +}); + +std::vector profs_ICMW2020({ + "00rtot", + "rliq", + "thl", + "wvar", + "prflux", + "clfrac", + "sd_conc", + "cl_nc", + "cl_nc_up", + "w", + "u", + "v", + "base_prflux_vs_clhght", + "non_gccn_rw_cl", + "gccn_rw_cl," + //, "N_c", + //,"vel_div" + //, "nc_up" + //,"sat_RH_up" + //, "act_conc_up" + //, "nc_down" +}); + +std::vector fields_ICMW2020({ + "rl", + "nc", + "rr", + "nr", + //"ef", "na", + "th", + "rv", + "u", + "w" + //"sd_conc",//, "r_dry", + //"RH", "supersat", +}); diff --git a/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp b/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp index 42e7900..a39b7ef 100644 --- a/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp @@ -2,32 +2,25 @@ const std::vector series_Lasher_Trapp({ - //"clfrac", + "clfrac", "lwp", "rwp", - "cwp", - "lwm", - "cwm", - "rwm", "surf_precip", "acc_precip", - "acc_vol_precip", - //"cl_nc", + "cl_nc", "cloud_base", "RH_max", - "cloud_top_height", - "total_droplets_number", - //"surf_flux_latent", - //"surf_flux_sensible", - //"sd_conc_avg", - //"mass_dry", - //"cl_gccn_conc", - //"gccn_conc", - //"cl_non_gccn_conc", - //"non_gccn_conc", - //"cl_gccn_to_non_gccn_conc_ratio" - //, "cl_gccn_meanr" - //,"cl_avg_cloud_rad" + "surf_flux_latent", + "surf_flux_sensible", + "sd_conc_avg", + "mass_dry", + "cl_gccn_conc", + "gccn_conc", + "cl_non_gccn_conc", + "non_gccn_conc", + "cl_gccn_to_non_gccn_conc_ratio", + "cl_gccn_meanr", + "cl_avg_cloud_rad" // "sd_conc_std_dev", // "tot_water" }); diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index 005a37f..c1b25f9 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -785,8 +785,7 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool // res_pos = i * n["dz"] / z_i; if(!res_pos_out_done) { - //oprof_file << "position" << endl; - oprof_file << "time" << endl; + oprof_file << "position" << endl; oprof_file << res_pos; res_pos_out_done = true; } diff --git a/drawbicyc/include/drawbicyc/plot_series.hpp b/drawbicyc/include/drawbicyc/plot_series.hpp index 7c9b30b..4401274 100644 --- a/drawbicyc/include/drawbicyc/plot_series.hpp +++ b/drawbicyc/include/drawbicyc/plot_series.hpp @@ -501,16 +501,10 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) // Total number of Cloud and Rain Droplets try { - // cloud fraction (cloudy if ql > 1e-5)) - auto tmp = plotter.h5load_timestep("cloud_rw_mom0", at *n["outfreq"]); + auto tmp = plotter.h5load_timestep("all_rw_mom0", at *n["outfreq"]); typename Plotter_t::arr_t snap(tmp); snap *= rhod * plotter.CellVol; - auto tmp2 = plotter.h5load_timestep("rain_rw_mom0", at *n["outfreq"]); - typename Plotter_t::arr_t snap2(tmp2); - snap2 *= rhod * plotter.CellVol; - auto tmp3 = plotter.h5load_timestep("all_rw_mom0", at *n["outfreq"]); - typename Plotter_t::arr_t snap3(tmp3); - res_prof(at) = blitz::sum(snap3);// + blitz::sum(snap2); + res_prof(at) = blitz::sum(snap); } catch(...){;} } @@ -617,7 +611,7 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) // accumulated volume precipitation[m^3] try { - res_prof(at) = plotter.calc_acc_volume_precip(prec_vol); + res_prof(at) = plotter.calc_acc_surf_precip_volume(prec_vol); } catch(...) {;} } @@ -627,9 +621,9 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) try { { - auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]);// kg/kg * 1e3; //g/kg + auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]) * 1e3; //g/kg typename Plotter_t::arr_t snap(tmp); - snap += plotter.h5load_rr_timestep(at * n["outfreq"]);// kg/kg * 1e3; //g/kg + snap += plotter.h5load_rr_timestep(at * n["outfreq"]) * 1e3; //g/kg snap *= rhod; // water per cubic metre (should be wet density...) res_prof(at) = blitz::mean(snap); } @@ -656,7 +650,7 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { { typename Plotter_t::arr_t snap(plotter.h5load_rc_timestep(at * n["outfreq"])); - snap *= rhod; //kg/kg *1e3; // water per cubic metre (should be wet density ...) & g/kg + snap *= rhod *1e3; // water per cubic metre (should be wet density ...) & g/kg res_prof(at) = blitz::mean(snap); } } @@ -671,8 +665,9 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]); typename Plotter_t::arr_t snap(tmp); snap += plotter.h5load_rr_timestep(at * n["outfreq"]); - snap *= rhod; - res_prof(at) = blitz::sum(snap) * plotter.DomainSurf; + snap *= rhod * plotter.CellVol; + res_prof(at) = blitz::sum(snap) + blitz::sum(snap(plotter.hrzntl_slice(0))/2) + + blitz::sum(snap(plotter.hrzntl_slice(-1))/2); } } catch(...) {;} diff --git a/drawbicyc/include/drawbicyc/plots.hpp b/drawbicyc/include/drawbicyc/plots.hpp index a362193..82ae950 100644 --- a/drawbicyc/include/drawbicyc/plots.hpp +++ b/drawbicyc/include/drawbicyc/plots.hpp @@ -5,6 +5,7 @@ #include "cases/moist_thermal/plots.hpp" #include "cases/PiChamber/plots.hpp" #include "cases/Lasher_Trapp/plots.hpp" +#include "cases/ICMW2020_cumulus_congestus/plots.hpp" const std::vector series_sgs({ // "tot_tke" @@ -56,6 +57,11 @@ class Plots series.insert(series.end(), series_Lasher_Trapp.begin(), series_Lasher_Trapp.end()); fields.insert(fields.end(), fields_Lasher_Trapp.begin(), fields_Lasher_Trapp.end()); } + else if(type == "ICMW2020") { + //profs.insert(profs.end(), profs_ICMW2020.begin(), profs_ICMW2020.end()); + series.insert(series.end(), series_ICMW2020.begin(), series_ICMW2020.end()); + fields.insert(fields.end(), fields_ICMW2020.begin(), fields_ICMW2020.end()); + } /* else if(type == "base_prflux_vs_clhght") { profs.insert(profs.end(), profs_base_prflux_vs_clhght.begin(), profs_base_prflux_vs_clhght.end()); From 3533d8840f435f5401eea0843b3cbb176385a468 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 13 Aug 2020 11:02:21 +0200 Subject: [PATCH 07/30] ICMW2020 --- .../ICMW2020_cumulus_congestus_series_comparison.py | 6 +++--- drawbicyc/drawbicyc.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cases/ICMW2020_cumulus_congestus/ICMW2020_cumulus_congestus_series_comparison.py b/cases/ICMW2020_cumulus_congestus/ICMW2020_cumulus_congestus_series_comparison.py index 8bc45b0..0b8aa02 100644 --- a/cases/ICMW2020_cumulus_congestus/ICMW2020_cumulus_congestus_series_comparison.py +++ b/cases/ICMW2020_cumulus_congestus/ICMW2020_cumulus_congestus_series_comparison.py @@ -12,20 +12,20 @@ # activate latex text rendering rc('text', usetex=True) -Lasher_Trapp_vars = ["RH_max", "cloud_top_height", "surf_precip", "acc_precip", "acc_vol_precip"] +ICMW2020_vars = ["RH_max", "cloud_top_height", "surf_precip", "acc_precip", "acc_vol_precip"] # init the plot nplotx = 2 nploty= 3 fig, axarr = plt.subplots(nplotx,nploty) -plot_series( Lasher_Trapp_vars, 0, nplotx, nploty, axarr, xscaledict, yscaledict, xlimdict_series, ylimdict_series, xlabel='Time [h]') +plot_series( ICMW2020_vars, 0, nplotx, nploty, axarr, xscaledict, yscaledict, xlimdict_series, ylimdict_series, xlabel='Time [h]') # legend font size plt.rcParams.update({'font.size': 8}) # hide axes on empty plots -if len( Lasher_Trapp_vars) % nploty == 0: +if len( ICMW2020_vars) % nploty == 0: nemptyplots = 0 else: nemptyplots = nploty - len( ICMW2020_vars) % nploty diff --git a/drawbicyc/drawbicyc.cpp b/drawbicyc/drawbicyc.cpp index f9c6d33..ccd5252 100644 --- a/drawbicyc/drawbicyc.cpp +++ b/drawbicyc/drawbicyc.cpp @@ -32,7 +32,7 @@ int main(int argc, char** argv) // handling the "type" option std::string type = vm["type"].as(); - if(type != "dycoms" && type != "moist_thermal" && type != "rico" && type != "pi_chamber" && type != "Lasher_Trapp") && type != "ICMW2020"); + if(type != "dycoms" && type != "moist_thermal" && type != "rico" && type != "pi_chamber" && type != "Lasher_Trapp" && type != "ICMW2020"); throw std::runtime_error("Unrecognized 'type' option, only dycoms, rico, moist_thermal, pi_chamber, Lasher_Trapp, ICMW2020 available now");//, base_prflux_vs_clhght available now"); // should profiles be normalized by inversion height From 6f1c66ba671fcc82c0ca11eaa3769d5ef19eaad3 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 13 Aug 2020 12:02:31 +0200 Subject: [PATCH 08/30] Revert "Update latex_labels.py" This reverts commit ed62eef45e9a85c2d74b1b141f913b26cef5a866. --- Matplotlib_common/latex_labels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Matplotlib_common/latex_labels.py b/Matplotlib_common/latex_labels.py index fb204c1..f2425fe 100644 --- a/Matplotlib_common/latex_labels.py +++ b/Matplotlib_common/latex_labels.py @@ -10,7 +10,7 @@ "sgs_tke_sd" : 'SGS TKE (Super-droplets) [m$^{2}$ s$^{-2}$]', "surf_precip" : 'Surface precip. [mm/day]', "acc_precip" : 'Accumulated precip. [mm]', - "acc_precip_vol" : 'Accumulated precip. [m^3]', + "acc_vol_precip" : 'Accumulated volume precipitation [m^3]', "cl_nc" : '$N_c$ [cm$^{-3}$] (cloudy cells)', "cl_nr" : '$N_{r>25\mu m}$ [cm$^{-3}$]', "cl_gccn_conc" : '$N_{GCCN}$ [cm$^{-3}$] (cloudy cells)', From a88d8fbcd493beece4bb63e4bde4c322da093731 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 13 Aug 2020 14:43:37 +0200 Subject: [PATCH 09/30] working --- Matplotlib_common/latex_labels.py | 2 +- Matplotlib_common/plot_profs.py | 3 +- Matplotlib_common/plot_series.py | 1 + .../ICMW2020_cumulus_congestus/plot_ranges.py | 6 +- drawbicyc/average.cpp | 8 +-- drawbicyc/include/drawbicyc/PlotterMicro.hpp | 4 +- .../ICMW2020_cumulus_congestus/plots.hpp | 56 ------------------- .../drawbicyc/cases/Lasher_Trapp/plots.hpp | 35 +++++++----- drawbicyc/include/drawbicyc/plot_prof.hpp | 3 +- drawbicyc/include/drawbicyc/plot_series.hpp | 13 ++--- drawbicyc/include/drawbicyc/plots.hpp | 6 +- 11 files changed, 44 insertions(+), 93 deletions(-) delete mode 100644 drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp diff --git a/Matplotlib_common/latex_labels.py b/Matplotlib_common/latex_labels.py index f2425fe..fb204c1 100644 --- a/Matplotlib_common/latex_labels.py +++ b/Matplotlib_common/latex_labels.py @@ -10,7 +10,7 @@ "sgs_tke_sd" : 'SGS TKE (Super-droplets) [m$^{2}$ s$^{-2}$]', "surf_precip" : 'Surface precip. [mm/day]', "acc_precip" : 'Accumulated precip. [mm]', - "acc_vol_precip" : 'Accumulated volume precipitation [m^3]', + "acc_precip_vol" : 'Accumulated precip. [m^3]', "cl_nc" : '$N_c$ [cm$^{-3}$] (cloudy cells)', "cl_nr" : '$N_{r>25\mu m}$ [cm$^{-3}$]', "cl_gccn_conc" : '$N_{GCCN}$ [cm$^{-3}$] (cloudy cells)', diff --git a/Matplotlib_common/plot_profs.py b/Matplotlib_common/plot_profs.py index d2c0a0c..c77b629 100644 --- a/Matplotlib_common/plot_profs.py +++ b/Matplotlib_common/plot_profs.py @@ -19,7 +19,8 @@ def plot_profiles(var_list, plot_iter, nplotx, nploty, axarr, xscaledict, yscale print file_name # try: profiles_file = open(file_name, "r") - my_pos = read_my_var(profiles_file, "position") + ## my_pos = read_my_var(profiles_file, "position") + my_pos = read_my_var(profiles_file, "time") my_res = read_my_var(profiles_file, var) profiles_file.close() diff --git a/Matplotlib_common/plot_series.py b/Matplotlib_common/plot_series.py index eddbe05..91b9732 100644 --- a/Matplotlib_common/plot_series.py +++ b/Matplotlib_common/plot_series.py @@ -23,6 +23,7 @@ def plot_series(var_list, plot_iter, nplotx, nploty, axarr, xscaledict, yscaledi # rescale time to hours my_times = my_times / 3600. ##H + series_file.close() linestyles = ['--', '-.', ':'] diff --git a/cases/ICMW2020_cumulus_congestus/plot_ranges.py b/cases/ICMW2020_cumulus_congestus/plot_ranges.py index 26c572f..b77ca0d 100644 --- a/cases/ICMW2020_cumulus_congestus/plot_ranges.py +++ b/cases/ICMW2020_cumulus_congestus/plot_ranges.py @@ -41,7 +41,7 @@ "RH_max" : "linear", "cloud_top_height" : "linear", "total_droplets_number" : "linear", - "acc_precip_vol" : "linear", + "ac_precip_vol" : "linear", "rwp" : "linear", "er" : "linear", "wvarmax" : "linear", @@ -64,8 +64,8 @@ "wvar" : None, "w3rd" : None, "sat_RH" : None, - "RH_max" : None, - "cloud_top_height" : None, + ##"RH_max" : None, + ##"cloud_top_height" : None, "rad_flx" : None, "gccn_rw_cl" : (0,90), "non_gccn_rw_cl" : (0,12), diff --git a/drawbicyc/average.cpp b/drawbicyc/average.cpp index af3646a..5a8446a 100644 --- a/drawbicyc/average.cpp +++ b/drawbicyc/average.cpp @@ -49,8 +49,7 @@ void average(int argc, char* argv[], int wtp, std::vector types, st int ver = double(types.size()) / 4. + 0.99999; init_prof(gp, ofile + string(".svg"), ver, hor); - // types.insert(types.begin(), "position"); - types.insert(types.begin(), "time"); + types.insert(types.begin(), "position"); int prof_ctr = 0; @@ -116,9 +115,8 @@ void average(int argc, char* argv[], int wtp, std::vector types, st avg = where(weight > 0, avg / weight, 0); //std_dev = where(weight > 0, sqrt(std_dev / weight - avg * avg), 0); // without the Bessel correction std_dev = where(weight > 0, sqrt(weight / (weight - 1) * (std_dev / weight - avg * avg)), 0); // with the Bessel correction - //if(plt == "position") - if(plt == "time") - pos = avg; + if(plt == "position") + pos = avg; else { gp << "plot '-' with l \n"; diff --git a/drawbicyc/include/drawbicyc/PlotterMicro.hpp b/drawbicyc/include/drawbicyc/PlotterMicro.hpp index fed3e40..6c2b8bb 100644 --- a/drawbicyc/include/drawbicyc/PlotterMicro.hpp +++ b/drawbicyc/include/drawbicyc/PlotterMicro.hpp @@ -308,10 +308,10 @@ class PlotterMicro_t : public Plotter_t * 1e3; // to mm } // accumulated volume precipitation [m^3] - double calc_acc_surf_precip_volume(double prec_vol) + double calc_acc_surf_precip__volume(double prec_vol) { if(this->micro == "lgrngn") - return prec_vol / this->DomainSurf * calc_acc_surf_precip(prec_vol); //DomainVolume; + return prec_vol / this->DomainSurf * calc_acc_surf_precip(prec_vol); if(this->micro == "blk_1m") return prec_vol * this->map["dt"] / (this->map["x"] * this->map["y"] * this->map["z"]) diff --git a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp deleted file mode 100644 index cdfbb40..0000000 --- a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - - -const std::vector series_ICMW2020({ - "lwp", - "rwp", - "cwp", - "lwm", - "cwm", - "rwm", - "surf_precip", - "acc_precip", - "acc_precip_vol", - "cloud_base", - "RH_max", - "cloud_top_height", - "total_droplets_number" -}); - -std::vector profs_ICMW2020({ - "00rtot", - "rliq", - "thl", - "wvar", - "prflux", - "clfrac", - "sd_conc", - "cl_nc", - "cl_nc_up", - "w", - "u", - "v", - "base_prflux_vs_clhght", - "non_gccn_rw_cl", - "gccn_rw_cl," - //, "N_c", - //,"vel_div" - //, "nc_up" - //,"sat_RH_up" - //, "act_conc_up" - //, "nc_down" -}); - -std::vector fields_ICMW2020({ - "rl", - "nc", - "rr", - "nr", - //"ef", "na", - "th", - "rv", - "u", - "w" - //"sd_conc",//, "r_dry", - //"RH", "supersat", -}); diff --git a/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp b/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp index a39b7ef..57ce990 100644 --- a/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/Lasher_Trapp/plots.hpp @@ -5,24 +5,31 @@ const std::vector series_Lasher_Trapp({ "clfrac", "lwp", "rwp", - "surf_precip", - "acc_precip", + "cwp", + //"lwm", + //"cwm", + //"rwm", + //"surf_precip", + //"acc_precip", + //"acc_vol_precip", "cl_nc", - "cloud_base", + //"cloud_base", "RH_max", - "surf_flux_latent", - "surf_flux_sensible", - "sd_conc_avg", - "mass_dry", - "cl_gccn_conc", + //"cloud_top_height", + //"total_droplets_number", + //"surf_flux_latent", + //"surf_flux_sensible", + //"sd_conc_avg", + //"mass_dry", + //"cl_gccn_conc", "gccn_conc", - "cl_non_gccn_conc", - "non_gccn_conc", - "cl_gccn_to_non_gccn_conc_ratio", - "cl_gccn_meanr", - "cl_avg_cloud_rad" + //"cl_non_gccn_conc", + //"non_gccn_conc", + //"cl_gccn_to_non_gccn_conc_ratio" + //, "cl_gccn_meanr" + //,"cl_avg_cloud_rad" // "sd_conc_std_dev", - // "tot_water" + "tot_water" }); std::vector profs_Lasher_Trapp({ diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index c1b25f9..005a37f 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -785,7 +785,8 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool // res_pos = i * n["dz"] / z_i; if(!res_pos_out_done) { - oprof_file << "position" << endl; + //oprof_file << "position" << endl; + oprof_file << "time" << endl; oprof_file << res_pos; res_pos_out_done = true; } diff --git a/drawbicyc/include/drawbicyc/plot_series.hpp b/drawbicyc/include/drawbicyc/plot_series.hpp index 58e7c4a..57e35a6 100644 --- a/drawbicyc/include/drawbicyc/plot_series.hpp +++ b/drawbicyc/include/drawbicyc/plot_series.hpp @@ -611,7 +611,7 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) // accumulated volume precipitation[m^3] try { - res_prof(at) = plotter.calc_acc_surf_precip_volume(prec_vol); + res_prof(at) = plotter.calc_acc_surf_precip__volume(prec_vol); } catch(...) {;} } @@ -666,8 +666,7 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) typename Plotter_t::arr_t snap(tmp); snap += plotter.h5load_rr_timestep(at * n["outfreq"]); snap *= rhod * plotter.CellVol; - res_prof(at) = blitz::sum(snap) + blitz::sum(snap(plotter.hrzntl_slice(0))/2) + - blitz::sum(snap(plotter.hrzntl_slice(-1))/2); + res_prof(at) = blitz::sum(snap);// + blitz::sum(snap(plotter.hrzntl_slice(0))/2) + blitz::sum(snap(plotter.hrzntl_slice(-1))/2); } } catch(...) {;} @@ -680,8 +679,8 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]); typename Plotter_t::arr_t snap(tmp); - snap *= rhod; - res_prof(at) = blitz::sum(snap) * plotter.DomainSurf; + snap *= rhod * plotter.CellVol; + res_prof(at) = blitz::sum(snap); } } catch(...) {;} @@ -694,8 +693,8 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { auto tmp = plotter.h5load_rr_timestep(at * n["outfreq"]); typename Plotter_t::arr_t snap(tmp); - snap *= rhod; - res_prof(at) = blitz::sum(snap) * plotter.DomainSurf; + snap *= rhod * plotter.CellVol; + res_prof(at) = blitz::sum(snap); } } catch(...) {;} diff --git a/drawbicyc/include/drawbicyc/plots.hpp b/drawbicyc/include/drawbicyc/plots.hpp index 82ae950..b14e5d5 100644 --- a/drawbicyc/include/drawbicyc/plots.hpp +++ b/drawbicyc/include/drawbicyc/plots.hpp @@ -58,11 +58,11 @@ class Plots fields.insert(fields.end(), fields_Lasher_Trapp.begin(), fields_Lasher_Trapp.end()); } else if(type == "ICMW2020") { - //profs.insert(profs.end(), profs_ICMW2020.begin(), profs_ICMW2020.end()); + // profs.insert(profs.end(), profs_ICMW2020.begin(), profs_ICMW2020.end()); series.insert(series.end(), series_ICMW2020.begin(), series_ICMW2020.end()); - fields.insert(fields.end(), fields_ICMW2020.begin(), fields_ICMW2020.end()); + fields.insert(fields.end(), fields_ICMW2020.begin(), fields_ICMW2020.end()); } - /* + /* else if(type == "base_prflux_vs_clhght") { profs.insert(profs.end(), profs_base_prflux_vs_clhght.begin(), profs_base_prflux_vs_clhght.end()); }*/ From c94291fdb01a831825e479262d1aeb985fad1237 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Fri, 28 Aug 2020 15:13:38 +0200 Subject: [PATCH 10/30] LWM --- drawbicyc/drawbicyc.cpp | 5 +- .../ICMW2020_cumulus_congestus/plots.hpp | 71 +++++++++++++++++++ drawbicyc/include/drawbicyc/plot_series.hpp | 49 ++++++++----- 3 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp diff --git a/drawbicyc/drawbicyc.cpp b/drawbicyc/drawbicyc.cpp index ccd5252..7963546 100644 --- a/drawbicyc/drawbicyc.cpp +++ b/drawbicyc/drawbicyc.cpp @@ -19,7 +19,8 @@ int main(int argc, char** argv) ("qv_qc_2_6_10_min", po::value()->default_value(false) , "plot comparison of qv and qc fields at 2, 6 and 10 min?") ("dir", po::value()->required() , "directory containing out_lgrngn") ("micro", po::value()->required(), "one of: blk_1m, blk_2m, lgrngn") - ("type", po::value()->required(), "one of: dycoms, moist_thermal, rico, Lasher_Trapp, ICMW2020");//, base_prflux_vs_clhght") + ("type", po::value()->required(), "one of: dycoms, moist_thermal, rico, Lasher_Trapp, ICMW2020")//, base_prflux_vs_clhght") + ; po::variables_map vm; po::store(po::command_line_parser(ac, av).options(opts_main).allow_unregistered().run(), vm); // ignores unknown @@ -32,7 +33,7 @@ int main(int argc, char** argv) // handling the "type" option std::string type = vm["type"].as(); - if(type != "dycoms" && type != "moist_thermal" && type != "rico" && type != "pi_chamber" && type != "Lasher_Trapp" && type != "ICMW2020"); + if(type != "dycoms" && type != "moist_thermal" && type != "rico" && type != "pi_chamber" && type != "Lasher_Trapp" && type != "ICMW2020") throw std::runtime_error("Unrecognized 'type' option, only dycoms, rico, moist_thermal, pi_chamber, Lasher_Trapp, ICMW2020 available now");//, base_prflux_vs_clhght available now"); // should profiles be normalized by inversion height diff --git a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp new file mode 100644 index 0000000..4658042 --- /dev/null +++ b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp @@ -0,0 +1,71 @@ +#pragma once + + +const std::vector series_ICMW2020({ + //"clfrac", + "lwp", + "rwp", + "cwp", + "lwm", + "cwm", + "rwm", + //"surf_precip", + //"acc_precip", + "acc_vol_precip", + //"cl_nc", + //"cloud_base", + //"RH_max", + "cloud_top_height", + "total_droplets_number", + //"surf_flux_latent", + //"surf_flux_sensible", + //"sd_conc_avg", + //"mass_dry", + //"cl_gccn_conc", + //"gccn_conc", + //"cl_non_gccn_conc", + //"non_gccn_conc", + //"cl_gccn_to_non_gccn_conc_ratio" + //, "cl_gccn_meanr" + //,"cl_avg_cloud_rad" + // "sd_conc_std_dev", + // "tot_water" +}); + +std::vector profs_ICMW2020({ + "00rtot", + "rliq", + "thl", + "wvar", + "prflux", + "clfrac", + "sd_conc", + "cl_nc", + "cl_nc_up", + "w", + "u", + "v", + "base_prflux_vs_clhght", + "non_gccn_rw_cl", + "gccn_rw_cl," + //, "N_c", + //,"vel_div" + //, "nc_up" + //,"sat_RH_up" + //, "act_conc_up" + //, "nc_down" +}); + +std::vector fields_ICMW2020({ + "rl", + "nc", + "rr", + "nr", + //"ef", "na", + "th", + "rv", + "u", + "w" + //"sd_conc",//, "r_dry", + //"RH", "supersat", +}); diff --git a/drawbicyc/include/drawbicyc/plot_series.hpp b/drawbicyc/include/drawbicyc/plot_series.hpp index 57e35a6..cf99b0e 100644 --- a/drawbicyc/include/drawbicyc/plot_series.hpp +++ b/drawbicyc/include/drawbicyc/plot_series.hpp @@ -501,9 +501,9 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) // Total number of Cloud and Rain Droplets try { - auto tmp = plotter.h5load_timestep("all_rw_mom0", at *n["outfreq"]); + auto tmp = plotter.h5load_timestep("cloud_rw_mom0", at *n["outfreq"]) * rhod; typename Plotter_t::arr_t snap(tmp); - snap *= rhod * plotter.CellVol; + snap *= plotter.CellVol; res_prof(at) = blitz::sum(snap); } catch(...){;} @@ -637,7 +637,7 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { { typename Plotter_t::arr_t snap(plotter.h5load_rr_timestep(at * n["outfreq"])); - snap *= rhod; //kg/kg * 1e3; // water per cubic metre (should be wet density...) & g/kg + snap *= rhod* 1e3; // water per cubic metre (should be wet density...) & g/kg res_prof(at) = blitz::mean(snap); } } @@ -662,11 +662,18 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) try { { - auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]); + auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]) * rhod; typename Plotter_t::arr_t snap(tmp); - snap += plotter.h5load_rr_timestep(at * n["outfreq"]); - snap *= rhod * plotter.CellVol; - res_prof(at) = blitz::sum(snap);// + blitz::sum(snap(plotter.hrzntl_slice(0))/2) + blitz::sum(snap(plotter.hrzntl_slice(-1))/2); + snap += plotter.h5load_rr_timestep(at * n["outfreq"]) * rhod; + snap *= plotter.CellVol; + snap(plotter.hrzntl_slice(0)) = snap(plotter.hrzntl_slice(0))/2; + snap(plotter.hrzntl_slice(-1)) = snap(plotter.hrzntl_slice(-1))/2; + //auto slice = snap(plotter.hrzntl_slice(0))/2; + snap(plotter.hrzntl_slice(-1))/2; + //plotter.k_i2 = snap(plotter.hrzntl_slice(-1)/2); + //snap += blitz::snap(plotter.hrzntl_slice(0)/2); + //snap += blitz::snap(plotter.hrzntl_slice(-1)/2); + //res_prof(at) = blitz::sum(snap(plotter.hirzntl_slice(0)))/2 + blitz::sum(snap(plotter.hrzntl_slice(-1)))/2; + res_prof(at) = blitz::sum( snap);// + blitz::sum(slice);///blitz::sum(snap(plotter.hrzntl_slice(0))/2 + snap(plotter.hrzntl_slice(-1))/2 + snap); } } catch(...) {;} @@ -680,6 +687,8 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) auto tmp = plotter.h5load_rc_timestep(at * n["outfreq"]); typename Plotter_t::arr_t snap(tmp); snap *= rhod * plotter.CellVol; + snap(plotter.hrzntl_slice(0)) = snap(plotter.hrzntl_slice(0))/2; + snap(plotter.hrzntl_slice(-1)) = snap(plotter.hrzntl_slice(-1))/2; res_prof(at) = blitz::sum(snap); } } @@ -694,6 +703,8 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) auto tmp = plotter.h5load_rr_timestep(at * n["outfreq"]); typename Plotter_t::arr_t snap(tmp); snap *= rhod * plotter.CellVol; + snap(plotter.hrzntl_slice(0)) = snap(plotter.hrzntl_slice(0))/2; + snap(plotter.hrzntl_slice(-1)) = snap(plotter.hrzntl_slice(-1))/2; res_prof(at) = blitz::sum(snap); } } @@ -1331,18 +1342,18 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller } - else if (plt == "lwm") - { - res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller - } - else if (plt == "cwm") - { - res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller - } - else if (plt == "rwm") - { - res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller - } + // else if (plt == "lwm") + // { + // res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller + // } + // else if (plt == "cwm") + // { + // res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller + // } + // else if (plt == "rwm") + // { + // res_prof *= (n["z"] - 1) * n["dz"]; // top and bottom cells are smaller + // } else if (plt == "er") { // central difference, in cm From 5fa75f92e280f02f2ba3785a9434f612c69ca4c8 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Fri, 4 Sep 2020 10:49:52 +0200 Subject: [PATCH 11/30] time series --- Matplotlib_common/plot_profs.py | 3 +-- Matplotlib_common/plot_series.py | 4 ++-- drawbicyc/drawbicyc.cpp | 6 +++--- drawbicyc/include/drawbicyc/PlotterMicro.hpp | 8 +++----- drawbicyc/include/drawbicyc/plot_prof.hpp | 3 +-- drawbicyc/include/drawbicyc/plot_series.hpp | 11 ++++++----- drawbicyc/include/drawbicyc/plots.hpp | 2 +- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Matplotlib_common/plot_profs.py b/Matplotlib_common/plot_profs.py index c77b629..d2c0a0c 100644 --- a/Matplotlib_common/plot_profs.py +++ b/Matplotlib_common/plot_profs.py @@ -19,8 +19,7 @@ def plot_profiles(var_list, plot_iter, nplotx, nploty, axarr, xscaledict, yscale print file_name # try: profiles_file = open(file_name, "r") - ## my_pos = read_my_var(profiles_file, "position") - my_pos = read_my_var(profiles_file, "time") + my_pos = read_my_var(profiles_file, "position") my_res = read_my_var(profiles_file, var) profiles_file.close() diff --git a/Matplotlib_common/plot_series.py b/Matplotlib_common/plot_series.py index 91b9732..1a56a95 100644 --- a/Matplotlib_common/plot_series.py +++ b/Matplotlib_common/plot_series.py @@ -17,8 +17,8 @@ def plot_series(var_list, plot_iter, nplotx, nploty, axarr, xscaledict, yscaledi for file_name in file_names: print file_name, var series_file = open(file_name, "r") - #my_times = read_my_var(series_file, "position") - my_time = read_my_var(series_file, "time") + my_times = read_my_var(series_file, "position") + #my_time = read_my_var(series_file, "time") my_res = read_my_var(series_file, var) # rescale time to hours diff --git a/drawbicyc/drawbicyc.cpp b/drawbicyc/drawbicyc.cpp index 7963546..029f867 100644 --- a/drawbicyc/drawbicyc.cpp +++ b/drawbicyc/drawbicyc.cpp @@ -19,7 +19,7 @@ int main(int argc, char** argv) ("qv_qc_2_6_10_min", po::value()->default_value(false) , "plot comparison of qv and qc fields at 2, 6 and 10 min?") ("dir", po::value()->required() , "directory containing out_lgrngn") ("micro", po::value()->required(), "one of: blk_1m, blk_2m, lgrngn") - ("type", po::value()->required(), "one of: dycoms, moist_thermal, rico, Lasher_Trapp, ICMW2020")//, base_prflux_vs_clhght") + ("type", po::value()->required(), "one of: dycoms, moist_thermal, rico, Lasher_Trapp, ICMW2020_cc")//, base_prflux_vs_clhght") ; po::variables_map vm; @@ -33,8 +33,8 @@ int main(int argc, char** argv) // handling the "type" option std::string type = vm["type"].as(); - if(type != "dycoms" && type != "moist_thermal" && type != "rico" && type != "pi_chamber" && type != "Lasher_Trapp" && type != "ICMW2020") - throw std::runtime_error("Unrecognized 'type' option, only dycoms, rico, moist_thermal, pi_chamber, Lasher_Trapp, ICMW2020 available now");//, base_prflux_vs_clhght available now"); + if(type != "dycoms" && type != "moist_thermal" && type != "rico" && type != "pi_chamber" && type != "Lasher_Trapp" && type != "ICMW2020_cc") + throw std::runtime_error("Unrecognized 'type' option, only dycoms, rico, moist_thermal, pi_chamber, Lasher_Trapp, ICMW2020_cc available now");//, base_prflux_vs_clhght available now"); // should profiles be normalized by inversion height const bool normalize_prof = type == "dycoms"; diff --git a/drawbicyc/include/drawbicyc/PlotterMicro.hpp b/drawbicyc/include/drawbicyc/PlotterMicro.hpp index 6c2b8bb..087b6a1 100644 --- a/drawbicyc/include/drawbicyc/PlotterMicro.hpp +++ b/drawbicyc/include/drawbicyc/PlotterMicro.hpp @@ -308,14 +308,12 @@ class PlotterMicro_t : public Plotter_t * 1e3; // to mm } // accumulated volume precipitation [m^3] - double calc_acc_surf_precip__volume(double prec_vol) + double calc_acc_surf_precip_volume(double prec_vol) { if(this->micro == "lgrngn") - return prec_vol / this->DomainSurf * calc_acc_surf_precip(prec_vol); + return calc_acc_surf_precip(prec_vol) * this->DomainSurf / 1000.; if(this->micro == "blk_1m") - return prec_vol * this->map["dt"] - / (this->map["x"] * this->map["y"] * this->map["z"]) - / 1e3; // to m^3 of water + return calc_acc_surf_precip(prec_vol) * this->DomainSurf / 1000.;// to m^3 of water } //ctor PlotterMicro_t(const string &file, const string µ): diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index 005a37f..c1b25f9 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -785,8 +785,7 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool // res_pos = i * n["dz"] / z_i; if(!res_pos_out_done) { - //oprof_file << "position" << endl; - oprof_file << "time" << endl; + oprof_file << "position" << endl; oprof_file << res_pos; res_pos_out_done = true; } diff --git a/drawbicyc/include/drawbicyc/plot_series.hpp b/drawbicyc/include/drawbicyc/plot_series.hpp index cf99b0e..548cbba 100644 --- a/drawbicyc/include/drawbicyc/plot_series.hpp +++ b/drawbicyc/include/drawbicyc/plot_series.hpp @@ -64,8 +64,8 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) com_x_idx(last_timestep - first_timestep + 1); // index of the center of mass cell // save time steps to the series file - //oprof_file << "position" << endl; - oprof_file << "time" << endl; + oprof_file << "position" << endl; + //oprof_file << "time" << endl; oprof_file << plotter.timesteps; @@ -503,8 +503,9 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) { auto tmp = plotter.h5load_timestep("cloud_rw_mom0", at *n["outfreq"]) * rhod; typename Plotter_t::arr_t snap(tmp); - snap *= plotter.CellVol; - res_prof(at) = blitz::sum(snap); + auto tmp2 = plotter.h5load_timestep("rain_rw_mom0", at * n["outfreq"]); + typename Plotter_t::arr_t snap2(tmp2); + res_prof(at) = (blitz::sum(snap) + blitz::sum(snap2))*plotter.CellVol; } catch(...){;} } @@ -611,7 +612,7 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) // accumulated volume precipitation[m^3] try { - res_prof(at) = plotter.calc_acc_surf_precip__volume(prec_vol); + res_prof(at) = plotter.calc_acc_surf_precip_volume(prec_vol); } catch(...) {;} } diff --git a/drawbicyc/include/drawbicyc/plots.hpp b/drawbicyc/include/drawbicyc/plots.hpp index b14e5d5..ac249d1 100644 --- a/drawbicyc/include/drawbicyc/plots.hpp +++ b/drawbicyc/include/drawbicyc/plots.hpp @@ -57,7 +57,7 @@ class Plots series.insert(series.end(), series_Lasher_Trapp.begin(), series_Lasher_Trapp.end()); fields.insert(fields.end(), fields_Lasher_Trapp.begin(), fields_Lasher_Trapp.end()); } - else if(type == "ICMW2020") { + else if(type == "ICMW2020_cc") { // profs.insert(profs.end(), profs_ICMW2020.begin(), profs_ICMW2020.end()); series.insert(series.end(), series_ICMW2020.begin(), series_ICMW2020.end()); fields.insert(fields.end(), fields_ICMW2020.begin(), fields_ICMW2020.end()); From 590c1fe58d57b4768d611da715e51899e01a7dff Mon Sep 17 00:00:00 2001 From: ryba183 Date: Tue, 22 Sep 2020 23:09:15 +0200 Subject: [PATCH 12/30] profs --- Matplotlib_common/latex_labels.py | 8 ++- .../ICMW2020_cumulus_congestus/plots.hpp | 31 +++++---- .../drawbicyc/gnuplot_profs_set_labels.hpp | 13 ++++ drawbicyc/include/drawbicyc/plot_prof.hpp | 64 ++++++++++++++++++- drawbicyc/include/drawbicyc/plots.hpp | 2 +- 5 files changed, 101 insertions(+), 17 deletions(-) diff --git a/Matplotlib_common/latex_labels.py b/Matplotlib_common/latex_labels.py index fb204c1..326c2db 100644 --- a/Matplotlib_common/latex_labels.py +++ b/Matplotlib_common/latex_labels.py @@ -37,7 +37,13 @@ "clb_bigrain_mean_kappa" : '$\kappa$ of (r$>$40um) @ clbase', "clb_bigrain_mean_conc" : 'conc. of (r$>$40um) @ clbase [1/cc]', "clb_bigrain_mean_inclt" : 'time since act. of (r$>$40um) @ clbase [s]', - "clb_bigrain_mean_gccn_fraction" : 'frac. of (r$>$40um) on gccn @ clbase' + "clb_bigrain_mean_gccn_fraction" : 'frac. of (r$>$40um) on gccn @ clbase', + "N_c" : 'number concentration of droplets n [#]', + "rliq" : 'liquid water content LWC', + "actrw_reff_cl" : 'effective radius [um]', + "ratio_mean_volue_r_to_eff_r_cubed" : 'ratio of mean volume radius to effective radius cubed', + "cloud_std_dev" : 'standard deviation' + } diff --git a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp index 4658042..afaa39c 100644 --- a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp @@ -35,20 +35,23 @@ const std::vector series_ICMW2020({ std::vector profs_ICMW2020({ "00rtot", "rliq", - "thl", - "wvar", - "prflux", - "clfrac", - "sd_conc", - "cl_nc", - "cl_nc_up", - "w", - "u", - "v", - "base_prflux_vs_clhght", - "non_gccn_rw_cl", - "gccn_rw_cl," - //, "N_c", + // "thl", + // "wvar", + //"prflux", + //"clfrac", + //"sd_conc", + // "cl_nc", + //"cl_nc_up", + //"w", + //"u", + //"v", + //"base_prflux_vs_clhght", + //"non_gccn_rw_cl", + //"gccn_rw_cl," + "N_c", + "actrw_reff_cl", + "ratio_mean_volue_r_to_eff_r_cubed", + "cloud_std_dev" //,"vel_div" //, "nc_up" //,"sat_RH_up" diff --git a/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp b/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp index eaba9c2..fcb9422 100644 --- a/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp +++ b/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp @@ -76,6 +76,19 @@ void gnuplot_profs_set_labels(Gnuplot &gp, std::string plt, const bool normalize { gp << "set title 'activated (rw>rc) droplets mean dry radius'\n"; } + if (plt == "actrw_reff_cl") + { + gp << "set title 'activated (rw>rc) effective radius'\n"; + } + if (plt == "cloud_std_dev") + { + gp << "set title 'standard deviation'\n"; + } + if (plt == "ratio_mean_volue_r_to_eff_r_cubed") + { + gp << "set title 'ratio of mean volume radius to effective radius cubed'\n"; + } + else if (plt == "rv") { gp << "set title 'rv [g/kg] averaged over 2h-6h, w/o rw<0.5um'\n"; diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index c1b25f9..97bdf94 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -66,7 +66,10 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool blitz::secondIndex j; typename Plotter_t::arr_t res(rhod.shape()); typename Plotter_t::arr_t res_tmp(rhod.shape()); + typename Plotter_t::arr_t res_tmp1(rhod.shape()); typename Plotter_t::arr_t res_tmp2(rhod.shape()); + typename Plotter_t::arr_t res_tmp3(rhod.shape()); + typename Plotter_t::arr_t res_tmp4(rhod.shape()); blitz::Array res_prof_sum(n["z"]); // profile interpolate to the uniform grid summed over timesteps blitz::Array res_prof(n["z"]); // profile interpolate to the uniform grid blitz::Array res_prof_hlpr(n["z"]); // actual profile @@ -85,7 +88,7 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool if (plt == "rliq") { // liquid water content - res += plotter.h5load_ra_timestep(at * n["outfreq"]) * 1e3; // aerosol + //res += plotter.h5load_ra_timestep(at * n["outfreq"]) * 1e3; // aerosol res += plotter.h5load_rc_timestep(at * n["outfreq"]) * 1e3; // cloud res += plotter.h5load_rr_timestep(at * n["outfreq"]) * 1e3; // rain res_prof_hlpr = plotter.horizontal_mean(res); // average in x @@ -310,6 +313,65 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool prof_tmp = plotter.horizontal_sum(res_tmp2); // number of downdraft cells on a given level res_prof_hlpr = where(prof_tmp > 0 , plotter.horizontal_sum(res_tmp) / prof_tmp, 0); } + if (plt == "ratio_mean_volue_r_to_eff_r_cubed") + { + { + //auto tmp0 = plotter.h5load_timestep("actrw_rw_mom0", at * n["outfreq"]); + typename Plotter_t::arr_t snap(plotter.h5load_timestep("actrw_rw_mom0", at * n["outfreq"])); + res_tmp = snap; + } + { + auto tmp2 = plotter.h5load_timestep("actrw_rw_mom2", at * n["outfreq"]); + typename Plotter_t::arr_t snap(tmp2); + res_tmp2 = snap; + } + { + auto tmp3 = plotter.h5load_timestep("actrw_rw_mom3", at * n["outfreq"]); + typename Plotter_t::arr_t snap(tmp3); + res_tmp3 = snap; + } + { + typename Plotter_t::arr_t snap(plotter.h5load_rc_timestep(at * n["outfreq"])); + res_tmp4 = iscloudy_rc_rico(snap); + } + + res_tmp = where(res_tmp > 0, res_tmp2 * res_tmp2 * res_tmp2 / res_tmp, 0. ); + res_tmp = where(res_tmp3 > 0, res_tmp / res_tmp3 / res_tmp3, 0.); + res_tmp *= res_tmp4; + //mean only over downdraught cells + prof_tmp = plotter.horizontal_sum(res_tmp4); // number of downdraft cells on a given level + res_prof_hlpr = where(prof_tmp > 0 , plotter.horizontal_sum(res_tmp) / prof_tmp, 0); + } + if (plt == "cloud_std_dev") + { + { + auto tmp1 = plotter.h5load_timestep("actrw_rw_mom1", at * n["outfreq"] *1e6); + typename Plotter_t::arr_t snap(tmp1); + res_tmp1 = snap; + } + { + auto tmp2 = plotter.h5load_timestep("actrw_rw_mom2", at * n["outfreq"] *1e12); + typename Plotter_t::arr_t snap(tmp2); + res_tmp2 = snap; + } + { + auto tmp0 = plotter.h5load_timestep("actrw_rw_mom0", at * n["outfreq"]); + typename Plotter_t::arr_t snap(tmp0); + res_tmp = snap; + } + { + typename Plotter_t::arr_t snap(plotter.h5load_rc_timestep(at * n["outfreq"])); + res_tmp3 = iscloudy_rc_rico(snap); + } + res_tmp = where(res_tmp > 0, res_tmp2 / res_tmp - res_tmp1 / res_tmp * res_tmp1 / res_tmp, 0.); + res_tmp = where(res_tmp < 0 , 0, res_tmp); + res_tmp = sqrt(res_tmp); + res_tmp *= res_tmp3; + // mean only over downdraught cells + prof_tmp = plotter.horizontal_sum(res_tmp3); // number of downdraft cells on a given level + res_prof_hlpr = where(prof_tmp > 0 , plotter.horizontal_sum(res_tmp) / prof_tmp, 0); + + } if (plt == "nc_up") { // updraft only diff --git a/drawbicyc/include/drawbicyc/plots.hpp b/drawbicyc/include/drawbicyc/plots.hpp index ac249d1..5d5a699 100644 --- a/drawbicyc/include/drawbicyc/plots.hpp +++ b/drawbicyc/include/drawbicyc/plots.hpp @@ -58,7 +58,7 @@ class Plots fields.insert(fields.end(), fields_Lasher_Trapp.begin(), fields_Lasher_Trapp.end()); } else if(type == "ICMW2020_cc") { - // profs.insert(profs.end(), profs_ICMW2020.begin(), profs_ICMW2020.end()); + profs.insert(profs.end(), profs_ICMW2020.begin(), profs_ICMW2020.end()); series.insert(series.end(), series_ICMW2020.begin(), series_ICMW2020.end()); fields.insert(fields.end(), fields_ICMW2020.begin(), fields_ICMW2020.end()); } From c0db4f2892acb0afccbea91ed6fa54c32363ae7f Mon Sep 17 00:00:00 2001 From: ryba183 Date: Wed, 23 Sep 2020 15:10:58 +0200 Subject: [PATCH 13/30] ICMW_profs --- drawbicyc/include/drawbicyc/plot_prof.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index 97bdf94..57d1a7f 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -345,12 +345,12 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool if (plt == "cloud_std_dev") { { - auto tmp1 = plotter.h5load_timestep("actrw_rw_mom1", at * n["outfreq"] *1e6); + auto tmp1 = plotter.h5load_timestep("actrw_rw_mom1", at * n["outfreq"]) *1e6; typename Plotter_t::arr_t snap(tmp1); res_tmp1 = snap; } { - auto tmp2 = plotter.h5load_timestep("actrw_rw_mom2", at * n["outfreq"] *1e12); + auto tmp2 = plotter.h5load_timestep("actrw_rw_mom2", at * n["outfreq"]) * 1e12; typename Plotter_t::arr_t snap(tmp2); res_tmp2 = snap; } From 0e35c11a86169bddc70ad1590a8c97c92ca339fa Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 24 Sep 2020 15:37:40 +0200 Subject: [PATCH 14/30] NC_vs_AF python3 --- NC_vs_AF/nc_vs_af.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/NC_vs_AF/nc_vs_af.py b/NC_vs_AF/nc_vs_af.py index ba6316b..0a5d058 100644 --- a/NC_vs_AF/nc_vs_af.py +++ b/NC_vs_AF/nc_vs_af.py @@ -2,10 +2,11 @@ # adiabatic rl calculated based on mean th and rv at cloud base cells from sys import argv, path, maxsize -path.insert(0, "/home/piotr/usr/local/lib/python2.7/dist-packages/") - +path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") import h5py import numpy as np +import matplotlib +matplotlib.use('Agg') import matplotlib.pyplot as plt from libcloudphxx import common as lcmn @@ -16,8 +17,13 @@ plt.figure(figsize=(16,10)) evap_lat = 2.5e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) -timesteps = [12000, 36000, 72000] +for i in range(1, 91): + timesteps[i] = i*240 +11 +timesteps = timesteps[1:91] +print(timesteps) input_dir = argv[1] outfile = argv[2] @@ -29,8 +35,8 @@ for timestep in timesteps: plt.clf() - print timestep - filename = input_dir + "/timestep" + str(timestep).zfill(10) + ".h5" + print(int(timestep)) + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" #rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:] + h5py.File(filename, "r")["rain_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:,:] * rhod / 1e6; # 1 / cm^3 @@ -38,20 +44,20 @@ # cloudiness mask - as in DYCOMS paper cloudy_mask = np.where(nc > 20, 1, 0) - print 'nc>20 cloudy cells: ', np.sum(cloudy_mask) - print 'nc>20 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask) + print('nc>20 cloudy cells: ', np.sum(cloudy_mask)) + print('nc>20 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) # cloudiness mask - rl > 1e-4 cloudy_mask = np.where(rl > 1e-4, 1, 0) - print 'rl>1e-4 cloudy cells: ', np.sum(cloudy_mask) - print 'rl>1e-4 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask) + print('rl>1e-4 cloudy cells: ', np.sum(cloudy_mask)) + print('rl>1e-4 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) # cloudiness mask - as in RICO paper cloudy_mask = np.where(rl > 1e-5, 1, 0) - print 'rl>1e-5 cloudy cells: ', np.sum(cloudy_mask) - print 'rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask) + print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask)) + print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) # ---- adiabatic LWC ---- AF = np.zeros([nx, ny, nz]) @@ -88,7 +94,7 @@ parcel_th = np.mean(clb_th[clb_th>0]) parcel_rl = 0 - print 'parcel init: th = ', parcel_th, ' rv = ', parcel_rv + print('parcel init: th = ', parcel_th, ' rv = ', parcel_rv) for k in np.arange(nz): parcel_T = parcel_th * lcmn.exner(p_e.astype(float)[k]) @@ -100,8 +106,8 @@ parcel_rl += delta_rv adia_rl[k] = parcel_rl - print p_e - print adia_rl + print(p_e) + print(adia_rl) #for i, j in zip(np.arange(nx), np.arange(ny)): # parcel_rv = rv[i, j, clb_idx[i, j]] @@ -140,7 +146,7 @@ #print nc[nc>0] plt.plot((AF * cloudy_mask).flatten(), (nc * cloudy_mask).flatten(), '.', markersize=1) - plt.xlim(0,10) + plt.xlim(0,2) plt.ylim(0,200) plt.xlabel('AF') From cde1e025666cc696afd03ec9486d4d16d094528f Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 8 Oct 2020 10:32:47 +0200 Subject: [PATCH 15/30] Workshops --- NC_vs_AF/nc_vs_af_AFperCol.py | 112 +++++++++--------- .../ICMW2020_cumulus_congestus/plots.hpp | 21 ++-- drawbicyc/include/drawbicyc/plot_fields.hpp | 69 +++++++++++ drawbicyc/include/drawbicyc/plot_prof.hpp | 53 +++++++++ 4 files changed, 191 insertions(+), 64 deletions(-) diff --git a/NC_vs_AF/nc_vs_af_AFperCol.py b/NC_vs_AF/nc_vs_af_AFperCol.py index 0606d46..5df0c2a 100644 --- a/NC_vs_AF/nc_vs_af_AFperCol.py +++ b/NC_vs_AF/nc_vs_af_AFperCol.py @@ -2,7 +2,8 @@ # adiabatic rl calculated separately for each column from sys import argv, path, maxsize -path.insert(0, "/home/piotr/usr/local/lib/python2.7/dist-packages/") +#path.insert(0, "/home/piotr/usr/local/lib/python2.7/dist-packages/") +path.insert(0,"/home/piotr/usr/local/lib/python3/dist-packages/") import h5py import numpy as np @@ -17,8 +18,8 @@ evap_lat = 2.5e6 # [J/kg] latent heat of evaporation -timesteps = [12000, 36000, 72000] -#timesteps = [36000] +#timesteps = [12000, 36000, 72000] +timesteps = [13200] input_dir = argv[1] outfile = argv[2] @@ -30,33 +31,33 @@ for timestep in timesteps: plt.clf() - print timestep filename = input_dir + "/timestep" + str(timestep).zfill(10) + ".h5" #rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:] + h5py.File(filename, "r")["rain_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:,:] * rhod / 1e6; # 1 / cm^3 - + # cloudiness mask - as in DYCOMS paper cloudy_mask = np.where(nc > 20, 1, 0) - - print 'nc>20 cloudy cells: ', np.sum(cloudy_mask) - print 'nc>20 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask) - + + print('nc>20 cloudy cells: ', np.sum(cloudy_mask)) + print('nc>20 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) + # cloudiness mask - rl > 1e-4 cloudy_mask = np.where(rl > 1e-4, 1, 0) - - print 'rl>1e-4 cloudy cells: ', np.sum(cloudy_mask) - print 'rl>1e-4 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask) - + + print('rl>1e-4 cloudy cells: ', np.sum(cloudy_mask)) + print('rl>1e-4 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) + # cloudiness mask - as in RICO paper cloudy_mask = np.where(rl > 1e-5, 1, 0) cloudy_mask_used = cloudy_mask - - print 'rl>1e-5 cloudy cells: ', np.sum(cloudy_mask) - print 'rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask) + + print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask)) + print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) hght_abv_clb = np.zeros([nx, ny, nz]) - + hght = np.arange(nz) * dz + # ---- adiabatic LWC ---- AF = np.zeros([nx, ny, nz]) adia_rl = np.zeros([nx, ny, nz]) @@ -64,37 +65,37 @@ # th and rv th = h5py.File(filename, "r")["th"][:,:,:]; rv = h5py.File(filename, "r")["rv"][:,:,:]; - + # T Vexner = np.vectorize(lcmn.exner) T = th * Vexner(p_e.astype(float)) - + # RH Vr_vs = np.vectorize(lcmn.r_vs) r_vs = Vr_vs(T, p_e.astype(float)) RH = rv / r_vs - + # cloud base #clb_idx = np.argmax(RH > 1, axis=2) clb_idx = np.argmax(cloudy_mask_used>0, axis=2) - + # clb condition per column clb_rv = np.zeros([nx, ny]) clb_th = np.zeros([nx, ny]) - + for i in np.arange(nx): for j in np.arange(ny): if clb_idx[i,j] > 0: clb_rv[i,j] = rv[i, j, clb_idx[i, j]] clb_th[i,j] = th[i, j, clb_idx[i, j]] - + # model a parcel to get an adiabatic rl for i in np.arange(nx): for j in np.arange(ny): parcel_rv = clb_rv[i,j] parcel_th = clb_th[i,j] parcel_rl = 0 - + for k in np.arange(nz): parcel_T = parcel_th * lcmn.exner(p_e.astype(float)[k]) delta_rv = parcel_rv - lcmn.r_vs(parcel_T, p_e.astype(float)[k]) @@ -104,37 +105,26 @@ parcel_th += delta_rv * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) parcel_rl += delta_rv adia_rl[i, j, k] = parcel_rl - - #for i, j in zip(np.arange(nx), np.arange(ny)): - # parcel_rv = rv[i, j, clb_idx[i, j]] - # parcel_th = th[i, j, clb_idx[i, j]] - # for k in np.arange(nz): - # if k < clb_idx[i, j]: - # adia_rl[i,j,k] = 0 - # else: - # parcel_T = parcel_th * lcmn.exner(p_e.astype(float)[k]) - # delta_rv = parcel_rv - lcmn.r_vs(parcel_T, p_e.astype(float)[k]) - # parcel_rv -= delta_rv - # parcel_th += delta_rv * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) - # adia_rl[i,j,k] = rl[i,j,k] / delta_rv - - + #adia_rl = np.where(adia_rl > 0., adia_rl, 0) #print adia_rl - + # translate rl to AF #AF = np.where(adia_rl > 0., rl / adia_rl, 0) #AF = np.where(adia_rl > 1e-5, rl / adia_rl, 0) - + for i in np.arange(nx): for j in np.arange(ny): for k in np.arange(nz): # if rl[i,j,k] > 0 and adia_rl[k] == 0: # print 'i: ',i, ' j: ',j, ' k: ',k, 'rl: ', rl[i,j,k], 'adia_rl: ', adia_rl[k], 'nc: ', nc[i,j,k] - AF[i, j, k] = rl[i,j,k] / adia_rl[i, j, k] - hght_abv_clb[i, j, k] = (k - clb_idx[i,j]) * 40 + if adia_rl[i, j, k] == 0: + AF[i, j, k] = 0 + else: + AF[i, j, k] = rl[i,j,k] / adia_rl[i, j, k] + hght_abv_clb[i, j, k] = (k - clb_idx[i,j]) * dz # print 'i: ',i, ' j: ',j, ' k: ',k, 'rl: ', rl[i,j,k], 'adia_rl: ', adia_rl[k], 'nc: ', nc[i,j,k], 'AF: ', AF[i,j,k] - + #print cloudy_mask_used[cloudy_mask_used>0] #print AF[AF>0] #print nc[nc>0] @@ -149,16 +139,16 @@ # plot cloudy points plt.scatter(AF[cloudy_mask_used==1].flatten(), nc[cloudy_mask_used==1].flatten(), c = hght_abv_clb[cloudy_mask_used==1].flatten(), s=2, cmap='hot', alpha=0.5) -# jet, hot +# jet, hot cb = plt.colorbar() cb.set_label("Height above cloud base [m]") - plt.clim(0,1400) - plt.xlim(0,10) - plt.ylim(0,200) - +# plt.clim(0,1400) +# plt.xlim(0,10) +# plt.ylim(0,200) + plt.xlabel('AF') plt.ylabel('Nc [1/cc]') - + #plt.plot((rl*cloudy_mask_used).flatten(), (nc*cloudy_mask_used).flatten(), 'o') # #plt.xscale('log') @@ -170,10 +160,10 @@ # plot adia_rl vs rl plt.clf() plt.scatter(adia_rl[cloudy_mask_used==1].flatten(), rl[cloudy_mask_used==1].flatten(), c = hght_abv_clb[cloudy_mask_used==1].flatten(), s=2, cmap='hot', alpha=0.5) -# jet, hot +# jet, hot cb = plt.colorbar() cb.set_label("Height above cloud base [m]") - plt.clim(0,1400) +# plt.clim(0,1400) plt.gca().set_xlim(left=0) plt.gca().set_ylim(bottom=0) plt.ylabel('r_l') @@ -185,12 +175,12 @@ # # plot NC vs rl plt.clf() plt.scatter(rl[cloudy_mask_used==1].flatten(), nc[cloudy_mask_used==1].flatten(), c = hght_abv_clb[cloudy_mask_used==1].flatten(), s=2, cmap='hot', alpha=0.5) -# jet, hot +# jet, hot cb = plt.colorbar() cb.set_label("Height above cloud base [m]") - plt.clim(0,1400) - plt.xlim(0,5e-3) - plt.ylim(0,200) +# plt.clim(0,1400) +# plt.xlim(0,5e-3) +# plt.ylim(0,200) plt.xlabel('r_l') plt.ylabel('Nc [1/cc]') plt.savefig(outfile + '_NCvsrl_AFperCol_' + str(timestep) +'.png') @@ -200,3 +190,13 @@ # plt.scatter(hght_abv_clb[cloudy_mask_used==1].flatten(), nc[cloudy_mask_used==1].flatten(), c = AF[cloudy_mask_used==1].flatten()) # plt.colorbar() # plt.savefig(outfile + '_NCvsHght_AFperCol_' + str(timestep) +'.png') + + # plot AF profile + plt.clf() + AF[AF==0] = np.nan + AF[cloudy_mask_used==0] = np.nan + AF_mean = np.nanmean(AF, axis=(0,1)) + AF_mean[np.isnan(AF_mean)] = 0 # set AF=0 above and below cloud +# plt.xlim(0,1.5) + plt.plot(AF_mean, hght) + plt.savefig(outfile + '_AFprofile_AFperCol_' + str(timestep) +'.png') diff --git a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp index afaa39c..9a0f64a 100644 --- a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp @@ -60,15 +60,20 @@ std::vector profs_ICMW2020({ }); std::vector fields_ICMW2020({ - "rl", + //"rl", "nc", - "rr", - "nr", - //"ef", "na", - "th", - "rv", - "u", - "w" + "rliq", + //"mass_conc_cloud", + "ratio_mean_volue_r_to_eff_r_cubed", + "cloud_std_dev", + //"rr", + //"nr", + "ef" + //"na", + //"th", + //"rv" + //"u", + //"w" //"sd_conc",//, "r_dry", //"RH", "supersat", }); diff --git a/drawbicyc/include/drawbicyc/plot_fields.hpp b/drawbicyc/include/drawbicyc/plot_fields.hpp index ba7f4b0..c9a8b41 100644 --- a/drawbicyc/include/drawbicyc/plot_fields.hpp +++ b/drawbicyc/include/drawbicyc/plot_fields.hpp @@ -20,6 +20,9 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) auto& n = plotter.map; + // read in density + typename Plotter_t::arr_t rhod(plotter.h5load(plotter.file + "/const.h5", "G")); + blitz::firstIndex i; blitz::secondIndex j; blitz::Range all = blitz::Range::all(); @@ -45,6 +48,18 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } + else if (plt == "mass_conc_cloud") + { + //mass concentration of cloud droplets qc + try{ + auto tmp = plotter.h5load_timestep("actrw_rc_mom3", at * n["outfreq"]) * 4. / 3 * 3.14 * 1e3 / rhod; + + std::string title = " mass concentration of cloud droplets q_c"; + gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; + plotter.plot(gp, tmp); + } + catch(...){} + } else if (plt == "rr") { try{ @@ -60,6 +75,17 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } + else if (plt == "rliq") + { + // liquid water content + try{ + auto tmp = (plotter.h5load_rc_timestep(at * n["outfreq"]) + plotter.h5load_rr_timestep(at * n["outfreq"])) * 1e3;//cloud + rain + std::string title = "liquid water content [g/kg]"; + gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; + plotter.plot(gp, tmp); + } + catch(...){} + } else if (plt == "nc") { // cloud particle concentration @@ -114,6 +140,49 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } + else if (plt == "ratio_mean_volue_r_to_eff_r_cubed") + { + //Ratio of mean radius cubed k + try{ + + typename Plotter_t::arr_t tmp(plotter.h5load_timestep("actrw_rw_mom0", at * n["outfreq"])); + typename Plotter_t::arr_t tmp2(plotter.h5load_timestep("actrw_rw_mom2", at * n["outfreq"])); + typename Plotter_t::arr_t tmp3(plotter.h5load_timestep("actrw_rw_mom3", at * n["outfreq"])); + typename Plotter_t::arr_t snap(plotter.h5load_rc_timestep(at * n["outfreq"])); + auto tmp4 = iscloudy_rc_rico(snap); + + auto tmp5 = where(tmp > 0, tmp2 * tmp2 * tmp2 / tmp, 0); + auto tmp6 = where(tmp3 > 0, tmp5 / tmp3 / tmp3, 0); + auto ratio = tmp6 * tmp4; + + std::string title = "Ratio of mean radius cubed k"; + gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; + plotter.plot(gp, ratio); + } + catch(...){} + } + else if (plt == "cloud_std_dev") + { + //Stadndard deviation of the size distribution + try{ + typename Plotter_t::arr_t tmp1(plotter.h5load_timestep("actrw_rw_mom1", at * n["outfreq"]); + typename Plotter_t::arr_t tmp2(plotter.h5load_timestep("actrw_rw_mom2", at * n["outfreq"])); + typename Plotter_t::arr_t tmp0(plotter.h5load_timestep("actrw_rw_mom0", at * n["outfreq"])); + typename Plotter_t::arr_t snap(plotter.h5load_rc_timestep(at * n["outfreq"])); + auto tmp3 = iscloudy_rc_rico(snap); + + auto tmp = where(tmp0 > 0, tmp2 / tmp0 - tmp1 / tmp0 * tmp1 / tmp0, 0.); + auto tmp4 = where(tmp < 0 , 0, tmp); + auto tmp5 = sqrt(tmp4); + auto tmp6 = tmp5 * tmp3 * 1e6; + + std::string title = "Standardi deviation of the size distribution [um]"; + gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; + plotter.plot(gp, tmp6); + } + catch(...){} + } + /* else if (plt == "na") { diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index 57d1a7f..a95e881 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -620,6 +620,59 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool } catch(...){;} } +// else if (plt == "AF") +// { +// // Adiabatic fraction +// try +// { +// auto tmp = plotter.h5load_timestep("cloud_rw_mom3", at * n["outfreq"]) * 4. / 3. * 3.1416 * 1e3; // kg/kg +// typename Plotter::arr_t snap(tmp); +// snap = iscloudy_rc_rico(snap); // cloudiness mask +// res = plotter.h5load_RH_timestep(at * n["outfreq"]); +// plotter.k_i = blitz::sum(snap, plotter.LastIndex); // sum in the vertical, assumes that all cloudy cells in a column belong to the same cloud + + //Cloud base +// plotter.tmp_int_hrzntl_slice = blitz::first(res > 0, plotter.LastIndex); // cloud base hgt over dz + +// typename Plotter_t::arr_t th(plotter.h5load_timestep("th", at * n["outfreq"])); +// typename Plotter_t::arr_t rv(plotter.h5load_timestep("rv", at * n["outfreq"])); +// typename Plotter_t::arr_t T = th.copy(); +// T *= pow(plotter.p_e(plotter.LastIndex) / p_1000, R_d / c_pd); + +// plotter.tmp_float_hrzntl_slice2 = plotter.get_value_at_hgt(rv, plotter.tmp_int_hrzntl_slice); +// plotter.tmp_float_hrzntl_slice = plotter.get_value_at_hgt(th, plotter.tmp_int_hrzntl_slice); + + // NOTE: we assume that k_i and tmp_float_hr... is contiguous in memory +// for(int i=0; i 0) +// { +// occur_no(cl_hgt_over_dz)+=1; +// res_prof_hlpr(cl_hgt_over_dz) += *(plotter.tmp_float_hrzntl_slice.data() + i); +// } +// } + + // (plotter.h5load_timestep("libcloud_temperature", at * n["outfreq"])); + // init pressure, from rv just to get correct size +// typename Plotter_t::arr_t p(rv); + // T = pow(th_d * pow(rhod * R_d / (p_1000), R_d / c_pd), c_pd / (c_pd - R_d)); + // TODO: env pressure should be used below! + // p = rhod * R_d * (1 + 29./18. * rv) * T; // Rv/Rd = 29/18 +// res = th / T * (T - ql * L / c_p); +// res += ql; +// +// +// typename Plotter_t::arr_t snap(plotter.h5load_rc_timestep(at * n["outfreq"])); +// snap = iscloudy_rc(snap); // cloudiness mask +// plotter.k_i = blitz::first((snap == 1), plotter.LastIndex); +// +// plotter.tmp_int_hrzntl_slice = blitz::first(snap > 0, plotter.LastIndex); // cloud base hgt over dz + // precipitation flux(doesnt include vertical velocity w!) +// plotter.tmp_float_hrzntl_slice = plotter.get_value_at_hgt(th, plotter.tmp_int_hrzntl_slice); // precip flux at cloud base +// } +// res_prof_hlpr = plotter.horizontal_mean(res); // average in x +// } else if (plt == "thl") { // liquid potential temp [K] From 86c5545897e009fa84444d1ccfa07ec613f184b9 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 3 Dec 2020 13:31:24 +0100 Subject: [PATCH 16/30] ICMW_CC_2020 --- Matplotlib_common/latex_labels.py | 12 ++-- NC_vs_AF/nc_vs_af_AFperCol.py | 66 +++++++++++-------- .../ICMW2020_cumulus_congestus/plots.hpp | 6 +- .../drawbicyc/gnuplot_profs_set_labels.hpp | 8 +-- drawbicyc/include/drawbicyc/plot_fields.hpp | 2 +- drawbicyc/include/drawbicyc/plot_prof.hpp | 53 ++++++++++----- drawbicyc/include/drawbicyc/plot_series.hpp | 10 +-- 7 files changed, 95 insertions(+), 62 deletions(-) diff --git a/Matplotlib_common/latex_labels.py b/Matplotlib_common/latex_labels.py index 326c2db..3992252 100644 --- a/Matplotlib_common/latex_labels.py +++ b/Matplotlib_common/latex_labels.py @@ -11,7 +11,7 @@ "surf_precip" : 'Surface precip. [mm/day]', "acc_precip" : 'Accumulated precip. [mm]', "acc_precip_vol" : 'Accumulated precip. [m^3]', - "cl_nc" : '$N_c$ [cm$^{-3}$] (cloudy cells)', + #"cl_nc" : '$N_c$ [cm$^{-3}$] (cloudy cells)', "cl_nr" : '$N_{r>25\mu m}$ [cm$^{-3}$]', "cl_gccn_conc" : '$N_{GCCN}$ [cm$^{-3}$] (cloudy cells)', "thl" : r'$\theta_l$ [K]', @@ -38,11 +38,11 @@ "clb_bigrain_mean_conc" : 'conc. of (r$>$40um) @ clbase [1/cc]', "clb_bigrain_mean_inclt" : 'time since act. of (r$>$40um) @ clbase [s]', "clb_bigrain_mean_gccn_fraction" : 'frac. of (r$>$40um) on gccn @ clbase', - "N_c" : 'number concentration of droplets n [#]', - "rliq" : 'liquid water content LWC', - "actrw_reff_cl" : 'effective radius [um]', - "ratio_mean_volue_r_to_eff_r_cubed" : 'ratio of mean volume radius to effective radius cubed', - "cloud_std_dev" : 'standard deviation' + "cl_nc" : 'Number Concentration of Cloud and Rain droplets n [#]', + "rliq" : 'Liquid Water Content [g/m^3]', + "actrw_reff_cl" : 'Activated Effective Radius [um]', + "ratio_mean_volue_r_to_eff_r_cubed" : 'Ratio of Mean Volume Radius to Effective Radius Cubed []', + "cloud_std_dev" : 'Standard Deviation of Droplet Radius [um]' } diff --git a/NC_vs_AF/nc_vs_af_AFperCol.py b/NC_vs_AF/nc_vs_af_AFperCol.py index 5df0c2a..75f6f81 100644 --- a/NC_vs_AF/nc_vs_af_AFperCol.py +++ b/NC_vs_AF/nc_vs_af_AFperCol.py @@ -3,10 +3,12 @@ from sys import argv, path, maxsize #path.insert(0, "/home/piotr/usr/local/lib/python2.7/dist-packages/") -path.insert(0,"/home/piotr/usr/local/lib/python3/dist-packages/") - +#path.insert(0,"/home/piotr/usr/local/lib/python3/dist-packages/") +path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") import h5py import numpy as np +import matplotlib +matplotlib.use('Agg') import matplotlib.pyplot as plt from libcloudphxx import common as lcmn @@ -19,7 +21,13 @@ evap_lat = 2.5e6 # [J/kg] latent heat of evaporation #timesteps = [12000, 36000, 72000] -timesteps = [13200] +#timesteps = [13200] + +timesteps = np.ones(91) + +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] input_dir = argv[1] outfile = argv[2] @@ -31,7 +39,7 @@ for timestep in timesteps: plt.clf() - filename = input_dir + "/timestep" + str(timestep).zfill(10) + ".h5" + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" #rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:] + h5py.File(filename, "r")["rain_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:,:] * rhod / 1e6; # 1 / cm^3 @@ -138,16 +146,16 @@ cloudy_mask_used[i,j,k] = 0 # plot cloudy points - plt.scatter(AF[cloudy_mask_used==1].flatten(), nc[cloudy_mask_used==1].flatten(), c = hght_abv_clb[cloudy_mask_used==1].flatten(), s=2, cmap='hot', alpha=0.5) +# plt.scatter(AF[cloudy_mask_used==1].flatten(), nc[cloudy_mask_used==1].flatten(), c = hght_abv_clb[cloudy_mask_used==1].flatten(), s=2, cmap='hot', alpha=0.5) # jet, hot - cb = plt.colorbar() - cb.set_label("Height above cloud base [m]") +# cb = plt.colorbar() +# cb.set_label("Height above cloud base [m]") # plt.clim(0,1400) # plt.xlim(0,10) # plt.ylim(0,200) - plt.xlabel('AF') - plt.ylabel('Nc [1/cc]') +# plt.xlabel('AF') +# plt.ylabel('Nc [1/cc]') #plt.plot((rl*cloudy_mask_used).flatten(), (nc*cloudy_mask_used).flatten(), 'o') # @@ -155,35 +163,35 @@ #plt.yscale('log') # #plt.show() - plt.savefig(outfile + '_NCvsAF_AFperCol_' + str(timestep) +'.png') +# plt.savefig(outfile + '_NCvsAF_AFperCol_' + str(timestep) +'.png') # plot adia_rl vs rl - plt.clf() - plt.scatter(adia_rl[cloudy_mask_used==1].flatten(), rl[cloudy_mask_used==1].flatten(), c = hght_abv_clb[cloudy_mask_used==1].flatten(), s=2, cmap='hot', alpha=0.5) +# plt.clf() +# plt.scatter(adia_rl[cloudy_mask_used==1].flatten(), rl[cloudy_mask_used==1].flatten(), c = hght_abv_clb[cloudy_mask_used==1].flatten(), s=2, cmap='hot', alpha=0.5) # jet, hot - cb = plt.colorbar() - cb.set_label("Height above cloud base [m]") +# cb = plt.colorbar() +# cb.set_label("Height above cloud base [m]") # plt.clim(0,1400) - plt.gca().set_xlim(left=0) - plt.gca().set_ylim(bottom=0) - plt.ylabel('r_l') - plt.xlabel('adia r_l') - xpoints = ypoints = plt.xlim() - plt.plot(xpoints, ypoints, linestyle='--', color='k', lw=3, scalex=False, scaley=False) - plt.savefig(outfile + '_rl_vs_AdiaRl_AFperCol_' + str(timestep) +'.png') +# plt.gca().set_xlim(left=0) +# plt.gca().set_ylim(bottom=0) +# plt.ylabel('r_l') +# plt.xlabel('adia r_l') +# xpoints = ypoints = plt.xlim() +# plt.plot(xpoints, ypoints, linestyle='--', color='k', lw=3, scalex=False, scaley=False) +# plt.savefig(outfile + '_rl_vs_AdiaRl_AFperCol_' + str(timestep) +'.png') # # plot NC vs rl - plt.clf() - plt.scatter(rl[cloudy_mask_used==1].flatten(), nc[cloudy_mask_used==1].flatten(), c = hght_abv_clb[cloudy_mask_used==1].flatten(), s=2, cmap='hot', alpha=0.5) +# plt.clf() +# plt.scatter(rl[cloudy_mask_used==1].flatten(), nc[cloudy_mask_used==1].flatten(), c = hght_abv_clb[cloudy_mask_used==1].flatten(), s=2, cmap='hot', alpha=0.5) # jet, hot - cb = plt.colorbar() - cb.set_label("Height above cloud base [m]") +# cb = plt.colorbar() +# cb.set_label("Height above cloud base [m]") # plt.clim(0,1400) # plt.xlim(0,5e-3) # plt.ylim(0,200) - plt.xlabel('r_l') - plt.ylabel('Nc [1/cc]') - plt.savefig(outfile + '_NCvsrl_AFperCol_' + str(timestep) +'.png') +# plt.xlabel('r_l') +# plt.ylabel('Nc [1/cc]') +# plt.savefig(outfile + '_NCvsrl_AFperCol_' + str(timestep) +'.png') # # plot NC vs hght abv clb # plt.clf() @@ -199,4 +207,4 @@ AF_mean[np.isnan(AF_mean)] = 0 # set AF=0 above and below cloud # plt.xlim(0,1.5) plt.plot(AF_mean, hght) - plt.savefig(outfile + '_AFprofile_AFperCol_' + str(timestep) +'.png') + plt.savefig(outfile + '_AFprofile_AFperCol_' + str(int(timestep)) +'.png') diff --git a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp index 9a0f64a..7cade5b 100644 --- a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp @@ -40,7 +40,7 @@ std::vector profs_ICMW2020({ //"prflux", //"clfrac", //"sd_conc", - // "cl_nc", + "cl_nc", //"cl_nc_up", //"w", //"u", @@ -48,7 +48,7 @@ std::vector profs_ICMW2020({ //"base_prflux_vs_clhght", //"non_gccn_rw_cl", //"gccn_rw_cl," - "N_c", + // "N_c", "actrw_reff_cl", "ratio_mean_volue_r_to_eff_r_cubed", "cloud_std_dev" @@ -67,7 +67,7 @@ std::vector fields_ICMW2020({ "ratio_mean_volue_r_to_eff_r_cubed", "cloud_std_dev", //"rr", - //"nr", + "nr", "ef" //"na", //"th", diff --git a/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp b/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp index fcb9422..faa7a28 100644 --- a/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp +++ b/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp @@ -78,15 +78,15 @@ void gnuplot_profs_set_labels(Gnuplot &gp, std::string plt, const bool normalize } if (plt == "actrw_reff_cl") { - gp << "set title 'activated (rw>rc) effective radius'\n"; + gp << "set title 'Activated Effective Radius [um]'\n"; } if (plt == "cloud_std_dev") { - gp << "set title 'standard deviation'\n"; + gp << "set title 'Standard Deviation of Droplet Radius [um]'\n"; } if (plt == "ratio_mean_volue_r_to_eff_r_cubed") { - gp << "set title 'ratio of mean volume radius to effective radius cubed'\n"; + gp << "set title 'Ratio of Mean Volume Radius to Effective Radius Cubed [-]'\n"; } else if (plt == "rv") @@ -138,7 +138,7 @@ void gnuplot_profs_set_labels(Gnuplot &gp, std::string plt, const bool normalize } else if (plt == "cl_nc") { - gp << "set title 'cloud droplets concentration in cloudy cells [1/cm^3]'\n"; + gp << "set title 'Number Concentration of Cloud and Rain droplets n [#]'\n"; } else if (plt == "thl") { diff --git a/drawbicyc/include/drawbicyc/plot_fields.hpp b/drawbicyc/include/drawbicyc/plot_fields.hpp index c9a8b41..b013541 100644 --- a/drawbicyc/include/drawbicyc/plot_fields.hpp +++ b/drawbicyc/include/drawbicyc/plot_fields.hpp @@ -165,7 +165,7 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) { //Stadndard deviation of the size distribution try{ - typename Plotter_t::arr_t tmp1(plotter.h5load_timestep("actrw_rw_mom1", at * n["outfreq"]); + typename Plotter_t::arr_t tmp1(plotter.h5load_timestep("actrw_rw_mom1", at * n["outfreq"])); typename Plotter_t::arr_t tmp2(plotter.h5load_timestep("actrw_rw_mom2", at * n["outfreq"])); typename Plotter_t::arr_t tmp0(plotter.h5load_timestep("actrw_rw_mom0", at * n["outfreq"])); typename Plotter_t::arr_t snap(plotter.h5load_rc_timestep(at * n["outfreq"])); diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index a95e881..e92829d 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -91,7 +91,13 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool //res += plotter.h5load_ra_timestep(at * n["outfreq"]) * 1e3; // aerosol res += plotter.h5load_rc_timestep(at * n["outfreq"]) * 1e3; // cloud res += plotter.h5load_rr_timestep(at * n["outfreq"]) * 1e3; // rain - res_prof_hlpr = plotter.horizontal_mean(res); // average in x + //res_prof_hlpr = plotter.horizontal_mean(res); // average in x + typename Plotter_t::arr_t rc_mask(plotter.h5load_rc_timestep(at * n["outfreq"])); + rc_mask = iscloudy_rc_rico(rc_mask); + //res *= rc_mask; + //res_prof_hlpr = plotter.horizontal_mean(res); // average in x + prof_tmp = plotter.horizontal_sum(rc_mask); + res_prof_hlpr = where(prof_tmp > 0, plotter.horizontal_sum(res) / prof_tmp, 0); } if (plt == "gccn_rw") { @@ -598,25 +604,42 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool res = plotter.h5load_nc_timestep(at * n["outfreq"]) * rhod / 1e6; // from sepcific to normal moment + per cm^3 res_prof_hlpr = plotter.horizontal_mean(res); // average in x } + //else if (plt == "cl_nc") + // { + // cloud droplet (0.5um < r < 25 um) concentration in cloudy grid cells + // try + // { + // cloud fraction (cloudy if N_c > 20/cm^3) + // auto tmp = plotter.h5load_nc_timestep(at * n["outfreq"]); + // typename Plotter_t::arr_t snap(tmp); + // snap *= rhod; // b4 it was specific moment + // snap /= 1e6; // per cm^3 + // typename Plotter_t::arr_t snap2; + // snap2.resize(snap.shape()); + // snap2=snap; + // snap = iscloudy_rc_rico(snap); // cloudiness mask + // snap2 *= snap; + + // mean only over cloudy cells + // prof_tmp = plotter.horizontal_sum(snap); // number of cloudy cells on a given level + // res_prof_hlpr = where(prof_tmp > 0 , plotter.horizontal_sum(snap2) / prof_tmp, 0); + // } + // catch(...){;} + //} else if (plt == "cl_nc") { - // cloud droplet (0.5um < r < 25 um) concentration in cloudy grid cells + // cloud droplet (0.5um < r < 25 um) concentration in cloudy grid cells try { - // cloud fraction (cloudy if N_c > 20/cm^3) - auto tmp = plotter.h5load_nc_timestep(at * n["outfreq"]); - typename Plotter_t::arr_t snap(tmp); - snap *= rhod; // b4 it was specific moment - snap /= 1e6; // per cm^3 - typename Plotter_t::arr_t snap2; - snap2.resize(snap.shape()); - snap2=snap; - snap = iscloudy(snap); // cloudiness mask - snap2 *= snap; - + typename Plotter_t::arr_t rc_mask(plotter.h5load_rc_timestep(at * n["outfreq"])); + rc_mask = iscloudy_rc_rico(rc_mask); + typename Plotter_t::arr_t nc(plotter.h5load_nc_timestep(at * n["outfreq"])); + nc *= rc_mask; + nc *= rhod; // b4 it was specific moment + nc /= 1e6; // to get 1/cc // mean only over cloudy cells - prof_tmp = plotter.horizontal_sum(snap); // number of cloudy cells on a given level - res_prof_hlpr = where(prof_tmp > 0 , plotter.horizontal_sum(snap2) / prof_tmp, 0); + prof_tmp = plotter.horizontal_sum(rc_mask); // number of cloudy cells on a given level + res_prof_hlpr = where(prof_tmp > 0 , plotter.horizontal_sum(nc) / prof_tmp, 0); } catch(...){;} } diff --git a/drawbicyc/include/drawbicyc/plot_series.hpp b/drawbicyc/include/drawbicyc/plot_series.hpp index 548cbba..9e3541d 100644 --- a/drawbicyc/include/drawbicyc/plot_series.hpp +++ b/drawbicyc/include/drawbicyc/plot_series.hpp @@ -501,11 +501,13 @@ void plot_series(Plotter_t plotter, Plots plots, std::string type) // Total number of Cloud and Rain Droplets try { - auto tmp = plotter.h5load_timestep("cloud_rw_mom0", at *n["outfreq"]) * rhod; + auto tmp = plotter.h5load_timestep("actrw_rw_mom0", at *n["outfreq"]) * rhod; + //auto tmp = plotter.h5load_timestep("cloud_rw_mom0", at *n["outfreq"]) * rhod; typename Plotter_t::arr_t snap(tmp); - auto tmp2 = plotter.h5load_timestep("rain_rw_mom0", at * n["outfreq"]); - typename Plotter_t::arr_t snap2(tmp2); - res_prof(at) = (blitz::sum(snap) + blitz::sum(snap2))*plotter.CellVol; + //auto tmp2 = plotter.h5load_timestep("rain_rw_mom0", at * n["outfreq"]); + //typename Plotter_t::arr_t snap2(tmp2); + //res_prof(at) = (blitz::sum(snap) + blitz::sum(snap2))*plotter.CellVol; + res_prof(at) = blitz::sum(snap)*plotter.CellVol; } catch(...){;} } From 4e3157d86c7fc0a7cff45dc251aa74dc7e791bb9 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Tue, 8 Dec 2020 22:41:24 +0100 Subject: [PATCH 17/30] working_on_rysy --- NC_vs_AF/af.py | 128 ++++++++++++++++++++++++ NC_vs_AF/af_test.py | 147 ++++++++++++++++++++++++++++ NC_vs_AF/nc_vs_af_AFperCol_coppy.py | 137 ++++++++++++++++++++++++++ NC_vs_AF/start.sh | 1 + 4 files changed, 413 insertions(+) create mode 100644 NC_vs_AF/af.py create mode 100644 NC_vs_AF/af_test.py create mode 100644 NC_vs_AF/nc_vs_af_AFperCol_coppy.py create mode 100644 NC_vs_AF/start.sh diff --git a/NC_vs_AF/af.py b/NC_vs_AF/af.py new file mode 100644 index 0000000..7839acd --- /dev/null +++ b/NC_vs_AF/af.py @@ -0,0 +1,128 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn + +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 20}) +plt.figure(figsize=(16,10)) + +evap_lat = 2.5e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) + +for i in range(1, 91): + timesteps[i] = i*240 + +timesteps = timesteps[1:91] +print(timesteps) + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, ny, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] + +for timestep in timesteps: + plt.clf() + print(int(timestep)) + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + #rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:] + h5py.File(filename, "r")["rain_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:,:] * rhod / 1e6; # 1 / cm^3 + + # cloudiness mask - as in DYCOMS paper + cloudy_mask = np.where(nc > 20, 1, 0) + + print('nc>20 cloudy cells: ', np.sum(cloudy_mask)) + print('nc>20 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) + + # cloudiness mask - rl > 1e-4 + cloudy_mask = np.where(rl > 1e-4, 1, 0) + + print('rl>1e-4 cloudy cells: ', np.sum(cloudy_mask)) + print('rl>1e-4 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + + print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask)) + print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) + + # ---- adiabatic LWC ---- + AF = np.zeros([nx, ny, nz]) + #adia_rl = np.zeros([nx, ny, nz]) + adia_rl = np.zeros([nz]) + # th and rv + th = h5py.File(filename, "r")["th"][:,:,:]; + rv = h5py.File(filename, "r")["rv"][:,:,:]; + + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + + # cloud base + clb_idx = np.argmax(RH > 1, axis=2) + + # clb condition per column + clb_rv = np.zeros([nx, ny]) + clb_th = np.zeros([nx, ny]) + + for i in np.arange(nx): + for j in np.arange(ny): + if clb_idx[i,j] > 0: + clb_rv[i,j] = rv[i, j, clb_idx[i, j]] + clb_th[i,j] = th[i, j, clb_idx[i, j]] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + parcel_rv = np.mean(clb_rv[clb_rv>0]) + parcel_th = np.mean(clb_th[clb_th>0]) + parcel_rl = 0 + + print('parcel init: th = ', parcel_th, ' rv = ', parcel_rv) + + for k in np.arange(nz): + parcel_T = parcel_th * lcmn.exner(p_e.astype(float)[k]) + delta_rv = parcel_rv - lcmn.r_vs(parcel_T, p_e.astype(float)[k]) + if delta_rv <= 0: + delta_rv = 0 + parcel_rv -= delta_rv + parcel_th += delta_rv * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl += delta_rv + adia_rl[k] = parcel_rl + + print(p_e) + print(adia_rl) + + for j in np.arange(ny): + for k in np.arange(nz): + if cloudy_mask[i,j,k] > 0: + AF[i, j, k] = rl[i,j,k] / adia_rl[k] + else: + AF[i, j, k] = 0 + + + #plt.plot((AF * cloudy_mask).flatten(), (dz * cloudy_mask).flatten(), '.', markersize=1) + plt.plot((AF * cloudy_mask).flatten(), (dz*cloudy_mask*50).flatten(), '.', markersize=1) + plt.xlim(0,2) + #plt.ylim(0,10000) + + plt.xlabel('AF') + plt.ylabel('Height') + + plt.savefig(outfile + '_NCvsAF_' + str(timestep) +'.png') diff --git a/NC_vs_AF/af_test.py b/NC_vs_AF/af_test.py new file mode 100644 index 0000000..7d741ff --- /dev/null +++ b/NC_vs_AF/af_test.py @@ -0,0 +1,147 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn + +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 20}) +plt.figure(figsize=(16,10)) + +evap_lat = 2.5e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) + +for i in range(1, 91): + timesteps[i] = i*240 + +#timesteps = [ 8400, 10800, 13200, 17040, 18720, 20400, 21600] +timesteps = timesteps[1:91] +print(timesteps) + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, ny, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] + +for timestep in timesteps: + plt.clf() + print(int(timestep)) + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + #rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:] + h5py.File(filename, "r")["rain_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + #rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + + # ---- adiabatic LWC ---- + AF = np.zeros([nx, ny, nz]) + adia_rl = np.zeros([nx, ny, nz]) + #adia_rl = np.zeros([nz]) + clb_rv = np.zeros([nx, ny]) + clb_th = np.zeros([nx, ny]) + height = np.zeros(nz) + # th and rv + th = h5py.File(filename, "r")["th"][:,:,:]; + rv = h5py.File(filename, "r")["rv"][:,:,:]; + + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + + # cloud base + clb_idx = np.argmax(RH > 1, axis=2) + ''' + for i in np.arange(nx): + for j in np.arange(ny): + if clb_idx[i,j] > 0: + clb_rv[i,j] = rv[i, j, clb_idx[i, j]] + clb_th[i,j] = th[i, j, clb_idx[i, j]] + ''' + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + ''' + parcel_rv = np.mean(clb_rv[clb_rv>0]) + parcel_th = np.mean(clb_th[clb_th>0]) + parcel_rl = 0 + ''' + #print('parcel init: th = ', parcel_th, ' rv = ', parcel_rv) + ''' + for k in np.arange(nz): + parcel_T = parcel_th * lcmn.exner(p_e.astype(float)[k]) + delta_rv = parcel_rv - lcmn.r_vs(parcel_T, p_e.astype(float)[k]) + vif delta_rv <= 0: + delta_rv = 0 + parcel_0rv -= delta_rv + parcel_th += delta_rv * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl += delta_rv + adia_rl[k] = parcel_rl + ''' + for i in np.arange(nx): + for j in np.arange(ny): + parcel_rv = rv[i, j, clb_idx[i, j]] + parcel_th = th[i, j, clb_idx[i, j]] + parcel_rl = 0 + for k in np.arange(nz): + if k < clb_idx[i, j] or clb_idx[i,j] == 0: + adia_rl[i,j,k] = 0 + else: + parcel_T = parcel_th * lcmn.exner(p_e.astype(float)[k]) + delta_rv = parcel_rv - lcmn.r_vs(parcel_T, p_e.astype(float)[k]) + if delta_rv <= 0: + delta_rv = 0 + parcel_rv -= delta_rv + parcel_th += delta_rv * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl += delta_rv + adia_rl[i,j,k] = parcel_rl + #print(rl[rl>0]) + #print(adia_rl[adia_rl>0]) + + for i in np.arange(nx): + for j in np.arange(ny): + for k in np.arange(nz): + height[k] = k *50 + if cloudy_mask[i,j,k] > 0: + if adia_rl[i, j ,k] > 0: + AF[i, j, k] = rl[i,j,k] / (adia_rl[i, j, k] *1e3) + else: + AF[i, j, k] = 0 + else: + AF[i, j, k] = 0 + + #print(AF.shape) + #print(AF[AF>0].shape) + AF[AF == 0] = np.nan + AF_yz = np.nanmean(AF, axis=0) + AF_z = np.nanmean(AF_yz, axis=0) + + + #AF = np.average(AF[AF>0], axis=1) + #height = [height, height, height] + #plt.plot((AF * cloudy_mask).flatten(), (dz * cloudy_mask).flatten(), '.', markersize=1) + # plt.plot((AF * cloudy_mask).flatten(), height.flatten(), '.', markersize=1) + plt.plot(AF_z , height) + # plt.plot((AF * cloudy_mask).flatten(), height.flatten()) + plt.xlim(0,2) + plt.ylim(0,10000) + + #plt.xlabel('AF') + #plt.ylabel('Height') + + plt.savefig(outfile + '_NCvsAF_' + str(int(timestep)) +'.png') + + diff --git a/NC_vs_AF/nc_vs_af_AFperCol_coppy.py b/NC_vs_AF/nc_vs_af_AFperCol_coppy.py new file mode 100644 index 0000000..737f803 --- /dev/null +++ b/NC_vs_AF/nc_vs_af_AFperCol_coppy.py @@ -0,0 +1,137 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated separately for each column + +from sys import argv, path, maxsize +#path.insert(0,"/home/piotr/usr/local/lib/python3/dist-packages/") +path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn + +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 20}) +plt.figure(figsize=(16,10)) + +evap_lat = 2.5e6 # [J/kg] latent heat of evaporation + +#timesteps = [12000, 36000, 72000] +#timesteps = [13200] + +timesteps = np.ones(91) + +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, ny, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] + +for timestep in timesteps: + plt.clf() + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + #rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:] + h5py.File(filename, "r")["rain_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:,:] * rhod / 1e6; # 1 / cm^3 + + # cloudiness mask - as in DYCOMS paper + cloudy_mask = np.where(nc > 20, 1, 0) + + print('nc>20 cloudy cells: ', np.sum(cloudy_mask)) + print('nc>20 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) + + # cloudiness mask - rl > 1e-4 + cloudy_mask = np.where(rl > 1e-4, 1, 0) + + print('rl>1e-4 cloudy cells: ', np.sum(cloudy_mask)) + print('rl>1e-4 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask)) + print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask) / np.sum(cloudy_mask)) + + hght_abv_clb = np.zeros([nx, ny, nz]) + hght = np.arange(nz) * dz + + # ---- adiabatic LWC ---- + AF = np.zeros([nx, ny, nz]) + adia_rl = np.zeros([nx, ny, nz]) + # th and rv + th = h5py.File(filename, "r")["th"][:,:,:]; + rv = h5py.File(filename, "r")["rv"][:,:,:]; + + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + + # cloud base + #clb_idx = np.argmax(RH > 1, axis=2) + clb_idx = np.argmax(cloudy_mask_used>0, axis=2) + + # clb condition per column + clb_rv = np.zeros([nx, ny]) + clb_th = np.zeros([nx, ny]) + + + # model a parcel to get an adiabatic rl + for i in np.arange(nx): + for j in np.arange(ny): + parcel_rl = 0 + parcel_th = 0 + parcel_rv = 0 + if clb_idx[i,j] > 0: + parcel_rv[i,j] = rv[i, j, clb_idx[i, j]] + parcel_th[i,j] = th[i, j, clb_idx[i, j]] + for k in np.arange(nz): + parcel_T = parcel_th * lcmn.exner(p_e.astype(float)[k]) + delta_rv = parcel_rv - lcmn.r_vs(parcel_T, p_e.astype(float)[k]) + if delta_rv <= 0: + delta_rv = 0 + parcel_rv -= delta_rv + parcel_th += delta_rv * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl += delta_rv + adia_rl[i, j, k] = parcel_rl + + + for i in np.arange(nx): + for j in np.arange(ny): + for k in np.arange(nz): + if adia_rl[i, j, k] == 0: + AF[i, j, k] = 0 + else: + AF[i, j, k] = rl[i,j,k] / adia_rl[i, j, k] + hght_abv_clb[i, j, k] = (k - clb_idx[i,j]) * dz + + # set cloudy_mask=0 below cloud base and in non-cloudy columns + # not needed? after cloud base detection based on cloudy mask and not RH? + for i in np.arange(nx): + for j in np.arange(ny): + for k in np.arange(nz): + if k < clb_idx[i,j] or clb_idx[i,j]==0: + cloudy_mask_used[i,j,k] = 0 + # plot AF profile + plt.clf() + AF[AF==0] = np.nan + AF[cloudy_mask_used==0] = np.nan + AF_mean = np.nanmean(AF, axis=(0,1)) + AF_mean[np.isnan(AF_mean)] = 0 # set AF=0 above and below cloud +# plt.xlim(0,1.5) + plt.plot(AF_mean, hght) + plt.savefig(outfile + '_AFprofile_AFperCol_' + str(int(timestep)) +'.png') diff --git a/NC_vs_AF/start.sh b/NC_vs_AF/start.sh new file mode 100644 index 0000000..eb0940a --- /dev/null +++ b/NC_vs_AF/start.sh @@ -0,0 +1 @@ +python3 af_test.py /home/pzmij/wyniki/LT_3D/Lt_ws_sd_40_dt5_3h_200_15_07_out_lgrngn /home/pzmij/wyniki/LT_3D/NC_test2/NC From d0a1d852c0e9e5ad97a7dd5580907b5f2cad092e Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 15 Apr 2021 22:52:10 +0200 Subject: [PATCH 18/30] Adiabatic Fraction ICMW2020 --- NC_vs_AF/AF_rysy.py | 156 ++++++++++++++++++ NC_vs_AF/AF_rysy_xz2d.py | 110 ++++++++++++ .../ICMW2020_cumulus_congestus/plots.hpp | 12 +- .../drawbicyc/gnuplot_profs_set_labels.hpp | 2 +- drawbicyc/include/drawbicyc/plot_fields.hpp | 27 ++- drawbicyc/include/drawbicyc/plot_prof.hpp | 2 +- 6 files changed, 292 insertions(+), 17 deletions(-) create mode 100644 NC_vs_AF/AF_rysy.py create mode 100644 NC_vs_AF/AF_rysy_xz2d.py diff --git a/NC_vs_AF/AF_rysy.py b/NC_vs_AF/AF_rysy.py new file mode 100644 index 0000000..efda1f7 --- /dev/null +++ b/NC_vs_AF/AF_rysy.py @@ -0,0 +1,156 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") #/home/pzmij/biblioteki/local_folder/seed/lib/python3/dist-packages") + +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 10}) +#plt.figure(figsize=(16,10)) + +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +#timesteps = [12960, 13200, 14400] +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:90] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, ny, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +hght = np.arange(nz) * dz +bin = np.linspace(0,1.4,len(np.arange(nz))) +bin_size = bin[2]-bin[1] +#print(bin_size) + +# ---- adiabatic LWC ---- +AF_min = np.zeros([nx, ny, nz]) +adia_rl = np.zeros([nz]) +adia_rl_min = np.zeros([nz]) +clb_rv_min = np.zeros([nx, ny]) +clb_th_min = np.zeros([nx, ny]) +Biny = [0 for i in np.arange(nz)] +Biny_x = [0 for i in np.arange(nz)] +Slice = np.zeros([nx,ny]) + +for timestep in timesteps: + plt.clf() + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:,:] * rhod / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask_used)) + # print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask_used) / np.sum(cloudy_mask_used)) + + # th and rv + th = h5py.File(filename, "r")["th"][:,:,:]; + rv = h5py.File(filename, "r")["rv"][:,:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=2) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + + for i in np.arange(nx): + for j in np.arange(ny): + if clb_idx[i,j] > 0: + clb_rv_min[i,j] = rv[i, j, int(min_hght/dz)] + clb_th_min[i,j] = th[i, j, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for j in np.arange(ny): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, j, k] = 0 + else: + AF_min[i, j, k] = rl[i,j,k] / adia_rl_min[k] + +######Biny + + AF = AF_min * cloudy_mask_used + for k in np.arange(nz): + for i in np.arange(nx): + for j in np.arange(ny): + Slice[i, j] = AF[i, j, k] + Slice[i,:][Slice[i,:]==0] = np.nan + Biny[i] = np.digitize(Slice[i,:],bin) + Biny[i] = np.bincount(Biny[i]) + Biny[i] = np.pad(Biny[i], (0, (len(bin)+1)-len(Biny[i])), mode='constant') + Biny = list(map(list,Biny)) + Biny_x[k] = np.log10(np.sum(Biny,0)/bin_size) + + #print(Biny_x) + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min, axis=(0,1)) + AF_mean_min[np.isnan(AF_mean_min)] = 0 + bins = np.array(Biny_x) + bins = bins[:,:-1] + + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="60%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.3, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + e = ax.contourf(bin, hght, np.round(bins,2), 200, cmap='gnuplot') #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)") + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim(0,10000) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.savefig(outfile + '_NCvsAF_' + str(int(timestep)) +'.png') + diff --git a/NC_vs_AF/AF_rysy_xz2d.py b/NC_vs_AF/AF_rysy_xz2d.py new file mode 100644 index 0000000..37f5020 --- /dev/null +++ b/NC_vs_AF/AF_rysy_xz2d.py @@ -0,0 +1,110 @@ +from sys import argv, path, maxsize +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages")#/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") + +import h5py +import numpy as np +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 11}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, ny, nz = rhod.shape +ny_cross = ny//2 +rhod_cros = rhod[:,ny_cross,:] +#print(rhod_cros.shape) +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +dx = h5py.File(input_dir + "/const.h5", "r").attrs["dx"] + +hght = np.arange(nz) * dz +X = np.arange(nx) * dx + +# ---- adiabatic LWC ---- +AF_min = np.zeros([nx, nz]) +adia_rl = np.zeros(nz) +adia_rl_min = np.zeros(nz) +clb_rv_min = np.zeros(nz) +clb_th_min = np.zeros(nz) + +for timestep in timesteps: + plt.clf() + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,ny_cross,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,ny_cross,:] * rhod_cros / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th = h5py.File(filename, "r")["th"][:,ny_cross,:]; + rv = h5py.File(filename, "r")["rv"][:,ny_cross,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + for i in np.arange(nz): + if clb_idx[i] > 0: + clb_rv_min[i] = rv[i, int(min_hght/dz)] + clb_th_min[i] = th[i, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, k] = 0 + else: + AF_min[i, k] = rl[i, k] / adia_rl_min[k] + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_min[AF_min>1.4] = np.nan + AF_min = np.transpose(AF_min) + + e = plt.contourf(X, hght, AF_min, 10, cmap='gnuplot', vmin=0, vmax=1.4, levels=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) #bin[1:] + plt.colorbar(e, orientation='vertical', label=r"AF[]", ticks=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) + plt.clim(0, 1.4) + plt.ylabel('Height [m]') + plt.xlabel('X [m]') + plt.title('Adiabatic Fraction [](Y=5000 m, {}s )'.format(int(timestep/2))) + plt.savefig(outfile + '_AF_xz2d_' + str(int(timestep/2)) +'.png') diff --git a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp index 7cade5b..e6b645d 100644 --- a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp @@ -50,7 +50,7 @@ std::vector profs_ICMW2020({ //"gccn_rw_cl," // "N_c", "actrw_reff_cl", - "ratio_mean_volue_r_to_eff_r_cubed", + "ratio_mean_volume_r_to_eff_r_cubed", "cloud_std_dev" //,"vel_div" //, "nc_up" @@ -61,14 +61,14 @@ std::vector profs_ICMW2020({ std::vector fields_ICMW2020({ //"rl", - "nc", - "rliq", + "number_concentration", + "LWC", //"mass_conc_cloud", - "ratio_mean_volue_r_to_eff_r_cubed", + "ratio_mean_volume_r_to_eff_r_cubed", "cloud_std_dev", //"rr", - "nr", - "ef" + "rain_drops_concentration", + "effective_radius", //"na", //"th", //"rv" diff --git a/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp b/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp index faa7a28..153f205 100644 --- a/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp +++ b/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp @@ -84,7 +84,7 @@ void gnuplot_profs_set_labels(Gnuplot &gp, std::string plt, const bool normalize { gp << "set title 'Standard Deviation of Droplet Radius [um]'\n"; } - if (plt == "ratio_mean_volue_r_to_eff_r_cubed") + if (plt == "ratio_mean_volume_r_to_eff_r_cubed") { gp << "set title 'Ratio of Mean Volume Radius to Effective Radius Cubed [-]'\n"; } diff --git a/drawbicyc/include/drawbicyc/plot_fields.hpp b/drawbicyc/include/drawbicyc/plot_fields.hpp index b013541..c573219 100644 --- a/drawbicyc/include/drawbicyc/plot_fields.hpp +++ b/drawbicyc/include/drawbicyc/plot_fields.hpp @@ -22,7 +22,7 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) // read in density typename Plotter_t::arr_t rhod(plotter.h5load(plotter.file + "/const.h5", "G")); - + blitz::firstIndex i; blitz::secondIndex j; blitz::Range all = blitz::Range::all(); @@ -75,7 +75,7 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } - else if (plt == "rliq") + else if (plt == "LWC") { // liquid water content try{ @@ -86,7 +86,7 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } - else if (plt == "nc") + else if (plt == "number_concentration") { // cloud particle concentration try{ @@ -114,7 +114,7 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } - else if (plt == "nr") + else if (plt == "rain_drops_concentration") { try{ // rain particle concentration @@ -128,19 +128,28 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } - else if (plt == "ef") + else if (plt == "effective_radius") { try{ // effective radius - auto tmp = plotter.h5load_timestep("cloud_rw_mom3", at * n["outfreq"]) / plotter.h5load_timestep("cloud_rw_mom2", at * n["outfreq"]) * 1e6; - std::string title = "cloud (0.5um < r < 25um) droplet effective radius [μm]"; + //auto tmp = plotter.h5load_timestep("actrw_rw_mom3", at * n["outfreq"]) / plotter.h5load_timestep("actrw_rw_mom2", at * n["outfreq"];//) * 1e6; + + typename Plotter_t::arr_t tmp2(plotter.h5load_timestep("actrw_rw_mom2", at * n["outfreq"])); + typename Plotter_t::arr_t tmp3(plotter.h5load_timestep("actrw_rw_mom3", at * n["outfreq"])); + typename Plotter_t::arr_t snap(plotter.h5load_rc_timestep(at * n["outfreq"])); + auto tmp4 = iscloudy_rc_rico(snap); + + auto tmp5 = where(tmp2 > 0, tmp3 / tmp2, 0); + auto ratio = tmp5 * tmp4*1e6; + + std::string title = "cloud (0.5um < r < 25um) droplet effective radius [μm]"; gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; // gp << "set cbrange [1:20]\n"; - plotter.plot(gp, tmp); + plotter.plot(gp, ratio); } catch(...){} } - else if (plt == "ratio_mean_volue_r_to_eff_r_cubed") + else if (plt == "ratio_mean_volume_r_to_eff_r_cubed") { //Ratio of mean radius cubed k try{ diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index e92829d..825c29e 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -319,7 +319,7 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool prof_tmp = plotter.horizontal_sum(res_tmp2); // number of downdraft cells on a given level res_prof_hlpr = where(prof_tmp > 0 , plotter.horizontal_sum(res_tmp) / prof_tmp, 0); } - if (plt == "ratio_mean_volue_r_to_eff_r_cubed") + if (plt == "ratio_mean_volume_r_to_eff_r_cubed") { { //auto tmp0 = plotter.h5load_timestep("actrw_rw_mom0", at * n["outfreq"]); From 46ead79d391e0bb2c01da539841803f57e1ae3aa Mon Sep 17 00:00:00 2001 From: ryba183 Date: Mon, 2 Aug 2021 21:54:56 +0200 Subject: [PATCH 19/30] preparation for randomness --- NC_vs_AF/AF_mean_parallel.py | 222 ++++++++++++++++++ NC_vs_AF/AF_rysy_multi.py | 180 ++++++++++++++ NC_vs_AF/AF_rysy_xz2d_multi.py | 126 ++++++++++ drawbicyc/average.cpp | 2 +- .../ICMW2020_cumulus_congestus/plots.hpp | 10 +- drawbicyc/include/drawbicyc/plot_fields.hpp | 30 ++- papers/ICMW2020_CC/compare_profs.py | 6 +- 7 files changed, 559 insertions(+), 17 deletions(-) create mode 100644 NC_vs_AF/AF_mean_parallel.py create mode 100644 NC_vs_AF/AF_rysy_multi.py create mode 100644 NC_vs_AF/AF_rysy_xz2d_multi.py diff --git a/NC_vs_AF/AF_mean_parallel.py b/NC_vs_AF/AF_mean_parallel.py new file mode 100644 index 0000000..19ae21b --- /dev/null +++ b/NC_vs_AF/AF_mean_parallel.py @@ -0,0 +1,222 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + +''' +HOW TO RUN: + + +python3 AF_test.py /home/piotr/Piotr/WORKSHOPS/Prof_dat /dxyz100_SD100_Coal_NA2_1_SH_out_lgrngn /dxyz100_SD100_Coal_NA2_2_SH_out_lgrngn /dxyz100_SD100_Coal_NA2_3_SH_out_lgrngn /dxyz100_SD100_Coal_NA2_4_SH_out_lgrngn /dxyz100_SD100_Coal_NA2_5_SH_out_lgrngn + + + +''' + +import h5py +import numpy as np +import matplotlib +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + +def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + +def licz_srednia(parameter_name, iter_value, paths): + dl = len(parameter_name) + srednia =[0 for i in range(len(paths))] + STD = [0 for i in range(len(paths))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + return srednia[iter_value], STD[iter_value] + +start = time.perf_counter() +plt.rcParams.update({'font.size': 12}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i +timesteps = timesteps[1:90] +np.set_printoptions(threshold=maxsize) + +n = len(argv) +paths = argv[1] +const = [argv[i] for i in range(2,n)] + + + +files = [0 for i in range(len(paths))] +series_file = [0 for i in range(len(paths))] + +# for i in range(1,91): +# i = np.linspace(1,91,91) +def Adia_fraction(i): + + rhod = [0 for i in range(len(const))] + p_e = [0 for i in range(len(const))] + dz = [0 for i in range(len(const))] + rl = [0 for i in range(len(const))] + rl_base = [0 for i in range(len(const))] + nc = [0 for i in range(len(const))] + th = [0 for i in range(len(const))] + rv = [0 for i in range(len(const))] + + for p in range(len(const)): + rhod[p] = h5py.File(paths + const[p]+"/const.h5", "r")["G"][:,:,:] + p_e[p] = h5py.File(paths + const[p]+"/const.h5", "r")["p_e"][:] + dz[p] = h5py.File(paths + const[p]+"/const.h5", "r").attrs["dz"] + rl[p] = (h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["actrw_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[p] = (h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc[p] = h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom0"][:,:,:] + th[p] = h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["th"][:,:,:]; + rv[p] = h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["rv"][:,:,:]; + rhod = np.mean(rhod,axis=0) + p_e = np.mean(p_e,axis=0) + dz = np.mean(dz,axis=0) + rl = np.mean(rl,axis=0) + rl_base = np.mean(rl_base,axis=0) + nc = np.mean(nc,axis=0) * rhod / 1e6# 1 / cm^3 + th = np.mean(th,axis=0) + rv = np.mean(rv,axis=0) + + nx, ny, nz = rhod.shape + hght = np.arange(nz) * dz + bin = np.linspace(0,1.4,len(np.arange(nz))) + bin_size = bin[2]-bin[1] + + + plt.clf() + # ---- adiabatic LWC ---- + AF_min = np.zeros([nx, ny, nz]) + adia_rl = np.zeros([nz]) + adia_rl_min = np.zeros([nz]) + clb_rv_min = np.zeros([nx, ny]) + clb_th_min = np.zeros([nx, ny]) + Biny = [0 for i in np.arange(nz)] + Biny_x = [0 for i in np.arange(nz)] + Slice = np.zeros([nx,ny]) + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=2) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + for d in np.arange(nx): + for j in np.arange(ny): + if clb_idx[d,j] > 0: + clb_rv_min[d,j] = rv[d, j, int(min_hght/dz)] + clb_th_min[d,j] = th[d, j, int(min_hght/dz)] + + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for y in np.arange(nx): + for j in np.arange(ny): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[y, j, k] = 0 + else: + AF_min[y, j, k] = rl[y,j,k] / adia_rl_min[k] + + ######Biny + + AF = AF_min * cloudy_mask_used + for k in np.arange(nz): + # for k iny range(25,30): + for y in np.arange(nx): + for j in np.arange(ny): + Slice[y, j] = AF[y, j, k] + Slice[y,:][Slice[y,:]==0] = np.nan + # print(Slice[i,:]) + Biny[y] = np.digitize(Slice[y,:],bin) + # print(Biny[i]) + Biny[y] = np.bincount(Biny[y]) + Biny[y] = np.pad(Biny[y], (0, (len(bin)+1)-len(Biny[y])), mode='constant') + Biny = list(map(list,Biny)) + Biny_x[k] = np.log10(np.sum(Biny,0)/bin_size) + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min, axis=(0,1)) + AF_mean_min[np.isnan(AF_mean_min)] = 0 + bins = np.array(Biny_x) + bins = bins[:,:-1] + + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="50%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.4, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + e = ax.contourf(bin, hght, bins, 200, cmap='gnuplot') #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)", format='%.2f') + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim(0,10000) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.savefig(paths + '/AF_average_' + str(240*i).zfill(10) +'.png') + +punkty = np.intc(np.linspace(1,91,91)) +with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(Adia_fraction, punkty) + +# Adia_fraction(punkty[20]) +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/AF_rysy_multi.py b/NC_vs_AF/AF_rysy_multi.py new file mode 100644 index 0000000..ffd5fe8 --- /dev/null +++ b/NC_vs_AF/AF_rysy_multi.py @@ -0,0 +1,180 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import h5py +import numpy as np +import matplotlib +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 12}) +#plt.figure(figsize=(16,10)) + +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +#timesteps = [12960, 13200, 14400] +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:90] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, ny, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +hght = np.arange(nz) * dz +bin = np.linspace(0,1.4,len(np.arange(nz))) +bin_size = bin[2]-bin[1] + + + + +def Adia_fraction(timestep): + +# for timestep in timesteps: + plt.clf() + # ---- adiabatic LWC ---- + AF_min = np.zeros([nx, ny, nz]) + adia_rl = np.zeros([nz]) + adia_rl_min = np.zeros([nz]) + clb_rv_min = np.zeros([nx, ny]) + clb_th_min = np.zeros([nx, ny]) + Biny = [0 for i in np.arange(nz)] + Biny_x = [0 for i in np.arange(nz)] + Slice = np.zeros([nx,ny]) + + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:,:] * rhod / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask_used)) + # print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask_used) / np.sum(cloudy_mask_used)) + + # th and rv + th = h5py.File(filename, "r")["th"][:,:,:]; + rv = h5py.File(filename, "r")["rv"][:,:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=2) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + + for i in np.arange(nx): + for j in np.arange(ny): + if clb_idx[i,j] > 0: + clb_rv_min[i,j] = rv[i, j, int(min_hght/dz)] + clb_th_min[i,j] = th[i, j, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for j in np.arange(ny): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, j, k] = 0 + else: + AF_min[i, j, k] = rl[i,j,k] / adia_rl_min[k] + +######Biny + + AF = AF_min * cloudy_mask_used + for k in np.arange(nz): +# for k in range(25,30): + for i in np.arange(nx): + for j in np.arange(ny): + Slice[i, j] = AF[i, j, k] + Slice[i,:][Slice[i,:]==0] = np.nan +# print(Slice[i,:]) + Biny[i] = np.digitize(Slice[i,:],bin) +# print(Biny[i]) + Biny[i] = np.bincount(Biny[i]) + Biny[i] = np.pad(Biny[i], (0, (len(bin)+1)-len(Biny[i])), mode='constant') + Biny = list(map(list,Biny)) + Biny_x[k] = np.log10(np.sum(Biny,0)/bin_size) + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min, axis=(0,1)) + AF_mean_min[np.isnan(AF_mean_min)] = 0 + bins = np.array(Biny_x) + bins = bins[:,:-1] + + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="50%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.4, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + e = ax.contourf(bin, hght, bins, 200, cmap='gnuplot') #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)", format='%.2f') + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim(0,10000) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.savefig(outfile + '_NCvsAF_' + str(int(timestep)) +'.png') + +# Adia_fraction(timesteps[10]) +with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(Adia_fraction, timesteps) + +# with concurrent.futures.ThreadPoolExecutor() as executor: +# results = [executor.submit(Adia_fraction, timestep) for timestep in timesteps[50:60]] + +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/AF_rysy_xz2d_multi.py b/NC_vs_AF/AF_rysy_xz2d_multi.py new file mode 100644 index 0000000..e204532 --- /dev/null +++ b/NC_vs_AF/AF_rysy_xz2d_multi.py @@ -0,0 +1,126 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 11}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, ny, nz = rhod.shape +ny_cross = ny//2 +rhod_cros = rhod[:,ny_cross,:] +print(rhod_cros.shape) +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +dx = h5py.File(input_dir + "/const.h5", "r").attrs["dx"] + +hght = np.arange(nz) * dz +X = np.arange(nx) * dx + + + +def Adia_fraction(timestep): + + + plt.clf() + # ---- adiabatic LWC ---- + AF_min = np.zeros([nx, nz]) + adia_rl = np.zeros(nz) + adia_rl_min = np.zeros(nz) + clb_rv_min = np.zeros(nz) + clb_th_min = np.zeros(nz) + + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,ny_cross,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,ny_cross,:] * rhod_cros / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th = h5py.File(filename, "r")["th"][:,ny_cross,:]; + rv = h5py.File(filename, "r")["rv"][:,ny_cross,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + for i in np.arange(nz): + if clb_idx[i] > 0: + clb_rv_min[i] = rv[i, int(min_hght/dz)] + clb_th_min[i] = th[i, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, k] = 0 + else: + AF_min[i, k] = rl[i, k] / adia_rl_min[k] + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_min[AF_min>1.4] = np.nan + AF_min = np.transpose(AF_min) + + e = plt.contourf(X, hght, AF_min, 10, cmap='gnuplot', vmin=0, vmax=1.4, levels=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) #bin[1:] + plt.colorbar(e, orientation='vertical', label=r"AF[]", ticks=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) + plt.clim(0, 1.4) + plt.ylabel('Height [m]') + plt.xlabel('X [m]') + plt.title('Adiabatic Fraction [](Y=5000 m, {}s )'.format(int(timestep/2))) + plt.savefig(outfile + '_NCvsAF_' + str(int(timestep/2)) +'.png') + + +with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(Adia_fraction, timesteps) + +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/drawbicyc/average.cpp b/drawbicyc/average.cpp index 5a8446a..ee143af 100644 --- a/drawbicyc/average.cpp +++ b/drawbicyc/average.cpp @@ -154,7 +154,7 @@ int main(int argc, char* argv[]) const string profiles_suffix = string("_profiles_")+argv[2]+string("_")+argv[3]; string plot_type; // determine type of plots based on the name of the first file - const string types[] = {"rico", "dycoms", "moist_thermal"}; + const string types[] = {"rico", "dycoms", "moist_thermal","ICMW2020_cc"}; for(auto type : types) { if(hasEnding(string(argv[4]), type)) diff --git a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp index e6b645d..d8558f7 100644 --- a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp @@ -10,7 +10,7 @@ const std::vector series_ICMW2020({ "cwm", "rwm", //"surf_precip", - //"acc_precip", + "acc_precip", "acc_vol_precip", //"cl_nc", //"cloud_base", @@ -61,13 +61,15 @@ std::vector profs_ICMW2020({ std::vector fields_ICMW2020({ //"rl", - "number_concentration", + "mass_conc_rain_drops", + "mass_conc_cloud_droplets", + "num_conc_droplets", "LWC", //"mass_conc_cloud", "ratio_mean_volume_r_to_eff_r_cubed", - "cloud_std_dev", + "std_dev_droplet_size_dist", //"rr", - "rain_drops_concentration", + "num_conc_rain_drops", "effective_radius", //"na", //"th", diff --git a/drawbicyc/include/drawbicyc/plot_fields.hpp b/drawbicyc/include/drawbicyc/plot_fields.hpp index c573219..f2191a4 100644 --- a/drawbicyc/include/drawbicyc/plot_fields.hpp +++ b/drawbicyc/include/drawbicyc/plot_fields.hpp @@ -48,11 +48,11 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } - else if (plt == "mass_conc_cloud") + else if (plt == "mass_conc_cloud_droplets") { //mass concentration of cloud droplets qc try{ - auto tmp = plotter.h5load_timestep("actrw_rc_mom3", at * n["outfreq"]) * 4. / 3 * 3.14 * 1e3 / rhod; + auto tmp = plotter.h5load_timestep("cloud_rw_mom3", at * n["outfreq"]) * 4. / 3 * 3.14 * 1e3 / rhod; std::string title = " mass concentration of cloud droplets q_c"; gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; @@ -60,6 +60,18 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } + else if (plt == "mass_conc_rain_drops") + { + //mass concentration of cloud droplets qc + try{ + auto tmp = plotter.h5load_timestep("rain_rw_mom3", at * n["outfreq"]) * 4. / 3 * 3.14 * 1e3 / rhod; + + std::string title = " mass concentration of rain drops q_r"; + gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; + plotter.plot(gp, tmp); + } + catch(...){} + } else if (plt == "rr") { try{ @@ -86,12 +98,12 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } - else if (plt == "number_concentration") + else if (plt == "num_conc_droplets") { // cloud particle concentration try{ auto tmp = plotter.h5load_timestep("actrw_rw_mom0", at * n["outfreq"]) * 1e-6; - std::string title ="activated droplet spec. conc. [mg^{-1}]"; + std::string title ="activated droplets spec. conc. [mg^{-1}]"; gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; // gp << "set cbrange [0:150]\n"; plotter.plot(gp, tmp); @@ -114,12 +126,12 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } - else if (plt == "rain_drops_concentration") + else if (plt == "num_conc_rain_drops") { try{ // rain particle concentration auto tmp = plotter.h5load_timestep("rain_rw_mom0", at * n["outfreq"]) * 1e-6; - std::string title = "rain (r > 25um) drop spec. conc. [mg^{-1}]"; + std::string title = "rain (r > 25um) drops spec. conc. [mg^{-1}]"; gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; // gp << "set cbrange [.01:10]\n"; gp << "set logscale cb\n"; @@ -142,7 +154,7 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) auto tmp5 = where(tmp2 > 0, tmp3 / tmp2, 0); auto ratio = tmp5 * tmp4*1e6; - std::string title = "cloud (0.5um < r < 25um) droplet effective radius [μm]"; + std::string title = "act. droplet effective radius [μm]"; gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; // gp << "set cbrange [1:20]\n"; plotter.plot(gp, ratio); @@ -170,7 +182,7 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) } catch(...){} } - else if (plt == "cloud_std_dev") + else if (plt == "std_dev_droplet_size_dist") { //Stadndard deviation of the size distribution try{ @@ -185,7 +197,7 @@ void plot_fields(Plotter_t plotter, Plots plots, std::string type) auto tmp5 = sqrt(tmp4); auto tmp6 = tmp5 * tmp3 * 1e6; - std::string title = "Standardi deviation of the size distribution [um]"; + std::string title = "Standard deviation of the size distribution [um]"; gp << "set title '" + title + " t = " << std::fixed << std::setprecision(2) << (double(at) * n["outfreq"] * n["dt"] / 60.) << "min'\n"; plotter.plot(gp, tmp6); } diff --git a/papers/ICMW2020_CC/compare_profs.py b/papers/ICMW2020_CC/compare_profs.py index cd53714..809eea9 100644 --- a/papers/ICMW2020_CC/compare_profs.py +++ b/papers/ICMW2020_CC/compare_profs.py @@ -39,14 +39,14 @@ for prof in profs: - print prof + print( prof) for no in np.arange(2, 3*file_no+2, 3): ino = int(no) time = sys.argv[ino+2] - print ino,time + print (ino,time) file_name = sys.argv[ino] + "_" + str(time) + "_" + str(time) + ".dat" - print file_name + print (file_name) profs_file = open(file_name, "r") my_hgt = read_my_var(profs_file, "position") my_prof = read_my_var(profs_file, prof) From af2e716250b08fe5328f2b101975912507d424dc Mon Sep 17 00:00:00 2001 From: ryba183 Date: Mon, 16 Aug 2021 09:49:37 +0200 Subject: [PATCH 20/30] paper prepare --- NC_vs_AF/AF_mean_parallel_2D.py | 222 ++++++++++++++++++ NC_vs_AF/AF_rysy_2D.py | 152 ++++++++++++ NC_vs_AF/AF_rysy_multi_2D.py | 180 ++++++++++++++ NC_vs_AF/AF_rysy_xz2d_2D.py | 110 +++++++++ NC_vs_AF/AF_rysy_xz2d_multi_2D.py | 126 ++++++++++ .../ICMW2020_cumulus_congestus/plots.hpp | 2 + .../drawbicyc/gnuplot_profs_set_labels.hpp | 8 + drawbicyc/include/drawbicyc/plot_prof.hpp | 26 ++ 8 files changed, 826 insertions(+) create mode 100644 NC_vs_AF/AF_mean_parallel_2D.py create mode 100644 NC_vs_AF/AF_rysy_2D.py create mode 100644 NC_vs_AF/AF_rysy_multi_2D.py create mode 100644 NC_vs_AF/AF_rysy_xz2d_2D.py create mode 100644 NC_vs_AF/AF_rysy_xz2d_multi_2D.py diff --git a/NC_vs_AF/AF_mean_parallel_2D.py b/NC_vs_AF/AF_mean_parallel_2D.py new file mode 100644 index 0000000..19ae21b --- /dev/null +++ b/NC_vs_AF/AF_mean_parallel_2D.py @@ -0,0 +1,222 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + +''' +HOW TO RUN: + + +python3 AF_test.py /home/piotr/Piotr/WORKSHOPS/Prof_dat /dxyz100_SD100_Coal_NA2_1_SH_out_lgrngn /dxyz100_SD100_Coal_NA2_2_SH_out_lgrngn /dxyz100_SD100_Coal_NA2_3_SH_out_lgrngn /dxyz100_SD100_Coal_NA2_4_SH_out_lgrngn /dxyz100_SD100_Coal_NA2_5_SH_out_lgrngn + + + +''' + +import h5py +import numpy as np +import matplotlib +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + +def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + +def licz_srednia(parameter_name, iter_value, paths): + dl = len(parameter_name) + srednia =[0 for i in range(len(paths))] + STD = [0 for i in range(len(paths))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + return srednia[iter_value], STD[iter_value] + +start = time.perf_counter() +plt.rcParams.update({'font.size': 12}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i +timesteps = timesteps[1:90] +np.set_printoptions(threshold=maxsize) + +n = len(argv) +paths = argv[1] +const = [argv[i] for i in range(2,n)] + + + +files = [0 for i in range(len(paths))] +series_file = [0 for i in range(len(paths))] + +# for i in range(1,91): +# i = np.linspace(1,91,91) +def Adia_fraction(i): + + rhod = [0 for i in range(len(const))] + p_e = [0 for i in range(len(const))] + dz = [0 for i in range(len(const))] + rl = [0 for i in range(len(const))] + rl_base = [0 for i in range(len(const))] + nc = [0 for i in range(len(const))] + th = [0 for i in range(len(const))] + rv = [0 for i in range(len(const))] + + for p in range(len(const)): + rhod[p] = h5py.File(paths + const[p]+"/const.h5", "r")["G"][:,:,:] + p_e[p] = h5py.File(paths + const[p]+"/const.h5", "r")["p_e"][:] + dz[p] = h5py.File(paths + const[p]+"/const.h5", "r").attrs["dz"] + rl[p] = (h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["actrw_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[p] = (h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc[p] = h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom0"][:,:,:] + th[p] = h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["th"][:,:,:]; + rv[p] = h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["rv"][:,:,:]; + rhod = np.mean(rhod,axis=0) + p_e = np.mean(p_e,axis=0) + dz = np.mean(dz,axis=0) + rl = np.mean(rl,axis=0) + rl_base = np.mean(rl_base,axis=0) + nc = np.mean(nc,axis=0) * rhod / 1e6# 1 / cm^3 + th = np.mean(th,axis=0) + rv = np.mean(rv,axis=0) + + nx, ny, nz = rhod.shape + hght = np.arange(nz) * dz + bin = np.linspace(0,1.4,len(np.arange(nz))) + bin_size = bin[2]-bin[1] + + + plt.clf() + # ---- adiabatic LWC ---- + AF_min = np.zeros([nx, ny, nz]) + adia_rl = np.zeros([nz]) + adia_rl_min = np.zeros([nz]) + clb_rv_min = np.zeros([nx, ny]) + clb_th_min = np.zeros([nx, ny]) + Biny = [0 for i in np.arange(nz)] + Biny_x = [0 for i in np.arange(nz)] + Slice = np.zeros([nx,ny]) + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=2) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + for d in np.arange(nx): + for j in np.arange(ny): + if clb_idx[d,j] > 0: + clb_rv_min[d,j] = rv[d, j, int(min_hght/dz)] + clb_th_min[d,j] = th[d, j, int(min_hght/dz)] + + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for y in np.arange(nx): + for j in np.arange(ny): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[y, j, k] = 0 + else: + AF_min[y, j, k] = rl[y,j,k] / adia_rl_min[k] + + ######Biny + + AF = AF_min * cloudy_mask_used + for k in np.arange(nz): + # for k iny range(25,30): + for y in np.arange(nx): + for j in np.arange(ny): + Slice[y, j] = AF[y, j, k] + Slice[y,:][Slice[y,:]==0] = np.nan + # print(Slice[i,:]) + Biny[y] = np.digitize(Slice[y,:],bin) + # print(Biny[i]) + Biny[y] = np.bincount(Biny[y]) + Biny[y] = np.pad(Biny[y], (0, (len(bin)+1)-len(Biny[y])), mode='constant') + Biny = list(map(list,Biny)) + Biny_x[k] = np.log10(np.sum(Biny,0)/bin_size) + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min, axis=(0,1)) + AF_mean_min[np.isnan(AF_mean_min)] = 0 + bins = np.array(Biny_x) + bins = bins[:,:-1] + + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="50%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.4, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + e = ax.contourf(bin, hght, bins, 200, cmap='gnuplot') #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)", format='%.2f') + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim(0,10000) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.savefig(paths + '/AF_average_' + str(240*i).zfill(10) +'.png') + +punkty = np.intc(np.linspace(1,91,91)) +with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(Adia_fraction, punkty) + +# Adia_fraction(punkty[20]) +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/AF_rysy_2D.py b/NC_vs_AF/AF_rysy_2D.py new file mode 100644 index 0000000..9bb54d0 --- /dev/null +++ b/NC_vs_AF/AF_rysy_2D.py @@ -0,0 +1,152 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") #/home/pzmij/biblioteki/local_folder/seed/lib/python3/dist-packages") + +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 10}) +#plt.figure(figsize=(16,10)) + +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +#timesteps = [12960, 13200, 14400] +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:90] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +hght = np.arange(nz) * dz +bin = np.linspace(0,1.4,len(np.arange(nz))) +bin_size = bin[2]-bin[1] +#print(bin_size) + +# ---- adiabatic LWC ---- +AF_min = np.zeros([nx, nz]) +adia_rl = np.zeros([nz]) +adia_rl_min = np.zeros([nz]) +clb_rv_min = np.zeros(nx) +clb_th_min = np.zeros(nx) +Biny = [0 for i in np.arange(nz)] +Biny_x = [0 for i in np.arange(nz)] +Slice = np.zeros(nx) + +for timestep in timesteps: + plt.clf() + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask_used)) + # print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask_used) / np.sum(cloudy_mask_used)) + + # th and rv + th = h5py.File(filename, "r")["th"][:,:]; + rv = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=2) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + + for i in np.arange(nx): + if clb_idx[i] > 0: + clb_rv_min[i] = rv[i, int(min_hght/dz)] + clb_th_min[i] = th[i, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, k] = 0 + else: + AF_min[i, k] = rl[i,k] / adia_rl_min[k] + +######Biny + + AF = AF_min * cloudy_mask_used + for k in np.arange(nz): + for i in np.arange(nx): + Slice[i] = AF[i, k] + Slice[i][Slice[i]==0] = np.nan + Biny[i] = np.digitize(Slice[i],bin) + Biny[i] = np.bincount(Biny[i]) + Biny[i] = np.pad(Biny[i], (0, (len(bin)+1)-len(Biny[i])), mode='constant') + Biny = list(map(list,Biny)) + Biny_x[k] = np.log10(np.sum(Biny,0)/bin_size) + + #print(Biny_x) + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min) + AF_mean_min[np.isnan(AF_mean_min)] = 0 + bins = np.array(Biny_x) + + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="60%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.3, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + e = ax.contourf(bin, hght, np.round(bins,2), 200, cmap='gnuplot') #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)") + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim(0,10000) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.savefig(outfile + '_NCvsAF_' + str(int(timestep)) +'.png') + diff --git a/NC_vs_AF/AF_rysy_multi_2D.py b/NC_vs_AF/AF_rysy_multi_2D.py new file mode 100644 index 0000000..ffd5fe8 --- /dev/null +++ b/NC_vs_AF/AF_rysy_multi_2D.py @@ -0,0 +1,180 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import h5py +import numpy as np +import matplotlib +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 12}) +#plt.figure(figsize=(16,10)) + +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +#timesteps = [12960, 13200, 14400] +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:90] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, ny, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +hght = np.arange(nz) * dz +bin = np.linspace(0,1.4,len(np.arange(nz))) +bin_size = bin[2]-bin[1] + + + + +def Adia_fraction(timestep): + +# for timestep in timesteps: + plt.clf() + # ---- adiabatic LWC ---- + AF_min = np.zeros([nx, ny, nz]) + adia_rl = np.zeros([nz]) + adia_rl_min = np.zeros([nz]) + clb_rv_min = np.zeros([nx, ny]) + clb_th_min = np.zeros([nx, ny]) + Biny = [0 for i in np.arange(nz)] + Biny_x = [0 for i in np.arange(nz)] + Slice = np.zeros([nx,ny]) + + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:,:] * rhod / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask_used)) + # print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask_used) / np.sum(cloudy_mask_used)) + + # th and rv + th = h5py.File(filename, "r")["th"][:,:,:]; + rv = h5py.File(filename, "r")["rv"][:,:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=2) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + + for i in np.arange(nx): + for j in np.arange(ny): + if clb_idx[i,j] > 0: + clb_rv_min[i,j] = rv[i, j, int(min_hght/dz)] + clb_th_min[i,j] = th[i, j, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for j in np.arange(ny): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, j, k] = 0 + else: + AF_min[i, j, k] = rl[i,j,k] / adia_rl_min[k] + +######Biny + + AF = AF_min * cloudy_mask_used + for k in np.arange(nz): +# for k in range(25,30): + for i in np.arange(nx): + for j in np.arange(ny): + Slice[i, j] = AF[i, j, k] + Slice[i,:][Slice[i,:]==0] = np.nan +# print(Slice[i,:]) + Biny[i] = np.digitize(Slice[i,:],bin) +# print(Biny[i]) + Biny[i] = np.bincount(Biny[i]) + Biny[i] = np.pad(Biny[i], (0, (len(bin)+1)-len(Biny[i])), mode='constant') + Biny = list(map(list,Biny)) + Biny_x[k] = np.log10(np.sum(Biny,0)/bin_size) + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min, axis=(0,1)) + AF_mean_min[np.isnan(AF_mean_min)] = 0 + bins = np.array(Biny_x) + bins = bins[:,:-1] + + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="50%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.4, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + e = ax.contourf(bin, hght, bins, 200, cmap='gnuplot') #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)", format='%.2f') + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim(0,10000) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.savefig(outfile + '_NCvsAF_' + str(int(timestep)) +'.png') + +# Adia_fraction(timesteps[10]) +with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(Adia_fraction, timesteps) + +# with concurrent.futures.ThreadPoolExecutor() as executor: +# results = [executor.submit(Adia_fraction, timestep) for timestep in timesteps[50:60]] + +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/AF_rysy_xz2d_2D.py b/NC_vs_AF/AF_rysy_xz2d_2D.py new file mode 100644 index 0000000..e896293 --- /dev/null +++ b/NC_vs_AF/AF_rysy_xz2d_2D.py @@ -0,0 +1,110 @@ +from sys import argv, path, maxsize +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages")#/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") + +import h5py +import numpy as np +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 11}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, nz = rhod.shape +ny_cross = ny//2 +rhod_cros = rhod[:,ny_cross,:] +#print(rhod_cros.shape) +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +dx = h5py.File(input_dir + "/const.h5", "r").attrs["dx"] + +hght = np.arange(nz) * dz +X = np.arange(nx) * dx + +# ---- adiabatic LWC ---- +AF_min = np.zeros([nx, nz]) +adia_rl = np.zeros(nz) +adia_rl_min = np.zeros(nz) +clb_rv_min = np.zeros(nz) +clb_th_min = np.zeros(nz) + +for timestep in timesteps: + plt.clf() + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,ny_cross,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,ny_cross,:] * rhod_cros / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th = h5py.File(filename, "r")["th"][:,ny_cross,:]; + rv = h5py.File(filename, "r")["rv"][:,ny_cross,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + for i in np.arange(nz): + if clb_idx[i] > 0: + clb_rv_min[i] = rv[i, int(min_hght/dz)] + clb_th_min[i] = th[i, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, k] = 0 + else: + AF_min[i, k] = rl[i, k] / adia_rl_min[k] + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_min[AF_min>1.4] = np.nan + AF_min = np.transpose(AF_min) + + e = plt.contourf(X, hght, AF_min, 10, cmap='gnuplot', vmin=0, vmax=1.4, levels=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) #bin[1:] + plt.colorbar(e, orientation='vertical', label=r"AF[]", ticks=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) + plt.clim(0, 1.4) + plt.ylabel('Height [m]') + plt.xlabel('X [m]') + plt.title('Adiabatic Fraction [](Y=5000 m, {}s )'.format(int(timestep/2))) + plt.savefig(outfile + '_AF_xz2d_' + str(int(timestep/2)) +'.png') diff --git a/NC_vs_AF/AF_rysy_xz2d_multi_2D.py b/NC_vs_AF/AF_rysy_xz2d_multi_2D.py new file mode 100644 index 0000000..e204532 --- /dev/null +++ b/NC_vs_AF/AF_rysy_xz2d_multi_2D.py @@ -0,0 +1,126 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 11}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, ny, nz = rhod.shape +ny_cross = ny//2 +rhod_cros = rhod[:,ny_cross,:] +print(rhod_cros.shape) +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +dx = h5py.File(input_dir + "/const.h5", "r").attrs["dx"] + +hght = np.arange(nz) * dz +X = np.arange(nx) * dx + + + +def Adia_fraction(timestep): + + + plt.clf() + # ---- adiabatic LWC ---- + AF_min = np.zeros([nx, nz]) + adia_rl = np.zeros(nz) + adia_rl_min = np.zeros(nz) + clb_rv_min = np.zeros(nz) + clb_th_min = np.zeros(nz) + + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,ny_cross,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,ny_cross,:] * rhod_cros / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th = h5py.File(filename, "r")["th"][:,ny_cross,:]; + rv = h5py.File(filename, "r")["rv"][:,ny_cross,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + for i in np.arange(nz): + if clb_idx[i] > 0: + clb_rv_min[i] = rv[i, int(min_hght/dz)] + clb_th_min[i] = th[i, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, k] = 0 + else: + AF_min[i, k] = rl[i, k] / adia_rl_min[k] + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_min[AF_min>1.4] = np.nan + AF_min = np.transpose(AF_min) + + e = plt.contourf(X, hght, AF_min, 10, cmap='gnuplot', vmin=0, vmax=1.4, levels=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) #bin[1:] + plt.colorbar(e, orientation='vertical', label=r"AF[]", ticks=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) + plt.clim(0, 1.4) + plt.ylabel('Height [m]') + plt.xlabel('X [m]') + plt.title('Adiabatic Fraction [](Y=5000 m, {}s )'.format(int(timestep/2))) + plt.savefig(outfile + '_NCvsAF_' + str(int(timestep/2)) +'.png') + + +with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(Adia_fraction, timesteps) + +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp index d8558f7..4e46723 100644 --- a/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp +++ b/drawbicyc/include/drawbicyc/cases/ICMW2020_cumulus_congestus/plots.hpp @@ -51,6 +51,8 @@ std::vector profs_ICMW2020({ // "N_c", "actrw_reff_cl", "ratio_mean_volume_r_to_eff_r_cubed", + "cloud_water_std", + "rain_water_std", "cloud_std_dev" //,"vel_div" //, "nc_up" diff --git a/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp b/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp index 00d7ddf..2b81716 100644 --- a/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp +++ b/drawbicyc/include/drawbicyc/gnuplot_profs_set_labels.hpp @@ -12,6 +12,14 @@ void gnuplot_profs_set_labels(Gnuplot &gp, std::string plt, const bool normalize { gp << "set title 'liquid water [g/kg]'\n"; } + if (plt == "cloud_water_std") + { + gp << "set title 'cloud water [g/kg]'\n"; + } + if (plt == "rain_water_std") + { + gp << "set title 'rain water [g/kg]'\n"; + } if (plt == "gccn_rw") { gp << "set title 'gccn-based droplets mean wet radius'\n"; diff --git a/drawbicyc/include/drawbicyc/plot_prof.hpp b/drawbicyc/include/drawbicyc/plot_prof.hpp index f815d79..a1c4a57 100644 --- a/drawbicyc/include/drawbicyc/plot_prof.hpp +++ b/drawbicyc/include/drawbicyc/plot_prof.hpp @@ -101,6 +101,32 @@ void plot_profiles(Plotter_t plotter, Plots plots, std::string type, const bool prof_tmp = plotter.horizontal_sum(rc_mask); res_prof_hlpr = where(prof_tmp > 0, plotter.horizontal_sum(res) / prof_tmp, 0); } + if (plt == "cloud_water_std") + { + // cloud_water_std + res = plotter.h5load_rc_timestep(at * n["outfreq"]) * 1e3; // cloud + //typename Plotter_t::arr_t rc_mask(plotter.h5load_rc_timestep(at * n["outfreq"])); + //rc_mask = iscloudy_rc_rico(rc_mask); + rc_mask = iscloudy_rc_rico(res); + res_prof = res * rc_mask; + res_prof_num = plotter.horizontal_sum(rc_mask); + res_mean = plotter.horizontal_sum(res_prof) / res_prof_num; + res_sum = plotter.horizontal_sum((res_prof - res_mean) * (res_prof - res_mean)) / (res_prof_num -1); + res_prof_hlpr = where(rc_mask >0 , sqrt(res_sum) , 0); + } + if (plt == "rain_water_std") + { + // rain_water_std + res = plotter.h5load_rr_timestep(at * n["outfreq"]) * 1e3; // cloud + //typename Plotter_t::arr_t rc_mask(plotter.h5load_rc_timestep(at * n["outfreq"])); + //rc_mask = iscloudy_rc_rico(rc_mask); + rc_mask = iscloudy_rc_rico(res); + res_prof = res * rc_mask; + res_prof_num = plotter.horizontal_sum(rc_mask); + res_mean = plotter.horizontal_sum(res_prof) / res_prof_num; + res_sum = plotter.horizontal_sum((res_prof - res_mean) * (res_prof - res_mean)) / (res_prof_num -1); + res_prof_hlpr = where(rc_mask >0 , sqrt(res_sum) , 0); + } if (plt == "gccn_rw") { // gccn (rd>1um) droplets dry radius From 5a12c36dcc216dcd63ac78cc6521fbc99d77731d Mon Sep 17 00:00:00 2001 From: ryba183 Date: Tue, 31 Aug 2021 23:32:43 +0200 Subject: [PATCH 21/30] plots for paper --- Energy_spectrum/spectrum.py | 34 +-- Energy_spectrum/spectrum_2D.py | 83 +++++++ Energy_spectrum/spectrum_2D_multi_many.py | 88 ++++++++ .../spectrum_2D_multi_many_parallel.py | 98 +++++++++ Energy_spectrum/spectrum_2D_multiplot.py | 84 ++++++++ NC_vs_AF/Randomness/AF_mean_parallel_2D.py | 202 ++++++++++++++++++ NC_vs_AF/Randomness/AF_rysy_2D.py | 181 ++++++++++++++++ .../Randomness/AF_rysy_single_parallel_2D.py | 175 +++++++++++++++ NC_vs_AF/Randomness/AF_rysy_xz2d_2D.py | 114 ++++++++++ NC_vs_AF/Randomness/AF_rysy_xz2d_multi_2D.py | 129 +++++++++++ NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py | 169 +++++++++++++++ Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py | 113 ++++++++++ Rain_distribution/RAIN_rysy_xz2d_2D_test.py | 100 +++++++++ Rain_distribution/Rain.py | 110 ++++++++++ Rain_distribution/Rain_many.py | 109 ++++++++++ Rain_distribution/distribution_Py3.py | 116 ++++++++++ Rain_distribution/distribution_Py3_2D.py | 129 +++++++++++ Rain_distribution/distribution_Py3_2D_mean.py | 124 +++++++++++ .../distribution_Py3_2D_mean_part.py | 126 +++++++++++ 19 files changed, 2267 insertions(+), 17 deletions(-) create mode 100644 Energy_spectrum/spectrum_2D.py create mode 100644 Energy_spectrum/spectrum_2D_multi_many.py create mode 100644 Energy_spectrum/spectrum_2D_multi_many_parallel.py create mode 100644 Energy_spectrum/spectrum_2D_multiplot.py create mode 100644 NC_vs_AF/Randomness/AF_mean_parallel_2D.py create mode 100644 NC_vs_AF/Randomness/AF_rysy_2D.py create mode 100644 NC_vs_AF/Randomness/AF_rysy_single_parallel_2D.py create mode 100644 NC_vs_AF/Randomness/AF_rysy_xz2d_2D.py create mode 100644 NC_vs_AF/Randomness/AF_rysy_xz2d_multi_2D.py create mode 100644 NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py create mode 100644 Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py create mode 100644 Rain_distribution/RAIN_rysy_xz2d_2D_test.py create mode 100644 Rain_distribution/Rain.py create mode 100644 Rain_distribution/Rain_many.py create mode 100644 Rain_distribution/distribution_Py3.py create mode 100644 Rain_distribution/distribution_Py3_2D.py create mode 100644 Rain_distribution/distribution_Py3_2D_mean.py create mode 100644 Rain_distribution/distribution_Py3_2D_mean_part.py diff --git a/Energy_spectrum/spectrum.py b/Energy_spectrum/spectrum.py index 31c997c..bf70d81 100644 --- a/Energy_spectrum/spectrum.py +++ b/Energy_spectrum/spectrum.py @@ -6,9 +6,9 @@ import matplotlib.pyplot as plt #velocities = ["u", "v", "w"] -#velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"] +velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"] #velocities = ["cloud_rw_mom3"] -velocities = ["w"] +# velocities = ["w"] time_start = int(argv[1]) time_end = int(argv[2]) @@ -18,54 +18,54 @@ directories = argv[6:len(argv):2] labels = argv[7:len(argv):2] -print directories, labels +print(directories, labels) # read in nx, ny, nz for directory, lab in zip(directories, labels): - w3d = h5py.File(directory + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:,:] + w3d = h5py.File(directory + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] nx, ny, nz = w3d.shape Exy_avg = {} for vel in velocities: Exy_avg[vel] = np.zeros(((nx+1)/2)) - + for t in range(time_start, time_end+1, outfreq): filename = directory + "/timestep" + str(t).zfill(10) + ".h5" - print filename - + print(filename) + for vel in velocities: - - w3d = h5py.File(filename, "r")[vel][:,:,:] # * 4. / 3. * 3.1416 * 1e3 - + + w3d = h5py.File(filename, "r")[vel][:,:,:] # * 4. / 3. * 3.1416 * 1e3 + for lvl in range(from_lvl, to_lvl+1): w2d = w3d[:, :, lvl] - + wkx = 1.0 / np.sqrt(nx - 1) * np.fft.rfft(w2d, axis = 0) wky = 1.0 / np.sqrt(ny - 1) * np.fft.rfft(w2d, axis = 1) - + #Ex = 0.5 * (np.abs(wkx) ** 2) Ex = (np.abs(wkx) ** 2) Ex = np.mean(Ex, axis = 1) #Ey = 0.5 * (np.abs(wky) ** 2) Ey = (np.abs(wky) ** 2) Ey = np.mean(Ey, axis = 0) - + Exy = 0.5 * (Ex + Ey) Exy_avg[vel] += Exy - + K = np.fft.rfftfreq(nx - 1) # plt.loglog(K, Exy) lmbd = 50. / K # assume dx=50m - + if (t == time_start and lab==labels[0]): plt.loglog(lmbd, 2e-1* K**(-5./3.) ) - + for vel in velocities: Exy_avg[vel] /= (time_end - time_start) / outfreq + 1 Exy_avg[vel] /= to_lvl+1 - from_lvl #crudely scale # Exy_avg[vel] /= Exy_avg[vel][len(Exy_avg[vel])-1] plt.loglog(lmbd, Exy_avg[vel] , linewidth=2, label=lab+"_"+vel) - + plt.xlim(10**4,10**2) plt.xlabel("l[m]") plt.ylabel("PSD") diff --git a/Energy_spectrum/spectrum_2D.py b/Energy_spectrum/spectrum_2D.py new file mode 100644 index 0000000..f395c16 --- /dev/null +++ b/Energy_spectrum/spectrum_2D.py @@ -0,0 +1,83 @@ +# (C) Maciej Waruszewski + +import h5py +import numpy as np +from sys import argv +import matplotlib.pyplot as plt + +# velocities = ["u", "v", "w"] +# velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"] +# velocities = ["u", "w", "cloud_rw_mom3", "rv", "th", "RH", "actrw_rw_mom3"] +velocities = ["cloud_rw_mom3", "actrw_rw_mom3"] +# velocities = ["u"] + +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) +from_lvl = int(argv[4]) +to_lvl = int(argv[5]) + +directories = argv[6:len(argv):2] +labels = argv[7:len(argv):2] +print(directories, labels) + +# read in nx, ny, nz +for directory, lab in zip(directories, labels): + w3d = h5py.File(directory + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] + nx, nz = w3d.shape + Exy_avg = {} + for vel in velocities: + Exy_avg[vel] = np.zeros(int((nx+1)/2)) + + for t in range(time_start, time_end+1, outfreq): + filename = directory + "/timestep" + str(t).zfill(10) + ".h5" + print(filename) + + for vel in velocities: + if (vel == "cloud_rw_mom3") | (vel == "actrw_rw_mom3"): + w3d = h5py.File(filename, "r")[vel][:,:]# * 4. / 3. * 3.1416 * 1e3 + else: + w3d = h5py.File(filename, "r")[vel][:,:] # * 4. / 3. * 3.1416 * 1e3 + + for lvl in range(from_lvl, to_lvl+1): + w2d = w3d[:, lvl] +<<<<<<< HEAD + # print(w2d) +======= +>>>>>>> acb609f27a00d77f0818e5edfbeeadf46112742a + wkx = 1.0 / np.sqrt(nx - 1) * np.fft.rfft(w2d, axis = 0) + + # wky = 1.0 / np.sqrt(nz - 1) * np.fft.rfft(w2d, axis = 1) + + #Ex = 0.5 * (np.abs(wkx) ** 2) + Ex = (np.abs(wkx) ** 2) + # Ex = np.mean(Ex) + #Ey = 0.5 * (np.abs(wky) ** 2) + # Ey = (np.abs(wky) ** 2) + # Ey = np.mean(Ey, axis = 0) + + # Exy = 0.5 * (Ex + Ey) + Exy = Ex + Exy_avg[vel] += Exy + + K = np.fft.rfftfreq(nx - 1) + # plt.loglog(K, Exy) + lmbd = 100. / K # assume dx=50m + + if (t == time_start and lab==labels[0]): + plt.loglog(lmbd, 2e-1* K**(-5./3.)*1e-8, label="-5/3" ) + + for vel in velocities: + Exy_avg[vel] /= (time_end - time_start) / outfreq + 1 + Exy_avg[vel] /= to_lvl+1 - from_lvl + #crudely scale + # Exy_avg[vel] /= Exy_avg[vel][len(Exy_avg[vel])-1] + plt.loglog(lmbd, Exy_avg[vel] , linewidth=2, label=lab+"_"+vel) + +plt.xlim(2*10**4,10**2) +plt.xlabel("l[m]") +plt.ylabel("PSD") +plt.legend() +plt.grid(True, which='both', linestyle='--') +# plt.title("Mean PSD of w 322m 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + # print(cloudy_mask_used) + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + print(min_hght) + if min_hght/dz < 10: + min_hght = 10*dz + d+=1 + + for j in np.arange(nx): + if clb_idx[j] > 0: + clb_rv_min[j] = rv[j, int(min_hght/dz)] + clb_th_min[j] = th[j, int(min_hght/dz)] + + parcel_rv_min = np.nan_to_num(np.nanmean(clb_rv_min[clb_rv_min>0])) + parcel_th_min = np.nan_to_num(np.nanmean(clb_th_min[clb_th_min>0])) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + # print(adia_rl_min) + + for j in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[j, k] = 0 + else: + AF_min[j, k] = rl[j,k] / adia_rl_min[k] + # print(AF_min) + + ######Biny + + AF = AF_min * cloudy_mask_used + for k in np.arange(nz): + for j in np.arange(nx): + Slice[j, k] = AF[j, k] + Slice[:,k][Slice[:,k]==0] = np.nan + Biny[k] = np.digitize(Slice[:,k],bin) + Biny[k] = np.bincount(Biny[k]) + Biny[k] = np.pad(Biny[k], (0, (len(bin)+1)-len(Biny[k])), mode='constant') + Biny_x[k] = np.log10(Biny[k]/bin_size) + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min, axis=0) + bins = np.array(Biny_x) + bins = bins[:,:-1] + # print(AF_mean_min) + + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="50%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.4, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + e = ax.contourf(bin, hght, bins, 200, cmap='gnuplot') #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)", format='%.2f') + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim(0,10000) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.title('time = '+str(i*240)+ 's') + plt.savefig(outfile + '/AF_average/' + str(240*i).zfill(10) +'.png') + + +punkty = np.intc(np.linspace(1,91,91)) +with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(Adia_fraction, punkty) + +# for i in range(1,91): +# Adia_fraction(89) +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/Randomness/AF_rysy_2D.py b/NC_vs_AF/Randomness/AF_rysy_2D.py new file mode 100644 index 0000000..1bd06b0 --- /dev/null +++ b/NC_vs_AF/Randomness/AF_rysy_2D.py @@ -0,0 +1,181 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +OK + +HOW TO RUN + +python3 AF_rysy_2D.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_piggy_25_out_lgrngn /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ + +''' + +import h5py +import time +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 12}) +#plt.figure(figsize=(16,10)) + +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +# timesteps = timesteps[1:91] +timesteps = timesteps[1:91] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +hght = np.arange(nz) * dz +bin = np.linspace(0,1.4,len(np.arange(nz))) +bin_size = bin[2]-bin[1] +# print(bin_size) + +# ---- adiabatic LWC ---- +AF_min = np.zeros([nx, nz]) +adia_rl = np.zeros([nz]) +adia_rl_min = np.zeros([nz]) +clb_rv_min = np.zeros([nx]) +clb_th_min = np.zeros([nx]) +Biny = [0 for i in np.arange(nz)] +Biny_x = [0 for i in np.arange(nz)] +Slice = np.zeros([nx, nz]) + + +for timestep in timesteps: + plt.clf() + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod / 1e6; # 1 / cm^3 + + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + # print(cloudy_mask_used) + + # print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask_used)) + # print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask_used) / np.sum(cloudy_mask_used)) + + # th and rv + th = h5py.File(filename, "r")["th"][:,:]; + rv = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + + if min_hght/dz < 10: + min_hght = 10*dz + + for i in np.arange(nx): + if clb_idx[i] > 0: + clb_rv_min[i] = rv[i, int(min_hght/dz)] + clb_th_min[i] = th[i, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + + parcel_rv_min = np.nan_to_num(np.nanmean(clb_rv_min[clb_rv_min>0])) + parcel_th_min = np.nan_to_num(np.nanmean(clb_th_min[clb_th_min>0])) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + # print(adia_rl_min) + + + for i in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, k] = 0 + else: + AF_min[i, k] = rl[i,k] / adia_rl_min[k] + # print(AF_min) +######Biny + + AF = AF_min * cloudy_mask_used + for k in np.arange(nz): + for i in np.arange(nx): + Slice[i, k] = AF[i, k] + Slice[:,k][Slice[:,k]==0] = np.nan + Biny[k] = np.digitize(Slice[:,k],bin) + Biny[k] = np.bincount(Biny[k]) + Biny[k] = np.pad(Biny[k], (0, (len(bin)+1)-len(Biny[k])), mode='constant') + Biny_x[k] = np.log10(Biny[k]/bin_size) + # print(Biny_x) + + + + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min,axis=0) + bins = np.array(Biny_x) + bins = bins[:,:-1] + # print(bins.shape) + # print(AF_mean_min) + + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="70%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.4, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + e = ax.contourf(bin, hght, bins, 200, cmap='gnuplot')#, levels=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)")#, ticks=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim(0,10000) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.savefig(outfile + '/AF_single_' + str(int(timestep)) +'.png') + + +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/Randomness/AF_rysy_single_parallel_2D.py b/NC_vs_AF/Randomness/AF_rysy_single_parallel_2D.py new file mode 100644 index 0000000..7bdfecf --- /dev/null +++ b/NC_vs_AF/Randomness/AF_rysy_single_parallel_2D.py @@ -0,0 +1,175 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +''' +OK + +HOW TO RUN + +python3 AF_rysy_multi_2D.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_piggy_25_out_lgrngn /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ + +''' + +import h5py +import numpy as np +import matplotlib +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 12}) +#plt.figure(figsize=(16,10)) + +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:92] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +hght = np.arange(nz) * dz +bin = np.linspace(0,1.4,len(np.arange(nz))) +bin_size = bin[2]-bin[1] + +def Adia_fraction(timestep): + + plt.clf() + # ---- adiabatic LWC ---- + AF_min = np.zeros([nx, nz]) + adia_rl = np.zeros([nz]) + adia_rl_min = np.zeros([nz]) + clb_rv_min = np.zeros([nx]) + clb_th_min = np.zeros([nx]) + Biny = [0 for i in np.arange(nz)] + Biny_x = [0 for i in np.arange(nz)] + Slice = np.zeros([nx, nz]) + + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod / 1e6; # 1 / cm^3 + + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th = h5py.File(filename, "r")["th"][:,:]; + rv = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + if min_hght/dz < 10: + min_hght = 10*dz + + for i in np.arange(nx): + if clb_idx[i] > 0: + clb_rv_min[i] = rv[i, int(min_hght/dz)] + clb_th_min[i] = th[i, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + + parcel_rv_min = np.nan_to_num(np.nanmean(clb_rv_min[clb_rv_min>0])) + parcel_th_min = np.nan_to_num(np.nanmean(clb_th_min[clb_th_min>0])) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, k] = 0 + else: + AF_min[i, k] = rl[i,k] / adia_rl_min[k] +######Biny + AF = AF_min * cloudy_mask_used + for k in np.arange(nz): + for i in np.arange(nx): + Slice[i, k] = AF[i, k] + Slice[:,k][Slice[:,k]==0] = np.nan + Biny[k] = np.digitize(Slice[:,k],bin) + Biny[k] = np.bincount(Biny[k]) + Biny[k] = np.pad(Biny[k], (0, (len(bin)+1)-len(Biny[k])), mode='constant') + Biny_x[k] = np.log10(Biny[k]/bin_size) + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min,axis=0) + bins = np.array(Biny_x) + bins = bins[:,:-1] + + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="70%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.4, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + e = ax.contourf(bin, hght, bins, 200, cmap='gnuplot')#, levels=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)")#, ticks=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim(0,10000) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.savefig(outfile + 'AF_single_parallel_' + str(int(timestep)) +'.png') + +# Adia_fraction(timesteps[10]) +with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(Adia_fraction, timesteps) + +# with concurrent.futures.ThreadPoolExecutor() as executor: +# results = [executor.submit(Adia_fraction, timestep) for timestep in timesteps[50:60]] + +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/Randomness/AF_rysy_xz2d_2D.py b/NC_vs_AF/Randomness/AF_rysy_xz2d_2D.py new file mode 100644 index 0000000..4952ead --- /dev/null +++ b/NC_vs_AF/Randomness/AF_rysy_xz2d_2D.py @@ -0,0 +1,114 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +import h5py +import numpy as np +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 11}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, nz = rhod.shape +rhod_cros = rhod[:,:] +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +dx = h5py.File(input_dir + "/const.h5", "r").attrs["dx"] + +hght = np.arange(nz) * dz +X = np.arange(nx) * dx + +# ---- adiabatic LWC ---- +AF_min = np.zeros([nx, nz]) +adia_rl = np.zeros(nz) +adia_rl_min = np.zeros(nz) +clb_rv_min = np.zeros(nz) +clb_th_min = np.zeros(nz) + +for timestep in timesteps: + plt.clf() + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod_cros / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th = h5py.File(filename, "r")["th"][:,:]; + rv = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + if min_hght/dz < 10: + min_hght = 10*dz + + for i in np.arange(nz): + if clb_idx[i] > 0: + clb_rv_min[i] = rv[i, int(min_hght/dz)] + clb_th_min[i] = th[i, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, k] = 0 + else: + AF_min[i, k] = rl[i, k] / adia_rl_min[k] + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_min[AF_min>1.4] = np.nan + AF_plot = np.transpose(AF_min) + + e = plt.contourf(X, hght, AF_plot, 10, cmap='gnuplot', vmin=0, vmax=1.4, levels=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) #bin[1:] + plt.colorbar(e, orientation='vertical', label=r"AF[]", ticks=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) + plt.clim(0, 1.4) + plt.ylabel('Height [m]') + plt.xlabel('X [m]') + plt.title('Adiabatic Fraction [](Y=5000 m, {}s )'.format(int(timestep/2))) + plt.savefig(outfile + '/cross_single_' + str(int(timestep/2)) +'.png') diff --git a/NC_vs_AF/Randomness/AF_rysy_xz2d_multi_2D.py b/NC_vs_AF/Randomness/AF_rysy_xz2d_multi_2D.py new file mode 100644 index 0000000..4758c59 --- /dev/null +++ b/NC_vs_AF/Randomness/AF_rysy_xz2d_multi_2D.py @@ -0,0 +1,129 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 11}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, nz = rhod.shape +rhod_cros = rhod[:,:] +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +dx = h5py.File(input_dir + "/const.h5", "r").attrs["dx"] + +hght = np.arange(nz) * dz +X = np.arange(nx) * dx + +def Adia_fraction(timestep): + + + plt.clf() + # ---- adiabatic LWC ---- + AF_min = np.zeros([nx, nz]) + adia_rl = np.zeros(nz) + adia_rl_min = np.zeros(nz) + clb_rv_min = np.zeros(nz) + clb_th_min = np.zeros(nz) + + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod_cros / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th = h5py.File(filename, "r")["th"][:,:]; + rv = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + if min_hght/dz < 10: + min_hght = 10*dz + + for i in np.arange(nz): + if clb_idx[i] > 0: + clb_rv_min[i] = rv[i, int(min_hght/dz)] + clb_th_min[i] = th[i, int(min_hght/dz)] + + # model a parcel to get an adiabatic rl, assume a single parcel moving starting from mean rv and th at cloud base + parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) + parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for i in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[i, k] = 0 + else: + AF_min[i, k] = rl[i, k] / adia_rl_min[k] + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_min[AF_min>1.4] = np.nan + AF_plot = np.transpose(AF_min) + + e = plt.contourf(X, hght, AF_plot, 10, cmap='gnuplot', vmin=0, vmax=1.4, levels=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) #bin[1:] + plt.colorbar(e, orientation='vertical', label=r"AF[]", ticks=[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]) + plt.clim(0, 1.4) + plt.ylabel('Height [m]') + plt.xlabel('X [m]') + plt.title('Adiabatic Fraction []({}s )'.format(int(timestep/2))) + plt.savefig(outfile + '/cross' + str(int(timestep/2)) +'.png') + + +with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(Adia_fraction, timesteps) + +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py new file mode 100644 index 0000000..fcb9131 --- /dev/null +++ b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py @@ -0,0 +1,169 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +import pandas as pd +from scipy.stats import moment +from sys import argv +from matplotlib.ticker import MultipleLocator +import matplotlib.pyplot as plt +import matplotlib as mpl +import matplotlib.colors as mcolors +from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 20}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# +name = '2D_NA1' +#PATHS + +path_diff_NA1_piggy_VF = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF/' +path_diff_NA1_piggy_VF_tail = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' +path_diff_NA1_piggy_VF_multi = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' + +outfile = '' +#OPISY +text_diff_piggy_VF = 'same velo field in all simulations' +text_diff_piggy_VF_tail = 'same velo field in all simulations \n sd conc long tail' +text_diff_piggy_VF_multi = 'same velo field in all simulations \n sd conc same multiplicity' + +paths = [path_diff_NA1_piggy_VF+'SD100',path_diff_NA1_piggy_VF+'SD1000', path_diff_NA1_piggy_VF+'SD10000',path_diff_NA1_piggy_VF_tail+'SD100',path_diff_NA1_piggy_VF_tail+'SD1000', path_diff_NA1_piggy_VF+'SD10000'] + +label_list = ['100', '1000', '10000'] +podpisy = [text_diff_piggy_VF, text_diff_piggy_VF_tail]#, text_diff_piggy_VF_multi] +width_multiplier = 0.67 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],4)),1/2)/(2*STD[iter_value]) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.25 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 2.5e2) + plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'sigma_VF_tail_multi'+name+'.png') + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 5e-1) + plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_VF_tail_multi'+name+'.png') + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 4e-1) + plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_VF_tail_multi'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py b/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py new file mode 100644 index 0000000..2675b25 --- /dev/null +++ b/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py @@ -0,0 +1,113 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ + +''' + +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +paths = argv[1] +outfile = argv[2] + +file_names = os.listdir(paths) + +pliki = [ i for i in range(len(file_names))] + +for timestep in timesteps: + plt.clf() + rr_rows_clb = np.zeros((121, len(file_names))) + rr_rows_lvl0 = np.zeros((121, len(file_names))) + for p in range(len(file_names)): + path = paths+file_names[p] + rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] + p_e = h5py.File(path + "/const.h5", "r")["p_e"][:] + nx, nz = rhod.shape + rhod_cros = rhod[:,:] + dz = h5py.File(path + "/const.h5", "r").attrs["dz"] + dx = h5py.File(path + "/const.h5", "r").attrs["dx"] + + hght = np.arange(nz) * dz + X = np.arange(nx)# * dx + + filename = path + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rr_c = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod_cros / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th = h5py.File(filename, "r")["th"][:,:]; + rv = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + if min_hght/dz < 10: + min_hght = 10*int(dz) + + min_hght = np.nan_to_num(min_hght) + + # print(np.sum(rr_c[:][int(min_hght/dz)-1]>0), min_hght) + # print(rr_c[:,int(min_hght/dz)-1].shape) + rr_rows_clb[:,p] = rr[:,int(min_hght/dz)-1] + rr_rows_lvl0[:,p] = rr[:,0] + Rr_rows_clb = np.transpose(rr_rows_clb) + Rr_rows_lvl0 = np.transpose(rr_rows_lvl0) + + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(30,15)) + e0 = ax0.contourf(X, pliki, Rr_rows_clb, vmin=7e-15, vmax=4e-4, extend='neither',levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4], cmap='gnuplot')#, vmin=0, vmax=1.4, levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) #bin[1:] + # e = plt.pcolormesh(X, pliki, Rr_rows, vmin=7e-15, vmax=4e-4) + # fig.colorbar(e0, orientation='vertical', ax=ax0, label=r"$r_{v}$", ticks=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) + #opcjonalnie levele~!!!!! + ax0.set_ylabel('Simulation#') + ax0.set_xlabel('cell#') + ax0.set_title('Height = {}m'.format(int(min_hght)-100)) + e1 = ax1.contourf(X, pliki, Rr_rows_lvl0, vmin=7e-15, vmax=4e-4, extend='neither',levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4], cmap='gnuplot')#, vmin=0, vmax=1.4, levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) #bin[1:] + # e = plt.pcolormesh(X, pliki, Rr_rows, vmin=7e-15, vmax=4e-4) + fig.subplots_adjust(right=0.99) + fig.colorbar(e1, orientation='vertical', ax=[ax0,ax1], label=r"$r_{v}$", ticks=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) + #opcjonalnie levele~!!!!! + # fig.supylabel('Simulation#') + ax1.set_xlabel('cell#') + ax1.set_title('Height = {}m'.format(int(0))) + fig.suptitle('Current time {}s '.format(int(timestep/2))) + plt.axis(aspect='image') + plt.savefig(outfile + '/Multi_SD10000_' + str(int(timestep/2)) +'.png') + plt.close() diff --git a/Rain_distribution/RAIN_rysy_xz2d_2D_test.py b/Rain_distribution/RAIN_rysy_xz2d_2D_test.py new file mode 100644 index 0000000..b4a2e3a --- /dev/null +++ b/Rain_distribution/RAIN_rysy_xz2d_2D_test.py @@ -0,0 +1,100 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_test.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ + +''' + +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 11}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +paths = argv[1] +outfile = argv[2] + +file_names = os.listdir(paths) + +pliki = [ i for i in range(len(file_names))] + +for timestep in timesteps: + plt.clf() + rr_rows = np.zeros((121, len(file_names))) + for p in range(len(file_names)): + path = paths+file_names[p] + rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] + p_e = h5py.File(path + "/const.h5", "r")["p_e"][:] + nx, nz = rhod.shape + rhod_cros = rhod[:,:] + dz = h5py.File(path + "/const.h5", "r").attrs["dz"] + dx = h5py.File(path + "/const.h5", "r").attrs["dx"] + + hght = np.arange(nz) * dz + X = np.arange(nx)# * dx + + filename = path + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rr_c = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod_cros / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th = h5py.File(filename, "r")["th"][:,:]; + rv = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + if min_hght/dz < 10: + min_hght = 10*int(dz) + + min_hght = np.nan_to_num(min_hght) + + # print(np.sum(rr_c[:][int(min_hght/dz)-1]>0), min_hght) + # print(rr_c[:,int(min_hght/dz)-1].shape) + rr_rows[:,p] = rr[:,int(min_hght/dz)-1] + Rr_rows = np.transpose(rr_rows) + + e = plt.contourf(X, pliki, Rr_rows, vmin=7e-15, vmax=4e-4, extend='neither',levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4], cmap='gnuplot')#, vmin=0, vmax=1.4, levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) #bin[1:] + # e = plt.pcolormesh(X, pliki, Rr_rows, vmin=7e-15, vmax=4e-4) + plt.colorbar(e, orientation='vertical', label=r"$r_{v}$", ticks=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) + #opcjonalnie levele~!!!!! + # plt.clim(0, 1.4) + plt.ylabel('Simulation#') + plt.xlabel('cell#') + plt.title('Current time {}s '.format(int(timestep/2))) + plt.axis(aspect='image') + plt.savefig(outfile + '/Below_CLB_' + str(int(timestep/2)) +'.png') diff --git a/Rain_distribution/Rain.py b/Rain_distribution/Rain.py new file mode 100644 index 0000000..44175f2 --- /dev/null +++ b/Rain_distribution/Rain.py @@ -0,0 +1,110 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") + + +import h5py +import time +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +# print whole np arrays +np.set_printoptions(threshold=maxsize) + +plt.rcParams.update({'font.size': 12}) +#plt.figure(figsize=(16,10)) + +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] +# timesteps = timesteps[88:91] + +input_dir = argv[1] +outfile = argv[2] + +rhod = h5py.File(input_dir + "/const.h5", "r")["G"][:,:] +p_e = h5py.File(input_dir + "/const.h5", "r")["p_e"][:] +nx, nz = rhod.shape +dz = h5py.File(input_dir + "/const.h5", "r").attrs["dz"] +hght = np.arange(nz) * dz +bin = np.linspace(1,121,len(np.arange(nx))) +# bin_size = bin[2]-bin[1] +# print(bin_size) + + +# ---- adiabatic LWC ---- +AF_min = np.zeros([nx, nz]) +adia_rl = np.zeros([nz]) +adia_rl_min = np.zeros([nz]) +clb_ql_min = np.zeros([nx]) +sum_rr = np.zeros([nx]) +Biny = [0 for i in np.arange(nz)] +Biny_x = [0 for i in np.arange(nz)] +Slice = np.zeros([nx, nz]) + + +for timestep in timesteps: + plt.clf() + filename = input_dir + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod / 1e6; # 1 / cm^3 + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e6; # kg/kg + + rr = rr * rhod + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + + # print(timestep, rr) + # print('rl>1e-5 cloudy cells: ', np.sum(cloudy_mask_used)) + # print('rl>1e-5 mean nc in cloudy cells: ', np.sum(nc * cloudy_mask_used) / np.sum(cloudy_mask_used)) + + # th and rv + th = h5py.File(filename, "r")["th"][:,:]; + rv = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + + + for i in np.arange(nx): + if clb_idx[i] > 0: + # print(timestep, np.sum(ql[i,:int(min_hght/dz)-1]),i) + sum_rr[i] = np.sum(rr[i,:int(min_hght/dz)-1],0) + + + # plt.bar(bin, sum_rr) + plt.scatter(bin, hght_2) + # plt.ylim((0,0.02)) + plt.title("histogram") + plt.savefig(outfile + 'Rain_singel' + str(int(timestep)) +'.png') + # if clb_idx[i] > 0: + # clb_ql_min[i] = ql[i, int(min_hght/dz)-1] + # for k in np.arange(nx): + # if clb_idx[i] > 0: + # sum_ql[i] = np.sum(ql[i,:int(min_hght/dz)-1],0) diff --git a/Rain_distribution/Rain_many.py b/Rain_distribution/Rain_many.py new file mode 100644 index 0000000..7240742 --- /dev/null +++ b/Rain_distribution/Rain_many.py @@ -0,0 +1,109 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +import h5py +import time +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +import os +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +plt.rcParams.update({'font.size': 12}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i +timesteps = timesteps[1:91] +np.set_printoptions(threshold=maxsize) + + +paths = argv[1] +outfile = argv[2] +files = os.listdir(paths) +nr_files = len(files) + + +def Adia_fraction(timestep): + + rhod= [0 for i in range(nr_files)] + p_e = [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + nc = [0 for i in range(nr_files)] + th = [0 for i in range(nr_files)] + rv = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + sum_rr = [0 for i in range(nr_files)] + + + for file in range(nr_files): + # plt.clf() + p_e[file] = h5py.File(paths+files[file] + "/const.h5", "r")["p_e"][:] + rhod[file] = h5py.File(paths+files[file] + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(paths+files[file] + "/const.h5", "r").attrs["dz"] + + nx, nz = rhod[file].shape + hght = np.arange(nz) * dz[file] + bin = np.linspace(1,121,len(np.arange(nx))) + sum_rr[file] = np.zeros([nx]) + + filename = paths+files[file] + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc[file] = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod[file] / 1e6; # 1 / cm^3 + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e6; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th[file] = h5py.File(filename, "r")["th"][:,:]; + rv[file] = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner= np.vectorize(lcmn.exner) + T = th[file] * Vexner(p_e[file].astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e[file].astype(float)) + RH = rv[file] / r_vs[file] + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + # print(i, rr[file][i]) + + for j in np.arange(nx): + if clb_idx[j] > 0: + sum_rr[file][j] = np.sum(rr[file][j,:int(min_hght/dz[file])-1],0) + sum_rr[file][sum_rr[file]==0] = np.nan + # print(file) + srednie_rr = np.nanmean(sum_rr, axis=0) + STD_rr = np.nanstd(sum_rr, axis=0) + plt.errorbar(bin, srednie_rr, STD_rr, fmt='o', label='average') + plt.ylim((0,0.04)) + plt.xlim((0,120)) + plt.legend() + plt.savefig(outfile + 'Rain_many_' + str(i*240) +'.png') + # Od komentuj! + plt.clf() + +# bin_size = bin[2]-bin[1] +# print(bin_size) + +for i in range(1, 91): + Adia_fraction(i) diff --git a/Rain_distribution/distribution_Py3.py b/Rain_distribution/distribution_Py3.py new file mode 100644 index 0000000..19b4428 --- /dev/null +++ b/Rain_distribution/distribution_Py3.py @@ -0,0 +1,116 @@ +import h5py +import numpy as np +from sys import argv +import matplotlib.pyplot as plt +from collections import OrderedDict + +#rain_data = ["u", "v", "w"] +#rain_data = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"] +#rain_data = ["cloud_rw_mom3"] +rain_data = ["rain_rw_mom3", "precip_rate"] +layer_thickness = 10 +cloud_thresh = 1e-4 # qc at cloud base + +CellVol = 100.*100*1 # hardcoded cell volume [m^3] +L_evap = 2264.76e3 # latent heat of evapporation [J/kg] + +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) +#from_lvl = int(argv[4]) +#to_lvl = int(argv[5]) + +directories = argv[4:len(argv):2] +labels = argv[5:len(argv):2] +print(directories, labels) + +levels = ["ground", "cloud_base"] + +for lvl in levels: + total_arr = OrderedDict() + for data in rain_data: + total_arr[data] = OrderedDict() + + plot_labels = OrderedDict() + tot_cloud_base_lvl = OrderedDict() + for lab in labels: + tot_cloud_base_lvl[lab] = np.zeros(0) + + # read in nx, ny, nz + for directory, lab in zip(directories, labels): + w3d = h5py.File(directory + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:,:] + nx, ny, nz = w3d.shape + plot_labels[lab] = lab + # Exy_avg = OrderedDict() + # for data in rain_data: + # Exy_avg[data] = np.zeros(((nx+1)/2)) + + + for data in rain_data: + total_arr[data][lab] = np.zeros(0) + + for t in range(time_start, time_end+1, outfreq): + filename = directory + "/timestep" + str(t).zfill(10) + ".h5" + print(filename) + + # find cloud base + + # based on cloud rw + w3d = h5py.File(filename, "r")["cloud_rw_mom3"][:,:,:] * 4. / 3. * 3.1416 * 1e3 + cloud_base_lvl = np.argmax(np.average(w3d, axis=(0,1)) > cloud_thresh) + # based on RH + # w3d = h5py.File(filename, "r")["RH"][:,:,:] # * 4. / 3. * 3.1416 * 1e3 + # cloud_base_lvl = np.argmax(np.average(w3d, axis=(0,1)) > .99) + + tot_cloud_base_lvl[lab] = np.append(tot_cloud_base_lvl[lab], cloud_base_lvl) # done for each data, but we dont care - wont affect average + + print('cloud base lvl = ', cloud_base_lvl) + + if lvl == "cloud_base": + total_arr[data][lab] = np.append(total_arr[data][lab], h5py.File(filename, "r")[data][:,:,cloud_base_lvl-layer_thickness : cloud_base_lvl]) + if lvl == "ground": + total_arr[data][lab] = np.append(total_arr[data][lab], h5py.File(filename, "r")[data][:,:, 0 : layer_thickness ]) + + # hists[lab] = np.hist(total_arr, bins=100) + # _ = plt.hist(total_arr, bins='auto') + + # convert to typical units + if data == "rain_rw_mom3": + total_arr[data][lab] *= 4./3. * 3.1416 * 1e3 * 1e3 # [g/kg] + if data == "precip_rate": + total_arr[data][lab] *= 4./3. * 3.1416 * 1e3 / CellVol * L_evap + + + for lab in labels: + # print np.average(total_arr[lab]) + plot_labels[lab] = plot_labels[lab] + '\n = {:.3e}'.format(np.average(total_arr["rain_rw_mom3"][lab])) \ + + '\n = {:.3e}'.format(np.average(total_arr["precip_rate"][lab])) \ + + '\n = {:.2f}'.format(np.average(tot_cloud_base_lvl[lab] * 5)) + + plt.figure(0) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + #_ = plt.hist(total_arr["rain_rw_mom3"].values(), bins='auto', label=plot_labels.values(), density=True) + data = total_arr["rain_rw_mom3"].values() + +# _ = plt.hist(data, bins=100, label=plot_labels.values(), density=False, histtype='step', linewidth=2) + _ = plt.hist(data, bins=np.logspace(np.log10(1e-6), np.log10(np.amax(data)), 100), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + plt.xscale('log') + plt.legend(loc = 'lower center') + plt.yscale('log') + plt.xlabel('q_r [g/kg]') + plt.ylabel('# of cells') + plt.savefig('rain_histo_' + lvl + '_' + str(time_start) + '_' + str(time_end) +'.png') + + plt.figure(1) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + data = total_arr["precip_rate"].values() + #_ = plt.hist(data, bins=100, label=plot_labels.values(), density=False, histtype='step', linewidth=2) + _ = plt.hist(data, bins=np.logspace(np.log10(1e-3), np.log10(np.amax(data)), 100), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + plt.xscale('log') + plt.legend(loc = 'lower center') + plt.yscale('log') + plt.xlabel('precipitation flux [W / m^2]') + plt.ylabel('# of cells') + plt.savefig('precip_rate_histo_' + lvl + '_' + str(time_start) + '_' + str(time_end) +'.png') diff --git a/Rain_distribution/distribution_Py3_2D.py b/Rain_distribution/distribution_Py3_2D.py new file mode 100644 index 0000000..2d6367a --- /dev/null +++ b/Rain_distribution/distribution_Py3_2D.py @@ -0,0 +1,129 @@ +import h5py +import numpy as np +from sys import argv +import matplotlib.pyplot as plt +from collections import OrderedDict + +''' +HOW TO run + +python3 distribution_Py3_2D.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_piggy_25_out_lgrngn "test" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_piggy_26_out_lgrngn "test2" + +''' + +#rain_data = ["u", "v", "w"] +#rain_data = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"] +#rain_data = ["cloud_rw_mom3"] +rain_data = ["rain_rw_mom3", "precip_rate"] +layer_thickness = 10 +cloud_thresh = 1e-4 # qc at cloud base + +CellVol = 100.*100*1 # hardcoded cell volume [m^3] +L_evap = 2264.76e3 # latent heat of evapporation [J/kg] + +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) +#from_lvl = int(argv[4]) +#to_lvl = int(argv[5]) + +directories = argv[4:len(argv):2] +labels = argv[5:len(argv):2] +print(directories, labels) + +levels = ["ground", "cloud_base"] + +for lvl in levels: + total_arr = OrderedDict() + for data in rain_data: + total_arr[data] = OrderedDict() + + plot_labels = OrderedDict() + tot_cloud_base_lvl = OrderedDict() + for lab in labels: + tot_cloud_base_lvl[lab] = np.zeros(0) + + # read in nx, ny, nz + for directory, lab in zip(directories, labels): + w3d = h5py.File(directory + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] + nx, nz = w3d.shape + plot_labels[lab] = lab + # Exy_avg = OrderedDict() + # for data in rain_data: + # Exy_avg[data] = np.zeros(((nx+1)/2)) + + + for data in rain_data: + total_arr[data][lab] = np.zeros(0) + + for t in range(time_start, time_end+1, outfreq): + filename = directory + "/timestep" + str(t).zfill(10) + ".h5" + print(filename) + + # find cloud base + + # based on cloud rw + w3d = h5py.File(filename, "r")["cloud_rw_mom3"][:,:] * 4. / 3. * 3.1416 * 1e3 + cloud_base_lvl = np.argmax(np.average(w3d, axis=(0)) > cloud_thresh) + # based on RH + # w3d = h5py.File(filename, "r")["RH"][:,:,:] # * 4. / 3. * 3.1416 * 1e3 + # cloud_base_lvl = np.argmax(np.average(w3d, axis=(0,1)) > .99) + + tot_cloud_base_lvl[lab] = np.append(tot_cloud_base_lvl[lab], cloud_base_lvl) # done for each data, but we dont care - wont affect average + + print('cloud base lvl = ', cloud_base_lvl) + + if lvl == "cloud_base": + total_arr[data][lab] = np.append(total_arr[data][lab], h5py.File(filename, "r")[data][:,cloud_base_lvl-layer_thickness : cloud_base_lvl]) + if lvl == "ground": + total_arr[data][lab] = np.append(total_arr[data][lab], h5py.File(filename, "r")[data][:, 0 : layer_thickness ]) + + # hists[lab] = np.hist(total_arr, bins=100) + # _ = plt.hist(total_arr, bins='auto') + + # convert to typical units + if data == "rain_rw_mom3": + total_arr[data][lab] *= 4./3. * 3.1416 * 1e3 * 1e3 # [g/kg] + if data == "precip_rate": + total_arr[data][lab] *= 4./3. * 3.1416 * 1e3 / CellVol * L_evap + + + for lab in labels: + # print np.average(total_arr[lab]) + plot_labels[lab] = plot_labels[lab] + '\n = {:.3e}'.format(np.average(total_arr["rain_rw_mom3"][lab])) \ + + '\n = {:.3e}'.format(np.average(total_arr["precip_rate"][lab])) \ + + '\n = {:.2f}'.format(np.average(tot_cloud_base_lvl[lab] * 5)) + + plt.figure(0) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + # _ = plt.hist(total_arr["rain_rw_mom3"].values(), bins='auto', label=plot_labels.values(), density=True) + data = total_arr["rain_rw_mom3"].values() + # B = np.amax(data) + # print(np.log10(B)) + + # _ = plt.hist(data, bins=100, label=plot_labels.values(), density=False, histtype='step', linewidth=2) + # _ = plt.hist(data, bins=np.logspace(np.log10(1e-6), np.log10(np.amax(data)), 100), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + _ = plt.hist(data, bins=np.logspace(np.log10(1e-6), np.log10(1e3), 121), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + + plt.xscale('log') + # plt.legend(loc = 'lower center') + plt.yscale('log') + plt.xlabel('q_r [g/kg]') + plt.ylabel('# of cells') + plt.savefig('rain_histo_' + lvl + '_' + str(time_start) + '_' + str(time_end) +'.png') + + plt.figure(1) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + data = total_arr["precip_rate"].values() + # _ = plt.hist(data, bins=100, label=plot_labels.values(), density=False, histtype='step', linewidth=2) + # _ = plt.hist(data, bins=np.logspace(np.log10(1e-3), np.log10(np.amax(data)), 100), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + _ = plt.hist(data, bins=np.logspace(np.log10(1e-3), np.log10(1e3), 121), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + + plt.xscale('log') + # plt.legend(loc = 'lower center') + plt.yscale('log') + plt.xlabel('precipitation flux [W / m^2]') + plt.ylabel('# of cells') + plt.savefig('precip_rate_histo_' + lvl + '_' + str(time_start) + '_' + str(time_end) +'.png') diff --git a/Rain_distribution/distribution_Py3_2D_mean.py b/Rain_distribution/distribution_Py3_2D_mean.py new file mode 100644 index 0000000..6a6b652 --- /dev/null +++ b/Rain_distribution/distribution_Py3_2D_mean.py @@ -0,0 +1,124 @@ +import h5py +import numpy as np +from sys import argv +import matplotlib.pyplot as plt +from collections import OrderedDict +import os + +''' +HOW TO run + +python3 distribution_Py3_2D_mean.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "test" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/ + +''' + +#rain_data = ["u", "v", "w"] +#rain_data = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"] +#rain_data = ["cloud_rw_mom3"] +rain_data = ["rain_rw_mom3", "precip_rate"] +layer_thickness = 10 +# cloud_thresh = 1e-4 # qc at cloud base +cloud_thresh = 1e-5 # qc at cloud base + +CellVol = 100.*100*1 # hardcoded cell volume [m^3] +L_evap = 2264.76e3 # latent heat of evapporation [J/kg] + +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) +#from_lvl = int(argv[4]) +#to_lvl = int(argv[5]) + +directories = argv[4:len(argv):2] +labels = argv[5:len(argv):2] +outfile = argv[6] +print(directories, labels) + +levels = ["ground", "cloud_base"] +for lvl in levels: + total_arr = OrderedDict() + for data in rain_data: + total_arr[data] = OrderedDict() + plot_labels = OrderedDict() + tot_cloud_base_lvl = OrderedDict() +def Rain_distribution(directories, labels, lvl): + for directory, lab in zip(directories, labels): + path_file = os.listdir(directory) + Rain_mean = {} + + for path in path_file: + path_to_file = os.listdir(directory+path) + joined = os.path.join(directory,path) + + file = '#'+(path.split("_piggy_",-3))[-1].split("_out")[0] + tot_cloud_base_lvl[file] = np.zeros(0) + w3d = h5py.File(joined+"/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] + nx, nz = w3d.shape + + for data in rain_data: + total_arr[data][file] = np.zeros(0) + + for t in range(time_start, time_end+1, outfreq): + filename = joined + "/timestep" + str(t).zfill(10) + ".h5" + # find cloud base + # based on cloud rw + w3d = h5py.File(filename, "r")["cloud_rw_mom3"][:,:] * 4. / 3. * 3.1416 * 1e3 + cloud_base_lvl = np.argmax(np.average(w3d, axis=(0)) > cloud_thresh) + # based on RH + # w3d = h5py.File(filename, "r")["RH"][:,:,:] # * 4. / 3. * 3.1416 * 1e3 + # cloud_base_lvl = np.argmax(np.average(w3d, axis=(0,1)) > .99) + + tot_cloud_base_lvl[file] = np.append(tot_cloud_base_lvl[file], cloud_base_lvl) # done for each data, but we dont care - wont affect average + + # print('cloud base lvl = ', cloud_base_lvl) + + if lvl == "cloud_base": + total_arr[data][file] = np.append(total_arr[data][file], h5py.File(filename, "r")[data][:,cloud_base_lvl-layer_thickness : cloud_base_lvl]) + if lvl == "ground": + total_arr[data][file] = np.append(total_arr[data][file], h5py.File(filename, "r")[data][:, 0 : layer_thickness ]) + + # convert to typical units + if data == "rain_rw_mom3": + total_arr[data][file] *= 4./3. * 3.1416 * 1e3 * 1e3 # [g/kg] + if data == "precip_rate": + total_arr[data][file] *= 4./3. * 3.1416 * 1e3 / CellVol * L_evap + A = [i for i in range(len(path_file))] + B = [i for i in range(len(path_file))] + i =0 + for path in path_file: + file = '#'+(path.split("_piggy_",-3))[-1].split("_out")[0] + A[i] = total_arr["rain_rw_mom3"][file] + B[i] = total_arr["precip_rate"][file] + i += 1 + A_mean = np.average(A, axis=0) + A_Std = np.std(A, axis=0) + B_mean = np.average(B, axis=0) + + + plt.figure(0) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + _ = plt.hist(A_mean, bins=np.logspace(np.log10(1e-6), np.log10(np.amax(A_mean)), nx), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + + plt.xscale('log') + # plt.legend(loc = 'lower center') + plt.yscale('log') + plt.xlabel('q_r [g/kg]') + plt.ylabel('# of cells') + plt.savefig(outfile+'Mean_rain_histo_' + lvl + '_' + str(time_start) + '_' + str(time_end) +'.png') + + plt.figure(1) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + _ = plt.hist(B_mean, bins=np.logspace(np.log10(1e-3), np.log10(np.amax(B_mean)), nx), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + + plt.xscale('log') + # plt.legend(loc = 'lower center') + plt.yscale('log') + plt.xlabel('precipitation flux [W / m^2]') + plt.ylabel('# of cells') + plt.savefig(outfile+'Mean_precip_rate_histo_' + lvl + '_' + str(time_start) + '_' + str(time_end) +'.png') + + +Rain_distribution(directories, labels, levels[0]) +Rain_distribution(directories, labels, levels[1]) diff --git a/Rain_distribution/distribution_Py3_2D_mean_part.py b/Rain_distribution/distribution_Py3_2D_mean_part.py new file mode 100644 index 0000000..f275c83 --- /dev/null +++ b/Rain_distribution/distribution_Py3_2D_mean_part.py @@ -0,0 +1,126 @@ +import h5py +import numpy as np +from sys import argv +import matplotlib.pyplot as plt +from collections import OrderedDict +import os + +''' +HOW TO run + +python3 distribution_Py3_2D.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_piggy_25_out_lgrngn "test" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_piggy_26_out_lgrngn "test2" + +''' + +#rain_data = ["u", "v", "w"] +#rain_data = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"] +#rain_data = ["cloud_rw_mom3"] +rain_data = ["rain_rw_mom3", "precip_rate"] +layer_thickness = 10 +# cloud_thresh = 1e-4 # qc at cloud base +cloud_thresh = 1e-5 # qc at cloud base + +CellVol = 100.*100*1 # hardcoded cell volume [m^3] +L_evap = 2264.76e3 # latent heat of evapporation [J/kg] + +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) +#from_lvl = int(argv[4]) +#to_lvl = int(argv[5]) + +directories = argv[4:len(argv):2] +labels = argv[5:len(argv):2] +print(directories, labels) + +levels = ["ground", "cloud_base"] + + +def Rain_distribution(directories, labels): + for directory, lab in zip(directories, labels): + path_file = os.listdir(directory) + Rain_mean = {} + # read in nx, nz + for lvl in levels: + total_arr = OrderedDict() + for data in rain_data: + total_arr[data] = OrderedDict() + + plot_labels = OrderedDict() + tot_cloud_base_lvl = OrderedDict() + for path in path_file: + path_to_file = os.listdir(directory+path) + joined = os.path.join(directory,path) + + file = '#'+(path.split("_piggy_",-3))[-1].split("_out")[0] + tot_cloud_base_lvl[file] = np.zeros(0) + + # print((path.split("_piggy_",-3))[-1].split("_out")) + w3d = h5py.File(joined+"/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] + nx, nz = w3d.shape + + for data in rain_data: + total_arr[data][file] = np.zeros(0) + + for t in range(time_start, time_end+1, outfreq): + filename = joined + "/timestep" + str(t).zfill(10) + ".h5" + # find cloud base + # based on cloud rw + w3d = h5py.File(filename, "r")["cloud_rw_mom3"][:,:] * 4. / 3. * 3.1416 * 1e3 + cloud_base_lvl = np.argmax(np.average(w3d, axis=(0)) > cloud_thresh) + # based on RH + # w3d = h5py.File(filename, "r")["RH"][:,:,:] # * 4. / 3. * 3.1416 * 1e3 + # cloud_base_lvl = np.argmax(np.average(w3d, axis=(0,1)) > .99) + + tot_cloud_base_lvl[file] = np.append(tot_cloud_base_lvl[file], cloud_base_lvl) # done for each data, but we dont care - wont affect average + + # print('cloud base lvl = ', cloud_base_lvl) + + if lvl == "cloud_base": + total_arr[data][file] = np.append(total_arr[data][file], h5py.File(filename, "r")[data][:,cloud_base_lvl-layer_thickness : cloud_base_lvl]) + if lvl == "ground": + total_arr[data][file] = np.append(total_arr[data][file], h5py.File(filename, "r")[data][:, 0 : layer_thickness ]) + + # convert to typical units + if data == "rain_rw_mom3": + total_arr[data][file] *= 4./3. * 3.1416 * 1e3 * 1e3 # [g/kg] + if data == "precip_rate": + total_arr[data][file] *= 4./3. * 3.1416 * 1e3 / CellVol * L_evap + A = [i for i in range(len(path_file))] + B = [i for i in range(len(path_file))] + i =0 + for path in path_file: + file = '#'+(path.split("_piggy_",-3))[-1].split("_out")[0] + A[i] = total_arr["rain_rw_mom3"][file] + B[i] = total_arr["precip_rate"][file] + i += 1 + A_mean = np.average(A, axis=0) + B_mean = np.average(B, axis=0) + + + plt.figure(0) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + _ = plt.hist(A_mean, bins=np.logspace(np.log10(1e-6), np.log10(np.amax(A_mean)), nx), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + + plt.xscale('log') + # plt.legend(loc = 'lower center') + plt.yscale('log') + plt.xlabel('q_r [g/kg]') + plt.ylabel('# of cells') + plt.savefig('rain_histo_' + lvl + '_' + str(time_start) + '_' + str(time_end) +'.png') + + plt.figure(1) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + _ = plt.hist(B_mean, bins=np.logspace(np.log10(1e-3), np.log10(np.amax(B_mean)), nx), label=plot_labels.values(), density=False, histtype='step', linewidth=6) + + plt.xscale('log') + # plt.legend(loc = 'lower center') + plt.yscale('log') + plt.xlabel('precipitation flux [W / m^2]') + plt.ylabel('# of cells') + plt.savefig('precip_rate_histo_' + lvl + '_' + str(time_start) + '_' + str(time_end) +'.png') + + +Rain_distribution(directories, labels) From 0990d78d3fa323a49442c2349e25f88eb21f5843 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Mon, 6 Sep 2021 23:21:13 +0200 Subject: [PATCH 22/30] plots for paper vol3 --- Energy_spectrum/spectrum_2D.py | 16 +- Energy_spectrum/spectrum_2D_multi_many.py | 38 +++-- .../spectrum_2D_multi_many_mod_2.py | 84 ++++++++++ .../spectrum_2D_multi_many_modyfikacje.py | 84 ++++++++++ .../spectrum_2D_multi_many_parallel.py | 10 +- Energy_spectrum/spectrum_2D_srednie_nowe.py | 66 ++++++++ NC_vs_AF/AF_mean_parallel_2D.py | 147 ++++++++---------- Rain_distribution/Rain_many.py | 34 +++- Rain_distribution/Rain_many_copare.py | 129 +++++++++++++++ 9 files changed, 483 insertions(+), 125 deletions(-) create mode 100644 Energy_spectrum/spectrum_2D_multi_many_mod_2.py create mode 100644 Energy_spectrum/spectrum_2D_multi_many_modyfikacje.py create mode 100644 Energy_spectrum/spectrum_2D_srednie_nowe.py create mode 100644 Rain_distribution/Rain_many_copare.py diff --git a/Energy_spectrum/spectrum_2D.py b/Energy_spectrum/spectrum_2D.py index f395c16..514cdc1 100644 --- a/Energy_spectrum/spectrum_2D.py +++ b/Energy_spectrum/spectrum_2D.py @@ -7,9 +7,9 @@ # velocities = ["u", "v", "w"] # velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"] -# velocities = ["u", "w", "cloud_rw_mom3", "rv", "th", "RH", "actrw_rw_mom3"] -velocities = ["cloud_rw_mom3", "actrw_rw_mom3"] -# velocities = ["u"] +velocities = ["u", "w", "cloud_rw_mom3", "rv", "th", "RH", "actrw_rw_mom3"] +# velocities = ["cloud_rw_mom3", "actrw_rw_mom3"] +# velocities = ["u", "w"] time_start = int(argv[1]) time_end = int(argv[2]) @@ -35,16 +35,12 @@ for vel in velocities: if (vel == "cloud_rw_mom3") | (vel == "actrw_rw_mom3"): - w3d = h5py.File(filename, "r")[vel][:,:]# * 4. / 3. * 3.1416 * 1e3 + w3d = h5py.File(filename, "r")[vel][:,:] * 4. / 3. * 3.1416 * 1e3 else: w3d = h5py.File(filename, "r")[vel][:,:] # * 4. / 3. * 3.1416 * 1e3 for lvl in range(from_lvl, to_lvl+1): w2d = w3d[:, lvl] -<<<<<<< HEAD - # print(w2d) -======= ->>>>>>> acb609f27a00d77f0818e5edfbeeadf46112742a wkx = 1.0 / np.sqrt(nx - 1) * np.fft.rfft(w2d, axis = 0) # wky = 1.0 / np.sqrt(nz - 1) * np.fft.rfft(w2d, axis = 1) @@ -65,7 +61,7 @@ lmbd = 100. / K # assume dx=50m if (t == time_start and lab==labels[0]): - plt.loglog(lmbd, 2e-1* K**(-5./3.)*1e-8, label="-5/3" ) + plt.loglog(lmbd, 2e-1* K**(-5./3.), label="-5/3" ) for vel in velocities: Exy_avg[vel] /= (time_end - time_start) / outfreq + 1 @@ -77,7 +73,7 @@ plt.xlim(2*10**4,10**2) plt.xlabel("l[m]") plt.ylabel("PSD") -plt.legend() +# plt.legend() plt.grid(True, which='both', linestyle='--') # plt.title("Mean PSD of w 322m 1e-5, 1, 0) cloudy_mask_used = cloudy_mask + # print(cloudy_mask_used) # T Vexner = np.vectorize(lcmn.exner) T = th * Vexner(p_e.astype(float)) @@ -134,20 +111,22 @@ def Adia_fraction(i): r_vs = Vr_vs(T, p_e.astype(float)) RH = rv / r_vs # cloud base - clb_idx = np.argmax(cloudy_mask_used > 0, axis=2) + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) hght_2 = hght[clb_idx] hght_2[hght_2==0] = np.nan min_hght = np.nanmin(hght_2) max_hght = np.nanmax(hght_2) + if min_hght/dz < 10: + min_hght = 10*dz + # d+=1 - for d in np.arange(nx): - for j in np.arange(ny): - if clb_idx[d,j] > 0: - clb_rv_min[d,j] = rv[d, j, int(min_hght/dz)] - clb_th_min[d,j] = th[d, j, int(min_hght/dz)] + for j in np.arange(nx): + if clb_idx[j] > 0: + clb_rv_min[j] = rv[j, int(min_hght/dz)] + clb_th_min[j] = th[j, int(min_hght/dz)] - parcel_rv_min = np.mean(clb_rv_min[clb_rv_min>0]) - parcel_th_min = np.mean(clb_th_min[clb_th_min>0]) + parcel_rv_min = np.nan_to_num(np.nanmean(clb_rv_min[clb_rv_min>0])) + parcel_th_min = np.nan_to_num(np.nanmean(clb_th_min[clb_th_min>0])) parcel_rl_min = 0 for k in np.arange(nz): @@ -160,38 +139,33 @@ def Adia_fraction(i): parcel_rl_min += delta_rv_min adia_rl_min[k] = parcel_rl_min - for y in np.arange(nx): - for j in np.arange(ny): + for j in np.arange(nx): for k in np.arange(nz): if adia_rl_min[k] == 0: - AF_min[y, j, k] = 0 + AF_min[j, k] = 0 else: - AF_min[y, j, k] = rl[y,j,k] / adia_rl_min[k] + AF_min[j, k] = rl[j,k] / adia_rl_min[k] ######Biny - AF = AF_min * cloudy_mask_used + AF[AF==0]=np.nan + print(np.nanmean(AF, axis=0)) + for k in np.arange(nz): - # for k iny range(25,30): - for y in np.arange(nx): - for j in np.arange(ny): - Slice[y, j] = AF[y, j, k] - Slice[y,:][Slice[y,:]==0] = np.nan - # print(Slice[i,:]) - Biny[y] = np.digitize(Slice[y,:],bin) - # print(Biny[i]) - Biny[y] = np.bincount(Biny[y]) - Biny[y] = np.pad(Biny[y], (0, (len(bin)+1)-len(Biny[y])), mode='constant') - Biny = list(map(list,Biny)) - Biny_x[k] = np.log10(np.sum(Biny,0)/bin_size) + Biny[k] = np.digitize(AF[:,k],bin) + Biny[k] = np.bincount(Biny[k]) + Biny[k] = np.pad(Biny[k], (0, (len(bin)+1)-len(Biny[k])), mode='constant') + Biny_x[k] = np.log10(Biny[k]/bin_size) + print(Biny_x) + AF_min[AF_min==0] = np.nan AF_min[cloudy_mask_used==0] = np.nan - AF_mean_min = np.nanmean(AF_min, axis=(0,1)) - AF_mean_min[np.isnan(AF_mean_min)] = 0 + AF_mean_min = np.nanmean(AF_min, axis=0) bins = np.array(Biny_x) bins = bins[:,:-1] + fig,ax = plt.subplots(figsize=(11, 8)) axins = inset_axes(ax, width="50%", # width = 10% of parent_bbox width @@ -201,22 +175,25 @@ def Adia_fraction(i): bbox_transform=ax.transAxes, borderpad=0, ) - e = ax.contourf(bin, hght, bins, 200, cmap='gnuplot') #bin[1:] + e = ax.contourf( bin, hght, bins, 200, cmap='gnuplot') #bin[1:] cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)", format='%.2f') ax.set_ylabel('Height [m]') ax.set_xlabel('AF []') ax2=ax.twinx() - ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=2) + ax2.plot(AF_mean_min , hght, label="AF", c='k', linewidth=1) ax2.set_xlim((0.01,1.4)) - ax2.set_ylim(0,10000) + ax2.set_ylim((0,10000)) ax2.set_yticks([], []) ax2.set_yticks([], minor=True) - plt.savefig(paths + '/AF_average_' + str(240*i).zfill(10) +'.png') + plt.title('time = '+str(i*240)+ 's') + plt.savefig(outfile + '/AF_average/MELO_' + str(240*i).zfill(10) +'.png') + # plt.show() punkty = np.intc(np.linspace(1,91,91)) with concurrent.futures.ProcessPoolExecutor() as executor: results = executor.map(Adia_fraction, punkty) -# Adia_fraction(punkty[20]) +# for i in range(1,91): +# Adia_fraction(50) finish = time.perf_counter() print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/Rain_distribution/Rain_many.py b/Rain_distribution/Rain_many.py index 7240742..a62ea98 100644 --- a/Rain_distribution/Rain_many.py +++ b/Rain_distribution/Rain_many.py @@ -4,8 +4,18 @@ from sys import argv, path, maxsize #path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") # path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") -# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") -path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") +path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +How to run + +python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25_out_lgrngn /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain + +Singularity> python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ + +''' import h5py @@ -19,7 +29,7 @@ from mpl_toolkits.axes_grid1.inset_locator import inset_axes start = time.perf_counter() -plt.rcParams.update({'font.size': 12}) +plt.rcParams.update({'font.size': 20}) evap_lat = 2.501e6 # [J/kg] latent heat of evaporation timesteps = np.ones(91) for i in range(1, 91): @@ -50,16 +60,16 @@ def Adia_fraction(timestep): for file in range(nr_files): # plt.clf() - p_e[file] = h5py.File(paths+files[file] + "/const.h5", "r")["p_e"][:] - rhod[file] = h5py.File(paths+files[file] + "/const.h5", "r")["G"][:,:] - dz[file] = h5py.File(paths+files[file] + "/const.h5", "r").attrs["dz"] + p_e[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn" + "/const.h5", "r")["p_e"][:] + rhod[file] = h5py.File(paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn"+ "/const.h5", "r").attrs["dz"] nx, nz = rhod[file].shape hght = np.arange(nz) * dz[file] bin = np.linspace(1,121,len(np.arange(nx))) sum_rr[file] = np.zeros([nx]) - filename = paths+files[file] + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + filename = paths + files[file] + '/' + files[file] + "_out_lgrngn"+ "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" rl[file] = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg rl_base[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg nc[file] = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod[file] / 1e6; # 1 / cm^3 @@ -86,6 +96,10 @@ def Adia_fraction(timestep): max_hght = np.nanmax(hght_2) # print("wysokosc min",min_hght, " wysokosc max", max_hght) # print(i, rr[file][i]) + if min_hght/dz[file] < 10: + min_hght = 10*int(dz[file]) + + min_hght = np.nan_to_num(min_hght) for j in np.arange(nx): if clb_idx[j] > 0: @@ -94,9 +108,13 @@ def Adia_fraction(timestep): # print(file) srednie_rr = np.nanmean(sum_rr, axis=0) STD_rr = np.nanstd(sum_rr, axis=0) + fig = plt.figure() + fig.set_size_inches(18.5, 10.5) plt.errorbar(bin, srednie_rr, STD_rr, fmt='o', label='average') - plt.ylim((0,0.04)) + # plt.ylim((0,0.04)) plt.xlim((0,120)) + plt.xlabel('cell#') + plt.ylabel('$q_l$ (rain) [g/kg]') plt.legend() plt.savefig(outfile + 'Rain_many_' + str(i*240) +'.png') # Od komentuj! diff --git a/Rain_distribution/Rain_many_copare.py b/Rain_distribution/Rain_many_copare.py new file mode 100644 index 0000000..62ac27a --- /dev/null +++ b/Rain_distribution/Rain_many_copare.py @@ -0,0 +1,129 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +How to run + +python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25_out_lgrngn /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain + +Singularity> python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ + +''' + + +import h5py +import time +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +import os +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i +timesteps = timesteps[1:91] +np.set_printoptions(threshold=maxsize) + + +def Adia_fraction(timestep, paths): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + p_e = [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + nc = [0 for i in range(nr_files)] + th = [0 for i in range(nr_files)] + rv = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + sum_rr = [0 for i in range(nr_files)] + + + for file in range(nr_files): + # plt.clf() + p_e[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn" + "/const.h5", "r")["p_e"][:] + rhod[file] = h5py.File(paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn"+ "/const.h5", "r").attrs["dz"] + + nx, nz = rhod[file].shape + hght = np.arange(nz) * dz[file] + bin = np.linspace(1,121,len(np.arange(nx))) + sum_rr[file] = np.zeros([nx]) + + filename = paths + files[file] + '/' + files[file] + "_out_lgrngn"+ "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc[file] = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod[file] / 1e6; # 1 / cm^3 + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e6; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th[file] = h5py.File(filename, "r")["th"][:,:]; + rv[file] = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner= np.vectorize(lcmn.exner) + T = th[file] * Vexner(p_e[file].astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e[file].astype(float)) + RH = rv[file] / r_vs[file] + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + # print(i, rr[file][i]) + if min_hght/dz[file] < 10: + min_hght = 10*int(dz[file]) + + min_hght = np.nan_to_num(min_hght) + + for j in np.arange(nx): + if clb_idx[j] > 0: + sum_rr[file][j] = np.sum(rr[file][j,:int(min_hght/dz[file])-1],0) + sum_rr[file][sum_rr[file]==0] = np.nan + # print(file) + srednie_rr = np.nanmean(sum_rr, axis=0) + STD_rr = np.nanstd(sum_rr, axis=0) + return(srednie_rr, STD_rr, bin) + +# bin_size = bin[2]-bin[1] +# print(bin_size) +outfile = argv[1] +paths = argv[2:len(argv):2] +labels = argv[3:len(argv):2] + + +for i in range(1, 91): + fig = plt.figure() + fig.set_size_inches(18.5, 10.5) + for path, lab in zip(paths, labels): + average, std , bin= Adia_fraction(i, path) + plt.errorbar(bin, average, std, fmt='o',label=lab) + plt.ylim((0)) + plt.xlim((0,120)) + plt.xlabel('cell#') + plt.ylabel('$q_l$ (rain) [g/kg]') + plt.title('time = '+str(i*240) +' s') + plt.legend() + plt.savefig(outfile + 'Average_rain_many_' + str(i*240) +'.png') + # Od komentuj! + plt.clf() From 9ceb2c4e37b01d11666e449561e48044c01296e6 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Wed, 8 Sep 2021 22:43:06 +0200 Subject: [PATCH 23/30] plots for paper vol4 --- NC_vs_AF/AF_mean_parallel_2D_time_mean.py | 213 ++++++++++++++++++ Rain_distribution/Rain_many_copare.py | 37 +-- Rain_distribution/Rain_many_copare_time.py | 179 +++++++++++++++ .../Rain_many_copare_time_line.py | 193 ++++++++++++++++ 4 files changed, 606 insertions(+), 16 deletions(-) create mode 100644 NC_vs_AF/AF_mean_parallel_2D_time_mean.py create mode 100644 Rain_distribution/Rain_many_copare_time.py create mode 100644 Rain_distribution/Rain_many_copare_time_line.py diff --git a/NC_vs_AF/AF_mean_parallel_2D_time_mean.py b/NC_vs_AF/AF_mean_parallel_2D_time_mean.py new file mode 100644 index 0000000..e5bdfb3 --- /dev/null +++ b/NC_vs_AF/AF_mean_parallel_2D_time_mean.py @@ -0,0 +1,213 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") +path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") + + +''' +OK +HOW TO RUN: + +python3 AF_mean_parallel_2D.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/ + +python3 AF_mean_parallel_2D.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/ + +Singularity> python3 AF_mean_parallel_2D_time_mean.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/ + + +''' + +import h5py +import numpy as np +import matplotlib +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +plt.rcParams.update({'font.size': 12}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i +timesteps = timesteps[1:91] +np.set_printoptions(threshold=maxsize) + +n = len(argv) +paths = argv[1] +outfile = argv[2] + +const = os.listdir(paths) +# nr_files = len(files) +# const = [argv[i] for i in range(2,n)] + +files = [0 for i in range(len(paths))] +series_file = [0 for i in range(len(paths))] + + + +def Adia_fraction(i): + + rhod = [0 for i in range(len(const))] + p_e = [0 for i in range(len(const))] + dz = [0 for i in range(len(const))] + rl = [0 for i in range(len(const))] + rl_base = [0 for i in range(len(const))] + nc = [0 for i in range(len(const))] + th = [0 for i in range(len(const))] + rv = [0 for i in range(len(const))] + + for p in range(len(const)): + filename = paths + const[p]+'/'+ const[p]+'_out_lgrngn' + rhod[p] = h5py.File(filename + "/const.h5", "r")["G"][:,:] + p_e[p] = h5py.File(filename + "/const.h5", "r")["p_e"][:] + dz[p] = h5py.File(filename + "/const.h5", "r").attrs["dz"] + rl[p] = (h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[p] = (h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc[p] = h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom0"][:,:] + th[p] = h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["th"][:,:]; + rv[p] = h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["rv"][:,:]; + rhod = np.mean(rhod,axis=0) + p_e = np.mean(p_e,axis=0) + dz = np.mean(dz,axis=0) + rl = np.mean(rl,axis=0) + rl_base = np.mean(rl_base,axis=0) + nc = np.mean(nc,axis=0) * rhod / 1e6# 1 / cm^3 + th = np.mean(th,axis=0) + rv = np.mean(rv,axis=0) + + nx, nz = rhod.shape + hght = np.arange(nz) * dz + bin = np.linspace(0,1.4,len(np.arange(nx))) + bin_size = bin[2]-bin[1] + + + # plt.clf() + # ---- adiabatic LWC ---- + AF_min = np.zeros([nx, nz]) + adia_rl = np.zeros([nz]) + adia_rl_min = np.zeros([nz]) + clb_rv_min = np.zeros([nx]) + clb_th_min = np.zeros([nx]) + Biny = [0 for i in np.arange(nz)] + Biny_x = [0 for i in np.arange(nz)] + Slice = np.zeros([nx, nz]) + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + # print(cloudy_mask_used) + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + if min_hght/dz < 10: + min_hght = 10*dz + # d+=1 + + for j in np.arange(nx): + if clb_idx[j] > 0: + clb_rv_min[j] = rv[j, int(min_hght/dz)] + clb_th_min[j] = th[j, int(min_hght/dz)] + + parcel_rv_min = np.nan_to_num(np.nanmean(clb_rv_min[clb_rv_min>0])) + parcel_th_min = np.nan_to_num(np.nanmean(clb_th_min[clb_th_min>0])) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for j in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[j, k] = 0 + else: + AF_min[j, k] = rl[j,k] / adia_rl_min[k] + + ######Biny + AF = AF_min * cloudy_mask_used + AF[AF==0]=np.nan + + for k in np.arange(nz): + Biny[k] = np.digitize(AF[:,k],bin) + Biny[k] = np.bincount(Biny[k]) + Biny[k] = np.pad(Biny[k], (0, (len(bin)+1)-len(Biny[k])), mode='constant') + Biny[k] = np.where(Biny[k] != 0, Biny[k], np.nan) + Biny_x[k] = np.log10(Biny[k]/bin_size) + + AF_min[AF_min==0] = np.nan + AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min, axis=0) + bins = np.array(Biny_x) + bins = bins[:,:-1] + + return bins, AF_mean_min, hght, bin + + +# plt.show() + +punkty = np.intc(np.linspace(1,91,91)) +# with concurrent.futures.ProcessPoolExecutor() as executor: + # results = executor.map(Adia_fraction, punkty) +# Adia_fraction(50) + + +# +1 zeby doliczyc +bin_data = [0 for i in range(91-1)] +BIN =[] +b=0 +for i in range(1,91): + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="50%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.4, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + bins, AF_mean_min, hght, bin = Adia_fraction(i) + bin_data[b] = bins + BIN = np.nanmean(bin_data[:b+1], axis=0) + BIN = np.array(BIN) + e = ax.contourf( bin, hght, BIN, 200, cmap='gnuplot') #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)", format='%.2f') + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='r', linewidth=3) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim((0,10000)) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.title('time = '+str(i*240)+ 's') + plt.savefig(outfile + '/AF_average/Cumulative_AF_' + str(240*i).zfill(10) +'.png') + b += 1 + +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/Rain_distribution/Rain_many_copare.py b/Rain_distribution/Rain_many_copare.py index 62ac27a..1944fcf 100644 --- a/Rain_distribution/Rain_many_copare.py +++ b/Rain_distribution/Rain_many_copare.py @@ -107,23 +107,28 @@ def Adia_fraction(timestep, paths): # bin_size = bin[2]-bin[1] # print(bin_size) -outfile = argv[1] -paths = argv[2:len(argv):2] -labels = argv[3:len(argv):2] +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) +outfile = argv[4] +paths = argv[5:len(argv):2] +labels = argv[6:len(argv):2] -for i in range(1, 91): - fig = plt.figure() - fig.set_size_inches(18.5, 10.5) +for i in range(time_start/outfreq, time_end/outfreq+1): + for path, lab in zip(paths, labels): average, std , bin= Adia_fraction(i, path) - plt.errorbar(bin, average, std, fmt='o',label=lab) - plt.ylim((0)) - plt.xlim((0,120)) - plt.xlabel('cell#') - plt.ylabel('$q_l$ (rain) [g/kg]') - plt.title('time = '+str(i*240) +' s') - plt.legend() - plt.savefig(outfile + 'Average_rain_many_' + str(i*240) +'.png') - # Od komentuj! - plt.clf() + +fig = plt.figure() +fig.set_size_inches(18.5, 10.5) +plt.errorbar(bin, average, std, fmt='o',label=lab) +plt.ylim((0)) +plt.xlim((0,120)) +plt.xlabel('cell#') +plt.ylabel('$q_l$ (rain) [g/kg]') +plt.title('time = '+str(i*240) +' s') +plt.legend() +plt.savefig(outfile + 'Average_rain_many_for_time range_'+str(time_start)+'_to_'+ str(time_end)+'.png') +# Od komentuj! +plt.clf() diff --git a/Rain_distribution/Rain_many_copare_time.py b/Rain_distribution/Rain_many_copare_time.py new file mode 100644 index 0000000..b0fe941 --- /dev/null +++ b/Rain_distribution/Rain_many_copare_time.py @@ -0,0 +1,179 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +How to run + +python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25_out_lgrngn /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain + +Singularity> python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ + +''' + +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import h5py +from scipy.stats import moment +import time +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +import os +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i +timesteps = timesteps[1:91] +np.set_printoptions(threshold=maxsize) + + +def Adia_fraction(timestep, paths): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + p_e = [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + nc = [0 for i in range(nr_files)] + th = [0 for i in range(nr_files)] + rv = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + sum_rr = [0 for i in range(nr_files)] + + + for file in range(nr_files): + # plt.clf() + p_e[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn" + "/const.h5", "r")["p_e"][:] + rhod[file] = h5py.File(paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn"+ "/const.h5", "r").attrs["dz"] + + nx, nz = rhod[file].shape + hght = np.arange(nz) * dz[file] + bin = np.linspace(1,121,len(np.arange(nx))) + sum_rr[file] = np.zeros([nx]) + + filename = paths + files[file] + '/' + files[file] + "_out_lgrngn"+ "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc[file] = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod[file] / 1e6; # 1 / cm^3 + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e6; # g/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th[file] = h5py.File(filename, "r")["th"][:,:]; + rv[file] = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner= np.vectorize(lcmn.exner) + T = th[file] * Vexner(p_e[file].astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e[file].astype(float)) + RH = rv[file] / r_vs[file] + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + # print(i, rr[file][i]) + if min_hght/dz[file] < 10: + min_hght = 10*int(dz[file]) + + min_hght = np.nan_to_num(min_hght) + + for j in np.arange(nx): + if clb_idx[j] > 0: + sum_rr[file][j] = np.sum(rr[file][j,:int(min_hght/dz[file])-1],0) + sum_rr[file][sum_rr[file]==0] = np.nan + # print(file) + srednie_rr = np.nanmean(sum_rr, axis=0) + STD_rr = np.nanstd(sum_rr, axis=0) + STD_error_mean = STD_rr/sqrt(nr_files) + error = np.power(1/nr_files * (moment(sum_rr,4) - (nr_files-3)/(nr_files-1)*np.power(STD_rr,4)),1/2)/(2*STD_rr) + return(srednie_rr, STD_rr, bin, STD_error_mean, error) + +# bin_size = bin[2]-bin[1] +# print(bin_size) +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) +outfile = argv[4] +paths = argv[5:len(argv):2] +labels = argv[6:len(argv):2] + + +Average = [] +STD = [] +Average_error = [] +STD_error = [] +average =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +average_error =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +std =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +std_error =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +fig = plt.figure() +fig.set_size_inches(18.5, 10.5) +shape = ['o', 'x', '.k' ] +for path, lab in zip(paths, labels): + b = 0 + for i in range(int(time_start/outfreq), int(time_end/outfreq)+1): + aver, sigma , bin, sigma_error, aver_error= Adia_fraction(i, path) + average[b] = aver + std[b] = sigma + std_error[b] = sigma_error + average_error[b] = aver_error + # std[b] = std + b += 1 + Average = np.nanmean(average,axis=0) + STD = np.nanmean(std,axis=0) + Average_error = np.nanmean(average_error,axis=0) + STD_error = np.nanmean(std_error,axis=0) + plt.errorbar(bin, Average, Average_error, fmt='o',label=lab)# +plt.ylim((0)) +plt.xlim((0,120)) +plt.xlabel('cell#') +plt.ylabel('$q_r$ (rain) [g/kg]') +plt.title('time range = '+str(time_start) + ' to '+str(time_end) +' s') +plt.legend() +print(outfile + 'Average_rain_many_for_time range_'+str(time_start)+'_to_'+ str(time_end)+'.png') +plt.savefig(outfile + 'Average_cloud_many_for_time range_'+str(time_start)+'_to_'+ str(time_end)+'.png') +# Od komentuj! +plt.clf() + +''' +python3 Rain_many_copare_time.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ 'multi' + +python3 Rain_many_copare_time.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/multi/ 'multi_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ 'multi_1c' + + +python3 Rain_many_copare_time.py 14400 15600 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 16800 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 18000 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 19200 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 17280 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 17760 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 17040 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' + + + + + + + +''' diff --git a/Rain_distribution/Rain_many_copare_time_line.py b/Rain_distribution/Rain_many_copare_time_line.py new file mode 100644 index 0000000..cf95597 --- /dev/null +++ b/Rain_distribution/Rain_many_copare_time_line.py @@ -0,0 +1,193 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +How to run + +python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25_out_lgrngn /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain + +Singularity> python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ + +python3 Rain_many_copare_time_line.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_SD1000" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_SD100" + + +''' + +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import h5py +from scipy.stats import moment +import time +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +import os +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i +timesteps = timesteps[1:91] +np.set_printoptions(threshold=maxsize) + + +def Adia_fraction(timestep, paths): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + p_e = [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + nc = [0 for i in range(nr_files)] + th = [0 for i in range(nr_files)] + rv = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + sum_rr = [0 for i in range(nr_files)] + + + for file in range(nr_files): + # plt.clf() + p_e[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn" + "/const.h5", "r")["p_e"][:] + rhod[file] = h5py.File(paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn"+ "/const.h5", "r").attrs["dz"] + + nx, nz = rhod[file].shape + hght = np.arange(nz) * dz[file] + bin = np.linspace(1,121,len(np.arange(nx))) + sum_rr[file] = np.zeros([nx]) + + filename = paths + files[file] + '/' + files[file] + "_out_lgrngn"+ "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc[file] = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod[file] / 1e6; # 1 / cm^3 + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e6; # g/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + # th and rv + th[file] = h5py.File(filename, "r")["th"][:,:]; + rv[file] = h5py.File(filename, "r")["rv"][:,:]; + # T + Vexner= np.vectorize(lcmn.exner) + T = th[file] * Vexner(p_e[file].astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e[file].astype(float)) + RH = rv[file] / r_vs[file] + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + # print("wysokosc min",min_hght, " wysokosc max", max_hght) + # print(i, rr[file][i]) + if min_hght/dz[file] < 10: + min_hght = 10*int(dz[file]) + + min_hght = np.nan_to_num(min_hght) + + for j in np.arange(nx): + if clb_idx[j] > 0: + sum_rr[file][j] = np.sum(rr[file][j,:int(min_hght/dz[file])-1],0) + sum_rr[file][sum_rr[file]==0] = np.nan + # print(file) + srednie_rr = np.nanmean(sum_rr, axis=0) + STD_rr = np.nanstd(sum_rr, axis=0) + ST_error_mean = STD_rr/sqrt(nr_files) + error_std = np.power(1/nr_files * (moment(sum_rr,4) - (nr_files-3)/(nr_files-1)*np.power(STD_rr,4)),1/2)/(2*STD_rr) + return(srednie_rr, STD_rr, bin, ST_error_mean, error_std) + +# bin_size = bin[2]-bin[1] +# print(bin_size) +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) +outfile = argv[4] +paths = argv[5:len(argv):2] +labels = argv[6:len(argv):2] + + +Average = [] +STD = [] +Average_error = [] +STD_error = [] +average =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +average_error =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +std =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +std_error =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +# fig = plt.figure() +# fig.set_size_inches(18.5, 10.5) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(30,15)) +shape = ['o', 'x', '.k' ] +for path, lab in zip(paths, labels): + b = 0 + for i in range(int(time_start/outfreq), int(time_end/outfreq)+1): + aver, sigma , bin, st_error, sigma_error= Adia_fraction(i, path) + average[b] = aver + std[b] = sigma + std_error[b] = sigma_error + average_error[b] = st_error + # std[b] = std + b += 1 + Average = np.nanmean(average,axis=0) + STD = np.nanmean(std,axis=0) + Average_error = np.nanmean(average_error,axis=0) + STD_error = np.nanmean(std_error,axis=0) + ax0.plot(bin, Average, label=lab)#, edgecolors='b' + ax0.fill_between(bin, Average-Average_error, Average+Average_error, alpha=0.2) + # ax1.plot(bin, STD, label=lab)#, edgecolors='b' + # ax1.fill_between(bin, STD-STD_error, STD+STD_error, alpha=0.2) + ax1.errorbar(bin, STD, STD_error, fmt='o',label=lab) + + # plt.errorbar(bin, Average, Average_error, fmt='o',label=lab)# +ax0.set_ylim((0)) +ax1.set_ylim((0)) +ax0.set_xlim((40,90)) +ax1.set_xlim((40,90)) +plt.xlabel('cell#') +ax0.set_ylabel('$q_r$ (rain) [g/kg]') +ax1.set_ylabel('$q_r$ (rain) [g/kg]') +ax0.legend(title='Average') +ax1.legend(title='STD') +fig.suptitle('time range = '+str(time_start) + ' to '+str(time_end) +' s') + +plt.savefig(outfile + 'Average_test2_many_for_time range_'+str(time_start)+'_to_'+ str(time_end)+'.png') +# Od komentuj! +plt.clf() + +''' +python3 Rain_many_copare_time.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ 'multi' + +python3 Rain_many_copare_time.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/multi/ 'multi_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ 'multi_1c' + + +python3 Rain_many_copare_time.py 14400 15600 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 16800 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 18000 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 19200 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 17280 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 17760 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 17040 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' + + + + + + + +''' From 60e67e72c02df9fa742c8f5f3e38f2aa70cc6db3 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Wed, 8 Sep 2021 22:47:36 +0200 Subject: [PATCH 24/30] cleaning --- Energy_spectrum/spectrum_2D_multi_many.py | 27 ++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Energy_spectrum/spectrum_2D_multi_many.py b/Energy_spectrum/spectrum_2D_multi_many.py index 2a7662e..7e932de 100644 --- a/Energy_spectrum/spectrum_2D_multi_many.py +++ b/Energy_spectrum/spectrum_2D_multi_many.py @@ -3,6 +3,8 @@ import h5py import numpy as np from sys import argv +import matplotlib +matplotlib.use('Agg') import matplotlib.pyplot as plt import os ''' @@ -13,8 +15,8 @@ # velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"] # velocities = ["u", "w", "cloud_rw_mom3", "rv", "th", "RH", "actrw_rw_mom3"] # velocities = ["cloud_rw_mom3", "actrw_rw_mom3"] -velocities = ["cloud_rw_mom3"] -# velocities = ["u"] +#velocities = ["cloud_rw_mom3"] +velocities = ["u"] time_start = int(argv[1]) time_end = int(argv[2]) @@ -22,10 +24,11 @@ from_lvl = int(argv[4]) to_lvl = int(argv[5]) -directories = argv[6:len(argv):2] +outfile = argv[6] +directories = argv[7:len(argv):2] -labels = argv[7:len(argv):2] -outfile = argv[8] +labels = argv[8:len(argv):2] +#outfile = argv[8] def Energy(directories, labels): @@ -37,20 +40,23 @@ def Energy(directories, labels): for path in path_file: path_to_file = os.listdir(directory+path) joined = os.path.join(directory,path) + #print(joined.split("/", -1)[-1]) Exy_avg_many = [0 for i in range(len(path_to_file))] Exy_avg = [0 for i in range(len(velocities))] # Exy_mean = [0 for i in range(len(velocities))] for file in range(len(path_to_file)): - w3d = h5py.File(joined+'/'+path_to_file[file] + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] + #w3d = h5py.File(joined+'/'+path_to_file[file] + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] + w3d = h5py.File(joined+'/'+joined.split("/",-1)[-1] +"_out_lgrngn"+ "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] nx, nz = w3d.shape for vel in range(len(velocities)): Exy_avg[vel] = np.zeros(int((nx+1)/2)) # Exy_avg_many[file][vel] =np.zeros(int((nx+1)/2)) for t in range(time_start, time_end+1, outfreq): - filename = joined+'/'+path_to_file[file] + "/timestep" + str(t).zfill(10) + ".h5" + #filename = joined+'/'+path_to_file[file] + "/timestep" + str(t).zfill(10) + ".h5" + filename = joined+'/'+joined.split("/",-1)[-1] + "_out_lgrngn"+"/timestep" + str(t).zfill(10) + ".h5" # print(filename) for vel in range(len(velocities)): @@ -74,15 +80,16 @@ def Energy(directories, labels): for path in path_file: Exy_mean[path] /= (time_end - time_start) / outfreq + 1 Exy_mean[path] /= to_lvl+1 - from_lvl - plt.loglog(lmbd, Exy_mean[path] , linewidth=2, label=lab+"_ "+path) + plt.loglog(lmbd, Exy_mean[path] , linewidth=2, label=lab) - plt.loglog(lmbd, 2e-1* K**(-5./3.)*1e-8, label="-5/3" ) + plt.loglog(lmbd, 2e-1* K**(-5./3.), label="-5/3" ) plt.xlim(2*10**4,10**2) plt.xlabel("l[m]") plt.ylabel("PSD") plt.legend() plt.grid(True, which='both', linestyle='--') # plt.title("Mean PSD of w 322m Date: Fri, 10 Sep 2021 21:53:50 +0200 Subject: [PATCH 25/30] beter cloud base --- NC_vs_AF/AF_mean_parallel_2D_time_mean.py | 55 ++++++++++--------- NC_vs_AF/Randomness/AF_mean_parallel_2D.py | 18 +++--- NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py | 24 ++++---- Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py | 4 +- .../Rain_many_copare_time_line.py | 8 +-- Rain_distribution/distribution_Py3_2D_mean.py | 13 +++-- 6 files changed, 65 insertions(+), 57 deletions(-) diff --git a/NC_vs_AF/AF_mean_parallel_2D_time_mean.py b/NC_vs_AF/AF_mean_parallel_2D_time_mean.py index e5bdfb3..5f45e33 100644 --- a/NC_vs_AF/AF_mean_parallel_2D_time_mean.py +++ b/NC_vs_AF/AF_mean_parallel_2D_time_mean.py @@ -4,8 +4,8 @@ from sys import argv, path, maxsize #path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") # path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") -# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") -path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") +#path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") ''' @@ -47,7 +47,7 @@ n = len(argv) paths = argv[1] outfile = argv[2] - +lab = argv[3] const = os.listdir(paths) # nr_files = len(files) # const = [argv[i] for i in range(2,n)] @@ -73,7 +73,7 @@ def Adia_fraction(i): rhod[p] = h5py.File(filename + "/const.h5", "r")["G"][:,:] p_e[p] = h5py.File(filename + "/const.h5", "r")["p_e"][:] dz[p] = h5py.File(filename + "/const.h5", "r").attrs["dz"] - rl[p] = (h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl[p] = (h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg rl_base[p] = (h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg nc[p] = h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom0"][:,:] th[p] = h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["th"][:,:]; @@ -119,9 +119,6 @@ def Adia_fraction(i): hght_2[hght_2==0] = np.nan min_hght = np.nanmin(hght_2) max_hght = np.nanmax(hght_2) - if min_hght/dz < 10: - min_hght = 10*dz - # d+=1 for j in np.arange(nx): if clb_idx[j] > 0: @@ -151,32 +148,39 @@ def Adia_fraction(i): ######Biny AF = AF_min * cloudy_mask_used - AF[AF==0]=np.nan + #AF[AF==0]=np.nan + print(np.count_nonzero(AF) ) for k in np.arange(nz): - Biny[k] = np.digitize(AF[:,k],bin) - Biny[k] = np.bincount(Biny[k]) - Biny[k] = np.pad(Biny[k], (0, (len(bin)+1)-len(Biny[k])), mode='constant') - Biny[k] = np.where(Biny[k] != 0, Biny[k], np.nan) - Biny_x[k] = np.log10(Biny[k]/bin_size) - + #Biny[k] = np.digitize(AF[:,k],bin) + #Biny[k] = np.bincount(Biny[k]) + #Biny[k] = np.pad(Biny[k], (0, (len(bin)+1)-len(Biny[k])), mode='constant') + #Biny[k] = np.where(Biny[k] != 0, Biny[k], np.nan) + #Biny_x[k] = np.log10(Biny[k]/bin_size) + Biny_x[k], bin = np.histogram(AF[:,k], bins=nx, range =[0, 1.4]) + print(np.count_nonzero(AF[:,k]), np.count_nonzero(Biny_x[k])) + #print(Biny_x) + print(np.count_nonzero(Biny_x)-nz) AF_min[AF_min==0] = np.nan AF_min[cloudy_mask_used==0] = np.nan AF_mean_min = np.nanmean(AF_min, axis=0) - bins = np.array(Biny_x) - bins = bins[:,:-1] - - return bins, AF_mean_min, hght, bin - + bins = np.array(np.log10(Biny_x/(bin[2]-bin[1]))) + #bins = bins[:,:-1] + #print(bins) + #return bins, AF_mean_min, hght, bin + #print(np.count_nonzero(AF_min) ) + return bins, AF_mean_min, hght, bin[:-1] # plt.show() punkty = np.intc(np.linspace(1,91,91)) # with concurrent.futures.ProcessPoolExecutor() as executor: # results = executor.map(Adia_fraction, punkty) -# Adia_fraction(50) +Adia_fraction(80) +#print(Adia_fraction(80)) +''' # +1 zeby doliczyc bin_data = [0 for i in range(91-1)] BIN =[] @@ -192,10 +196,10 @@ def Adia_fraction(i): borderpad=0, ) bins, AF_mean_min, hght, bin = Adia_fraction(i) - bin_data[b] = bins - BIN = np.nanmean(bin_data[:b+1], axis=0) - BIN = np.array(BIN) - e = ax.contourf( bin, hght, BIN, 200, cmap='gnuplot') #bin[1:] + #bin_data[b] = bins + #BIN = np.nanmean(bin_data[:b+1], axis=0) + #BIN = np.array(BIN) + e = ax.contourf( bin, hght, bins, 200, cmap='gnuplot') #bin[1:] cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)", format='%.2f') ax.set_ylabel('Height [m]') ax.set_xlabel('AF []') @@ -206,8 +210,9 @@ def Adia_fraction(i): ax2.set_yticks([], []) ax2.set_yticks([], minor=True) plt.title('time = '+str(i*240)+ 's') - plt.savefig(outfile + '/AF_average/Cumulative_AF_' + str(240*i).zfill(10) +'.png') + plt.savefig(outfile + 'Cumulative_AF_'+lab+'_' + str(240*i).zfill(10) +'.png') b += 1 finish = time.perf_counter() print(f'Finished in {round(finish-start,2)} seconds(s)') +''' diff --git a/NC_vs_AF/Randomness/AF_mean_parallel_2D.py b/NC_vs_AF/Randomness/AF_mean_parallel_2D.py index c240bcc..cdf258c 100644 --- a/NC_vs_AF/Randomness/AF_mean_parallel_2D.py +++ b/NC_vs_AF/Randomness/AF_mean_parallel_2D.py @@ -68,14 +68,14 @@ def Adia_fraction(i): rv = [0 for i in range(len(const))] for p in range(len(const)): - rhod[p] = h5py.File(paths + const[p]+"/const.h5", "r")["G"][:,:] - p_e[p] = h5py.File(paths + const[p]+"/const.h5", "r")["p_e"][:] - dz[p] = h5py.File(paths + const[p]+"/const.h5", "r").attrs["dz"] - rl[p] = (h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg - rl_base[p] = (h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg - nc[p] = h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom0"][:,:] - th[p] = h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["th"][:,:]; - rv[p] = h5py.File(paths + const[p] + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["rv"][:,:]; + rhod[p] = h5py.File(paths + const[p]+'/'+const[p]+'_out_lgrngn'+"/const.h5", "r")["G"][:,:] + p_e[p] = h5py.File(paths + const[p]+'/'+const[p]+'_out_lgrngn'+"/const.h5", "r")["p_e"][:] + dz[p] = h5py.File(paths + const[p]+'/'+const[p]+'_out_lgrngn'+"/const.h5", "r").attrs["dz"] + rl[p] = (h5py.File(paths + const[p] + '/'+const[p]+'_out_lgrngn'+"/timestep" + str(240*i).zfill(10) + ".h5", "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[p] = (h5py.File(paths + const[p] + '/'+const[p]+'_out_lgrngn'+"/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc[p] = h5py.File(paths + const[p] + '/'+const[p]+'_out_lgrngn'+"/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom0"][:,:] + th[p] = h5py.File(paths + const[p] + '/'+const[p]+'_out_lgrngn'+"/timestep" + str(240*i).zfill(10) + ".h5", "r")["th"][:,:]; + rv[p] = h5py.File(paths + const[p] + '/'+const[p]+'_out_lgrngn'+"/timestep" + str(240*i).zfill(10) + ".h5", "r")["rv"][:,:]; rhod = np.mean(rhod,axis=0) p_e = np.mean(p_e,axis=0) dz = np.mean(dz,axis=0) @@ -197,6 +197,6 @@ def Adia_fraction(i): results = executor.map(Adia_fraction, punkty) # for i in range(1,91): -# Adia_fraction(89) +#Adia_fraction(89) finish = time.perf_counter() print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py index fcb9131..3c76bc9 100644 --- a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py +++ b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py @@ -1,13 +1,12 @@ from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial import numpy as np -import pandas as pd from scipy.stats import moment from sys import argv -from matplotlib.ticker import MultipleLocator -import matplotlib.pyplot as plt -import matplotlib as mpl -import matplotlib.colors as mcolors -from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator import glob, os plt.rcParams.update({'font.size': 20}) @@ -20,16 +19,17 @@ path_diff_NA1_piggy_VF_tail = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' path_diff_NA1_piggy_VF_multi = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' -outfile = '' +outfile = '/home/pzmij/2D/RESULTS_NA1/Wyniki/' #OPISY text_diff_piggy_VF = 'same velo field in all simulations' text_diff_piggy_VF_tail = 'same velo field in all simulations \n sd conc long tail' text_diff_piggy_VF_multi = 'same velo field in all simulations \n sd conc same multiplicity' -paths = [path_diff_NA1_piggy_VF+'SD100',path_diff_NA1_piggy_VF+'SD1000', path_diff_NA1_piggy_VF+'SD10000',path_diff_NA1_piggy_VF_tail+'SD100',path_diff_NA1_piggy_VF_tail+'SD1000', path_diff_NA1_piggy_VF+'SD10000'] +#paths = [path_diff_NA1_piggy_VF+'SD100',path_diff_NA1_piggy_VF+'SD1000', path_diff_NA1_piggy_VF+'SD10000',path_diff_NA1_piggy_VF_tail+'SD100',path_diff_NA1_piggy_VF_tail+'SD1000', path_diff_NA1_piggy_VF+'SD10000'] +paths = ['/home/pzmij/2D/RESULTS_NA1/SD100_piggy/times_SD100_diff_piggy_VF/', '/home/pzmij/2D/RESULTS_NA1/SD100_piggy/times_SD100_diff_piggy_VF_tail', '/home/pzmij/2D/RESULTS_NA1/SD100_piggy/times_SD100_diff_piggy_VF_multi', '/home/pzmij/2D/RESULTS_NA1/SD1000_piggy/times_SD1000_diff_piggy_VF', '/home/pzmij/2D/RESULTS_NA1/SD1000_piggy/times_SD1000_diff_piggy_VF_tail', '/home/pzmij/2D/RESULTS_NA1/SD1000_piggy/times_SD1000_diff_piggy_VF_multi', '/home/pzmij/2D/RESULTS_NA1/SD10000_piggy/times_SD10000_diff_piggy', '/home/pzmij/2D/RESULTS_NA1/SD10000_piggy/times_SD10000_diff_piggy_VF_tail', '/home/pzmij/2D/RESULTS_NA1/SD10000_piggy/times_SD10000_diff_piggy_VF_multi'] label_list = ['100', '1000', '10000'] -podpisy = [text_diff_piggy_VF, text_diff_piggy_VF_tail]#, text_diff_piggy_VF_multi] +podpisy = [text_diff_piggy_VF, text_diff_piggy_VF_tail, text_diff_piggy_VF_multi] width_multiplier = 0.67 ########################################################################## def Rysuj_to(sciezki, etykiety, podpisy, name): @@ -112,7 +112,7 @@ def czas(iter_value): plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") plt.xticks(X, labels, ha = 'center') plt.ylim(0, 2.5e2) - plt.text(0.5, 265 , 'G', fontsize=26) + #plt.text(0.5, 265 , 'G', fontsize=26) plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) @@ -131,7 +131,7 @@ def czas(iter_value): A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") plt.ylabel(r"$\sigma$ [$m^3$]") plt.ylim(0, 5e-1) - plt.text(0.5, 0.53 , 'F', fontsize=26) + #plt.text(0.5, 0.53 , 'F', fontsize=26) plt.xticks(X, labels, ha = 'center') plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) @@ -153,7 +153,7 @@ def czas(iter_value): A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") plt.ylabel(r"Mean accumulated precipitation [$m^3$]") plt.ylim(0, 4e-1) - plt.text(0.5, 0.43 , 'E', fontsize=26) + #plt.text(0.5, 0.43 , 'E', fontsize=26) plt.xticks(X, labels, ha = 'center') plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) diff --git a/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py b/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py index 2675b25..d1b27bd 100644 --- a/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py +++ b/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py @@ -41,7 +41,7 @@ rr_rows_clb = np.zeros((121, len(file_names))) rr_rows_lvl0 = np.zeros((121, len(file_names))) for p in range(len(file_names)): - path = paths+file_names[p] + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] p_e = h5py.File(path + "/const.h5", "r")["p_e"][:] nx, nz = rhod.shape @@ -109,5 +109,5 @@ ax1.set_title('Height = {}m'.format(int(0))) fig.suptitle('Current time {}s '.format(int(timestep/2))) plt.axis(aspect='image') - plt.savefig(outfile + '/Multi_SD10000_' + str(int(timestep/2)) +'.png') + plt.savefig(outfile + '/Multi_SD100_' + str(int(timestep/2)) +'.png') plt.close() diff --git a/Rain_distribution/Rain_many_copare_time_line.py b/Rain_distribution/Rain_many_copare_time_line.py index cf95597..adb4588 100644 --- a/Rain_distribution/Rain_many_copare_time_line.py +++ b/Rain_distribution/Rain_many_copare_time_line.py @@ -4,8 +4,8 @@ from sys import argv, path, maxsize #path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") # path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") -path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") -# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") +#path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") ''' @@ -69,7 +69,7 @@ def Adia_fraction(timestep, paths): sum_rr[file] = np.zeros([nx]) filename = paths + files[file] + '/' + files[file] + "_out_lgrngn"+ "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" - rl[file] = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg rl_base[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg nc[file] = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod[file] / 1e6; # 1 / cm^3 rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e6; # g/kg @@ -165,7 +165,7 @@ def Adia_fraction(timestep, paths): ax1.legend(title='STD') fig.suptitle('time range = '+str(time_start) + ' to '+str(time_end) +' s') -plt.savefig(outfile + 'Average_test2_many_for_time range_'+str(time_start)+'_to_'+ str(time_end)+'.png') +plt.savefig(outfile + 'Average_many_for_time range_'+str(time_start)+'_to_'+ str(time_end)+'.png') # Od komentuj! plt.clf() diff --git a/Rain_distribution/distribution_Py3_2D_mean.py b/Rain_distribution/distribution_Py3_2D_mean.py index 6a6b652..cc91646 100644 --- a/Rain_distribution/distribution_Py3_2D_mean.py +++ b/Rain_distribution/distribution_Py3_2D_mean.py @@ -1,6 +1,8 @@ import h5py import numpy as np from sys import argv +import matplotlib +matplotlib.use('Agg') import matplotlib.pyplot as plt from collections import OrderedDict import os @@ -29,9 +31,10 @@ #from_lvl = int(argv[4]) #to_lvl = int(argv[5]) -directories = argv[4:len(argv):2] -labels = argv[5:len(argv):2] -outfile = argv[6] +outfile = argv[4] +directories = argv[5:len(argv):2] +labels = argv[6:len(argv):2] +#outfile = argv[6] print(directories, labels) levels = ["ground", "cloud_base"] @@ -52,14 +55,14 @@ def Rain_distribution(directories, labels, lvl): file = '#'+(path.split("_piggy_",-3))[-1].split("_out")[0] tot_cloud_base_lvl[file] = np.zeros(0) - w3d = h5py.File(joined+"/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] + w3d = h5py.File(joined+'/'+joined.split("/",-1)[-1] +"_out_lgrngn"+"/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] nx, nz = w3d.shape for data in rain_data: total_arr[data][file] = np.zeros(0) for t in range(time_start, time_end+1, outfreq): - filename = joined + "/timestep" + str(t).zfill(10) + ".h5" + filename = joined +'/'+joined.split("/",-1)[-1] +"_out_lgrngn"+ "/timestep" + str(t).zfill(10) + ".h5" # find cloud base # based on cloud rw w3d = h5py.File(filename, "r")["cloud_rw_mom3"][:,:] * 4. / 3. * 3.1416 * 1e3 From 4114ec6759453cceb40d7ffa2c08d171bdfd2571 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Fri, 10 Sep 2021 21:56:30 +0200 Subject: [PATCH 26/30] plots for paper vol4 --- NC_vs_AF/AF_mean_parallel_2D_time_mean.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NC_vs_AF/AF_mean_parallel_2D_time_mean.py b/NC_vs_AF/AF_mean_parallel_2D_time_mean.py index e5bdfb3..c2933aa 100644 --- a/NC_vs_AF/AF_mean_parallel_2D_time_mean.py +++ b/NC_vs_AF/AF_mean_parallel_2D_time_mean.py @@ -4,8 +4,8 @@ from sys import argv, path, maxsize #path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") # path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") -# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") -path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") +#path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") ''' @@ -206,7 +206,7 @@ def Adia_fraction(i): ax2.set_yticks([], []) ax2.set_yticks([], minor=True) plt.title('time = '+str(i*240)+ 's') - plt.savefig(outfile + '/AF_average/Cumulative_AF_' + str(240*i).zfill(10) +'.png') + plt.savefig(outfile + '/AF_average/AF_cumulu_SD100_VF_' + str(240*i).zfill(10) +'.png') b += 1 finish = time.perf_counter() From 41e588d2d00ac8d242ca3dd00f3a9d2a60227d14 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Fri, 10 Sep 2021 22:37:22 +0200 Subject: [PATCH 27/30] plots for paper vol5 --- NC_vs_AF/AF_2D_time_mean_new.py | 212 ++++++++++++++++++ NC_vs_AF/AF_mean_parallel_2D_time_mean.py | 8 +- .../Rain_many_copare_time_line.py | 3 +- 3 files changed, 216 insertions(+), 7 deletions(-) create mode 100644 NC_vs_AF/AF_2D_time_mean_new.py diff --git a/NC_vs_AF/AF_2D_time_mean_new.py b/NC_vs_AF/AF_2D_time_mean_new.py new file mode 100644 index 0000000..4a54928 --- /dev/null +++ b/NC_vs_AF/AF_2D_time_mean_new.py @@ -0,0 +1,212 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") + + +''' +OK +HOW TO RUN: + +python3 AF_mean_parallel_2D.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/ + +python3 AF_mean_parallel_2D.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/ + +Singularity> python3 AF_mean_parallel_2D_time_mean.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/ + + +''' + +import h5py +import numpy as np +import matplotlib +import time +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +plt.rcParams.update({'font.size': 12}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i +timesteps = timesteps[1:91] +np.set_printoptions(threshold=maxsize) + +n = len(argv) +paths = argv[1] +outfile = argv[2] +lab = argv[3] +const = os.listdir(paths) +# nr_files = len(files) +# const = [argv[i] for i in range(2,n)] + +files = [0 for i in range(len(paths))] +series_file = [0 for i in range(len(paths))] + + + +def Adia_fraction(i): + + rhod = [0 for i in range(len(const))] + p_e = [0 for i in range(len(const))] + dz = [0 for i in range(len(const))] + rl = [0 for i in range(len(const))] + rl_base = [0 for i in range(len(const))] + nc = [0 for i in range(len(const))] + th = [0 for i in range(len(const))] + rv = [0 for i in range(len(const))] + + for p in range(len(const)): + filename = paths + const[p]+'/'+ const[p]+'_out_lgrngn' + rhod[p] = h5py.File(filename + "/const.h5", "r")["G"][:,:] + p_e[p] = h5py.File(filename + "/const.h5", "r")["p_e"][:] + dz[p] = h5py.File(filename + "/const.h5", "r").attrs["dz"] + rl[p] = (h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[p] = (h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc[p] = h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["cloud_rw_mom0"][:,:] + th[p] = h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["th"][:,:]; + rv[p] = h5py.File(filename + "/timestep" + str(240*i).zfill(10) + ".h5", "r")["rv"][:,:]; + rhod = np.mean(rhod,axis=0) + p_e = np.mean(p_e,axis=0) + dz = np.mean(dz,axis=0) + rl = np.mean(rl,axis=0) + # rl_base = np.mean(rl_base,axis=0) + nc = np.mean(nc,axis=0) * rhod / 1e6# 1 / cm^3 + th = np.mean(th,axis=0) + rv = np.mean(rv,axis=0) + + nx, nz = rhod.shape + hght = np.arange(nz) * dz + bin = np.linspace(0,1.4,len(np.arange(nx))) + bin_size = bin[2]-bin[1] + + + # plt.clf() + # ---- adiabatic LWC ---- + AF_min = [np.zeros([nx, nz]) for i in range(len(const))] + adia_rl = np.zeros([nz]) + adia_rl_min = np.zeros([nz]) + clb_rv_min = np.zeros([nx]) + clb_th_min = np.zeros([nx]) + Biny = [0 for i in range(len(const))] + Biny_x = [0 for i in np.arange(nz)] + Biny_finish = [0 for i in np.arange(nz)] + Slice = np.zeros([nx, nz]) + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + # print(cloudy_mask_used) + # T + Vexner = np.vectorize(lcmn.exner) + T = th * Vexner(p_e.astype(float)) + # RH + Vr_vs = np.vectorize(lcmn.r_vs) + r_vs = Vr_vs(T, p_e.astype(float)) + RH = rv / r_vs + # cloud base + clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + max_hght = np.nanmax(hght_2) + + for j in np.arange(nx): + if clb_idx[j] > 0: + clb_rv_min[j] = rv[j, int(min_hght/dz)] + clb_th_min[j] = th[j, int(min_hght/dz)] + + parcel_rv_min = np.nan_to_num(np.nanmean(clb_rv_min[clb_rv_min>0])) + parcel_th_min = np.nan_to_num(np.nanmean(clb_th_min[clb_th_min>0])) + parcel_rl_min = 0 + + for k in np.arange(nz): + parcel_T_min = parcel_th_min * lcmn.exner(p_e.astype(float)[k]) + delta_rv_min = parcel_rv_min - lcmn.r_vs(parcel_T_min, p_e.astype(float)[k]) + if delta_rv_min <= 0: + delta_rv_min = 0 + parcel_rv_min -= delta_rv_min + parcel_th_min += delta_rv_min * evap_lat / lcmn.c_pd / lcmn.exner(p_e.astype(float)[k]) + parcel_rl_min += delta_rv_min + adia_rl_min[k] = parcel_rl_min + + for p in range(len(const)): + for j in np.arange(nx): + for k in np.arange(nz): + if adia_rl_min[k] == 0: + AF_min[p][j, k] = 0 + else: + AF_min[p][j, k] = rl_base[p][j,k] / adia_rl_min[k] +######Biny + AF = AF_min[p] * cloudy_mask_used + AF[AF==0]=np.nan + # print(np.count_nonzero(AF) ) + for k in np.arange(nz): + Biny_x[k], bin = np.histogram(AF[:,k], bins=nx, range =[0, 1.4]) + # print(np.count_nonzero(AF[:,k]), np.count_nonzero(Biny_x[k])) + Biny[p] = Biny_x + # print(np.count_nonzero(Biny_x)-nz) + + AF_min = AF_min * cloudy_mask_used + AF_min[AF_min==0] = np.nan + # AF_min[cloudy_mask_used==0] = np.nan + AF_mean_min = np.nanmean(AF_min, axis=(0,1)) + # Biny_finish = np.nanmean(Biny, axis=0) + bins = np.array(np.log10(Biny/(bin[2]-bin[1]))) + #bins = bins[:,:-1] + return bins, AF_mean_min, hght, bin[:-1] + + +# punkty = np.intc(np.linspace(1,91,91)) +# with concurrent.futures.ProcessPoolExecutor() as executor: + # results = executor.map(Adia_fraction, punkty) +Adia_fraction(80) + +#print(Adia_fraction(80)) + + +# +1 zeby doliczyc +bin_data = [0 for i in range(91-1)] +BIN =[] +b=0 +for i in range(1,91): + fig,ax = plt.subplots(figsize=(11, 8)) + axins = inset_axes(ax, + width="50%", # width = 10% of parent_bbox width + height="5%", # height : 50% + loc=2, + bbox_to_anchor=(0.4, 0., 1, 1), + bbox_transform=ax.transAxes, + borderpad=0, + ) + bins, AF_mean_min, hght, bin = Adia_fraction(i) + #bin_data[b] = bins + #BIN = np.nanmean(bin_data[:b+1], axis=0) + #BIN = np.array(BIN) + for p in range(len(const)): + e = ax.contourf( bin, hght, bins[p], 200, cmap='gnuplot') #bin[1:] + cbar = plt.colorbar(e, cax=axins, orientation='horizontal', label=r"$log_{10}$($\frac{m^{3}}{\frac{unit AF}{m}}$)", format='%.2f') + ax.set_ylabel('Height [m]') + ax.set_xlabel('AF []') + ax2=ax.twinx() + ax2.plot(AF_mean_min , hght, label="AF", c='r', linewidth=3) + ax2.set_xlim((0.01,1.4)) + ax2.set_ylim((0,10000)) + ax2.set_yticks([], []) + ax2.set_yticks([], minor=True) + plt.title('time = '+str(i*240)+ 's') + plt.savefig(outfile + 'Cumulative_AF_'+lab+'_' + str(240*i).zfill(10) +'.png') + b += 1 + +finish = time.perf_counter() +print(f'Finished in {round(finish-start,2)} seconds(s)') diff --git a/NC_vs_AF/AF_mean_parallel_2D_time_mean.py b/NC_vs_AF/AF_mean_parallel_2D_time_mean.py index 46566c3..0c41e37 100644 --- a/NC_vs_AF/AF_mean_parallel_2D_time_mean.py +++ b/NC_vs_AF/AF_mean_parallel_2D_time_mean.py @@ -4,8 +4,8 @@ from sys import argv, path, maxsize #path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") # path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") -path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") -#path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") +path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") ''' @@ -210,11 +210,7 @@ def Adia_fraction(i): ax2.set_yticks([], []) ax2.set_yticks([], minor=True) plt.title('time = '+str(i*240)+ 's') -<<<<<<< HEAD - plt.savefig(outfile + '/AF_average/AF_cumulu_SD100_VF_' + str(240*i).zfill(10) +'.png') -======= plt.savefig(outfile + 'Cumulative_AF_'+lab+'_' + str(240*i).zfill(10) +'.png') ->>>>>>> 41e1ba007f2b6dcf8996d7596bf7589e50f97c8c b += 1 finish = time.perf_counter() diff --git a/Rain_distribution/Rain_many_copare_time_line.py b/Rain_distribution/Rain_many_copare_time_line.py index adb4588..ce4b02f 100644 --- a/Rain_distribution/Rain_many_copare_time_line.py +++ b/Rain_distribution/Rain_many_copare_time_line.py @@ -102,7 +102,8 @@ def Adia_fraction(timestep, paths): for j in np.arange(nx): if clb_idx[j] > 0: - sum_rr[file][j] = np.sum(rr[file][j,:int(min_hght/dz[file])-1],0) + # sum_rr[file][j] = np.sum(rr[file][j,:int(min_hght/dz[file])-1],0) + sum_rr[file][j] = np.sum(rr[file][j,int(min_hght/dz[file])-1],0) sum_rr[file][sum_rr[file]==0] = np.nan # print(file) srednie_rr = np.nanmean(sum_rr, axis=0) From c0bf1571d8a0c21442ba10d18cd582889361f9c3 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Sat, 1 Jan 2022 11:42:15 +0100 Subject: [PATCH 28/30] ICM maintenance problems --- NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py | 64 +++--- .../Randomness/STD_mean_2D_fun_ICCP_rysy.py | 186 +++++++++++++++++ .../STD_mean_2D_fun_ICCP_rysy_single.py | 193 ++++++++++++++++++ Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py | 6 +- Rain_distribution/Rain_many_copare_time.py | 4 +- .../Rain_many_copare_time_line.py | 108 ++++------ .../Rain_many_copare_time_line_21_12.py | 176 ++++++++++++++++ Rain_distribution/distribution_Py3_2D_mean.py | 4 +- .../distribution_Py3_2D_mean_nowa_wersja.py | 130 ++++++++++++ Rain_distribution/rain_histogram.py | 87 ++++++++ Rain_distribution/rain_histogram_21_12.py | 98 +++++++++ Rain_distribution/rain_histogram_multi.py | 104 ++++++++++ .../rain_histogram_multi_SD1k.py | 111 ++++++++++ Rain_distribution/rain_histogram_vol2.py | 67 ++++++ .../rain_histogram_vol2_SD_compare.py | 162 +++++++++++++++ .../rain_histogram_vol2_no_piggy.py | 104 ++++++++++ 16 files changed, 1512 insertions(+), 92 deletions(-) create mode 100644 NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy.py create mode 100644 NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single.py create mode 100644 Rain_distribution/Rain_many_copare_time_line_21_12.py create mode 100644 Rain_distribution/distribution_Py3_2D_mean_nowa_wersja.py create mode 100644 Rain_distribution/rain_histogram.py create mode 100644 Rain_distribution/rain_histogram_21_12.py create mode 100644 Rain_distribution/rain_histogram_multi.py create mode 100644 Rain_distribution/rain_histogram_multi_SD1k.py create mode 100644 Rain_distribution/rain_histogram_vol2.py create mode 100644 Rain_distribution/rain_histogram_vol2_SD_compare.py create mode 100644 Rain_distribution/rain_histogram_vol2_no_piggy.py diff --git a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py index 3c76bc9..511c883 100644 --- a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py +++ b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP.py @@ -1,12 +1,13 @@ from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial import numpy as np +import pandas as pd from scipy.stats import moment from sys import argv -#from matplotlib.ticker import MultipleLocator -import matplotlib as plt -#import matplotlib as mpl -#import matplotlib.colors as mcolors -#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +from matplotlib.ticker import MultipleLocator +import matplotlib.pyplot as plt +import matplotlib as mpl +import matplotlib.colors as mcolors +from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator import glob, os plt.rcParams.update({'font.size': 20}) @@ -14,22 +15,39 @@ #### DO RECZNEGO UZUPELNIENIA############# name = '2D_NA1' #PATHS - +path_same_NA1 = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_same/' +path_diff_NA1 = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff/' +path_diff_NA1_piggy_ICCP = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/ICCP/times_SD100_diff_piggy/' +path_same_NA1_piggy = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_same_piggy/' +path_diff_NA1_piggy = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy/' path_diff_NA1_piggy_VF = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF/' path_diff_NA1_piggy_VF_tail = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' -path_diff_NA1_piggy_VF_multi = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' +path_diff_NA1_piggy_VF_multi = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_multi/' +path_testy = '/home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/' -outfile = '/home/pzmij/2D/RESULTS_NA1/Wyniki/' #OPISY +text_same = 'Same rng_seed_init same rng_seed \n with dynamic' +text_diff = 'diff velo field in all simulations' +text_diff_piggy = 'same velo field for each SD value' text_diff_piggy_VF = 'same velo field in all simulations' text_diff_piggy_VF_tail = 'same velo field in all simulations \n sd conc long tail' text_diff_piggy_VF_multi = 'same velo field in all simulations \n sd conc same multiplicity' -#paths = [path_diff_NA1_piggy_VF+'SD100',path_diff_NA1_piggy_VF+'SD1000', path_diff_NA1_piggy_VF+'SD10000',path_diff_NA1_piggy_VF_tail+'SD100',path_diff_NA1_piggy_VF_tail+'SD1000', path_diff_NA1_piggy_VF+'SD10000'] - -paths = ['/home/pzmij/2D/RESULTS_NA1/SD100_piggy/times_SD100_diff_piggy_VF/', '/home/pzmij/2D/RESULTS_NA1/SD100_piggy/times_SD100_diff_piggy_VF_tail', '/home/pzmij/2D/RESULTS_NA1/SD100_piggy/times_SD100_diff_piggy_VF_multi', '/home/pzmij/2D/RESULTS_NA1/SD1000_piggy/times_SD1000_diff_piggy_VF', '/home/pzmij/2D/RESULTS_NA1/SD1000_piggy/times_SD1000_diff_piggy_VF_tail', '/home/pzmij/2D/RESULTS_NA1/SD1000_piggy/times_SD1000_diff_piggy_VF_multi', '/home/pzmij/2D/RESULTS_NA1/SD10000_piggy/times_SD10000_diff_piggy', '/home/pzmij/2D/RESULTS_NA1/SD10000_piggy/times_SD10000_diff_piggy_VF_tail', '/home/pzmij/2D/RESULTS_NA1/SD10000_piggy/times_SD10000_diff_piggy_VF_multi'] -label_list = ['100', '1000', '10000'] -podpisy = [text_diff_piggy_VF, text_diff_piggy_VF_tail, text_diff_piggy_VF_multi] +# paths = [path_diff_NA1+'SD100', path_diff_NA1+'SD1000',path_diff_NA1+'SD10000',path_diff_NA1_piggy+'SD100',path_diff_NA1_piggy+'SD1000', path_diff_NA1_piggy+'SD10000',path_diff_NA1_piggy_VF+'SD100',path_diff_NA1_piggy_VF+'SD1000', path_diff_NA1_piggy_VF+'SD10000']#,path_diff+'SD100', path_diff+'SD1000', path_diff+'SD10000'] +# paths = [path_diff_NA1+'SD100', path_diff_NA1+'SD1000',path_diff_NA1+'SD10000',path_diff_NA1_piggy_VF+'SD100',path_diff_NA1_piggy_VF+'SD1000', path_diff_NA1_piggy_VF+'SD10000'] +paths = [path_diff_NA1_piggy_VF+'SD10',path_diff_NA1_piggy_VF+'SD100',path_diff_NA1_piggy_VF+'SD1000', path_diff_NA1_piggy_VF+'SD10000', \ + path_diff_NA1_piggy_VF_tail+'SD10',path_diff_NA1_piggy_VF_tail+'SD100',path_diff_NA1_piggy_VF_tail+'SD1000', path_diff_NA1_piggy_VF_tail+'SD10000']#, \ + # path_diff_NA1_piggy_VF_multi+'SD10',path_diff_NA1_piggy_VF_multi+'SD100',path_diff_NA1_piggy_VF_multi+'SD1000_2']#,path_diff_NA1_piggy_VF_multi+'SD1000_2'] +# paths = [path_diff_NA1_piggy_VF+'SD10',path_diff_NA1_piggy_VF+'SD100',path_diff_NA1_piggy_VF+'SD1000', \ +# path_diff_NA1_piggy_VF_tail+'SD10',path_diff_NA1_piggy_VF_tail+'SD100',path_diff_NA1_piggy_VF_tail+'SD1000', \ +# path_diff_NA1_piggy_VF_multi+'SD10',path_diff_NA1_piggy_VF_multi+'SD100',path_diff_NA1_piggy_VF_multi+'SD1000_2'] +# paths = [path_diff_NA1_piggy_VF_multi+'SD10',path_diff_NA1_piggy_VF_multi+'SD100',path_diff_NA1_piggy_VF_multi+'SD1000',path_diff_NA1_piggy_VF_multi+'SD10_2',path_diff_NA1_piggy_VF_multi+'SD100_3',path_diff_NA1_piggy_VF_multi+'SD1000_2']#,path_diff_NA1_piggy_VF_multi+'SD100_2',path_diff_NA1_piggy_VF_multi+'SD100_1'] +# paths = [path_testy+'SD100/VF',path_testy+'SD1000/VF', path_testy+'SD10000/VF',path_testy+'SD100/tail',path_testy+'SD1000/tail', path_testy+'SD10000/tail',path_testy+'SD100/multi',path_testy+'SD1000/multi', path_testy+'SD10000/multi'] + +label_list = ['10','100', '1000', '10000'] +podpisy = [text_diff_piggy_VF, text_diff_piggy_VF_tail]#, text_diff_piggy_VF_multi] +# podpisy = ['1st ', '2nd'] +# podpisy = [text_diff,text_diff_piggy,text_diff_piggy_VF] width_multiplier = 0.67 ########################################################################## def Rysuj_to(sciezki, etykiety, podpisy, name): @@ -93,10 +111,10 @@ def czas(iter_value): series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] files[p] = glob.glob("*.dat") - colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + colors = [ 'forestgreen', 'gold', 'forestgreen', 'blue', 'gold', 'forestgreen', 'gold', 'blue'] u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) u = np.tile(u_init, len(podpisy)) - width = 0.25 + width = 0.3 colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] colors = colors_list[0:len(etykiety)] *len(podpisy) multi = len(etykiety) @@ -111,8 +129,8 @@ def czas(iter_value): A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") plt.xticks(X, labels, ha = 'center') - plt.ylim(0, 2.5e2) - #plt.text(0.5, 265 , 'G', fontsize=26) + # plt.ylim(0, 2.5e2) + # plt.text(0.5, 265 , 'G', fontsize=26) plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) @@ -120,7 +138,7 @@ def czas(iter_value): height = rect.get_height() ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, '%d' % int(height) + "%", ha='center', va='bottom') - plt.savefig(outfile+'sigma_VF_tail_multi'+name+'.png') + plt.savefig('/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/ICCP/Wyniki/Sigma_VF_tail'+name+'.png') fig1, ax = plt.subplots() fig1.set_size_inches(18.5, 10.5) @@ -130,8 +148,8 @@ def czas(iter_value): error = licz_srednia("acc_vol_precip", p, sciezki)[2] A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") plt.ylabel(r"$\sigma$ [$m^3$]") - plt.ylim(0, 5e-1) - #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.ylim(0, 1.5e-1) + # plt.text(0.5, 0.53 , 'F', fontsize=26) plt.xticks(X, labels, ha = 'center') plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) @@ -141,7 +159,7 @@ def czas(iter_value): ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, f"{height:.2e}", ha='center', va='bottom') # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') - plt.savefig(outfile+'STD_VF_tail_multi'+name+'.png') + plt.savefig('/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/ICCP/Wyniki/STD_VF_tail'+name+'.png') fig1, ax = plt.subplots() fig1.set_size_inches(18.5, 10.5) @@ -153,7 +171,7 @@ def czas(iter_value): A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") plt.ylabel(r"Mean accumulated precipitation [$m^3$]") plt.ylim(0, 4e-1) - #plt.text(0.5, 0.43 , 'E', fontsize=26) + # plt.text(0.5, 0.43 , 'E', fontsize=26) plt.xticks(X, labels, ha = 'center') plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) @@ -163,7 +181,7 @@ def czas(iter_value): ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, f"{height:.2e}", ha='center', va='bottom') # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') - plt.savefig(outfile+'Mean_VF_tail_multi'+name+'.png') + plt.savefig('/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/ICCP/Wyniki/Mean_VF_tail'+name+'.png') Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy.py b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy.py new file mode 100644 index 0000000..09f6236 --- /dev/null +++ b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy.py @@ -0,0 +1,186 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 17}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# +name = '2D_NA1' +#PATHS + +# path_diff_NA1_piggy_VF = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF/' +# path_diff_NA1_piggy_VF_tail = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' +# path_diff_NA1_piggy_VF_multi = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' + + +#OPISY + + +####CASE Piggy +paths = ['/home/pzmij/2D/PAPER/Piggy/SD10/times_classic','/home/pzmij/2D/PAPER/Piggy/SD50/times_classic','/home/pzmij/2D/PAPER/Piggy/SD100/times_classic','/home/pzmij/2D/PAPER/Piggy/SD1000/times_classic', + '/home/pzmij/2D/PAPER/Piggy/SD10/times_tail','/home/pzmij/2D/PAPER/Piggy/SD50/times_tail','/home/pzmij/2D/PAPER/Piggy/SD100/times_tail','/home/pzmij/2D/PAPER/Piggy/SD1000/times_tail', + '/home/pzmij/2D/PAPER/Piggy/SD10/times_multi','/home/pzmij/2D/PAPER/Piggy/SD50/times_multi','/home/pzmij/2D/PAPER/Piggy/SD100/times_multi','/home/pzmij/2D/PAPER/Piggy/SD1000/times_multi'] +# paths = ['/home/pzmij/2D/PAPER/Piggy/SD10/only_ten_classic','/home/pzmij/2D/PAPER/Piggy/SD100/only_ten_classic','/home/pzmij/2D/PAPER/Piggy/SD1000/only_ten_classic','/home/pzmij/2D/PAPER/Piggy/SD10/only_ten_tail','/home/pzmij/2D/PAPER/Piggy/SD100/only_ten_tail','/home/pzmij/2D/PAPER/Piggy/SD1000/only_ten_tail','/home/pzmij/2D/PAPER/Piggy/SD10/only_ten_multi','/home/pzmij/2D/PAPER/Piggy/SD100/only_ten_multi','/home/pzmij/2D/PAPER/Piggy/SD1000/only_ten_multi'] +outfile = '/home/pzmij/2D/PAPER/Wyniki/STD_barrs/Piggy/' +text_diff_piggy_VF = 'Classic' +text_diff_piggy_VF_tail = 'Tail' +text_diff_piggy_VF_multi = 'Multi' +####CASE NO_Piggy +# paths = ['/home/pzmij/2D/PAPER/no_Piggy/SD10/times_classic','/home/pzmij/2D/PAPER/no_Piggy/SD100/times_classic','/home/pzmij/2D/PAPER/no_Piggy/SD1000/times_classic', +# '/home/pzmij/2D/PAPER/no_Piggy/SD10/times_tail','/home/pzmij/2D/PAPER/no_Piggy/SD100/times_tail','/home/pzmij/2D/PAPER/no_Piggy/SD1000/times_tail', +# '/home/pzmij/2D/PAPER/no_Piggy/SD10/times_multi','/home/pzmij/2D/PAPER/no_Piggy/SD100/times_multi','/home/pzmij/2D/PAPER/no_Piggy/SD1000/times_multi'] +# outfile = '/home/pzmij/2D/PAPER/Wyniki/STD_barrs/no_Piggy/' +# text_diff_piggy_VF = 'diff velo field in all simulations' +# text_diff_piggy_VF_tail = 'diff velo field in all simulations \n sd conc long tail' +# text_diff_piggy_VF_multi = 'diff velo field in all simulations \n sd conc same multiplicity' + +label_list = ['10', '50', '100', '1000'] +podpisy = [text_diff_piggy_VF, text_diff_piggy_VF_tail, text_diff_piggy_VF_multi] +width_multiplier = 0.67 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],4)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.25 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'sigma_VF_tail_multi_21_12'+name+'.png') + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_VF_tail_multi_21_12'+name+'.png') + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 12e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.1e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_VF_tail_multi_21_12'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single.py b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single.py new file mode 100644 index 0000000..bd25e03 --- /dev/null +++ b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single.py @@ -0,0 +1,193 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 19}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +#PATHS + +# path_diff_NA1_piggy_VF = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF/' +# path_diff_NA1_piggy_VF_tail = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' +# path_diff_NA1_piggy_VF_multi = '/home/piotr-pc/Piotr/WORKSHOPS/2D/NA1/time_series_diff_piggy_VF_tail/' + + +#OPISY + + +####CASE Piggy +paths = ['/home/pzmij/2D/PAPER/Piggy/SD10/times_classic','/home/pzmij/2D/PAPER/Piggy/SD50/times_classic','/home/pzmij/2D/PAPER/Piggy/SD100/times_classic','/home/pzmij/2D/PAPER/Piggy/SD1000/times_classic','/home/pzmij/2D/PAPER/Piggy/SD10000/times_classic'] + #'/home/pzmij/2D/PAPER/Piggy/SD10/times_tail','/home/pzmij/2D/PAPER/Piggy/SD50/times_tail','/home/pzmij/2D/PAPER/Piggy/SD100/times_tail','/home/pzmij/2D/PAPER/Piggy/SD1000/times_tail', + #'/home/pzmij/2D/PAPER/Piggy/SD10/times_multi','/home/pzmij/2D/PAPER/Piggy/SD50/times_multi','/home/pzmij/2D/PAPER/Piggy/SD100/times_multi','/home/pzmij/2D/PAPER/Piggy/SD1000/times_multi'] +# paths = ['/home/pzmij/2D/PAPER/Piggy/SD10/only_ten_classic','/home/pzmij/2D/PAPER/Piggy/SD100/only_ten_classic','/home/pzmij/2D/PAPER/Piggy/SD1000/only_ten_classic','/home/pzmij/2D/PAPER/Piggy/SD10/only_ten_tail','/home/pzmij/2D/PAPER/Piggy/SD100/only_ten_tail','/home/pzmij/2D/PAPER/Piggy/SD1000/only_ten_tail','/home/pzmij/2D/PAPER/Piggy/SD10/only_ten_multi','/home/pzmij/2D/PAPER/Piggy/SD100/only_ten_multi','/home/pzmij/2D/PAPER/Piggy/SD1000/only_ten_multi'] +outfile = '/home/pzmij/2D/PAPER/Wyniki/STD_barrs/Piggy/' +text_diff_piggy_VF = 'Classic' +text_diff_piggy_VF_tail = 'Tail' +text_diff_piggy_VF_multi = 'Multi' +####CASE NO_Piggy +# paths = ['/home/pzmij/2D/PAPER/no_Piggy/SD10/times_classic','/home/pzmij/2D/PAPER/no_Piggy/SD100/times_classic','/home/pzmij/2D/PAPER/no_Piggy/SD1000/times_classic', +# '/home/pzmij/2D/PAPER/no_Piggy/SD10/times_tail','/home/pzmij/2D/PAPER/no_Piggy/SD100/times_tail','/home/pzmij/2D/PAPER/no_Piggy/SD1000/times_tail', +# '/home/pzmij/2D/PAPER/no_Piggy/SD10/times_multi','/home/pzmij/2D/PAPER/no_Piggy/SD100/times_multi','/home/pzmij/2D/PAPER/no_Piggy/SD1000/times_multi'] +# outfile = '/home/pzmij/2D/PAPER/Wyniki/STD_barrs/no_Piggy/' +# text_diff_piggy_VF = 'diff velo field in all simulations' +# text_diff_piggy_VF_tail = 'diff velo field in all simulations \n sd conc long tail' +# text_diff_piggy_VF_multi = 'diff velo field in all simulations \n sd conc same multiplicity' + +# label_list = ['10', '50', '100', '1000', '10000'] +label_list = ['5', '25', '50', '100'] +paths = ['/home/pzmij/2D/PAPER/Piggy/SD10/times_classic','/home/pzmij/2D/PAPER/Piggy/times_coal/SD10_coal25','/home/pzmij/2D/PAPER/Piggy/times_coal/SD10_coal50','/home/pzmij/2D/PAPER/Piggy/times_coal/SD10_coal100']#,'/home/pzmij/2D/PAPER/Piggy/SD10000/times_classic'] +name = 'Coal_comparison' +podpisy = [text_diff_piggy_VF]#, text_diff_piggy_VF_tail, text_diff_piggy_VF_multi] +width_multiplier = 0.67 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.25 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="sstp_coal: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="sstp_coal ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 12e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="sstp_coal ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py b/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py index d1b27bd..8c70796 100644 --- a/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py +++ b/Rain_distribution/RAIN_rysy_xz2d_2D_lvl0.py @@ -91,9 +91,10 @@ Rr_rows_clb = np.transpose(rr_rows_clb) Rr_rows_lvl0 = np.transpose(rr_rows_lvl0) + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(30,15)) + # e = plt.pcolormesh(X, pliki, Rr_rows, vmin=7e-15, vmax=4e-4) gnuplot e0 = ax0.contourf(X, pliki, Rr_rows_clb, vmin=7e-15, vmax=4e-4, extend='neither',levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4], cmap='gnuplot')#, vmin=0, vmax=1.4, levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) #bin[1:] - # e = plt.pcolormesh(X, pliki, Rr_rows, vmin=7e-15, vmax=4e-4) # fig.colorbar(e0, orientation='vertical', ax=ax0, label=r"$r_{v}$", ticks=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) #opcjonalnie levele~!!!!! ax0.set_ylabel('Simulation#') @@ -102,12 +103,13 @@ e1 = ax1.contourf(X, pliki, Rr_rows_lvl0, vmin=7e-15, vmax=4e-4, extend='neither',levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4], cmap='gnuplot')#, vmin=0, vmax=1.4, levels=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) #bin[1:] # e = plt.pcolormesh(X, pliki, Rr_rows, vmin=7e-15, vmax=4e-4) fig.subplots_adjust(right=0.99) - fig.colorbar(e1, orientation='vertical', ax=[ax0,ax1], label=r"$r_{v}$", ticks=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) + fig.colorbar(e1, orientation='vertical', ax=[ax0,ax1], label=r"$r_{r}$", ticks=[7e-15, 7e-14, 7e-13, 7e-12, 7e-11, 7e-10, 7e-9, 7e-8, 7e-7, 7e-6, 7e-5, 7e-4]) #opcjonalnie levele~!!!!! # fig.supylabel('Simulation#') ax1.set_xlabel('cell#') ax1.set_title('Height = {}m'.format(int(0))) fig.suptitle('Current time {}s '.format(int(timestep/2))) plt.axis(aspect='image') + # plt.legend(title =("Max ", np.max(Rr_rows_clb), "Min ", np.min(Rr_rows_clb))) plt.savefig(outfile + '/Multi_SD100_' + str(int(timestep/2)) +'.png') plt.close() diff --git a/Rain_distribution/Rain_many_copare_time.py b/Rain_distribution/Rain_many_copare_time.py index b0fe941..0ab0c90 100644 --- a/Rain_distribution/Rain_many_copare_time.py +++ b/Rain_distribution/Rain_many_copare_time.py @@ -4,8 +4,8 @@ from sys import argv, path, maxsize #path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") # path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") -path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") -# path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") +#path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") ''' diff --git a/Rain_distribution/Rain_many_copare_time_line.py b/Rain_distribution/Rain_many_copare_time_line.py index ce4b02f..5acab43 100644 --- a/Rain_distribution/Rain_many_copare_time_line.py +++ b/Rain_distribution/Rain_many_copare_time_line.py @@ -19,7 +19,7 @@ ''' - +import cProfile, pstats from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial import h5py from scipy.stats import moment @@ -46,74 +46,45 @@ def Adia_fraction(timestep, paths): files = os.listdir(paths) nr_files = len(files) rhod= [0 for i in range(nr_files)] - p_e = [0 for i in range(nr_files)] dz = [0 for i in range(nr_files)] rl = [0 for i in range(nr_files)] rl_base = [0 for i in range(nr_files)] - nc = [0 for i in range(nr_files)] - th = [0 for i in range(nr_files)] - rv = [0 for i in range(nr_files)] rr = [0 for i in range(nr_files)] sum_rr = [0 for i in range(nr_files)] - for file in range(nr_files): - # plt.clf() - p_e[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn" + "/const.h5", "r")["p_e"][:] - rhod[file] = h5py.File(paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + "/const.h5", "r")["G"][:,:] - dz[file] = h5py.File(paths+files[file] + '/' + files[file] + "_out_lgrngn"+ "/const.h5", "r").attrs["dz"] + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] - nx, nz = rhod[file].shape - hght = np.arange(nz) * dz[file] - bin = np.linspace(1,121,len(np.arange(nx))) - sum_rr[file] = np.zeros([nx]) - - filename = paths + files[file] + '/' + files[file] + "_out_lgrngn"+ "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg - rl_base[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg - nc[file] = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod[file] / 1e6; # 1 / cm^3 + rl_base[file] = rl[file] rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e6; # g/kg # cloudiness mask - as in RICO paper cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) - cloudy_mask_used = cloudy_mask - - # th and rv - th[file] = h5py.File(filename, "r")["th"][:,:]; - rv[file] = h5py.File(filename, "r")["rv"][:,:]; - # T - Vexner= np.vectorize(lcmn.exner) - T = th[file] * Vexner(p_e[file].astype(float)) - # RH - Vr_vs = np.vectorize(lcmn.r_vs) - r_vs = Vr_vs(T, p_e[file].astype(float)) - RH = rv[file] / r_vs[file] + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + bin = np.linspace(1,len(np.arange(nx)),len(np.arange(nx))) + sum_rr[file] = np.zeros([nx]) # cloud base - clb_idx = np.argmax(cloudy_mask_used > 0, axis=1) + clb_idx = np.argmax(cloudy_mask > 0, axis=1) hght_2 = hght[clb_idx] hght_2[hght_2==0] = np.nan min_hght = np.nanmin(hght_2) - max_hght = np.nanmax(hght_2) - # print("wysokosc min",min_hght, " wysokosc max", max_hght) - # print(i, rr[file][i]) - if min_hght/dz[file] < 10: - min_hght = 10*int(dz[file]) - + min_hght = np.where(min_hght/dz[file] < 10,10*int(dz[file]), min_hght ) min_hght = np.nan_to_num(min_hght) - for j in np.arange(nx): if clb_idx[j] > 0: - # sum_rr[file][j] = np.sum(rr[file][j,:int(min_hght/dz[file])-1],0) - sum_rr[file][j] = np.sum(rr[file][j,int(min_hght/dz[file])-1],0) + sum_rr[file][j] = np.sum(rr[file][j,0:int(min_hght/dz[file])-1],0) sum_rr[file][sum_rr[file]==0] = np.nan - # print(file) srednie_rr = np.nanmean(sum_rr, axis=0) STD_rr = np.nanstd(sum_rr, axis=0) ST_error_mean = STD_rr/sqrt(nr_files) - error_std = np.power(1/nr_files * (moment(sum_rr,4) - (nr_files-3)/(nr_files-1)*np.power(STD_rr,4)),1/2)/(2*STD_rr) + error_std = np.power(1/nr_files * (moment(sum_rr,4) - (nr_files-3)/(nr_files-1)*np.power(STD_rr,4)),0.5)/(2*STD_rr) return(srednie_rr, STD_rr, bin, ST_error_mean, error_std) -# bin_size = bin[2]-bin[1] -# print(bin_size) time_start = int(argv[1]) time_end = int(argv[2]) outfreq = int(argv[3]) @@ -121,7 +92,6 @@ def Adia_fraction(timestep, paths): paths = argv[5:len(argv):2] labels = argv[6:len(argv):2] - Average = [] STD = [] Average_error = [] @@ -130,43 +100,55 @@ def Adia_fraction(timestep, paths): average_error =np.zeros((int((time_end-time_start)/outfreq)+1,121)) std =np.zeros((int((time_end-time_start)/outfreq)+1,121)) std_error =np.zeros((int((time_end-time_start)/outfreq)+1,121)) -# fig = plt.figure() -# fig.set_size_inches(18.5, 10.5) + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(30,15)) shape = ['o', 'x', '.k' ] +col = ['red', 'green','blue', 'yellow', 'black'] +X = [6000, 6000] +Y1 = [0, 2] +Y2 = [0, 0.9] +profiler = cProfile.Profile() +profiler.enable() for path, lab in zip(paths, labels): b = 0 + d = 0 for i in range(int(time_start/outfreq), int(time_end/outfreq)+1): aver, sigma , bin, st_error, sigma_error= Adia_fraction(i, path) average[b] = aver std[b] = sigma std_error[b] = sigma_error average_error[b] = st_error - # std[b] = std b += 1 Average = np.nanmean(average,axis=0) STD = np.nanmean(std,axis=0) Average_error = np.nanmean(average_error,axis=0) STD_error = np.nanmean(std_error,axis=0) - ax0.plot(bin, Average, label=lab)#, edgecolors='b' + bin = bin *100 + ax0.plot(bin, Average, label=lab )#, edgecolors='b' + ax0.plot(X, Y1, linestyle=':', c = 'k') ax0.fill_between(bin, Average-Average_error, Average+Average_error, alpha=0.2) - # ax1.plot(bin, STD, label=lab)#, edgecolors='b' - # ax1.fill_between(bin, STD-STD_error, STD+STD_error, alpha=0.2) - ax1.errorbar(bin, STD, STD_error, fmt='o',label=lab) - + ax1.plot(bin, STD, label=lab)#, edgecolors='b' + ax1.fill_between(bin, STD-STD_error, STD+STD_error, alpha=0.2) + # ax1.errorbar(bin, STD, yerr=STD_error,label=lab, mfc=col[d]) + ax1.plot(X, Y2, linestyle=':', c = 'k') + d+=1 # plt.errorbar(bin, Average, Average_error, fmt='o',label=lab)# -ax0.set_ylim((0)) -ax1.set_ylim((0)) -ax0.set_xlim((40,90)) -ax1.set_xlim((40,90)) -plt.xlabel('cell#') -ax0.set_ylabel('$q_r$ (rain) [g/kg]') -ax1.set_ylabel('$q_r$ (rain) [g/kg]') -ax0.legend(title='Average') -ax1.legend(title='STD') +profiler.disable() +stats = pstats.Stats(profiler).sort_stats('cumtime') +stats.print_stats() +ax0.set_ylim((0,0.5)) +ax1.set_ylim((0, 0.5 )) +ax0.set_xlim((4000,8000)) +ax1.set_xlim((4000,8000)) +ax0.set_xlabel('X [m]') +ax1.set_xlabel('X [m]') +ax0.set_ylabel('Mean of $q_r$ [g/kg]') +ax1.set_ylabel('STD of $q_r$ [g/kg]') +ax0.legend(title='SD10') +ax1.legend(title='SD10') fig.suptitle('time range = '+str(time_start) + ' to '+str(time_end) +' s') -plt.savefig(outfile + 'Average_many_for_time range_'+str(time_start)+'_to_'+ str(time_end)+'.png') +plt.savefig(outfile + 'Average_many_for_time_range_'+str(time_start)+'_to_'+ str(time_end)+'.png') # Od komentuj! plt.clf() diff --git a/Rain_distribution/Rain_many_copare_time_line_21_12.py b/Rain_distribution/Rain_many_copare_time_line_21_12.py new file mode 100644 index 0000000..8f5d75e --- /dev/null +++ b/Rain_distribution/Rain_many_copare_time_line_21_12.py @@ -0,0 +1,176 @@ +# calculate cloud droplet conc. vs adiabatic fraction +# adiabatic rl calculated based on mean th and rv at cloud base cells + +from sys import argv, path, maxsize +#path.insert(0,"../../local_folder/uptodate/lib/python3/dist-packages") +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +#path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +How to run + +python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25/dxyz100_SD100_diff_seed_NA1_Coal_2D_VF_tail_piggy_25_out_lgrngn /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain + +Singularity> python3 Rain_many.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ + +python3 Rain_many_copare_time_line.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_SD1000" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_SD100" + + +''' +import cProfile, pstats +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import h5py +from scipy.stats import moment +import time +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +import os +from libcloudphxx import common as lcmn +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +start = time.perf_counter() +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i +timesteps = timesteps[1:91] +np.set_printoptions(threshold=maxsize) + + +def Adia_fraction(timestep, paths): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + sum_rr = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e6; # g/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + bin = np.linspace(1,len(np.arange(nx)),len(np.arange(nx))) + sum_rr[file] = np.zeros([nx]) + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + min_hght = np.nanmin(hght_2) + min_hght = np.where(min_hght/dz[file] < 10,10*int(dz[file]), min_hght ) + min_hght = np.nan_to_num(min_hght) + for j in np.arange(nx): + if clb_idx[j] > 0: + sum_rr[file][j] = np.sum(rr[file][j,0:int(min_hght/dz[file])-1],0) + sum_rr[file][sum_rr[file]==0] = np.nan + srednie_rr = np.nanmean(sum_rr, axis=0) + STD_rr = np.nanstd(sum_rr, axis=0) + ST_error_mean = STD_rr/sqrt(nr_files) + error_std = np.power(1/nr_files * (moment(sum_rr,4) - (nr_files-3)/(nr_files-1)*np.power(STD_rr,2)),0.5)/(2*np.sqrt(STD_rr)) + return(srednie_rr, STD_rr, bin, ST_error_mean, error_std) + +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) +outfile = argv[4] +paths = argv[5:len(argv):2] +labels = argv[6:len(argv):2] + +Average = [] +STD = [] +Average_error = [] +STD_error = [] +average =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +average_error =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +std =np.zeros((int((time_end-time_start)/outfreq)+1,121)) +std_error =np.zeros((int((time_end-time_start)/outfreq)+1,121)) + +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(30,15)) +shape = ['o', 'x', '.k' ] +col = ['red', 'green','blue', 'yellow', 'black'] +X = [6000, 6000] +Y1 = [0, 2] +Y2 = [0, 0.9] +profiler = cProfile.Profile() +profiler.enable() +for path, lab in zip(paths, labels): + b = 0 + d = 0 + for i in range(int(time_start/outfreq), int(time_end/outfreq)+1): + aver, sigma , bin, st_error, sigma_error= Adia_fraction(i, path) + average[b] = aver + std[b] = sigma + std_error[b] = sigma_error + average_error[b] = st_error + b += 1 + Average = np.nanmean(average,axis=0) + STD = np.nanmean(std,axis=0) + Average_error = np.nanmean(average_error,axis=0) + STD_error = np.nanmean(std_error,axis=0) + bin = bin *100 + ax0.plot(bin, Average, label=lab )#, edgecolors='b' + ax0.plot(X, Y1, linestyle=':', c = 'k') + ax0.fill_between(bin, Average-Average_error, Average+Average_error, alpha=0.2) + ax1.plot(bin, STD, label=lab)#, edgecolors='b' + ax1.fill_between(bin, STD-STD_error, STD+STD_error, alpha=0.2) + # ax1.errorbar(bin, STD, yerr=STD_error,label=lab, mfc=col[d]) + ax1.plot(X, Y2, linestyle=':', c = 'k') + d+=1 + # plt.errorbar(bin, Average, Average_error, fmt='o',label=lab)# +profiler.disable() +stats = pstats.Stats(profiler).sort_stats('cumtime') +stats.print_stats() +ax0.set_ylim((0,0.5)) +ax1.set_ylim((0, 0.5 )) +ax0.set_xlim((4000,8000)) +ax1.set_xlim((4000,8000)) +ax0.set_xlabel('X [m]') +ax1.set_xlabel('X [m]') +ax0.set_ylabel('Mean of $q_r$ [g/kg]') +ax1.set_ylabel('STD of $q_r$ [g/kg]') +ax0.legend(title='SD10') +ax1.legend(title='SD10') +fig.suptitle('time range = '+str(time_start) + ' to '+str(time_end) +' s') + +plt.savefig(outfile + 'Average_many_for_time_range_'+str(time_start)+'_to_'+ str(time_end)+'21_12.png') +# Od komentuj! +plt.clf() + +''' +python3 Rain_many_copare_time.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ 'multi' + +python3 Rain_many_copare_time.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/multi/ 'multi_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ 'multi_1c' + + +python3 Rain_many_copare_time.py 14400 15600 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 16800 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 18000 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 19200 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 17280 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 17760 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 17040 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' +python3 Rain_many_copare_time.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/VF/ "VF_1k" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/tail/ 'tail_1k' /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "VF_1c" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ 'tail_1c' + + + + + + + +''' diff --git a/Rain_distribution/distribution_Py3_2D_mean.py b/Rain_distribution/distribution_Py3_2D_mean.py index cc91646..a7db568 100644 --- a/Rain_distribution/distribution_Py3_2D_mean.py +++ b/Rain_distribution/distribution_Py3_2D_mean.py @@ -104,7 +104,7 @@ def Rain_distribution(directories, labels, lvl): _ = plt.hist(A_mean, bins=np.logspace(np.log10(1e-6), np.log10(np.amax(A_mean)), nx), label=plot_labels.values(), density=False, histtype='step', linewidth=6) plt.xscale('log') - # plt.legend(loc = 'lower center') + plt.legend(loc = 'lower center') plt.yscale('log') plt.xlabel('q_r [g/kg]') plt.ylabel('# of cells') @@ -116,7 +116,7 @@ def Rain_distribution(directories, labels, lvl): _ = plt.hist(B_mean, bins=np.logspace(np.log10(1e-3), np.log10(np.amax(B_mean)), nx), label=plot_labels.values(), density=False, histtype='step', linewidth=6) plt.xscale('log') - # plt.legend(loc = 'lower center') + plt.legend(loc = 'lower center') plt.yscale('log') plt.xlabel('precipitation flux [W / m^2]') plt.ylabel('# of cells') diff --git a/Rain_distribution/distribution_Py3_2D_mean_nowa_wersja.py b/Rain_distribution/distribution_Py3_2D_mean_nowa_wersja.py new file mode 100644 index 0000000..21dc3a1 --- /dev/null +++ b/Rain_distribution/distribution_Py3_2D_mean_nowa_wersja.py @@ -0,0 +1,130 @@ +import h5py +import numpy as np +from sys import argv +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from collections import OrderedDict +import os + +''' +HOW TO run + +python3 distribution_Py3_2D_mean.py 14400 20400 240 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "test" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/ + +''' + +rain_data = ["rain_rw_mom3", "precip_rate", "cloud_rw_mom3"] +cloud_thresh = 1e-5 # qc at cloud base + +CellVol = 100.*100*1 # hardcoded cell volume [m^3] +L_evap = 2264.76e3 # latent heat of evapporation [J/kg] + +time_start = int(argv[1]) +time_end = int(argv[2]) +outfreq = int(argv[3]) + + +outfile = argv[4] +directories = argv[5:len(argv):2] +labels = argv[6:len(argv):2] + +total_arr = OrderedDict() +for data in rain_data: + total_arr[data] = OrderedDict() + plot_labels = OrderedDict() + +def Rain_distribution(directories, labels): + RAIN, CLOUD, PRECIP = [[i for i in range(len(directories))] for i in range(3)] + for directory, lab in zip(directories, labels): + path_file = os.listdir(directory) + Rain_mean = {} + j = 0 + for path in path_file: + path_to_file = os.listdir(directory+path) + joined = os.path.join(directory,path) + + file = '#'+(path.split("_piggy_",-3))[-1].split("_out")[0] + w3d = h5py.File(joined+'/'+joined.split("/",-1)[-1] +"_out_lgrngn"+"/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:] + nx, nz = w3d.shape + + Tablica = np.zeros((nx, nz)) + for data in rain_data: + total_arr[data][file] = np.zeros(0) + for t in range(time_start, time_end+1, outfreq): + filename = joined +'/'+joined.split("/",-1)[-1] +"_out_lgrngn"+ "/timestep" + str(t).zfill(10) + ".h5" + Tablica += h5py.File(filename, "r")[data][:, : ] + + total_arr[data][file] = np.append(total_arr[data][file], Tablica/((time_end-time_start)/outfreq+1)) + + + # convert to typical units + if data == "rain_rw_mom3": + total_arr[data][file] *= 4./3. * 3.1416 * 1e3 # [kg/kg] + if data == "cloud_rw_mom3": + total_arr[data][file] *= 4./3. * 3.1416 * 1e3 # [kg/kg] + if data == "precip_rate": + total_arr[data][file] *= 4./3. * 3.1416 * 1e3 / CellVol * L_evap + Rain = [i for i in range(len(path_file))] + Cloud = [i for i in range(len(path_file))] + Precip = [i for i in range(len(path_file))] + i =0 + for path in path_file: + file = '#'+(path.split("_piggy_",-3))[-1].split("_out")[0] + Rain[i] = total_arr["rain_rw_mom3"][file] + Cloud[i] = total_arr["cloud_rw_mom3"][file] + Precip[i] = total_arr["precip_rate"][file] + i += 1 + Rain_mean = np.average(Rain, axis=0) + Rain_Std = np.std(Rain, axis=0) + Cloud_Std = np.std(Cloud, axis=0) + Cloud_mean = np.average(Cloud, axis=0) + Precip_mean = np.average(Precip, axis=0) + RAIN[j] = Rain_mean + CLOUD[j] = Cloud_mean + PRECIP[j] = Precip_mean + j += 1 + + + plt.figure(0) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + for k in range(len(directories)): + # _ = plt.hist(RAIN[k], bins=np.logspace(np.log10(np.amin(RAIN[k])), np.log10(np.amax(RAIN[k])), nx), label=labels[k], density=False, histtype='step', linewidth=6) + _ = plt.hist(RAIN[k], bins=50, label=labels[k], density=False, histtype='step', linewidth=6) + plt.xscale('log') + plt.legend(loc = 'best') + plt.yscale('log') + plt.xlabel('q_r [g/kg]') + plt.ylabel('# of cells') + plt.savefig(outfile+'A_Mean_rain_histo_' + str(time_start) + '_' + str(time_end) +'.png') + + plt.figure(1) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + for k in range(len(directories)): + # _ = plt.hist(PRECIP[j], bins=np.logspace(np.log10(1e-11), np.log10(np.amax(PRECIP[j])), nx), label=labels[k], density=False, histtype='step', linewidth=6) + _ = plt.hist(PRECIP[j], bins=50, label=labels[k], density=False, histtype='step', linewidth=6) + + plt.xscale('log') + plt.legend(loc = 'best') + plt.yscale('log') + plt.xlabel('precipitation flux [W / m^2]') + plt.ylabel('# of cells') + plt.savefig(outfile+'A_Mean_precip_rate_histo_' + str(time_start) + '_' + str(time_end) +'.png') + + plt.figure(0) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + for k in range(len(directories)): + # _ = plt.hist(CLOUD[k], bins=np.logspace(np.log10(1e-11), np.log10(np.amax(CLOUD[k])), nx), label=labels[k], density=False, histtype='step', linewidth=6) + _ = plt.hist(CLOUD[k], bins=50, label=labels[k], density=False, histtype='step', linewidth=6) + plt.xscale('log') + plt.legend(loc = 'best') + plt.yscale('log') + plt.xlabel('q_c [kg/kg]') + plt.ylabel('# of cells') + plt.savefig(outfile+'A_Mean_cloud_water_histo_' + str(time_start) + '_' + str(time_end) +'.png') + + +Rain_distribution(directories, labels) diff --git a/Rain_distribution/rain_histogram.py b/Rain_distribution/rain_histogram.py new file mode 100644 index 0000000..18a96e3 --- /dev/null +++ b/Rain_distribution/rain_histogram.py @@ -0,0 +1,87 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ +UPDATE + +python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/no_Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/ +Singularity> python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD100/classic/ + +''' + +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +# timesteps = timesteps[1:91] +timesteps = timesteps[1:91] +paths = argv[1] +outfile = argv[2] + +file_names = os.listdir(paths) + +pliki = [ i for i in range(len(file_names))] +bin = [1e-14, 1e-13,1e-12,1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2 ] +for timestep in timesteps: + plt.clf() + Hist = [] + rr_files = np.zeros((len(file_names), len(bin)-1)) + # rr_files = np.zeros((len(file_names), 121, 101)) + # rr_files = [] + # rr_rows_lvl0 = np.zeros((121, len(file_names))) + for p in range(len(file_names)): + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' + rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] + p_e = h5py.File(path + "/const.h5", "r")["p_e"][:] + nx, nz = rhod.shape + rhod_cros = rhod[:,:] + dz = h5py.File(path + "/const.h5", "r").attrs["dz"] + dx = h5py.File(path + "/const.h5", "r").attrs["dx"] + + X = np.arange(nx)# * dx + + filename = path + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rr_c = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + nc = h5py.File(filename, "r")["cloud_rw_mom0"][:,:] * rhod_cros / 1e6; # 1 / cm^3 + + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl > 1e-5, 1, 0) + cloudy_mask_used = cloudy_mask + + RR = rr * cloudy_mask_used + + hist = np.histogram(RR, bins=bin) + new_bin = hist[1] + rr_files[p,:] = hist[0] + Hist = np.mean(rr_files, axis=0) + + plt.figure(0) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + plt.step(new_bin[1:], Hist) + plt.xscale('log') + + plt.suptitle('Current time {}s '.format(int(timestep/2))) + plt.xlabel('q_r [kg/kg]') + plt.ylabel('# of cells') + plt.savefig(outfile+'New_hist' + str(timestep) +'.png') diff --git a/Rain_distribution/rain_histogram_21_12.py b/Rain_distribution/rain_histogram_21_12.py new file mode 100644 index 0000000..1fb42b0 --- /dev/null +++ b/Rain_distribution/rain_histogram_21_12.py @@ -0,0 +1,98 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ +UPDATE + +python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/no_Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/ +Singularity> python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD100/classic/ + +''' +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +# paths = argv[1] +# outfile = argv[2] +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +def Liczy_histogram(paths, i): + file_names = os.listdir(paths) + + Hist = np.zeros(( len(biny)-1)) + rr_files = np.zeros((len(file_names), len(biny)-1)) + for p in range(len(file_names)): + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' + filename = path + "/timestep" + str(240*i).zfill(10) + ".h5" + rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod * 4. / 3. * 3.1416 * 1e3; # kg/kg + hist = np.histogram(rr, bins=biny) + rr_files[p,:] = hist[0] + Hist = np.mean(rr_files, axis=0) + # Hist_data = np.sum(Hist, axis=0) + # Hist_data = Hist_data/ np.max(Hist_data) + return Hist, hist[1] + +def Run_hist(SD, path, kroki): + return Liczy_histogram(main_path+str(SD)+'/'+str(path)+'/', kroki) + +biny = [1e-14, 1e-13,1e-12,1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2, 1e-1, 1 ] +outfile = '/home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/' +main_path = '/home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD' +TITLE = 1000 +TITLE_save = 'testowy_SD_1000' +partial_fun_1000_VF = functools.partial(Run_hist, 100, "VF") +partial_fun_1000_tail = functools.partial(Run_hist, 1000, "tail") +partial_fun_1000_multi = functools.partial(Run_hist, 1000, "multi") +punkty = np.intc(np.linspace(1,90,91)) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic = executor.map(partial_fun_1000_VF, punkty) + Tails = executor.map(partial_fun_1000_tail, punkty) + Multis = executor.map(partial_fun_1000_multi, punkty) +Class = np.sum([i[0] for i in Classic], axis=0) +Tail = np.sum([i[0] for i in Tails], axis=0) +Multi = np.sum([i[0] for i in Multis], axis=0) + +plt.figure(0) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +plt.step(biny[1:], Class, c='y', label="classic", linewidth=9) +plt.step(biny[1:], Tail, c='r', label='tail', linewidth=9) +plt.step(biny[1:], Multi, c='g', label='multi', linewidth=9) +plt.title('SD= '+str(TITLE)+'[#]') +plt.xscale('log') +plt.xlim((1e-13, 1e-0)) +plt.grid(True) +plt.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +plt.xlabel(r'$q_r$ [kg/kg]') +plt.ylabel('# of cells') +plt.savefig(outfile+'hist_'+str(TITLE_save)+'.png') \ No newline at end of file diff --git a/Rain_distribution/rain_histogram_multi.py b/Rain_distribution/rain_histogram_multi.py new file mode 100644 index 0000000..a215e8f --- /dev/null +++ b/Rain_distribution/rain_histogram_multi.py @@ -0,0 +1,104 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ +UPDATE + +python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/no_Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/ +Singularity> python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD100/classic/ + +''' +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +# paths = argv[1] +# outfile = argv[2] +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +def Liczy_histogram(paths, i): + file_names = os.listdir(paths) + + Hist = np.zeros(( len(biny)-1)) + rr_files = np.zeros((len(file_names), len(biny)-1)) + for p in range(len(file_names)): + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' + filename = path + "/timestep" + str(240*i).zfill(10) + ".h5" + rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod * 4. / 3. * 3.1416 * 1e3; # kg/kg + hist = np.histogram(rr, bins=biny) + rr_files[p,:] = hist[0] + Hist = np.mean(rr_files, axis=0) + # Hist_data = np.sum(Hist, axis=0) + # Hist_data = Hist_data/ np.max(Hist_data) + return Hist, hist[1] + +# def Run_hist(SD, path, kroki): + # return Liczy_histogram(main_path+str(SD)+'/'+str(path)+'/', kroki) +def Run_hist(SD, kroki): + return Liczy_histogram(main_path+str(SD)+'/', kroki) + +biny = [1e-14, 1e-13,1e-12,1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2, 1e-1, 1 ] +outfile = '/home/pzmij/2D/PAPER/Wyniki/New_hist/Coal/' +main_path = '/home/pzmij/2D/PAPER/Piggy/' +TITLE = 10 +TITLE_save = 'testowy_SD_coal' +partial_fun_1000_VF = functools.partial(Run_hist, 'SD10_coal25')#, "VF") +partial_fun_1000_tail = functools.partial(Run_hist, 'SD10_coal50')#, "tail") +partial_fun_1000_multi = functools.partial(Run_hist, 'SD10_coal100')#, "multi") +partial_fun_1000_multi_3 = functools.partial(Run_hist, 'SD10/classic')#, "multi") +punkty = np.intc(np.linspace(1,90,91)) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic = executor.map(partial_fun_1000_VF, punkty) + Tails = executor.map(partial_fun_1000_tail, punkty) + Multis = executor.map(partial_fun_1000_multi, punkty) + Multis2 = executor.map(partial_fun_1000_multi_3, punkty) +Class = np.sum([i[0] for i in Classic], axis=0) +Tail = np.sum([i[0] for i in Tails], axis=0) +Multi = np.sum([i[0] for i in Multis], axis=0) +Multi2 = np.sum([i[0] for i in Multis2], axis=0) + +plt.figure(0) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +plt.step(biny[1:], Multi2, c='k', label="5", linewidth=9) +plt.step(biny[1:], Class, c='y', label="25", linewidth=9) +plt.step(biny[1:], Tail, c='r', label='50', linewidth=9) +plt.step(biny[1:], Multi, c='g', label='100', linewidth=9) +plt.title('SD= '+str(TITLE)+'[#]') +plt.xscale('log') +plt.xlim((1e-13, 1e-0)) +plt.grid(True) +plt.legend(title='sstp_coal') +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +plt.xlabel(r'$q_r$ [kg/kg]') +plt.ylabel('# of cells') +plt.savefig(outfile+'hist_'+str(TITLE_save)+'.png') \ No newline at end of file diff --git a/Rain_distribution/rain_histogram_multi_SD1k.py b/Rain_distribution/rain_histogram_multi_SD1k.py new file mode 100644 index 0000000..fb9eacb --- /dev/null +++ b/Rain_distribution/rain_histogram_multi_SD1k.py @@ -0,0 +1,111 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ +UPDATE + +python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/no_Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/ +Singularity> python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD100/classic/ + +''' +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +# paths = argv[1] +# outfile = argv[2] +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +def Liczy_histogram(paths, i): + file_names = os.listdir(paths) + + Hist = np.zeros(( len(biny)-1)) + rr_files = np.zeros((len(file_names), len(biny)-1)) + for p in range(len(file_names)): + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' + filename = path + "/timestep" + str(240*i).zfill(10) + ".h5" + rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod * 4. / 3. * 3.1416 * 1e3; # kg/kg + hist = np.histogram(rr, bins=biny) + rr_files[p,:] = hist[0] + Hist = np.mean(rr_files, axis=0) + # Hist_data = np.sum(Hist, axis=0) + # Hist_data = Hist_data/ np.max(Hist_data) + return Hist, hist[1] + +def Run_hist(SD, path, kroki): + return Liczy_histogram(main_path+str(SD)+'/'+str(path)+'/', kroki) +# def Run_hist(SD, kroki): + # return Liczy_histogram(main_path+str(SD)+'/', kroki) + +biny = [1e-14, 1e-13,1e-12,1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2, 1e-1, 1 ] +outfile = '/home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/' +main_path = '/home/pzmij/2D/PAPER/Piggy/SD' +TITLE = 'CLASSIC' +TITLE_save = 'SD10-10k' +partial_fun_1000_VF = functools.partial(Run_hist, '10', "classic") +partial_fun_1000_tail = functools.partial(Run_hist, '50', "classic") +partial_fun_1000_multi = functools.partial(Run_hist, '100', "classic") +partial_fun_1000_multi2 = functools.partial(Run_hist, '1000', "classic") +partial_fun_1000_multi3 = functools.partial(Run_hist, '10000', "classic") +# partial_fun_1000_multi_3 = functools.partial(Run_hist, 'SD10/classic', "multi") +punkty = np.intc(np.linspace(1,90,91)) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic = executor.map(partial_fun_1000_VF, punkty) + Tails = executor.map(partial_fun_1000_tail, punkty) + Multis = executor.map(partial_fun_1000_multi, punkty) + Multis2 = executor.map(partial_fun_1000_multi2, punkty) + Multis3 = executor.map(partial_fun_1000_multi3, punkty) +Class = np.sum([i[0] for i in Classic], axis=0) +Tail = np.sum([i[0] for i in Tails], axis=0) +Multi = np.sum([i[0] for i in Multis], axis=0) +Multi2 = np.sum([i[0] for i in Multis2], axis=0) +Multi3 = np.sum([i[0] for i in Multis3], axis=0) + +plt.figure(0) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +# plt.step(biny[1:], Multi2, c='k', label="5", linewidth=9) +plt.step(biny[1:], Class, c='y', label="10", linewidth=9) +plt.step(biny[1:], Tail, c='r', label='50', linewidth=9) +plt.step(biny[1:], Multi, c='g', label='100', linewidth=9) +plt.step(biny[1:], Multi2, c='k', label="1000", linewidth=9) +plt.step(biny[1:], Multi3, c='m', label="10000", linewidth=9) +# plt.title('SD= '+str(TITLE)+'[#]') +plt.title(str(TITLE)) +plt.xscale('log') +plt.xlim((1e-13, 1e-0)) +plt.grid(True) +plt.legend(title='SD [#]:') +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +plt.xlabel(r'$q_r$ [kg/kg]') +plt.ylabel('# of cells') +plt.savefig(outfile+'hist_'+str(TITLE_save)+'.png') diff --git a/Rain_distribution/rain_histogram_vol2.py b/Rain_distribution/rain_histogram_vol2.py new file mode 100644 index 0000000..06c5bd2 --- /dev/null +++ b/Rain_distribution/rain_histogram_vol2.py @@ -0,0 +1,67 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ +UPDATE + +python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/no_Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/ +Singularity> python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD100/classic/ + +''' +import cProfile, pstats +import h5py +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +plt.rcParams.update({'font.size': 20}) +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) + +timesteps = [i*240 for i in range(1, 91)] +def Liczy_histogram(paths): + file_names = os.listdir(paths) + bin = [1e-14, 1e-13,1e-12,1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2, 1e-1 ] + Hist = np.zeros((len(timesteps), len(bin)-1)) + for timestep in timesteps: + rr_files = np.zeros((len(file_names), len(bin)-1)) + for p in range(len(file_names)): + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' + filename = path + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod * 4. / 3. * 3.1416 * 1e3; # kg/kg + hist = np.histogram(rr, bins=bin) + rr_files[p,:] = hist[0] + Hist[int(timestep/240)-1,:] = np.mean(rr_files, axis=0) + Hist_data = np.sum(Hist, axis=0) + # Hist_data = Hist_data/ np.max(Hist_data) + return Hist_data, hist[1] + +plt.figure(0) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +main_path = str(argv[1]) #'/home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD' +sciezka = argv[4::]#['VF','tail','multi'] +outfile = str(argv[2]) #'/home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Rain/' +SD_order = [argv[3]]#[1000] +for path, SD in product(sciezka, SD_order): + Class, biny = Liczy_histogram(main_path+str(SD)+'/'+path+'/') + plt.step(biny[1:], Class, label=path, linewidth=9) +plt.title('SD= '+str(SD)+'[#]') +plt.xscale('log') +plt.xlim((1e-13, 1e-1)) +plt.grid(True) +plt.legend() +plt.xlabel(r'$q_r$ [kg/kg]') +plt.ylabel('# of cells') +plt.savefig(outfile+'histogram_SD_'+str(SD)+'.png') diff --git a/Rain_distribution/rain_histogram_vol2_SD_compare.py b/Rain_distribution/rain_histogram_vol2_SD_compare.py new file mode 100644 index 0000000..31c4df4 --- /dev/null +++ b/Rain_distribution/rain_histogram_vol2_SD_compare.py @@ -0,0 +1,162 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ +UPDATE + +python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/no_Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/ +Singularity> python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD100/classic/ + +''' + +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +plt.rcParams.update({'font.size': 20}) + + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +# paths = argv[1] +# outfile = argv[2] + +def Liczy_histogram(paths): + timesteps = np.ones(91) + for i in range(1, 91): + timesteps[i] = i*240 + timesteps = timesteps[1:91] + file_names = os.listdir(paths) + pliki = [ i for i in range(len(file_names))] + bin = [1e-14, 1e-13,1e-12,1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2, 1e-1 ] + Hist = np.zeros((len(timesteps), len(bin)-1)) + for timestep in timesteps: + rr_files = np.zeros((len(file_names), len(bin)-1)) + for p in range(len(file_names)): + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' + filename = path + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + # rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + + # cloudiness mask - as in RICO paper + # cloudy_mask = np.where(rl > 1e-5, 1, 0) + # cloudy_mask_used = cloudy_mask + + RR = rr + + hist = np.histogram(RR, bins=bin) + new_bin = hist[1] + rr_files[p,:] = hist[0] + + Hist[int(timestep/240)-1,:] = np.mean(rr_files, axis=0) + Hist_data = np.sum(Hist, axis=0) + # Hist_data = Hist_data/ np.max(Hist_data) + return Hist_data, hist[1] + + +SD_order = [10, 100, 1000] +# for SD in SD_order: +# sciezka = ['/home/pzmij/2D/PAPER/Piggy/SD'+str(SD)+'/classic/','/home/pzmij/2D/PAPER/Piggy/SD'+str(SD)+'/tail/','/home/pzmij/2D/PAPER/Piggy/SD'+str(SD)+'/multi/'] +outfile = '/home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD'#+str(SD)+'/comp/' +outfile2 = '/home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/' + # print(SD) + # Classic, biny = Liczy_histogram(sciezka[0]) + # print('tail') + # tail = Liczy_histogram(sciezka[1])[0] + # print('multi') + # multi = Liczy_histogram(sciezka[2])[0] + # + # np.save(outfile+'classic_no_mask'+str(SD), Classic) + # np.save(outfile+'tail_no_mask'+str(SD), tail) + # np.save(outfile+'multi_no_mask'+str(SD), multi) + # np.save(outfile+'biny_no_mask'+str(SD), biny) +#SD1 +Classic_10 = np.load(outfile+'10/comp/classic_no_mask10.npy') +tail_10 = np.load(outfile+'10/comp/tail_no_mask10.npy') +multi_10 = np.load(outfile+'10/comp/multi_no_mask10.npy') +#SD10 +Classic_100 = np.load(outfile+'100/comp/classic_no_mask100.npy') +tail_100 = np.load(outfile+'100/comp/tail_no_mask100.npy') +multi_100 = np.load(outfile+'100/comp/multi_no_mask100.npy') +#SD10 +Classic_1000 = np.load(outfile+'1000/comp/classic_no_mask1000.npy') +tail_1000 = np.load(outfile+'1000/comp/tail_no_mask1000.npy') +multi_1000 = np.load(outfile+'1000/comp/multi_no_mask1000.npy') +biny = np.load(outfile+'10/comp/biny_no_mask10.npy') + +plt.figure(0) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +plt.step(biny[1:], Classic_10, c='y', label="SD10", linewidth=9) +plt.step(biny[1:], Classic_100, c='g', label='SD100', linewidth=9) +plt.step(biny[1:], Classic_1000, c='r', label='SD1000', linewidth=9) +plt.title('Classic') +plt.xscale('log') +plt.xlim((1e-13, 1e-1)) +plt.grid(True) +plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) +plt.xlabel(r'$q_r$ [kg/kg]') +plt.ylabel('# of cells') +plt.savefig(outfile2+'hist_no_mask_piggy_Classic.png') + +plt.figure(0) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +plt.step(biny[1:], tail_10, c='y', label="SD10", linewidth=9) +plt.step(biny[1:], tail_100, c='g', label='SD100', linewidth=9) +plt.step(biny[1:], tail_1000, c='r', label='SD1000', linewidth=9) +plt.title('Tail') +plt.xscale('log') +plt.xlim((1e-13, 1e-1)) +plt.grid(True) +plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) +plt.xlabel(r'$q_r$ [kg/kg]') +plt.ylabel('# of cells') +plt.savefig(outfile2+'hist_no_mask_piggy_Tail.png') + +plt.figure(0) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +plt.step(biny[1:], multi_10, c='y', label="SD10", linewidth=9) +plt.step(biny[1:], multi_100, c='g', label='SD100', linewidth=9) +plt.step(biny[1:], multi_1000, c='r', label='SD1000', linewidth=9) +plt.title('Multi') +plt.xscale('log') +plt.xlim((1e-13, 1e-1)) +plt.grid(True) +plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) +plt.xlabel(r'$q_r$ [kg/kg]') +plt.ylabel('# of cells') +plt.savefig(outfile2+'hist_no_mask_piggy_Multi.png') + + # plt.figure(1) + # plt.rcParams.update({'font.size': 40}) + # plt.figure(figsize=(40,40)) + # plt.step(biny[1:], Classic/np.max(Classic), c='y', label="classic", linewidth=6) + # plt.step(biny[1:], tail/np.max(tail), c='r', label='tail', linewidth=6) + # plt.step(biny[1:], multi/np.max(multi), c='g', label='multi', linewidth=6) + # plt.title('SD= '+str(SD)+'[#]') + # plt.xscale('log') + # plt.xlim((1e-13, 1e-1)) + # plt.grid(linestyle=':') + # plt.legend() + # # plt.suptitle('Current time {}s '.format(int(timestep/2))) + # plt.xlabel(r'$q_r$ [kg/kg]') + # plt.ylabel('# of cells') + # plt.savefig(outfile+'hist_no_mask_norm_piggy_SD_'+str(SD)+'.png') diff --git a/Rain_distribution/rain_histogram_vol2_no_piggy.py b/Rain_distribution/rain_histogram_vol2_no_piggy.py new file mode 100644 index 0000000..0de8afb --- /dev/null +++ b/Rain_distribution/rain_histogram_vol2_no_piggy.py @@ -0,0 +1,104 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ +UPDATE + +python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/no_Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/ +Singularity> python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD100/classic/ + +''' + +import h5py +import numpy as np +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes + + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +# paths = argv[1] +# outfile = argv[2] + +def Liczy_histogram(paths): + timesteps = np.ones(91) + for i in range(1, 91): + timesteps[i] = i*240 + timesteps = timesteps[1:91] + file_names = os.listdir(paths) + pliki = [ i for i in range(len(file_names))] + bin = [1e-14, 1e-13,1e-12,1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2, 1e-1 ] + Hist = np.zeros((len(timesteps), len(bin)-1)) + for timestep in timesteps: + rr_files = np.zeros((len(file_names), len(bin)-1)) + for p in range(len(file_names)): + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' + filename = path + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + # rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + + # cloudiness mask - as in RICO paper + # cloudy_mask = np.where(rl > 1e-5, 1, 0) + # cloudy_mask_used = cloudy_mask + + RR = rr + + hist = np.histogram(RR, bins=bin) + new_bin = hist[1] + rr_files[p,:] = hist[0] + + Hist[int(timestep/240)-1,:] = np.mean(rr_files, axis=0) + Hist_data = np.sum(Hist, axis=0) + # Hist_data = Hist_data/ np.max(Hist_data) + return Hist_data, hist[1] + + +SD_order = [10, 100, 1000] +for SD in SD_order: + sciezka = ['/home/pzmij/2D/PAPER/no_Piggy/SD'+str(SD)+'/classic/','/home/pzmij/2D/PAPER/no_Piggy/SD'+str(SD)+'/tail/','/home/pzmij/2D/PAPER/no_Piggy/SD'+str(SD)+'/multi/'] + outfile = '/home/pzmij/2D/PAPER/Wyniki/New_hist/no_Piggy/SD'+str(SD)+'/comp/' + # print(SD) + # Classic, biny = Liczy_histogram(sciezka[0]) + # print('tail') + # tail = Liczy_histogram(sciezka[1])[0] + # print('multi') + # multi = Liczy_histogram(sciezka[2])[0] + # + # np.save(outfile+'classic_no_mask'+str(SD), Classic) + # np.save(outfile+'tail_no_mask'+str(SD), tail) + # np.save(outfile+'multi_no_mask'+str(SD), multi) + # np.save(outfile+'biny_no_mask'+str(SD), biny) + + Classic = np.load(outfile+'classic_no_mask'+str(SD)+'.npy') + tail = np.load(outfile+'tail_no_mask'+str(SD)+'.npy') + multi = np.load(outfile+'multi_no_mask'+str(SD)+'.npy') + biny = np.load(outfile+'biny_no_mask'+str(SD)+'.npy') + + plt.figure(0) + plt.rcParams.update({'font.size': 40}) + plt.figure(figsize=(40,40)) + plt.step(biny[1:], Classic, c='y', label="classic", linewidth=9) + plt.step(biny[1:], tail, c='r', label='tail', linewidth=9) + plt.step(biny[1:], multi, c='g', label='multi', linewidth=9) + plt.title('SD= '+str(SD)+'[#]') + plt.xscale('log') + plt.xlim((1e-13, 1e-1)) + plt.grid(True) + plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + plt.xlabel(r'$q_r$ [kg/kg]') + plt.ylabel('# of cells') + plt.savefig(outfile+'hist_no_mask_no_piggy_SD_'+str(SD)+'.png') From c3413e6f078aad7b577817756762266923a69e8f Mon Sep 17 00:00:00 2001 From: ryba183 Date: Thu, 20 Jan 2022 15:52:51 +0100 Subject: [PATCH 29/30] Distribution plots --- NC_vs_AF/Randomness/Distribution/Compare.py | 172 +++++++++++++++ NC_vs_AF/Randomness/Distribution/Piggy.py | 168 +++++++++++++++ NC_vs_AF/Randomness/Distribution/Piggy_2.py | 168 +++++++++++++++ ...an_2D_fun_ICCP_rysy_single_Piggy_1_vs_2.py | 170 +++++++++++++++ ...TD_mean_2D_fun_ICCP_rysy_single_Piggy_2.py | 169 +++++++++++++++ .../STD_mean_2D_fun_ICCP_rysy_single_SD100.py | 167 +++++++++++++++ ...n_2D_fun_ICCP_rysy_single_SD10_vs_SD100.py | 173 +++++++++++++++ ...tion_from_mom0_and_3_piggy_classic_m_cb.py | 160 ++++++++++++++ ...ution_from_mom0_and_3_piggy_classic_m_g.py | 160 ++++++++++++++ ...ion_from_mom0_and_3_piggy_classic_nm_cb.py | 160 ++++++++++++++ ...tion_from_mom0_and_3_piggy_classic_nm_g.py | 160 ++++++++++++++ .../Piggy/classic/Srednia_po_czasie_test.py | 172 +++++++++++++++ ...tion_from_mom0_and_3_piggy_compare_m_cb.py | 197 ++++++++++++++++++ ...ution_from_mom0_and_3_piggy_compare_m_g.py | 197 ++++++++++++++++++ ...ion_from_mom0_and_3_piggy_compare_nm_cb.py | 197 ++++++++++++++++++ ...tion_from_mom0_and_3_piggy_compare_nm_g.py | 196 +++++++++++++++++ ...ibution_from_mom0_and_3_piggy_tail_m_cb.py | 160 ++++++++++++++ ...ribution_from_mom0_and_3_piggy_tail_m_g.py | 160 ++++++++++++++ ...bution_from_mom0_and_3_piggy_tail_nm_cb.py | 160 ++++++++++++++ ...ibution_from_mom0_and_3_piggy_tail_nm_g.py | 160 ++++++++++++++ ...on_from_mom0_and_3_piggy_2_classic_m_cb.py | 160 ++++++++++++++ ...ion_from_mom0_and_3_piggy_2_classic_m_g.py | 160 ++++++++++++++ ...n_from_mom0_and_3_piggy_2_classic_nm_cb.py | 160 ++++++++++++++ ...on_from_mom0_and_3_piggy_2_classic_nm_g.py | 160 ++++++++++++++ ...on_from_mom0_and_3_piggy_2_compare_m_cb.py | 197 ++++++++++++++++++ ...ion_from_mom0_and_3_piggy_2_compare_m_g.py | 197 ++++++++++++++++++ ...n_from_mom0_and_3_piggy_2_compare_nm_cb.py | 197 ++++++++++++++++++ ...on_from_mom0_and_3_piggy_2_compare_nm_g.py | 197 ++++++++++++++++++ ...ution_from_mom0_and_3_piggy_2_tail_m_cb.py | 160 ++++++++++++++ ...bution_from_mom0_and_3_piggy_2_tail_m_g.py | 160 ++++++++++++++ ...tion_from_mom0_and_3_piggy_2_tail_nm_cb.py | 160 ++++++++++++++ ...ution_from_mom0_and_3_piggy_2_tail_nm_g.py | 160 ++++++++++++++ .../Distribution/Piggy_2/test.sh | 4 + Rain_distribution/Distribution_from_mom0.py | 158 ++++++++++++++ .../Distribution_from_mom0_Piggy.py | 147 +++++++++++++ .../Distribution_from_mom0_Piggy_2.py | 161 ++++++++++++++ .../Distribution_from_mom0_and_3.py | 164 +++++++++++++++ ...Distribution_from_mom0_and_3_piggy_2_cb.py | 158 ++++++++++++++ ...tion_from_mom0_and_3_piggy_2_cb_no_mask.py | 158 ++++++++++++++ ...ribution_from_mom0_and_3_piggy_2_ground.py | 158 ++++++++++++++ ..._from_mom0_and_3_piggy_2_ground_no_mask.py | 158 ++++++++++++++ ...Distribution_from_mom0_and_3_piggy_tail.py | 176 ++++++++++++++++ ...bution_from_mom0_and_3_piggy_tail_cb_nm.py | 176 ++++++++++++++++ ...ution_from_mom0_and_3_piggy_tail_ground.py | 176 ++++++++++++++++ ...on_from_mom0_and_3_piggy_tail_ground_nm.py | 176 ++++++++++++++++ .../Distribution_from_mom0_ground.py | 158 ++++++++++++++ .../Distribution_from_mom0_ground_Piggy.py | 148 +++++++++++++ .../Distribution_from_mom0_ground_Piggy_2.py | 158 ++++++++++++++ ...istribution_from_mom0_ground_Piggy_tail.py | 156 ++++++++++++++ .../Rain_many_copare_time_line_21_12.py | 18 +- Rain_distribution/rain_histogram.py | 5 +- .../rain_histogram_multi_Piggy2.py | 115 ++++++++++ .../rain_histogram_multi_SD1k.py | 6 +- .../rain_histogram_multi_coal.py | 110 ++++++++++ 54 files changed, 8327 insertions(+), 11 deletions(-) create mode 100644 NC_vs_AF/Randomness/Distribution/Compare.py create mode 100644 NC_vs_AF/Randomness/Distribution/Piggy.py create mode 100644 NC_vs_AF/Randomness/Distribution/Piggy_2.py create mode 100644 NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_Piggy_1_vs_2.py create mode 100644 NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_Piggy_2.py create mode 100644 NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_SD100.py create mode 100644 NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_SD10_vs_SD100.py create mode 100644 Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy/classic/Srednia_po_czasie_test.py create mode 100644 Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/test.sh create mode 100644 Rain_distribution/Distribution_from_mom0.py create mode 100644 Rain_distribution/Distribution_from_mom0_Piggy.py create mode 100644 Rain_distribution/Distribution_from_mom0_Piggy_2.py create mode 100644 Rain_distribution/Distribution_from_mom0_and_3.py create mode 100644 Rain_distribution/Distribution_from_mom0_and_3_piggy_2_cb.py create mode 100644 Rain_distribution/Distribution_from_mom0_and_3_piggy_2_cb_no_mask.py create mode 100644 Rain_distribution/Distribution_from_mom0_and_3_piggy_2_ground.py create mode 100644 Rain_distribution/Distribution_from_mom0_and_3_piggy_2_ground_no_mask.py create mode 100644 Rain_distribution/Distribution_from_mom0_and_3_piggy_tail.py create mode 100644 Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_cb_nm.py create mode 100644 Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_ground.py create mode 100644 Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_ground_nm.py create mode 100644 Rain_distribution/Distribution_from_mom0_ground.py create mode 100644 Rain_distribution/Distribution_from_mom0_ground_Piggy.py create mode 100644 Rain_distribution/Distribution_from_mom0_ground_Piggy_2.py create mode 100644 Rain_distribution/Distribution_from_mom0_ground_Piggy_tail.py create mode 100644 Rain_distribution/rain_histogram_multi_Piggy2.py create mode 100644 Rain_distribution/rain_histogram_multi_coal.py diff --git a/NC_vs_AF/Randomness/Distribution/Compare.py b/NC_vs_AF/Randomness/Distribution/Compare.py new file mode 100644 index 0000000..4a83620 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Compare.py @@ -0,0 +1,172 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['100', '1000', '10000'] +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_tail/'] +name = 'Piggy_2_Distribution' +text_diff_piggy = 'Classic_M1' +text_diff_piggy2 = 'Classic_M2' +text_diff_piggy3 = 'Tail_M1' +text_diff_piggy4 = 'Tail_M2' +podpisy = [text_diff_piggy, text_diff_piggy2, text_diff_piggy3, text_diff_piggy4] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.57 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 25e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Piggy.py b/NC_vs_AF/Randomness/Distribution/Piggy.py new file mode 100644 index 0000000..04ab7f1 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Piggy.py @@ -0,0 +1,168 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['100', '1000', '10000'] +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_tail/'] +name = 'Piggy_Distribution' +text_diff_piggy = 'Classic' +text_diff_piggy2 = 'Tail' +podpisy = [text_diff_piggy, text_diff_piggy2] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/barrs/' +width_multiplier = 0.57 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 25e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Piggy_2.py b/NC_vs_AF/Randomness/Distribution/Piggy_2.py new file mode 100644 index 0000000..4be9f3f --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Piggy_2.py @@ -0,0 +1,168 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['100', '1000', '10000'] +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_tail/'] +name = 'Piggy_2_Distribution' +text_diff_piggy = 'Classic' +text_diff_piggy2 = 'Tail' +podpisy = [text_diff_piggy, text_diff_piggy2] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/barrs/' +width_multiplier = 0.57 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 25e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_Piggy_1_vs_2.py b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_Piggy_1_vs_2.py new file mode 100644 index 0000000..94e5f84 --- /dev/null +++ b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_Piggy_1_vs_2.py @@ -0,0 +1,170 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['10', '50', '100', '1000', '10000', '70000'] +paths = ['/home/pzmij/2D/PAPER/Piggy/SD10/times_classic','/home/pzmij/2D/PAPER/Piggy/SD50/times_classic','/home/pzmij/2D/PAPER/Piggy/SD100/times_classic', + '/home/pzmij/2D/PAPER/Piggy/SD1000/times_classic','/home/pzmij/2D/PAPER/Piggy/SD10000/times_classic','/home/pzmij/2D/PAPER/Piggy/SD70000/times_classic', + '/home/pzmij/2D/PAPER/Piggy_2/series_SD10_dat', '/home/pzmij/2D/PAPER/Piggy_2/series_SD50_dat', '/home/pzmij/2D/PAPER/Piggy_2/series_SD100_dat', + '/home/pzmij/2D/PAPER/Piggy_2/series_SD1000_dat', '/home/pzmij/2D/PAPER/Piggy_2/series_SD10000_dat', '/home/pzmij/2D/PAPER/Piggy_2/series_SD70000_dat'] +name = 'Piggy_Classic_master_1_vs_2' +text_diff_piggy = 'Classic_master_1' +text_diff_piggy2 = 'Classic_master_2' +podpisy = [text_diff_piggy, text_diff_piggy2] +outfile = '/home/pzmij/2D/PAPER/Wyniki/STD_barrs/Piggy/' +width_multiplier = 0.37 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 25e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_Piggy_2.py b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_Piggy_2.py new file mode 100644 index 0000000..bd493d4 --- /dev/null +++ b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_Piggy_2.py @@ -0,0 +1,169 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 19}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['10', '50', '100', '1000', '10000', '70000'] +paths = ['/home/pzmij/2D/PAPER/Piggy_2/series_SD10_dat','/home/pzmij/2D/PAPER/Piggy_2/series_SD50_dat', + '/home/pzmij/2D/PAPER/Piggy_2/series_SD100_dat','/home/pzmij/2D/PAPER/Piggy_2/series_SD1000_dat', + '/home/pzmij/2D/PAPER/Piggy_2/series_SD10000_dat','/home/pzmij/2D/PAPER/Piggy_2/series_SD70000_dat'] +name = 'Piggy_Classic_master_2' +text_diff_piggy2 = 'Classic' +text_diff_piggy = 'Classic_SD100' +podpisy = [text_diff_piggy2] +outfile = '/home/pzmij/2D/PAPER/Wyniki/STD_barrs/Piggy/' +width_multiplier = 0.37 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.2 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 25e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_SD100.py b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_SD100.py new file mode 100644 index 0000000..540e644 --- /dev/null +++ b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_SD100.py @@ -0,0 +1,167 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 19}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['5', '25', '50', '100'] +paths = ['/home/pzmij/2D/PAPER/Piggy/SD100/times_classic','/home/pzmij/2D/PAPER/Piggy/times_coal/SD100_coal25', + '/home/pzmij/2D/PAPER/Piggy/times_coal/SD100_coal50','/home/pzmij/2D/PAPER/Piggy/times_coal/SD100_coal100'] +name = 'Coal_comparison_SD100' +text_diff_piggy_VF = 'Classic_SD#100' +podpisy = [text_diff_piggy_VF] +outfile = '/home/pzmij/2D/PAPER/Wyniki/STD_barrs/Piggy/' +width_multiplier = 0.65 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.25 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="sstp_coal: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 4e-2) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="sstp_coal ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 15e-3) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="sstp_coal ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_SD10_vs_SD100.py b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_SD10_vs_SD100.py new file mode 100644 index 0000000..3391c8c --- /dev/null +++ b/NC_vs_AF/Randomness/STD_mean_2D_fun_ICCP_rysy_single_SD10_vs_SD100.py @@ -0,0 +1,173 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 19}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['5', '25', '50', '100'] +# paths = ['/home/pzmij/2D/PAPER/Piggy/SD10/times_classic','/home/pzmij/2D/PAPER/Piggy/SD100/times_classic', + # '/home/pzmij/2D/PAPER/Piggy/times_coal/SD10_coal25','/home/pzmij/2D/PAPER/Piggy/times_coal/SD100_coal25', + # '/home/pzmij/2D/PAPER/Piggy/times_coal/SD10_coal50','/home/pzmij/2D/PAPER/Piggy/times_coal/SD100_coal50', + # '/home/pzmij/2D/PAPER/Piggy/times_coal/SD10_coal100','/home/pzmij/2D/PAPER/Piggy/times_coal/SD100_coal100'] +paths = ['/home/pzmij/2D/PAPER/Piggy/SD10/times_classic','/home/pzmij/2D/PAPER/Piggy/times_coal/SD10_coal25','/home/pzmij/2D/PAPER/Piggy/times_coal/SD10_coal50', + '/home/pzmij/2D/PAPER/Piggy/times_coal/SD10_coal100','/home/pzmij/2D/PAPER/Piggy/SD100/times_classic','/home/pzmij/2D/PAPER/Piggy/times_coal/SD100_coal25', + '/home/pzmij/2D/PAPER/Piggy/times_coal/SD100_coal50','/home/pzmij/2D/PAPER/Piggy/times_coal/SD100_coal100'] +name = 'Coal_comparison_SD10_vs_SD100' +text_diff_piggy_SD10 = 'Classic_SD10' +text_diff_piggy_SD100 = 'Classic_SD100' +podpisy = [text_diff_piggy_SD10, text_diff_piggy_SD100] +outfile = '/home/pzmij/2D/PAPER/Wyniki/STD_barrs/Piggy/' +width_multiplier = 0.67 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.25 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="sstp_coal: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="sstp_coal ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 12e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="sstp_coal ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_m_cb.py b/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_m_cb.py new file mode 100644 index 0000000..dfb1142 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_m_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/classic/mask/cb/' +name = 'Piggy_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_m_g.py b/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_m_g.py new file mode 100644 index 0000000..ff1e89b --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_m_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/classic/mask/g/' +name = 'Piggy_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_nm_cb.py b/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_nm_cb.py new file mode 100644 index 0000000..f48ad5e --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_nm_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/classic/no_mask/cb/' +name = 'Piggy_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_nm_g.py b/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_nm_g.py new file mode 100644 index 0000000..e22b51a --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/classic/Distribution_from_mom0_and_3_piggy_classic_nm_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/classic/no_mask/g/' +name = 'Piggy_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/classic/Srednia_po_czasie_test.py b/Rain_distribution/Distribution/Piggy/classic/Srednia_po_czasie_test.py new file mode 100644 index 0000000..faa180c --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/classic/Srednia_po_czasie_test.py @@ -0,0 +1,172 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/classic/mask/cb/' +name = 'Piggy_Average_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_m_cb.py b/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_m_cb.py new file mode 100644 index 0000000..9c47482 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_m_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/compare/mask/cb/' +name = 'Piggy_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_m_g.py b/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_m_g.py new file mode 100644 index 0000000..10c5127 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_m_g.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/compare/mask/g/' +name = 'Piggy_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_nm_cb.py b/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_nm_cb.py new file mode 100644 index 0000000..a34f221 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_nm_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/compare/no_mask/cb/' +name = 'Piggy_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_nm_g.py b/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_nm_g.py new file mode 100644 index 0000000..eeadcd7 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/mix/Distribution_from_mom0_and_3_piggy_compare_nm_g.py @@ -0,0 +1,196 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/compare/no_mask/g/' +name = 'Piggy_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_m_cb.py b/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_m_cb.py new file mode 100644 index 0000000..3f624ec --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_m_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/tail/mask/cb/' +name = 'Piggy_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_m_g.py b/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_m_g.py new file mode 100644 index 0000000..a46ae3d --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_m_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/tail/mask/g/' +name = 'Piggy_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_nm_cb.py b/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_nm_cb.py new file mode 100644 index 0000000..3d99644 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_nm_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/tail/no_mask/cb/' +name = 'Piggy_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_nm_g.py b/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_nm_g.py new file mode 100644 index 0000000..bdd9c9e --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/tail/Distribution_from_mom0_and_3_piggy_tail_nm_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/tail/no_mask/g/' +name = 'Piggy_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py b/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py new file mode 100644 index 0000000..7d54e8e --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/classic/mask/cb/' +name = 'Piggy_2_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py b/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py new file mode 100644 index 0000000..57a6217 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/classic/mask/g/' +name = 'Piggy_2_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py b/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py new file mode 100644 index 0000000..36cf7e6 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/classic/no_mask/cb/' +name = 'Piggy_2_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py b/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py new file mode 100644 index 0000000..cc69fe8 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/classic/no_mask/g/' +name = 'Piggy_2_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py b/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py new file mode 100644 index 0000000..96bd021 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/compare/mask/cb/' +name = 'Piggy_2_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py b/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py new file mode 100644 index 0000000..9bcd0bf --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/compare/mask/g/' +name = 'Piggy_2_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py b/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py new file mode 100644 index 0000000..85a78e9 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/compare/no_mask/cb/' +name = 'Piggy_2_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py b/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py new file mode 100644 index 0000000..8dea9b2 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/compare/no_mask/g/' +name = 'Piggy_2_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py b/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py new file mode 100644 index 0000000..b5e0f96 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/tail/mask/cb/' +name = 'Piggy_2_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py b/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py new file mode 100644 index 0000000..79f74fe --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/tail/mask/g/' +name = 'Piggy_2_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py b/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py new file mode 100644 index 0000000..2997a8b --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/tail/no_mask/cb/' +name = 'Piggy_2_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py b/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py new file mode 100644 index 0000000..5d5babd --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/tail/no_mask/g/' +name = 'Piggy_2_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/test.sh b/Rain_distribution/Distribution/Piggy_2/test.sh new file mode 100644 index 0000000..e5ace65 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/test.sh @@ -0,0 +1,4 @@ + +for files in /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/Distribution/Piggy_2/mix/*; do + echo $files + done diff --git a/Rain_distribution/Distribution_from_mom0.py b/Rain_distribution/Distribution_from_mom0.py new file mode 100644 index 0000000..97741ef --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0.py @@ -0,0 +1,158 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_drom_mom0/Piggy_2/' +name = 'histrogram_' + +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy_2/SD10/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy_2/SD50/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy_2/SD100/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy_2/SD1000/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy_2/SD10000/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Piggy_2/SD70000/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja = [0 for i in range(nr_files)] + wynik = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik[file] = dystrybucja[file][0]* rainy_mask[:,int(min_hght/100)-1] + wynik[file][wynik[file]==0]=np.nan + srednia = np.nanmean(wynik) + STD = np.nanstd(wynik) + return srednia, STD + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_1 = np.zeros((91, 29)) +odchylenie_1 = np.zeros((91, 29)) +Srednie_2 = np.zeros((91, 29)) +odchylenie_2 = np.zeros((91, 29)) +Srednie_3 = np.zeros((91, 29)) +odchylenie_3 = np.zeros((91, 29)) +Srednie_4 = np.zeros((91, 29)) +odchylenie_4 = np.zeros((91, 29)) +Srednie_5 = np.zeros((91, 29)) +odchylenie_5 = np.zeros((91, 29)) +Srednie_6 = np.zeros((91, 29)) +odchylenie_6 = np.zeros((91, 29)) + +plt.rcParams.update({'font.size': 40}) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +for i in range(91): + plt.clf() + for j in range(29): + Srednie_1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_3[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_3[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_6[i][j] = (((Class_6[i])[0])[j])[1] + plt.step(biny[1:-1], Srednie_1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + plt.step(biny[1:-1], Srednie_2[i]/biny_diff[0], c='k', linewidth=9, label='SD50') + plt.step(biny[1:-1], Srednie_3[i]/biny_diff[0], c='r', linewidth=9, label='SD100') + plt.step(biny[1:-1], Srednie_4[i]/biny_diff[0], c='b', linewidth=9, label='SD1000') + plt.step(biny[1:-1], Srednie_5[i]/biny_diff[0], c='y', linewidth=9, label='SD10000') + plt.step(biny[1:-1], Srednie_6[i]/biny_diff[0], c='m', linewidth=9, label='SD70000') + plt.title('time= '+str(i*120)+'[s]') + plt.xscale('log') + plt.yscale('log') + plt.ylim(bottom=0) + plt.grid(True) + plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + plt.xlabel(r'r [m]') + plt.ylabel('n(ln r) [# of droplets/ d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_Piggy.py b/Rain_distribution/Distribution_from_mom0_Piggy.py new file mode 100644 index 0000000..e3ceb9f --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_Piggy.py @@ -0,0 +1,147 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0/Piggy_ziemia/' +name = 'histrogram_base_no_mask' + +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy/SD10_distribution_2/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy/SD100_distribution/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy/SD1000_distribution/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy/SD10000_distribution_2/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja = [0 for i in range(nr_files)] + wynik = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik[file] = dystrybucja[file][:,int(min_hght/100)-1] #*rainy_mask[:,int(min_hght/100)-1] + wynik[file][wynik[file]==0]=np.nan + srednia = np.nanmean(wynik) + STD = np.nanstd(wynik) + return srednia, STD + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) + +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_1 = np.zeros((91, 29)) +odchylenie_1 = np.zeros((91, 29)) +Srednie_2 = np.zeros((91, 29)) +odchylenie_2 = np.zeros((91, 29)) +Srednie_3 = np.zeros((91, 29)) +odchylenie_3 = np.zeros((91, 29)) +Srednie_4 = np.zeros((91, 29)) +odchylenie_4 = np.zeros((91, 29)) + + +plt.rcParams.update({'font.size': 40}) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +for i in range(91): + plt.clf() + for j in range(29): + Srednie_1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_3[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_3[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_4[i][j] = (((Class_4[i])[0])[j])[1] + + plt.step(biny[1:-1], Srednie_1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + plt.step(biny[1:-1], Srednie_2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + plt.step(biny[1:-1], Srednie_3[i]/biny_diff[0], c='r', linewidth=9, label='SD1000') + plt.step(biny[1:-1], Srednie_4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + + plt.title('time= '+str(i*120)+'[s]') + plt.xscale('log') + plt.yscale('log') + plt.ylim(bottom=0) + plt.grid(True) + plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + plt.xlabel(r'r [m]') + plt.ylabel('n(ln r) [# of droplets/ d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') diff --git a/Rain_distribution/Distribution_from_mom0_Piggy_2.py b/Rain_distribution/Distribution_from_mom0_Piggy_2.py new file mode 100644 index 0000000..29f1feb --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_Piggy_2.py @@ -0,0 +1,161 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0/Piggy_2_ziemia/' +name = 'histrogram_base_no_mask' + +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy_2/SD10/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy_2/SD50/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy_2/SD100/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy_2/SD1000/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy_2/SD10000/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Piggy_2/SD70000/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja = [0 for i in range(nr_files)] + wynik = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik[file] = dystrybucja[file][:,int(min_hght/100)-1] #*rainy_mask[:,int(min_hght/100)-1] + wynik[file][wynik[file]==0]=np.nan + srednia = np.nanmean(wynik) + STD = np.nanstd(wynik) + return srednia, STD + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_1 = np.zeros((91, 29)) +odchylenie_1 = np.zeros((91, 29)) +Srednie_2 = np.zeros((91, 29)) +odchylenie_2 = np.zeros((91, 29)) +Srednie_3 = np.zeros((91, 29)) +odchylenie_3 = np.zeros((91, 29)) +Srednie_4 = np.zeros((91, 29)) +odchylenie_4 = np.zeros((91, 29)) +Srednie_5 = np.zeros((91, 29)) +odchylenie_5 = np.zeros((91, 29)) +Srednie_6 = np.zeros((91, 29)) +odchylenie_6 = np.zeros((91, 29)) + +plt.rcParams.update({'font.size': 40}) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +for i in range(91): + plt.clf() + for j in range(29): + Srednie_1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_3[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_3[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_6[i][j] = (((Class_6[i])[0])[j])[1] + plt.step(biny[1:-1], Srednie_1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + plt.step(biny[1:-1], Srednie_2[i]/biny_diff[0], c='k', linewidth=9, label='SD50') + plt.step(biny[1:-1], Srednie_3[i]/biny_diff[0], c='r', linewidth=9, label='SD100') + plt.step(biny[1:-1], Srednie_4[i]/biny_diff[0], c='b', linewidth=9, label='SD1000') + plt.step(biny[1:-1], Srednie_5[i]/biny_diff[0], c='y', linewidth=9, label='SD10000') + plt.step(biny[1:-1], Srednie_6[i]/biny_diff[0], c='m', linewidth=9, label='SD70000') + + plt.title('time= '+str(i*120)+'[s]') + plt.xscale('log') + plt.yscale('log') + plt.ylim(bottom=0) + plt.grid(True) + plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + plt.xlabel(r'r [m]') + plt.ylabel('n(ln r) [# of droplets/ d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') diff --git a/Rain_distribution/Distribution_from_mom0_and_3.py b/Rain_distribution/Distribution_from_mom0_and_3.py new file mode 100644 index 0000000..ceab01e --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_and_3.py @@ -0,0 +1,164 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0_and_3/Piggy_2_11_01/' +name = 'histrogram_Piggi_2_14_01' +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD10/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD100/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD1000/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy/SD10000_tail_distribution_part/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja+29).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 29)) +Srednie_mass1 = np.zeros((91, 29)) +odchylenie_num1 = np.zeros((91, 29)) +Srednie_num2 = np.zeros((91, 29)) +Srednie_mass2 = np.zeros((91, 29)) +odchylenie_num2 = np.zeros((91, 29)) +Srednie_num3 = np.zeros((91, 29)) +Srednie_mass3 = np.zeros((91, 29)) +odchylenie_num3 = np.zeros((91, 29)) +Srednie_num4 = np.zeros((91, 29)) +Srednie_mass4 = np.zeros((91, 29)) +odchylenie_num4 = np.zeros((91, 29)) + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(29): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000_tail') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000_tail') + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_cb.py b/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_cb.py new file mode 100644 index 0000000..9381aea --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_cb.py @@ -0,0 +1,158 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0_and_3/Piggy_2_11_01/' +name = 'histrogram_Piggi_2_real_14_01_cb_no_m' +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD10/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD100/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD1000/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja+29).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) + +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 29)) +Srednie_mass1 = np.zeros((91, 29)) +odchylenie_num1 = np.zeros((91, 29)) +Srednie_num2 = np.zeros((91, 29)) +Srednie_mass2 = np.zeros((91, 29)) +odchylenie_num2 = np.zeros((91, 29)) +Srednie_num3 = np.zeros((91, 29)) +Srednie_mass3 = np.zeros((91, 29)) +odchylenie_num3 = np.zeros((91, 29)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(29): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_cb_no_mask.py b/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_cb_no_mask.py new file mode 100644 index 0000000..aabb4ff --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_cb_no_mask.py @@ -0,0 +1,158 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0_and_3/Piggy_2_11_01/' +name = 'histrogram_Piggi_2_real_14_01_cb_no_mask' +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD10/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD100/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD1000/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja+29).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) + +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 29)) +Srednie_mass1 = np.zeros((91, 29)) +odchylenie_num1 = np.zeros((91, 29)) +Srednie_num2 = np.zeros((91, 29)) +Srednie_mass2 = np.zeros((91, 29)) +odchylenie_num2 = np.zeros((91, 29)) +Srednie_num3 = np.zeros((91, 29)) +Srednie_mass3 = np.zeros((91, 29)) +odchylenie_num3 = np.zeros((91, 29)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(29): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_ground.py b/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_ground.py new file mode 100644 index 0000000..df7444f --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_ground.py @@ -0,0 +1,158 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0_and_3/Piggy_2_11_01/' +name = 'histrogram_Piggi_2_real_14_01_ground' +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD10/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD100/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD1000/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja+29).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) + +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 29)) +Srednie_mass1 = np.zeros((91, 29)) +odchylenie_num1 = np.zeros((91, 29)) +Srednie_num2 = np.zeros((91, 29)) +Srednie_mass2 = np.zeros((91, 29)) +odchylenie_num2 = np.zeros((91, 29)) +Srednie_num3 = np.zeros((91, 29)) +Srednie_mass3 = np.zeros((91, 29)) +odchylenie_num3 = np.zeros((91, 29)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(29): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_ground_no_mask.py b/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_ground_no_mask.py new file mode 100644 index 0000000..d3549ad --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_and_3_piggy_2_ground_no_mask.py @@ -0,0 +1,158 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0_and_3/Piggy_2_11_01/' +name = 'histrogram_Piggi_2_real_14_01_ground_no_mask' +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD10/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD100/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy_2_distr/SD1000/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja+29).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) + +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 29)) +Srednie_mass1 = np.zeros((91, 29)) +odchylenie_num1 = np.zeros((91, 29)) +Srednie_num2 = np.zeros((91, 29)) +Srednie_mass2 = np.zeros((91, 29)) +odchylenie_num2 = np.zeros((91, 29)) +Srednie_num3 = np.zeros((91, 29)) +Srednie_mass3 = np.zeros((91, 29)) +odchylenie_num3 = np.zeros((91, 29)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(29): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail.py b/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail.py new file mode 100644 index 0000000..c4802e0 --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail.py @@ -0,0 +1,176 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0_and_3/Piggy_2_11_01/' +name = 'histrogram_Piggi_2_14_01' +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy/SD10_distribution_2/' +# path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy/SD100_distribution/' +# path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy/SD1000_distribution/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy/SD10000_distribution_2/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy/SD10000_tail_distribution_part/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja+29).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +# partial_fun_2 = functools.partial(Positions, path_to_file_2) +# partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + # Classic_2 = executor.map(partial_fun_2, punkty) + # Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + +Class_1 = [i for i in Classic_1] +# Class_2 = [i for i in Classic_2] +# Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 29)) +Srednie_mass1 = np.zeros((91, 29)) +odchylenie_num1 = np.zeros((91, 29)) +# Srednie_num2 = np.zeros((91, 29)) +# Srednie_mass2 = np.zeros((91, 29)) +# odchylenie_num2 = np.zeros((91, 29)) +# Srednie_num3 = np.zeros((91, 29)) +# Srednie_mass3 = np.zeros((91, 29)) +# odchylenie_num3 = np.zeros((91, 29)) +Srednie_num4 = np.zeros((91, 29)) +Srednie_mass4 = np.zeros((91, 29)) +odchylenie_num4 = np.zeros((91, 29)) +Srednie_num5 = np.zeros((91, 29)) +Srednie_mass5 = np.zeros((91, 29)) +odchylenie_num5 = np.zeros((91, 29)) + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(29): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + # Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + # odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + # Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + # Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + # odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + # Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + # ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + # ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='m', linewidth=9, label='SD10000_tail') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + # ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + # ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='m', linewidth=9, label='SD10000_tail') + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_cb_nm.py b/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_cb_nm.py new file mode 100644 index 0000000..b2420e4 --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_cb_nm.py @@ -0,0 +1,176 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0_and_3/Piggy_2_11_01/' +name = 'histrogram_Piggi_2_14_01_tail_ground_nm' +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy/SD10_distribution_2/' +# path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy/SD100_distribution/' +# path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy/SD1000_distribution/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy/SD10000_distribution_2/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy/SD10000_tail_distribution_part/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja+29).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +# partial_fun_2 = functools.partial(Positions, path_to_file_2) +# partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + # Classic_2 = executor.map(partial_fun_2, punkty) + # Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + +Class_1 = [i for i in Classic_1] +# Class_2 = [i for i in Classic_2] +# Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 29)) +Srednie_mass1 = np.zeros((91, 29)) +odchylenie_num1 = np.zeros((91, 29)) +# Srednie_num2 = np.zeros((91, 29)) +# Srednie_mass2 = np.zeros((91, 29)) +# odchylenie_num2 = np.zeros((91, 29)) +# Srednie_num3 = np.zeros((91, 29)) +# Srednie_mass3 = np.zeros((91, 29)) +# odchylenie_num3 = np.zeros((91, 29)) +Srednie_num4 = np.zeros((91, 29)) +Srednie_mass4 = np.zeros((91, 29)) +odchylenie_num4 = np.zeros((91, 29)) +Srednie_num5 = np.zeros((91, 29)) +Srednie_mass5 = np.zeros((91, 29)) +odchylenie_num5 = np.zeros((91, 29)) + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(29): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + # Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + # odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + # Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + # Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + # odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + # Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + # ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + # ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='m', linewidth=9, label='SD10000_tail') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + # ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + # ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='m', linewidth=9, label='SD10000_tail') + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_ground.py b/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_ground.py new file mode 100644 index 0000000..8d9e750 --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_ground.py @@ -0,0 +1,176 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0_and_3/Piggy_2_11_01/' +name = 'histrogram_Piggi_2_14_01_ground' +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy/SD10_distribution_2/' +# path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy/SD100_distribution/' +# path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy/SD1000_distribution/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy/SD10000_distribution_2/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy/SD10000_tail_distribution_part/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja+29).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +# partial_fun_2 = functools.partial(Positions, path_to_file_2) +# partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + # Classic_2 = executor.map(partial_fun_2, punkty) + # Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + +Class_1 = [i for i in Classic_1] +# Class_2 = [i for i in Classic_2] +# Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 29)) +Srednie_mass1 = np.zeros((91, 29)) +odchylenie_num1 = np.zeros((91, 29)) +# Srednie_num2 = np.zeros((91, 29)) +# Srednie_mass2 = np.zeros((91, 29)) +# odchylenie_num2 = np.zeros((91, 29)) +# Srednie_num3 = np.zeros((91, 29)) +# Srednie_mass3 = np.zeros((91, 29)) +# odchylenie_num3 = np.zeros((91, 29)) +Srednie_num4 = np.zeros((91, 29)) +Srednie_mass4 = np.zeros((91, 29)) +odchylenie_num4 = np.zeros((91, 29)) +Srednie_num5 = np.zeros((91, 29)) +Srednie_mass5 = np.zeros((91, 29)) +odchylenie_num5 = np.zeros((91, 29)) + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(29): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + # Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + # odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + # Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + # Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + # odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + # Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + # ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + # ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='m', linewidth=9, label='SD10000_tail') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + # ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + # ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='m', linewidth=9, label='SD10000_tail') + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_ground_nm.py b/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_ground_nm.py new file mode 100644 index 0000000..8cb7adb --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_and_3_piggy_tail_ground_nm.py @@ -0,0 +1,176 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0_and_3/Piggy_2_11_01/' +name = 'histrogram_Piggi_2_14_01_tail_ground_nm' +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy/SD10_distribution_2/' +# path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy/SD100_distribution/' +# path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy/SD1000_distribution/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy/SD10000_distribution_2/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy/SD10000_tail_distribution_part/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja+29).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +# partial_fun_2 = functools.partial(Positions, path_to_file_2) +# partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + # Classic_2 = executor.map(partial_fun_2, punkty) + # Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + +Class_1 = [i for i in Classic_1] +# Class_2 = [i for i in Classic_2] +# Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 29)) +Srednie_mass1 = np.zeros((91, 29)) +odchylenie_num1 = np.zeros((91, 29)) +# Srednie_num2 = np.zeros((91, 29)) +# Srednie_mass2 = np.zeros((91, 29)) +# odchylenie_num2 = np.zeros((91, 29)) +# Srednie_num3 = np.zeros((91, 29)) +# Srednie_mass3 = np.zeros((91, 29)) +# odchylenie_num3 = np.zeros((91, 29)) +Srednie_num4 = np.zeros((91, 29)) +Srednie_mass4 = np.zeros((91, 29)) +odchylenie_num4 = np.zeros((91, 29)) +Srednie_num5 = np.zeros((91, 29)) +Srednie_mass5 = np.zeros((91, 29)) +odchylenie_num5 = np.zeros((91, 29)) + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(29): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + # Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + # odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + # Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + # Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + # odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + # Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + # ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + # ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='m', linewidth=9, label='SD10000_tail') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + # ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + # ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='m', linewidth=9, label='SD10000_tail') + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution_from_mom0_ground.py b/Rain_distribution/Distribution_from_mom0_ground.py new file mode 100644 index 0000000..c134e67 --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_ground.py @@ -0,0 +1,158 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0/Piggy_2_ziemia/' +name = 'histrogram_ziemiai_' + +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy_2/SD10/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy_2/SD50/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy_2/SD100/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy_2/SD1000/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy_2/SD10000/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Piggy_2/SD70000/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja = [0 for i in range(nr_files)] + wynik = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik[file] = dystrybucja[file][0]* rainy_mask[0] + wynik[file][wynik[file]==0]=np.nan + srednia = np.nanmean(wynik) + STD = np.nanstd(wynik) + return srednia, STD + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_1 = np.zeros((91, 29)) +odchylenie_1 = np.zeros((91, 29)) +Srednie_2 = np.zeros((91, 29)) +odchylenie_2 = np.zeros((91, 29)) +Srednie_3 = np.zeros((91, 29)) +odchylenie_3 = np.zeros((91, 29)) +Srednie_4 = np.zeros((91, 29)) +odchylenie_4 = np.zeros((91, 29)) +Srednie_5 = np.zeros((91, 29)) +odchylenie_5 = np.zeros((91, 29)) +Srednie_6 = np.zeros((91, 29)) +odchylenie_6 = np.zeros((91, 29)) + +plt.rcParams.update({'font.size': 40}) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +for i in range(91): + plt.clf() + for j in range(29): + Srednie_1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_3[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_3[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_6[i][j] = (((Class_6[i])[0])[j])[1] + plt.step(biny[1:-1], Srednie_1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + plt.step(biny[1:-1], Srednie_2[i]/biny_diff[0], c='k', linewidth=9, label='SD50') + plt.step(biny[1:-1], Srednie_3[i]/biny_diff[0], c='r', linewidth=9, label='SD100') + plt.step(biny[1:-1], Srednie_4[i]/biny_diff[0], c='b', linewidth=9, label='SD1000') + plt.step(biny[1:-1], Srednie_5[i]/biny_diff[0], c='y', linewidth=9, label='SD10000') + plt.step(biny[1:-1], Srednie_6[i]/biny_diff[0], c='m', linewidth=9, label='SD70000') + plt.title('time= '+str(i*120)+'[s]') + plt.xscale('log') + plt.yscale('log') + plt.ylim(bottom=0) + plt.grid(True) + plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + plt.xlabel(r'r [m]') + plt.ylabel('n(ln r) [# of droplets/ d lnr]') + plt.savefig('/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0/Piggy_2_ziemia/'+name+str(i*240).zfill(10)+'.png') diff --git a/Rain_distribution/Distribution_from_mom0_ground_Piggy.py b/Rain_distribution/Distribution_from_mom0_ground_Piggy.py new file mode 100644 index 0000000..7d983f3 --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_ground_Piggy.py @@ -0,0 +1,148 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0/Piggy_ziemia/' +name = 'histrogram_ziemia_no_mask_14_01' + +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy/SD10_distribution_2/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy/SD100_distribution/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy/SD1000_distribution/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy/SD10000_distribution_2/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy/SD10000_tail_distribution_part/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja = [0 for i in range(nr_files)] + wynik = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik[file] = dystrybucja[file][0] + wynik[file][wynik[file]==0]=np.nan + srednia = np.nanmean(wynik) + STD = np.nanstd(wynik) + return srednia, STD + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) + +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_1 = np.zeros((91, 29)) +odchylenie_1 = np.zeros((91, 29)) +Srednie_2 = np.zeros((91, 29)) +odchylenie_2 = np.zeros((91, 29)) +Srednie_3 = np.zeros((91, 29)) +odchylenie_3 = np.zeros((91, 29)) +Srednie_4 = np.zeros((91, 29)) +odchylenie_4 = np.zeros((91, 29)) + + +plt.rcParams.update({'font.size': 40}) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +for i in range(91): + plt.clf() + for j in range(29): + Srednie_1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_3[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_3[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_4[i][j] = (((Class_4[i])[0])[j])[1] + + plt.step(biny[1:-1], Srednie_1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + plt.step(biny[1:-1], Srednie_2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + plt.step(biny[1:-1], Srednie_3[i]/biny_diff[0], c='r', linewidth=9, label='SD1000') + plt.step(biny[1:-1], Srednie_4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + + plt.title('time= '+str(i*120)+'[s]') + plt.xscale('log') + plt.yscale('log') + plt.ylim(bottom=0) + plt.grid(True) + plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + plt.xlabel(r'r [m]') + plt.ylabel('n(ln r) [# of droplets/ d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') diff --git a/Rain_distribution/Distribution_from_mom0_ground_Piggy_2.py b/Rain_distribution/Distribution_from_mom0_ground_Piggy_2.py new file mode 100644 index 0000000..371e387 --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_ground_Piggy_2.py @@ -0,0 +1,158 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0/Piggy_2_ziemia/' +name = 'histrogram_ziemia_no_mask_14_01' + +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy_2/SD10/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy_2/SD50/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy_2/SD100/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy_2/SD1000/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy_2/SD10000/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Piggy_2/SD70000/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja = [0 for i in range(nr_files)] + wynik = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik[file] = dystrybucja[file][0] + wynik[file][wynik[file]==0]=np.nan + srednia = np.nanmean(wynik) + STD = np.nanstd(wynik) + return srednia, STD + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_1 = np.zeros((91, 29)) +odchylenie_1 = np.zeros((91, 29)) +Srednie_2 = np.zeros((91, 29)) +odchylenie_2 = np.zeros((91, 29)) +Srednie_3 = np.zeros((91, 29)) +odchylenie_3 = np.zeros((91, 29)) +Srednie_4 = np.zeros((91, 29)) +odchylenie_4 = np.zeros((91, 29)) +Srednie_5 = np.zeros((91, 29)) +odchylenie_5 = np.zeros((91, 29)) +Srednie_6 = np.zeros((91, 29)) +odchylenie_6 = np.zeros((91, 29)) + +plt.rcParams.update({'font.size': 40}) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +for i in range(91): + plt.clf() + for j in range(29): + Srednie_1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_3[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_3[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_6[i][j] = (((Class_6[i])[0])[j])[1] + plt.step(biny[1:-1], Srednie_1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + plt.step(biny[1:-1], Srednie_2[i]/biny_diff[0], c='k', linewidth=9, label='SD50') + plt.step(biny[1:-1], Srednie_3[i]/biny_diff[0], c='r', linewidth=9, label='SD100') + plt.step(biny[1:-1], Srednie_4[i]/biny_diff[0], c='b', linewidth=9, label='SD1000') + plt.step(biny[1:-1], Srednie_5[i]/biny_diff[0], c='y', linewidth=9, label='SD10000') + plt.step(biny[1:-1], Srednie_6[i]/biny_diff[0], c='m', linewidth=9, label='SD70000') + plt.title('time= '+str(i*120)+'[s]') + plt.xscale('log') + plt.yscale('log') + plt.ylim(bottom=0) + plt.grid(True) + plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + plt.xlabel(r'r [m]') + plt.ylabel('n(ln r) [# of droplets/ d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') diff --git a/Rain_distribution/Distribution_from_mom0_ground_Piggy_tail.py b/Rain_distribution/Distribution_from_mom0_ground_Piggy_tail.py new file mode 100644 index 0000000..cb4ab22 --- /dev/null +++ b/Rain_distribution/Distribution_from_mom0_ground_Piggy_tail.py @@ -0,0 +1,156 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution_from_mom0/Piggy_ziemia/' +name = 'histrogram_ziemia_no_mask_14_01_tail' + +path_to_file_1 = '/home/pzmij/2D/PAPER/Piggy/SD10_distribution_2/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Piggy/SD100_distribution/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Piggy/SD1000_distribution/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Piggy/SD10000_distribution_2/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Piggy/SD10000_tail_distribution_part/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja = [0 for i in range(nr_files)] + wynik = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik[file] = dystrybucja[file][0] + wynik[file][wynik[file]==0]=np.nan + srednia = np.nanmean(wynik) + STD = np.nanstd(wynik) + return srednia, STD + +def Positions(paths, timestep): + Results = [0 for i in range(30)] + for i in range(29): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) + +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,31)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_1 = np.zeros((91, 29)) +odchylenie_1 = np.zeros((91, 29)) +Srednie_2 = np.zeros((91, 29)) +odchylenie_2 = np.zeros((91, 29)) +Srednie_3 = np.zeros((91, 29)) +odchylenie_3 = np.zeros((91, 29)) +Srednie_4 = np.zeros((91, 29)) +odchylenie_4 = np.zeros((91, 29)) +Srednie_5 = np.zeros((91, 29)) +odchylenie_5 = np.zeros((91, 29)) + + +plt.rcParams.update({'font.size': 40}) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +for i in range(91): + plt.clf() + for j in range(29): + Srednie_1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_3[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_3[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_5[i][j] = (((Class_5[i])[0])[j])[1] + + plt.step(biny[1:-1], Srednie_1[i]/biny_diff[0], c='g', linewidth=9, label='SD10') + plt.step(biny[1:-1], Srednie_2[i]/biny_diff[0], c='k', linewidth=9, label='SD100') + plt.step(biny[1:-1], Srednie_3[i]/biny_diff[0], c='r', linewidth=9, label='SD1000') + plt.step(biny[1:-1], Srednie_4[i]/biny_diff[0], c='b', linewidth=9, label='SD10000') + plt.step(biny[1:-1], Srednie_5[i]/biny_diff[0], c='b', linewidth=9, label='SD10000_tail') + + plt.title('time= '+str(i*120)+'[s]') + plt.xscale('log') + plt.yscale('log') + plt.ylim(bottom=0) + plt.grid(True) + plt.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + plt.xlabel(r'r [m]') + plt.ylabel('n(ln r) [# of droplets/ d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') diff --git a/Rain_distribution/Rain_many_copare_time_line_21_12.py b/Rain_distribution/Rain_many_copare_time_line_21_12.py index 8f5d75e..5e4c3c6 100644 --- a/Rain_distribution/Rain_many_copare_time_line_21_12.py +++ b/Rain_distribution/Rain_many_copare_time_line_21_12.py @@ -89,8 +89,10 @@ def Adia_fraction(timestep, paths): time_end = int(argv[2]) outfreq = int(argv[3]) outfile = argv[4] -paths = argv[5:len(argv):2] -labels = argv[6:len(argv):2] +Plot_name = str(argv[5]) +legend_title = str(argv[6]) +paths = argv[7:len(argv):2] +labels = argv[8:len(argv):2] Average = [] STD = [] @@ -137,18 +139,18 @@ def Adia_fraction(timestep, paths): stats = pstats.Stats(profiler).sort_stats('cumtime') stats.print_stats() ax0.set_ylim((0,0.5)) -ax1.set_ylim((0, 0.5 )) -ax0.set_xlim((4000,8000)) -ax1.set_xlim((4000,8000)) +ax1.set_ylim((0, 0.6 )) +ax0.set_xlim((3800,8000)) +ax1.set_xlim((3800,8000)) ax0.set_xlabel('X [m]') ax1.set_xlabel('X [m]') ax0.set_ylabel('Mean of $q_r$ [g/kg]') ax1.set_ylabel('STD of $q_r$ [g/kg]') -ax0.legend(title='SD10') -ax1.legend(title='SD10') +ax0.legend(title=legend_title) +ax1.legend(title=legend_title) fig.suptitle('time range = '+str(time_start) + ' to '+str(time_end) +' s') -plt.savefig(outfile + 'Average_many_for_time_range_'+str(time_start)+'_to_'+ str(time_end)+'21_12.png') +plt.savefig(outfile + Plot_name +str(time_start)+'_to_'+ str(time_end)+'21_12.png') # Od komentuj! plt.clf() diff --git a/Rain_distribution/rain_histogram.py b/Rain_distribution/rain_histogram.py index 18a96e3..07d6142 100644 --- a/Rain_distribution/rain_histogram.py +++ b/Rain_distribution/rain_histogram.py @@ -33,8 +33,8 @@ timesteps[i] = i*240 # timesteps = timesteps[1:91] timesteps = timesteps[1:91] -paths = argv[1] -outfile = argv[2] +paths = '/home/pzmij/2D/PAPER/Piggy_2/SD10000/' +outfile = '/home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/' file_names = os.listdir(paths) @@ -59,6 +59,7 @@ X = np.arange(nx)# * dx filename = path + "/timestep" + str(int(timestep)).zfill(10) + ".h5" + print(filename) rl = (h5py.File(filename, "r")["actrw_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg rr_c = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg diff --git a/Rain_distribution/rain_histogram_multi_Piggy2.py b/Rain_distribution/rain_histogram_multi_Piggy2.py new file mode 100644 index 0000000..3576f8e --- /dev/null +++ b/Rain_distribution/rain_histogram_multi_Piggy2.py @@ -0,0 +1,115 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ +UPDATE + +python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/no_Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/ +Singularity> python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD100/classic/ + +''' +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +# paths = argv[1] +# outfile = argv[2] +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +def Liczy_histogram(paths, i): + file_names = os.listdir(paths) + + Hist = np.zeros(( len(biny)-1)) + rr_files = np.zeros((len(file_names), len(biny)-1)) + for p in range(len(file_names)): + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' + filename = path + "/timestep" + str(240*i).zfill(10) + ".h5" + rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod * 4. / 3. * 3.1416 * 1e3; # kg/kg + hist = np.histogram(rr, bins=biny) + rr_files[p,:] = hist[0] + Hist = np.mean(rr_files, axis=0) + # Hist_data = np.sum(Hist, axis=0) + # Hist_data = Hist_data/ np.max(Hist_data) + return Hist, hist[1] + +def Run_hist(SD, kroki): + return Liczy_histogram(main_path+str(SD)+'/', kroki) +# def Run_hist(SD, kroki): + # return Liczy_histogram(main_path+str(SD)+'/', kroki) + +biny = [1e-14, 1e-13,1e-12,1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2, 1e-1, 1 ] +outfile = '/home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/' +main_path = '/home/pzmij/2D/PAPER/Piggy_2/SD' +TITLE = 'CLASSIC' +TITLE_save = 'SD10-70k_Piggy_2' +partial_fun_1000_VF = functools.partial(Run_hist, '10' ) +partial_fun_1000_tail = functools.partial(Run_hist, '50') +partial_fun_1000_multi = functools.partial(Run_hist, '100') +partial_fun_1000_multi2 = functools.partial(Run_hist, '1000') +partial_fun_1000_multi3 = functools.partial(Run_hist, '10000') +partial_fun_1000_multi4 = functools.partial(Run_hist, '70000') +# partial_fun_1000_multi_3 = functools.partial(Run_hist, 'SD10/classic', "multi") +punkty = np.intc(np.linspace(1,90,91)) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic = executor.map(partial_fun_1000_VF, punkty) + Tails = executor.map(partial_fun_1000_tail, punkty) + Multis = executor.map(partial_fun_1000_multi, punkty) + Multis2 = executor.map(partial_fun_1000_multi2, punkty) + Multis3 = executor.map(partial_fun_1000_multi3, punkty) + Multis4 = executor.map(partial_fun_1000_multi4, punkty) +Class = np.sum([i[0] for i in Classic], axis=0) +Tail = np.sum([i[0] for i in Tails], axis=0) +Multi = np.sum([i[0] for i in Multis], axis=0) +Multi2 = np.sum([i[0] for i in Multis2], axis=0) +Multi3 = np.sum([i[0] for i in Multis3], axis=0) +Multi4 = np.sum([i[0] for i in Multis4], axis=0) + +plt.figure(0) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +# plt.step(biny[1:], Multi2, c='k', label="5", linewidth=9) +plt.step(biny[1:], Class, c='y', label="10", linewidth=9) +plt.step(biny[1:], Tail, c='r', label='50', linewidth=9) +plt.step(biny[1:], Multi, c='g', label='100', linewidth=9) +plt.step(biny[1:], Multi2, c='k', label="1000", linewidth=9) +plt.step(biny[1:], Multi3, c='m', label="10000", linewidth=9) +plt.step(biny[1:], Multi4, c='b', label="70000", linewidth=9) +# plt.title('SD= '+str(TITLE)+'[#]') +plt.title(str(TITLE)) +plt.xscale('log') +plt.xlim((1e-13, 1e-0)) +plt.grid(True) +plt.legend(title='SD [#]:') +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +plt.xlabel(r'$q_r$ [kg/kg]') +plt.ylabel('# of cells') +plt.savefig(outfile+'hist_'+str(TITLE_save)+'.png') diff --git a/Rain_distribution/rain_histogram_multi_SD1k.py b/Rain_distribution/rain_histogram_multi_SD1k.py index fb9eacb..fff26de 100644 --- a/Rain_distribution/rain_histogram_multi_SD1k.py +++ b/Rain_distribution/rain_histogram_multi_SD1k.py @@ -70,12 +70,13 @@ def Run_hist(SD, path, kroki): outfile = '/home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/' main_path = '/home/pzmij/2D/PAPER/Piggy/SD' TITLE = 'CLASSIC' -TITLE_save = 'SD10-10k' +TITLE_save = 'SD10-70k' partial_fun_1000_VF = functools.partial(Run_hist, '10', "classic") partial_fun_1000_tail = functools.partial(Run_hist, '50', "classic") partial_fun_1000_multi = functools.partial(Run_hist, '100', "classic") partial_fun_1000_multi2 = functools.partial(Run_hist, '1000', "classic") partial_fun_1000_multi3 = functools.partial(Run_hist, '10000', "classic") +partial_fun_1000_multi4 = functools.partial(Run_hist, '70000', "classic") # partial_fun_1000_multi_3 = functools.partial(Run_hist, 'SD10/classic', "multi") punkty = np.intc(np.linspace(1,90,91)) with concurrent.futures.ProcessPoolExecutor() as executor: @@ -84,11 +85,13 @@ def Run_hist(SD, path, kroki): Multis = executor.map(partial_fun_1000_multi, punkty) Multis2 = executor.map(partial_fun_1000_multi2, punkty) Multis3 = executor.map(partial_fun_1000_multi3, punkty) + Multis4 = executor.map(partial_fun_1000_multi4, punkty) Class = np.sum([i[0] for i in Classic], axis=0) Tail = np.sum([i[0] for i in Tails], axis=0) Multi = np.sum([i[0] for i in Multis], axis=0) Multi2 = np.sum([i[0] for i in Multis2], axis=0) Multi3 = np.sum([i[0] for i in Multis3], axis=0) +Multi4 = np.sum([i[0] for i in Multis4], axis=0) plt.figure(0) plt.rcParams.update({'font.size': 40}) @@ -99,6 +102,7 @@ def Run_hist(SD, path, kroki): plt.step(biny[1:], Multi, c='g', label='100', linewidth=9) plt.step(biny[1:], Multi2, c='k', label="1000", linewidth=9) plt.step(biny[1:], Multi3, c='m', label="10000", linewidth=9) +plt.step(biny[1:], Multi4, c='b', label="70000", linewidth=9) # plt.title('SD= '+str(TITLE)+'[#]') plt.title(str(TITLE)) plt.xscale('log') diff --git a/Rain_distribution/rain_histogram_multi_coal.py b/Rain_distribution/rain_histogram_multi_coal.py new file mode 100644 index 0000000..b92d5ea --- /dev/null +++ b/Rain_distribution/rain_histogram_multi_coal.py @@ -0,0 +1,110 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + +''' +HOW TO RUN + +python3 RAIN_rysy_xz2d_2D_lvl0.py /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/AF/ +UPDATE + +python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/no_Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/ +Singularity> python3 /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/rain_histogram.py /home/pzmij/2D/PAPER/Piggy/SD100/classic/ /home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/SD100/classic/ + +''' +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +# print whole np arrays +np.set_printoptions(threshold=maxsize) +plt.rcParams.update({'font.size': 20}) +evap_lat = 2.501e6 # [J/kg] latent heat of evaporation + +# paths = argv[1] +# outfile = argv[2] +timesteps = np.ones(91) +for i in range(1, 91): + timesteps[i] = i*240 +timesteps = timesteps[1:91] + +def Liczy_histogram(paths, i): + file_names = os.listdir(paths) + + Hist = np.zeros(( len(biny)-1)) + rr_files = np.zeros((len(file_names), len(biny)-1)) + for p in range(len(file_names)): + path = paths+file_names[p]+'/'+file_names[p]+'_out_lgrngn' + filename = path + "/timestep" + str(240*i).zfill(10) + ".h5" + rhod = h5py.File(path + "/const.h5", "r")["G"][:,:] + rr = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) * rhod * 4. / 3. * 3.1416 * 1e3; # kg/kg + hist = np.histogram(rr, bins=biny) + rr_files[p,:] = hist[0] + Hist = np.mean(rr_files, axis=0) + # Hist_data = np.sum(Hist, axis=0) + # Hist_data = Hist_data/ np.max(Hist_data) + return Hist, hist[1] + +def Run_hist(SD, kroki): + return Liczy_histogram(main_path+str(SD)+'/', kroki) +# def Run_hist(SD, kroki): + # return Liczy_histogram(main_path+str(SD)+'/', kroki) + +biny = [1e-14, 1e-13,1e-12,1e-11,1e-10,1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2, 1e-1, 1 ] +outfile = '/home/pzmij/2D/PAPER/Wyniki/New_hist/Piggy/' +main_path = '/home/pzmij/2D/PAPER/Piggy/SD100' +TITLE = 'CLASSIC' +TITLE_save = 'SD100_coal' +partial_fun_1000_VF = functools.partial(Run_hist, '/classic' ) +partial_fun_1000_tail = functools.partial(Run_hist, '_coal25') +partial_fun_1000_multi = functools.partial(Run_hist, '_coal50') +partial_fun_1000_multi2 = functools.partial(Run_hist, '_coal100') + +# partial_fun_1000_multi_3 = functools.partial(Run_hist, 'SD10/classic', "multi") +punkty = np.intc(np.linspace(1,90,91)) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic = executor.map(partial_fun_1000_VF, punkty) + Tails = executor.map(partial_fun_1000_tail, punkty) + Multis = executor.map(partial_fun_1000_multi, punkty) + Multis2 = executor.map(partial_fun_1000_multi2, punkty) + +Class = np.sum([i[0] for i in Classic], axis=0) +Tail = np.sum([i[0] for i in Tails], axis=0) +Multi = np.sum([i[0] for i in Multis], axis=0) +Multi2 = np.sum([i[0] for i in Multis2], axis=0) + + +plt.figure(0) +plt.rcParams.update({'font.size': 40}) +plt.figure(figsize=(40,40)) +# plt.step(biny[1:], Multi2, c='k', label="5", linewidth=9) +plt.step(biny[1:], Class, c='y', label="5", linewidth=9) +plt.step(biny[1:], Tail, c='r', label='25', linewidth=9) +plt.step(biny[1:], Multi, c='g', label='50', linewidth=9) +plt.step(biny[1:], Multi2, c='k', label="100", linewidth=9) +# plt.title('SD= '+str(TITLE)+'[#]') +plt.title(str(TITLE)) +plt.xscale('log') +plt.xlim((1e-13, 1e-0)) +plt.grid(True) +plt.legend(title='sstp_coal [#]:') +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +plt.xlabel(r'$q_r$ [kg/kg]') +plt.ylabel('# of cells') +plt.savefig(outfile+'hist_'+str(TITLE_save)+'.png') From a9202bca64868f2e88f9e68410c728bd08eaab75 Mon Sep 17 00:00:00 2001 From: ryba183 Date: Tue, 15 Feb 2022 11:04:16 +0100 Subject: [PATCH 30/30] RYSY --- .../Precip_rate_master_SD50_comapre_100.py | 129 ++++++++++ .../Precip_rate_master_SD50_comapre_1000.py | 129 ++++++++++ .../Precip_rate_master_SD50_comapre_10000.py | 129 ++++++++++ NC_vs_AF/Randomness/Distribution/Compare.py | 40 ++-- .../Distribution/Compare_only_master.py | 170 +++++++++++++ .../Randomness/Distribution/Compare_testy.py | 167 +++++++++++++ .../Distribution/Compare_testy_single.py | 160 +++++++++++++ .../Distribution/Compare_with_many_master.py | 180 ++++++++++++++ .../Distribution/Compare_with_nP.py | 173 ++++++++++++++ .../Randomness/Distribution/Master_max.py | 55 +++++ NC_vs_AF/Randomness/Distribution/Piggy.py | 17 +- NC_vs_AF/Randomness/Distribution/Piggy_2.py | 17 +- NC_vs_AF/Randomness/Distribution/Piggy_3.py | 159 +++++++++++++ .../Piggy_SD100_from_master_SD100.py | 164 +++++++++++++ .../Piggy_SD100_from_master_SD150.py | 162 +++++++++++++ .../Piggy_SD100_from_master_SD50.py | 162 +++++++++++++ .../Piggy_SD100_from_master_SD50_all.py | 165 +++++++++++++ NC_vs_AF/Randomness/Distribution/Test.py | 169 +++++++++++++ NC_vs_AF/Randomness/Distribution/no_Piggy.py | 160 +++++++++++++ NC_vs_AF/precip_rate.py | 124 ++++++++++ NC_vs_AF/precip_rate_new_master.py | 223 ++++++++++++++++++ ...czasie_test.py => Srednia_classic_m_cb.py} | 2 +- .../Piggy/classic/Srednia_classic_m_g.py | 171 ++++++++++++++ .../Piggy/classic/Srednia_classic_nm_cb.py | 171 ++++++++++++++ .../Piggy/classic/Srednie_classic_nm_g.py | 171 ++++++++++++++ .../Piggy/mix/Srednie_compare_m_cb.py | 217 +++++++++++++++++ .../Piggy/mix/Srednie_compare_m_g.py | 217 +++++++++++++++++ .../Piggy/mix/Srednie_compare_nm_cb.py | 217 +++++++++++++++++ .../Piggy/mix/Srednie_compare_nm_g.py | 216 +++++++++++++++++ .../Piggy/tail/Srednie_tail_m_cb.py | 171 ++++++++++++++ .../Piggy/tail/Srednie_tail_m_g.py | 171 ++++++++++++++ .../Piggy/tail/Srednie_tail_nm_cb.py | 171 ++++++++++++++ .../Piggy/tail/Srednie_tail_nm_g.py | 171 ++++++++++++++ .../Piggy_2/classic/Srednie_classic_m_cb.py | 171 ++++++++++++++ .../Piggy_2/classic/Srednie_classic_m_g.py | 171 ++++++++++++++ .../Piggy_2/classic/Srednie_classic_nm_cb.py | 171 ++++++++++++++ .../Piggy_2/classic/Srednie_classic_nm_g.py | 171 ++++++++++++++ .../Piggy_2/mix/Srednie_compare_m_cb.py | 217 +++++++++++++++++ .../Piggy_2/mix/Srednie_compare_m_g.py | 217 +++++++++++++++++ .../Piggy_2/mix/Srednie_compare_nm_cb.py | 216 +++++++++++++++++ .../Piggy_2/mix/Srednie_compare_nm_g.py | 217 +++++++++++++++++ .../Piggy_2/tail/Srednie_tail_m_cb.py | 171 ++++++++++++++ .../Piggy_2/tail/Srednie_tail_m_g.py | 171 ++++++++++++++ .../Piggy_2/tail/Srednie_tail_nm_cb.py | 171 ++++++++++++++ .../Piggy_2/tail/Srednie_tail_nm_g.py | 171 ++++++++++++++ ...on_from_mom0_and_3_piggy_2_classic_m_cb.py | 160 +++++++++++++ ...ion_from_mom0_and_3_piggy_2_classic_m_g.py | 160 +++++++++++++ ...n_from_mom0_and_3_piggy_2_classic_nm_cb.py | 160 +++++++++++++ ...on_from_mom0_and_3_piggy_2_classic_nm_g.py | 160 +++++++++++++ .../Piggy_3/classic/Srednie_classic_m_cb.py | 171 ++++++++++++++ .../Piggy_3/classic/Srednie_classic_m_g.py | 171 ++++++++++++++ .../Piggy_3/classic/Srednie_classic_nm_cb.py | 171 ++++++++++++++ .../Piggy_3/classic/Srednie_classic_nm_g.py | 171 ++++++++++++++ ...on_from_mom0_and_3_piggy_2_compare_m_cb.py | 197 ++++++++++++++++ ...ion_from_mom0_and_3_piggy_2_compare_m_g.py | 197 ++++++++++++++++ ...n_from_mom0_and_3_piggy_2_compare_nm_cb.py | 197 ++++++++++++++++ ...on_from_mom0_and_3_piggy_2_compare_nm_g.py | 197 ++++++++++++++++ .../Piggy_3/mix/Srednie_compare_m_cb.py | 217 +++++++++++++++++ .../Piggy_3/mix/Srednie_compare_m_g.py | 217 +++++++++++++++++ .../Piggy_3/mix/Srednie_compare_nm_cb.py | 216 +++++++++++++++++ .../Piggy_3/mix/Srednie_compare_nm_g.py | 217 +++++++++++++++++ ...ution_from_mom0_and_3_piggy_2_tail_m_cb.py | 160 +++++++++++++ ...bution_from_mom0_and_3_piggy_2_tail_m_g.py | 160 +++++++++++++ ...tion_from_mom0_and_3_piggy_2_tail_nm_cb.py | 160 +++++++++++++ ...ution_from_mom0_and_3_piggy_2_tail_nm_g.py | 160 +++++++++++++ .../Piggy_3/tail/Srednie_tail_m_cb.py | 171 ++++++++++++++ .../Piggy_3/tail/Srednie_tail_m_g.py | 171 ++++++++++++++ .../Piggy_3/tail/Srednie_tail_nm_cb.py | 171 ++++++++++++++ .../Piggy_3/tail/Srednie_tail_nm_g.py | 171 ++++++++++++++ .../Distribution/Piggy_3/test.sh | 4 + ...on_from_mom0_and_3_piggy_2_classic_m_cb.py | 160 +++++++++++++ ...ion_from_mom0_and_3_piggy_2_classic_m_g.py | 160 +++++++++++++ ...n_from_mom0_and_3_piggy_2_classic_nm_cb.py | 160 +++++++++++++ ...on_from_mom0_and_3_piggy_2_classic_nm_g.py | 160 +++++++++++++ .../classic/Srednie_classic_m_cb.py | 171 ++++++++++++++ .../classic/Srednie_classic_m_g.py | 171 ++++++++++++++ .../classic/Srednie_classic_nm_cb.py | 171 ++++++++++++++ .../classic/Srednie_classic_nm_g.py | 171 ++++++++++++++ ...on_from_mom0_and_3_piggy_2_compare_m_cb.py | 197 ++++++++++++++++ ...ion_from_mom0_and_3_piggy_2_compare_m_g.py | 197 ++++++++++++++++ ...n_from_mom0_and_3_piggy_2_compare_nm_cb.py | 197 ++++++++++++++++ ...on_from_mom0_and_3_piggy_2_compare_nm_g.py | 197 ++++++++++++++++ .../mix/Srednie_compare_m_cb.py | 217 +++++++++++++++++ .../mix/Srednie_compare_m_g.py | 217 +++++++++++++++++ .../mix/Srednie_compare_nm_cb.py | 216 +++++++++++++++++ .../mix/Srednie_compare_nm_g.py | 217 +++++++++++++++++ ...ution_from_mom0_and_3_piggy_2_tail_m_cb.py | 171 ++++++++++++++ ...bution_from_mom0_and_3_piggy_2_tail_m_g.py | 172 ++++++++++++++ ...tion_from_mom0_and_3_piggy_2_tail_nm_cb.py | 172 ++++++++++++++ ...ution_from_mom0_and_3_piggy_2_tail_nm_g.py | 172 ++++++++++++++ .../tail/Srednie_tail_m_cb.py | 186 +++++++++++++++ .../tail/Srednie_tail_m_g.py | 186 +++++++++++++++ .../tail/Srednie_tail_nm_cb.py | 186 +++++++++++++++ .../tail/Srednie_tail_nm_g.py | 186 +++++++++++++++ .../Distribution/Piggy_new_masters/test.sh | 4 + ...n_from_mom0_and_3_no_piggy_classic_m_cb.py | 167 +++++++++++++ ...ion_from_mom0_and_3_piggy_2_classic_m_g.py | 168 +++++++++++++ ...n_from_mom0_and_3_piggy_2_classic_nm_cb.py | 168 +++++++++++++ ...on_from_mom0_and_3_piggy_2_classic_nm_g.py | 168 +++++++++++++ .../no_Piggy/classic/Srednie_classic_m_cb.py | 177 ++++++++++++++ .../no_Piggy/classic/Srednie_classic_m_g.py | 178 ++++++++++++++ .../no_Piggy/classic/Srednie_classic_nm_cb.py | 178 ++++++++++++++ .../no_Piggy/classic/Srednie_classic_nm_g.py | 179 ++++++++++++++ ...on_from_mom0_and_3_piggy_2_compare_m_cb.py | 197 ++++++++++++++++ ...ion_from_mom0_and_3_piggy_2_compare_m_g.py | 197 ++++++++++++++++ ...n_from_mom0_and_3_piggy_2_compare_nm_cb.py | 197 ++++++++++++++++ ...on_from_mom0_and_3_piggy_2_compare_nm_g.py | 197 ++++++++++++++++ .../no_Piggy/mix/Srednie_compare_m_cb.py | 217 +++++++++++++++++ .../no_Piggy/mix/Srednie_compare_m_g.py | 217 +++++++++++++++++ .../no_Piggy/mix/Srednie_compare_nm_cb.py | 216 +++++++++++++++++ .../no_Piggy/mix/Srednie_compare_nm_g.py | 217 +++++++++++++++++ ...ution_from_mom0_and_3_piggy_2_tail_m_cb.py | 168 +++++++++++++ ...bution_from_mom0_and_3_piggy_2_tail_m_g.py | 166 +++++++++++++ ...tion_from_mom0_and_3_piggy_2_tail_nm_cb.py | 167 +++++++++++++ ...ution_from_mom0_and_3_piggy_2_tail_nm_g.py | 166 +++++++++++++ .../no_Piggy/tail/Srednie_tail_m_cb.py | 178 ++++++++++++++ .../no_Piggy/tail/Srednie_tail_m_g.py | 178 ++++++++++++++ .../no_Piggy/tail/Srednie_tail_nm_cb.py | 178 ++++++++++++++ .../no_Piggy/tail/Srednie_tail_nm_g.py | 178 ++++++++++++++ .../Distribution/no_Piggy/test.sh | 4 + .../Rain_many_copare_time_line_21_12.py | 6 +- Rain_distribution/TEST_nP.py | 147 ++++++++++++ Rain_distribution/TEST_nP2.py | 120 ++++++++++ 123 files changed, 20519 insertions(+), 51 deletions(-) create mode 100644 NC_vs_AF/Precip_rate_master_SD50_comapre_100.py create mode 100644 NC_vs_AF/Precip_rate_master_SD50_comapre_1000.py create mode 100644 NC_vs_AF/Precip_rate_master_SD50_comapre_10000.py create mode 100644 NC_vs_AF/Randomness/Distribution/Compare_only_master.py create mode 100644 NC_vs_AF/Randomness/Distribution/Compare_testy.py create mode 100644 NC_vs_AF/Randomness/Distribution/Compare_testy_single.py create mode 100644 NC_vs_AF/Randomness/Distribution/Compare_with_many_master.py create mode 100644 NC_vs_AF/Randomness/Distribution/Compare_with_nP.py create mode 100644 NC_vs_AF/Randomness/Distribution/Master_max.py create mode 100644 NC_vs_AF/Randomness/Distribution/Piggy_3.py create mode 100644 NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD100.py create mode 100644 NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD150.py create mode 100644 NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD50.py create mode 100644 NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD50_all.py create mode 100644 NC_vs_AF/Randomness/Distribution/Test.py create mode 100644 NC_vs_AF/Randomness/Distribution/no_Piggy.py create mode 100644 NC_vs_AF/precip_rate.py create mode 100644 NC_vs_AF/precip_rate_new_master.py rename Rain_distribution/Distribution/Piggy/classic/{Srednia_po_czasie_test.py => Srednia_classic_m_cb.py} (98%) create mode 100644 Rain_distribution/Distribution/Piggy/classic/Srednia_classic_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy/classic/Srednia_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/classic/Srednie_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy/mix/Srednie_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/mix/Srednie_compare_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy/mix/Srednie_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/mix/Srednie_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy/tail/Srednie_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/tail/Srednie_tail_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy/tail/Srednie_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy/tail/Srednie_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_3/test.sh create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_m_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/Piggy_new_masters/test.sh create mode 100644 Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_no_piggy_classic_m_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_m_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_m_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_nm_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_nm_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_m_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_m_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_nm_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_nm_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_m_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_m_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_nm_cb.py create mode 100644 Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_nm_g.py create mode 100644 Rain_distribution/Distribution/no_Piggy/test.sh create mode 100644 Rain_distribution/TEST_nP.py create mode 100644 Rain_distribution/TEST_nP2.py diff --git a/NC_vs_AF/Precip_rate_master_SD50_comapre_100.py b/NC_vs_AF/Precip_rate_master_SD50_comapre_100.py new file mode 100644 index 0000000..f061d7b --- /dev/null +++ b/NC_vs_AF/Precip_rate_master_SD50_comapre_100.py @@ -0,0 +1,129 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/' +name = 'New_master_SD50_compare_100_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_2/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_21/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_27/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_72/SD100/tail/' + + + +def Precipitation_rate(paths, timestep): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + precip_rate= [0 for i in range(nr_files)] + precip_rate_STD= [0 for i in range(nr_files)] + p = 0 + for file in range(nr_files): + filename = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[p] = h5py.File(filename + "/const.h5", "r")["G"][:,:] + precip_rate[p] = (h5py.File(filename + "/timestep" + str(240*timestep).zfill(10) + ".h5", "r")["precip_rate"][:,:]) + p+=1 + rhod = np.mean(rhod,axis=0) + precip_rate = np.mean(precip_rate,axis=0) + precip_rate_STD = np.std(precip_rate,axis=0) + + nx, nz = rhod.shape + hght = np.arange(nz) * 100 + return precip_rate, precip_rate_STD, hght + + + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Precipitation_rate, path_to_file_1) +partial_fun_2 = functools.partial(Precipitation_rate, path_to_file_2) +partial_fun_3 = functools.partial(Precipitation_rate, path_to_file_3) +partial_fun_4 = functools.partial(Precipitation_rate, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) +Class_4_array = np.array(Class_4) + + +mean_p_rate1 = [0 for i in range(91)] +std_p_rate1 = [0 for i in range(91)] + +mean_p_rate2 = [0 for i in range(91)] +std_p_rate2 = [0 for i in range(91)] + +mean_p_rate3 = [0 for i in range(91)] +std_p_rate3 = [0 for i in range(91)] + +mean_p_rate4 = [0 for i in range(91)] +std_p_rate4 = [0 for i in range(91)] + + +for i in range(91): + + mean_p_rate1[i] = float(0) if np.all((Class_1_array[i])[0]) == np.nan else np.mean((Class_1_array[i])[0], axis=0) + std_p_rate1[i] = float(0) if np.all((Class_1_array[i])[1]) == np.nan else np.mean((Class_1_array[i])[1], axis=0) + + mean_p_rate2[i] = float(0) if np.all((Class_2_array[i])[0]) == np.nan else np.mean((Class_2_array[i])[0], axis=0) + std_p_rate2[i] = float(0) if np.all((Class_2_array[i])[1]) == np.nan else np.mean((Class_2_array[i])[1], axis=0) + + mean_p_rate3[i] = float(0) if np.all((Class_3_array[i])[0]) == np.nan else np.mean((Class_3_array[i])[0], axis=0) + std_p_rate3[i] = float(0) if np.all((Class_3_array[i])[1]) == np.nan else np.mean((Class_3_array[i])[1], axis=0) + + mean_p_rate4[i] = float(0) if np.all((Class_4_array[i])[0]) == np.nan else np.mean((Class_4_array[i])[0], axis=0) + std_p_rate4[i] = float(0) if np.all((Class_4_array[i])[1]) == np.nan else np.mean((Class_4_array[i])[1], axis=0) + +height = ((Class_1_array[i])[2]) + +Mean_precip_rate_1 = np.mean(mean_p_rate1, axis=0) +STD_precip_rate_1 = np.mean(std_p_rate1, axis=0) +Mean_precip_rate_2 = np.mean(mean_p_rate2, axis=0) +STD_precip_rate_2 = np.mean(std_p_rate2, axis=0) +Mean_precip_rate_3 = np.mean(mean_p_rate3, axis=0) +STD_precip_rate_3 = np.mean(std_p_rate3, axis=0) +Mean_precip_rate_4 = np.mean(mean_p_rate4, axis=0) +STD_precip_rate_4 = np.mean(std_p_rate4, axis=0) +plt.figure(figsize=(30,15)) +plt.plot(Mean_precip_rate_1,height, label = 'M_2', linewidth=5) +plt.plot(Mean_precip_rate_2,height, label = 'M_21', linewidth=5) +plt.plot(Mean_precip_rate_3, height, label = 'M_27', linewidth=5) +plt.plot(Mean_precip_rate_4, height, label = 'M_72', linewidth=5) + +plt.legend() +plt.title(name) +# plt.fill_betweenx(height, mean_p_rate-std_p_rate, mean_p_rate+std_p_rate, alpha=0.2) +plt.savefig(outfile+name+"_mean_"+str(91*240).zfill(10)+'.png') +plt.clf() + diff --git a/NC_vs_AF/Precip_rate_master_SD50_comapre_1000.py b/NC_vs_AF/Precip_rate_master_SD50_comapre_1000.py new file mode 100644 index 0000000..aec2ffb --- /dev/null +++ b/NC_vs_AF/Precip_rate_master_SD50_comapre_1000.py @@ -0,0 +1,129 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/' +name = 'New_master_SD50_compare_1000_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_2/SD1000/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_21/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_27/SD1000/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_72/SD1000/tail/' + + + +def Precipitation_rate(paths, timestep): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + precip_rate= [0 for i in range(nr_files)] + precip_rate_STD= [0 for i in range(nr_files)] + p = 0 + for file in range(nr_files): + filename = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[p] = h5py.File(filename + "/const.h5", "r")["G"][:,:] + precip_rate[p] = (h5py.File(filename + "/timestep" + str(240*timestep).zfill(10) + ".h5", "r")["precip_rate"][:,:]) + p+=1 + rhod = np.mean(rhod,axis=0) + precip_rate = np.mean(precip_rate,axis=0) + precip_rate_STD = np.std(precip_rate,axis=0) + + nx, nz = rhod.shape + hght = np.arange(nz) * 100 + return precip_rate, precip_rate_STD, hght + + + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Precipitation_rate, path_to_file_1) +partial_fun_2 = functools.partial(Precipitation_rate, path_to_file_2) +partial_fun_3 = functools.partial(Precipitation_rate, path_to_file_3) +partial_fun_4 = functools.partial(Precipitation_rate, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) +Class_4_array = np.array(Class_4) + + +mean_p_rate1 = [0 for i in range(91)] +std_p_rate1 = [0 for i in range(91)] + +mean_p_rate2 = [0 for i in range(91)] +std_p_rate2 = [0 for i in range(91)] + +mean_p_rate3 = [0 for i in range(91)] +std_p_rate3 = [0 for i in range(91)] + +mean_p_rate4 = [0 for i in range(91)] +std_p_rate4 = [0 for i in range(91)] + + +for i in range(91): + + mean_p_rate1[i] = float(0) if np.all((Class_1_array[i])[0]) == np.nan else np.mean((Class_1_array[i])[0], axis=0) + std_p_rate1[i] = float(0) if np.all((Class_1_array[i])[1]) == np.nan else np.mean((Class_1_array[i])[1], axis=0) + + mean_p_rate2[i] = float(0) if np.all((Class_2_array[i])[0]) == np.nan else np.mean((Class_2_array[i])[0], axis=0) + std_p_rate2[i] = float(0) if np.all((Class_2_array[i])[1]) == np.nan else np.mean((Class_2_array[i])[1], axis=0) + + mean_p_rate3[i] = float(0) if np.all((Class_3_array[i])[0]) == np.nan else np.mean((Class_3_array[i])[0], axis=0) + std_p_rate3[i] = float(0) if np.all((Class_3_array[i])[1]) == np.nan else np.mean((Class_3_array[i])[1], axis=0) + + mean_p_rate4[i] = float(0) if np.all((Class_4_array[i])[0]) == np.nan else np.mean((Class_4_array[i])[0], axis=0) + std_p_rate4[i] = float(0) if np.all((Class_4_array[i])[1]) == np.nan else np.mean((Class_4_array[i])[1], axis=0) + +height = ((Class_1_array[i])[2]) + +Mean_precip_rate_1 = np.mean(mean_p_rate1, axis=0) +STD_precip_rate_1 = np.mean(std_p_rate1, axis=0) +Mean_precip_rate_2 = np.mean(mean_p_rate2, axis=0) +STD_precip_rate_2 = np.mean(std_p_rate2, axis=0) +Mean_precip_rate_3 = np.mean(mean_p_rate3, axis=0) +STD_precip_rate_3 = np.mean(std_p_rate3, axis=0) +Mean_precip_rate_4 = np.mean(mean_p_rate4, axis=0) +STD_precip_rate_4 = np.mean(std_p_rate4, axis=0) +plt.figure(figsize=(30,15)) +plt.plot(Mean_precip_rate_1,height, label = 'M_2', linewidth=5) +plt.plot(Mean_precip_rate_2,height, label = 'M_21', linewidth=5) +plt.plot(Mean_precip_rate_3, height, label = 'M_27', linewidth=5) +plt.plot(Mean_precip_rate_4, height, label = 'M_72', linewidth=5) + +plt.legend() +plt.title(name) +# plt.fill_betweenx(height, mean_p_rate-std_p_rate, mean_p_rate+std_p_rate, alpha=0.2) +plt.savefig(outfile+name+"_mean_"+str(91*240).zfill(10)+'.png') +plt.clf() + diff --git a/NC_vs_AF/Precip_rate_master_SD50_comapre_10000.py b/NC_vs_AF/Precip_rate_master_SD50_comapre_10000.py new file mode 100644 index 0000000..7e16299 --- /dev/null +++ b/NC_vs_AF/Precip_rate_master_SD50_comapre_10000.py @@ -0,0 +1,129 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/' +name = 'New_master_SD50_compare_10000_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_2/SD10000/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_21/SD10000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_27/SD10000/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_72/SD10000/tail/' + + + +def Precipitation_rate(paths, timestep): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + precip_rate= [0 for i in range(nr_files)] + precip_rate_STD= [0 for i in range(nr_files)] + p = 0 + for file in range(nr_files): + filename = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[p] = h5py.File(filename + "/const.h5", "r")["G"][:,:] + precip_rate[p] = (h5py.File(filename + "/timestep" + str(240*timestep).zfill(10) + ".h5", "r")["precip_rate"][:,:]) + p+=1 + rhod = np.mean(rhod,axis=0) + precip_rate = np.mean(precip_rate,axis=0) + precip_rate_STD = np.std(precip_rate,axis=0) + + nx, nz = rhod.shape + hght = np.arange(nz) * 100 + return precip_rate, precip_rate_STD, hght + + + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Precipitation_rate, path_to_file_1) +partial_fun_2 = functools.partial(Precipitation_rate, path_to_file_2) +partial_fun_3 = functools.partial(Precipitation_rate, path_to_file_3) +partial_fun_4 = functools.partial(Precipitation_rate, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) +Class_4_array = np.array(Class_4) + + +mean_p_rate1 = [0 for i in range(91)] +std_p_rate1 = [0 for i in range(91)] + +mean_p_rate2 = [0 for i in range(91)] +std_p_rate2 = [0 for i in range(91)] + +mean_p_rate3 = [0 for i in range(91)] +std_p_rate3 = [0 for i in range(91)] + +mean_p_rate4 = [0 for i in range(91)] +std_p_rate4 = [0 for i in range(91)] + + +for i in range(91): + + mean_p_rate1[i] = float(0) if np.all((Class_1_array[i])[0]) == np.nan else np.mean((Class_1_array[i])[0], axis=0) + std_p_rate1[i] = float(0) if np.all((Class_1_array[i])[1]) == np.nan else np.mean((Class_1_array[i])[1], axis=0) + + mean_p_rate2[i] = float(0) if np.all((Class_2_array[i])[0]) == np.nan else np.mean((Class_2_array[i])[0], axis=0) + std_p_rate2[i] = float(0) if np.all((Class_2_array[i])[1]) == np.nan else np.mean((Class_2_array[i])[1], axis=0) + + mean_p_rate3[i] = float(0) if np.all((Class_3_array[i])[0]) == np.nan else np.mean((Class_3_array[i])[0], axis=0) + std_p_rate3[i] = float(0) if np.all((Class_3_array[i])[1]) == np.nan else np.mean((Class_3_array[i])[1], axis=0) + + mean_p_rate4[i] = float(0) if np.all((Class_4_array[i])[0]) == np.nan else np.mean((Class_4_array[i])[0], axis=0) + std_p_rate4[i] = float(0) if np.all((Class_4_array[i])[1]) == np.nan else np.mean((Class_4_array[i])[1], axis=0) + +height = ((Class_1_array[i])[2]) + +Mean_precip_rate_1 = np.mean(mean_p_rate1, axis=0) +STD_precip_rate_1 = np.mean(std_p_rate1, axis=0) +Mean_precip_rate_2 = np.mean(mean_p_rate2, axis=0) +STD_precip_rate_2 = np.mean(std_p_rate2, axis=0) +Mean_precip_rate_3 = np.mean(mean_p_rate3, axis=0) +STD_precip_rate_3 = np.mean(std_p_rate3, axis=0) +Mean_precip_rate_4 = np.mean(mean_p_rate4, axis=0) +STD_precip_rate_4 = np.mean(std_p_rate4, axis=0) +plt.figure(figsize=(30,15)) +plt.plot(Mean_precip_rate_1,height, label = 'M_2', linewidth=5) +plt.plot(Mean_precip_rate_2,height, label = 'M_21', linewidth=5) +plt.plot(Mean_precip_rate_3, height, label = 'M_27', linewidth=5) +plt.plot(Mean_precip_rate_4, height, label = 'M_72', linewidth=5) + +plt.legend() +plt.title(name) +# plt.fill_betweenx(height, mean_p_rate-std_p_rate, mean_p_rate+std_p_rate, alpha=0.2) +plt.savefig(outfile+name+"_mean_"+str(91*240).zfill(10)+'.png') +plt.clf() + diff --git a/NC_vs_AF/Randomness/Distribution/Compare.py b/NC_vs_AF/Randomness/Distribution/Compare.py index 4a83620..4f00c51 100644 --- a/NC_vs_AF/Randomness/Distribution/Compare.py +++ b/NC_vs_AF/Randomness/Distribution/Compare.py @@ -17,14 +17,18 @@ label_list = ['100', '1000', '10000'] paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_tail/', - '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_tail/'] -name = 'Piggy_2_Distribution' + '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/times_tail/'] +name = 'Piggy_3_Distribution' text_diff_piggy = 'Classic_M1' text_diff_piggy2 = 'Classic_M2' -text_diff_piggy3 = 'Tail_M1' -text_diff_piggy4 = 'Tail_M2' -podpisy = [text_diff_piggy, text_diff_piggy2, text_diff_piggy3, text_diff_piggy4] +text_diff_piggy3 = 'Classic_M3' +text_diff_piggy4 = 'Tail_M1' +text_diff_piggy5 = 'Tail_M2' +text_diff_piggy6 = 'Tail_M3' +podpisy = [text_diff_piggy, text_diff_piggy2, text_diff_piggy3, text_diff_piggy4, text_diff_piggy5, text_diff_piggy6] outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' width_multiplier = 0.57 ########################################################################## @@ -35,19 +39,11 @@ def Rysuj_to(sciezki, etykiety, podpisy, name): else: label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) multi = len(podpisy) - labels = [] - X = [] - for i in range(len(label)): - if i < len(label)/multi : - labels.append(podpisy[0]) - X.append(1) - elif i < len(label)/multi*2: - labels.append(podpisy[1]) - X.append(2) - else: - labels.append(podpisy[2]) - X.append(3) - + #Y = [i+1 for i in range(int(len(label)/len(podpisy)+1))] + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + #labels = [podpisy[i] for i in range(int(len(label)/len(podpisy)+1)) ] + labels = np.repeat(podpisy, int(len(etykiety))) def read_my_array(file_obj): arr_name = file_obj.readline() file_obj.readline() # discarded line with size of the array @@ -100,7 +96,7 @@ def czas(iter_value): colors = colors_list[0:len(etykiety)] *len(podpisy) multi = len(etykiety) - + print("X", X, "u", len(u), "col", len(colors)) fig1, ax = plt.subplots() fig1.set_size_inches(18.5, 10.5) for p in range( len(sciezki)): @@ -109,7 +105,7 @@ def czas(iter_value): A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") plt.xticks(X, labels, ha = 'center') - plt.ylim(0, 10.5e2) #piggy/ + plt.ylim(0, 6e2) #piggy/ # plt.ylim(0, 3.5e2) #no_piggy/ #plt.text(0.5, 265 , 'G', fontsize=26) plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') @@ -130,7 +126,7 @@ def czas(iter_value): error = licz_srednia("acc_vol_precip", p, sciezki)[2] A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") plt.ylabel(r"$\sigma$ [$m^3$]") - plt.ylim(0, 1.2e-1) #piggy + plt.ylim(0, 1.3e-1) #piggy # plt.ylim(0, 8e-1) #no_piggy #plt.text(0.5, 0.53 , 'F', fontsize=26) plt.xticks(X, labels, ha = 'center') @@ -152,7 +148,7 @@ def czas(iter_value): STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") plt.ylabel(r"Mean accumulated precipitation [$m^3$]") - plt.ylim(0, 25e-2) #piggy + plt.ylim(0, 43e-2) #piggy # plt.ylim(0, 65e-2) #no_piggy #plt.text(0.5, 0.43 , 'E', fontsize=26) plt.xticks(X, labels, ha = 'center') diff --git a/NC_vs_AF/Randomness/Distribution/Compare_only_master.py b/NC_vs_AF/Randomness/Distribution/Compare_only_master.py new file mode 100644 index 0000000..a6433ff --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Compare_only_master.py @@ -0,0 +1,170 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = [ 'P_n1', 'P_n2', 'P_n3', 'P_n4', 'P_n6', 'P_n7', 'P_n8', 'P_n9', 'P_n10', 'P_n11'] + +paths = ['/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_1/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_2/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_3/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_4/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_5/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_6/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_7/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_8/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_9/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_10/', + '/home/pzmij/2D/PAPER/Master/dxz100_SD100_Coal_NA1_master_n_11/'] +name = 'mASTER_COMPARE_ONLY' +text_diff_piggy = 'MA' +podpisy = [text_diff_piggy] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.07 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + print(line) + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value])))#,len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name))[-1] + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow', 'forestgreen', 'gold' ] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD = licz_srednia("acc_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD/srednia*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 6e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_precip", p, sciezki)[1] + error = licz_srednia("acc_precip", p, sciezki)[2] + print(error,'STD error dla symulacji',p) + A = plt.bar(X[p] + u[p]*width/multi, STD, color=colors[p],width =width*width_multiplier, yerr=error, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylabel(r"$\sigma$ [$mm$]") + plt.ylim(0, 2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia, color=colors[p],width =width*width_multiplier, yerr=STD_error_mean, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylabel(r"Mean accumulated precipitation [$mm$]") + plt.ylim(0, 2e-1) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Compare_testy.py b/NC_vs_AF/Randomness/Distribution/Compare_testy.py new file mode 100644 index 0000000..6e720df --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Compare_testy.py @@ -0,0 +1,167 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['100', '1000', '10000'] +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/times_tail/'] +name = 'TESTY' +text_diff_piggy = 'Classic_M1' +text_diff_piggy2 = 'Classic_M2' +text_diff_piggy3 = 'Classic_M3' +text_diff_piggy4 = 'Tail_M1' +text_diff_piggy5 = 'Tail_M2' +text_diff_piggy6 = 'Tail_M3' +podpisy = [text_diff_piggy, text_diff_piggy2, text_diff_piggy3, text_diff_piggy4, text_diff_piggy5, text_diff_piggy6] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.57 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + print(dl) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + print("X", X, "u", len(u), "col", len(colors)) + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 6e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.3e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 43e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Compare_testy_single.py b/NC_vs_AF/Randomness/Distribution/Compare_testy_single.py new file mode 100644 index 0000000..ed316b9 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Compare_testy_single.py @@ -0,0 +1,160 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['100'] +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/times_tail/'] +text_diff_piggy = 'Classic_M1' +name = 'TESTY_single' +podpisy = [text_diff_piggy] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.57 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + print(arr[-1]) + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + print(dl) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value])))#,len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name))[-1] + srednia[iter_value] = Zmienna.mean(0) + print("srednia",srednia[iter_value]) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + print(files) + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + print("X", X, "u", len(u), "col", len(colors)) + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD/srednia*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 6e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD, color=colors[p],width =width*width_multiplier, yerr=error, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.3e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia, color=colors[p],width =width*width_multiplier, yerr=STD_error_mean, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 43e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Compare_with_many_master.py b/NC_vs_AF/Randomness/Distribution/Compare_with_many_master.py new file mode 100644 index 0000000..9c3ed56 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Compare_with_many_master.py @@ -0,0 +1,180 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +# label_list = ['no_Mas', 'P', 'P2', 'P3', 'P_n1', 'P_n2', 'P_n3', 'P_n4', 'P_n6', 'P_n7', 'P_n8', 'P_n9', 'P_n10', 'P_n11'] +label_list = [ 'P_n1', 'P_n2', 'P_n3', 'P_n4', 'P_n5', 'P_n6', 'P_n7', 'P_n8', 'P_n9', 'P_n10', 'P_n11'] + +# paths = ['/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/times_tail/', +# '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_tail/', +# '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_tail/', +# '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/times_tail/', +# '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/times_tail/', +# '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/times_tail/', +# '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/times_tail/', +# '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/times_tail/', +# '/home/pzmij/2D/PAPER/Distribution/Piggy_n6/SD100/times_tail/', +# '/home/pzmij/2D/PAPER/Distribution/Piggy_n7/SD100/times_tail/'] +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n5/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n6/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n7/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n8/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n9/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n10/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_n11/SD100/times_tail/'] +name = 'ALL_Masters_check' +text_diff_piggy = 'slaves SD100' +podpisy = [text_diff_piggy] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.07 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value])))#,len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name))[-1] + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow', 'forestgreen', 'gold', 'navy', 'crimson' ] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD = licz_srednia("acc_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD/srednia*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 6e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_precip", p, sciezki)[1] + error = licz_srednia("acc_precip", p, sciezki)[2] + print(error,'STD error dla symulacji',p) + A = plt.bar(X[p] + u[p]*width/multi, STD, color=colors[p],width =width*width_multiplier, yerr=error, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylabel(r"$\sigma$ [$mm$]") + plt.ylim(0, 0.5e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia, color=colors[p],width =width*width_multiplier, yerr=STD_error_mean, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylabel(r"Mean accumulated precipitation [$mm$]") + plt.ylim(0, 0.5e-1) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Compare_with_nP.py b/NC_vs_AF/Randomness/Distribution/Compare_with_nP.py new file mode 100644 index 0000000..8f35707 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Compare_with_nP.py @@ -0,0 +1,173 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['100', '1000', '10000'] +paths = ['/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/times_tail/'] +name = 'Piggy_ALL_Distribution' +text_diff_piggy = 'Classic_nM' +text_diff_piggy1 = 'Classic_M1' +text_diff_piggy2 = 'Classic_M2' +text_diff_piggy3 = 'Classic_M3' +text_diff_piggy4 = 'Tail_nM' +text_diff_piggy5 = 'Tail_M1' +text_diff_piggy6 = 'Tail_M2' +text_diff_piggy7 = 'Tail_M3' + +podpisy = [text_diff_piggy, text_diff_piggy1, text_diff_piggy2, text_diff_piggy3, text_diff_piggy4, text_diff_piggy5, text_diff_piggy6, text_diff_piggy7] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.57 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value])))#,len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name))[-1] + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD = licz_srednia("acc_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD/srednia*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 6e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_precip", p, sciezki)[1] + error = licz_srednia("acc_precip", p, sciezki)[2] + print(error,'STD error dla symulacji',p) + A = plt.bar(X[p] + u[p]*width/multi, STD, color=colors[p],width =width*width_multiplier, yerr=error, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylabel(r"$\sigma$ [$mm$]") + plt.ylim(0, 5e-2) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia, color=colors[p],width =width*width_multiplier, yerr=STD_error_mean, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylabel(r"Mean accumulated precipitation [$mm$]") + plt.ylim(0, 5e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Master_max.py b/NC_vs_AF/Randomness/Distribution/Master_max.py new file mode 100644 index 0000000..20188f5 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Master_max.py @@ -0,0 +1,55 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + + + +def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + +def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr[-1] + +sciezki = '/home/pzmij/2D/PAPER/Master/Master_poszukiwania/times_SD100/' +Slownik = {} +dir_list = os.listdir(sciezki) +Nr_file = [(file.split("_out")[0]).split("_")[-1] for file in dir_list] + +# print(Nr_file) +for i in range(len(dir_list)): + Slownik[Nr_file[i]] = read_my_var(open(sciezki+dir_list[i], "r"), "acc_precip") + +# print(Slownik) + +myList = Slownik.items() +myList = sorted(myList) +print(max(Slownik.items(), key = lambda k : k[1])) +x, y = zip(*myList) +plt.plot(x, y) +plt.savefig('/home/pzmij/2D/PAPER/Wyniki/Distribution/Master_SD100.png') +# for i in range(len(dir_list)): +# Slownik[dir_list[i]] = read_my_var(open(sciezki+dir_list[i], "r"), "acc_precip") +Sorted = dict(sorted(Slownik.items(), key=lambda item: item[1])) +print([Sorted[i] for i in Sorted if Sorted[i] >= 0.1]) # prints [5] +# print(Sorted) diff --git a/NC_vs_AF/Randomness/Distribution/Piggy.py b/NC_vs_AF/Randomness/Distribution/Piggy.py index 04ab7f1..cd3391b 100644 --- a/NC_vs_AF/Randomness/Distribution/Piggy.py +++ b/NC_vs_AF/Randomness/Distribution/Piggy.py @@ -31,19 +31,10 @@ def Rysuj_to(sciezki, etykiety, podpisy, name): else: label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) multi = len(podpisy) - labels = [] - X = [] - for i in range(len(label)): - if i < len(label)/multi : - labels.append(podpisy[0]) - X.append(1) - elif i < len(label)/multi*2: - labels.append(podpisy[1]) - X.append(2) - else: - labels.append(podpisy[2]) - X.append(3) - + Y = [i+1 for i in range(int(len(label)/len(podpisy)+1))] + X = np.repeat(Y, int(len(etykiety))) + labels = [podpisy[i] for i in range(int(len(label)/len(podpisy)+1)) ] + labels = np.repeat(labels, int(len(etykiety))) def read_my_array(file_obj): arr_name = file_obj.readline() file_obj.readline() # discarded line with size of the array diff --git a/NC_vs_AF/Randomness/Distribution/Piggy_2.py b/NC_vs_AF/Randomness/Distribution/Piggy_2.py index 4be9f3f..2ef0052 100644 --- a/NC_vs_AF/Randomness/Distribution/Piggy_2.py +++ b/NC_vs_AF/Randomness/Distribution/Piggy_2.py @@ -31,19 +31,10 @@ def Rysuj_to(sciezki, etykiety, podpisy, name): else: label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) multi = len(podpisy) - labels = [] - X = [] - for i in range(len(label)): - if i < len(label)/multi : - labels.append(podpisy[0]) - X.append(1) - elif i < len(label)/multi*2: - labels.append(podpisy[1]) - X.append(2) - else: - labels.append(podpisy[2]) - X.append(3) - + Y = [i+1 for i in range(int(len(label)/len(podpisy)+1))] + X = np.repeat(Y, int(len(etykiety))) + labels = [podpisy[i] for i in range(int(len(label)/len(podpisy)+1)) ] + labels = np.repeat(labels, int(len(etykiety))) def read_my_array(file_obj): arr_name = file_obj.readline() file_obj.readline() # discarded line with size of the array diff --git a/NC_vs_AF/Randomness/Distribution/Piggy_3.py b/NC_vs_AF/Randomness/Distribution/Piggy_3.py new file mode 100644 index 0000000..c839c09 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Piggy_3.py @@ -0,0 +1,159 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['100', '1000', '10000'] +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/times_tail/'] +name = 'Piggy_3_Distribution' +text_diff_piggy = 'Classic' +text_diff_piggy2 = 'Tail' +podpisy = [text_diff_piggy, text_diff_piggy2] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/barrs/' +width_multiplier = 0.57 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(int(len(label)/len(podpisy)+1))] + X = np.repeat(Y, int(len(etykiety))) + labels = [podpisy[i] for i in range(int(len(label)/len(podpisy)+1)) ] + labels = np.repeat(labels, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 25e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD100.py b/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD100.py new file mode 100644 index 0000000..dae6892 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD100.py @@ -0,0 +1,164 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = [ 'M300', 'M422', 'M438', 'M497', 'M833', 'M879'] + +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy_SD100_300/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD100_422/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD100_438/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD100_497/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD100_833/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD100_879/SD100/times_tail/'] +name = 'SD100_Piggy_chosen' +text_diff_piggy = 'slaves SD100' +podpisy = [text_diff_piggy] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.37 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value])))#,len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name))[-1] + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow', 'forestgreen', 'gold', 'navy', 'crimson' ] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD = licz_srednia("acc_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD/srednia*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 6e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_precip", p, sciezki)[1] + error = licz_srednia("acc_precip", p, sciezki)[2] + print(error,'STD error dla symulacji',p) + A = plt.bar(X[p] + u[p]*width/multi, STD, color=colors[p],width =width*width_multiplier, yerr=error, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylabel(r"$\sigma$ [$mm$]") + plt.ylim(0, 0.5) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia, color=colors[p],width =width*width_multiplier, yerr=STD_error_mean, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylabel(r"Mean accumulated precipitation [$mm$]") + plt.ylim(0, 0.5) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD150.py b/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD150.py new file mode 100644 index 0000000..46a3aae --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD150.py @@ -0,0 +1,162 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = [ 'SD_34', 'SD_216', 'SD_145', 'SD_153'] + +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy_SD150_34/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD150_216/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD150_145/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD150_153/SD100/times_tail/'] +name = 'SD150_Piggy_chosen' +text_diff_piggy = 'slaves SD100' +podpisy = [text_diff_piggy] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.37 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value])))#,len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name))[-1] + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow', 'forestgreen', 'gold', 'navy', 'crimson' ] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD = licz_srednia("acc_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD/srednia*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 6e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_precip", p, sciezki)[1] + error = licz_srednia("acc_precip", p, sciezki)[2] + print(error,'STD error dla symulacji',p) + A = plt.bar(X[p] + u[p]*width/multi, STD, color=colors[p],width =width*width_multiplier, yerr=error, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylabel(r"$\sigma$ [$mm$]") + plt.ylim(0, 0.5) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia, color=colors[p],width =width*width_multiplier, yerr=STD_error_mean, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylabel(r"Mean accumulated precipitation [$mm$]") + plt.ylim(0, 0.5) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD50.py b/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD50.py new file mode 100644 index 0000000..46a8c2e --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD50.py @@ -0,0 +1,162 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = [ 'SD100', 'SD1000', 'SD1000', 'SD_72'] + +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_2/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_21/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_27/SD100/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_72/SD100/times_tail/'] +name = 'SD50_Piggy_chosen' +text_diff_piggy = 'slaves SD100' +podpisy = [text_diff_piggy] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.37 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value])))#,len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name))[-1] + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow', 'forestgreen', 'gold', 'navy', 'crimson' ] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD = licz_srednia("acc_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD/srednia*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 6e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_precip", p, sciezki)[1] + error = licz_srednia("acc_precip", p, sciezki)[2] + print(error,'STD error dla symulacji',p) + A = plt.bar(X[p] + u[p]*width/multi, STD, color=colors[p],width =width*width_multiplier, yerr=error, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylabel(r"$\sigma$ [$mm$]") + plt.ylim(0, 0.5) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia, color=colors[p],width =width*width_multiplier, yerr=STD_error_mean, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylabel(r"Mean accumulated precipitation [$mm$]") + plt.ylim(0, 0.5) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD50_all.py b/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD50_all.py new file mode 100644 index 0000000..6c352b7 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Piggy_SD100_from_master_SD50_all.py @@ -0,0 +1,165 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = [ 'SD100', 'SD1000', 'SD1000'] + +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_2/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_2/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_2/SD10000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_21/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_21/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_21/SD10000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_27/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_27/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_27/SD10000/times_tail/', + '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_72/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_72/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy_SD50_72/SD10000/times_tail/'] +name = 'SD50_Piggy_all' +piggy_1 = 'Master_SD50_2' +piggy_2 = 'Master_SD50_21' +piggy_3 = 'Master_SD50_27' +piggy_4 = 'Master_SD50_72' +podpisy = [piggy_1, piggy_2, piggy_3, piggy_4] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/barrs/' +width_multiplier = 0.37 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value])))#,len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name))[-1] + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow', 'forestgreen', 'gold', 'navy', 'crimson' ] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD = licz_srednia("acc_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD/srednia*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 6e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_precip", p, sciezki)[1] + error = licz_srednia("acc_precip", p, sciezki)[2] + print(error,'STD error dla symulacji',p) + A = plt.bar(X[p] + u[p]*width/multi, STD, color=colors[p],width =width*width_multiplier, yerr=error, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylabel(r"$\sigma$ [$mm$]") + plt.ylim(0, 0.5) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia, color=colors[p],width =width*width_multiplier, yerr=STD_error_mean, label=(label[p]) if (p < multi) else "") + # plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylabel(r"Mean accumulated precipitation [$mm$]") + plt.ylim(0, 0.5) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="Case name ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/Test.py b/NC_vs_AF/Randomness/Distribution/Test.py new file mode 100644 index 0000000..9577d33 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/Test.py @@ -0,0 +1,169 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['10000', '100', '1000'] +paths = ['/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_classic/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_classic/','/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/times_tail/'] +name = 'TEST_Piggy_Distribution' +text_diff_piggy = 'Classic' +text_diff_piggy2 = 'Tail' +podpisy = [text_diff_piggy, text_diff_piggy2] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/barrs/' +width_multiplier = 0.57 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + labels = [] + X = [] + for i in range(len(label)): + if i < len(label)/multi : + labels.append(podpisy[0]) + X.append(1) + elif i < len(label)/multi*2: + labels.append(podpisy[1]) + X.append(2) + else: + labels.append(podpisy[2]) + X.append(3) + + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + # print(arr, file_obj) + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 25e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/Randomness/Distribution/no_Piggy.py b/NC_vs_AF/Randomness/Distribution/no_Piggy.py new file mode 100644 index 0000000..dff9338 --- /dev/null +++ b/NC_vs_AF/Randomness/Distribution/no_Piggy.py @@ -0,0 +1,160 @@ +from math import exp, log, sqrt, pi, erf, cos, pow, asin, atan, acos, factorial +import numpy as np +from scipy.stats import moment +from sys import argv +#from matplotlib.ticker import MultipleLocator +import matplotlib as plt +import matplotlib.pyplot as plt +#import matplotlib as mpl +#import matplotlib.colors as mcolors +#from matplotlib.ticker import FormatStrFormatter, LogFormatter, LogLocator, LogFormatterSciNotation, AutoMinorLocator +import glob, os +plt.rcParams.update({'font.size': 15}) + +############################################################################ +#### DO RECZNEGO UZUPELNIENIA############# + +label_list = ['100', '1000', '10000'] +paths = ['/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/times_classic/', '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/times_classic/','/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/times_classic/', + '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/times_tail/', '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/times_tail/', '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/times_tail/'] +name = 'Piggy_3_Distribution' +text_diff_piggy = 'Classic' +text_diff_piggy2 = 'Tail' +podpisy = [text_diff_piggy, text_diff_piggy2] +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/barrs/' +width_multiplier = 0.57 +########################################################################## +def Rysuj_to(sciezki, etykiety, podpisy, name): + + if len(podpisy) == 1 : + label = etykiety + else: + label = etykiety[0:int(len(sciezki)/2)]*len(podpisy) + multi = len(podpisy) + #Y = [i+1 for i in range(int(len(label)/len(podpisy)+1))] + Y = [i+1 for i in range(multi)] + X = np.repeat(Y, int(len(etykiety))) + #labels = [podpisy[i] for i in range(int(len(label)/len(podpisy)+1)) ] + labels = np.repeat(podpisy, int(len(etykiety))) + def read_my_array(file_obj): + arr_name = file_obj.readline() + file_obj.readline() # discarded line with size of the array + line = file_obj.readline() + line = line.split(" ") + del line[0] + del line[len(line)-1] + arr = list(map(float,line)) + return np.array(arr), arr_name + + def read_my_var(file_obj, var_name): + file_obj.seek(0) + while True: + arr, name = read_my_array(file_obj) + if(str(name).strip() == str(var_name).strip()): + break + return arr + def licz_srednia(parameter_name, iter_value, sciezki): + dl = len(series_file[iter_value]) + srednia =[0 for i in range(len(sciezki))] + STD = [0 for i in range(len(sciezki))] + error = [0 for i in range(len(sciezki))] + STD_error_mean = [0 for i in range(len(sciezki))] + Zmienna = np.zeros((len(series_file[iter_value]),len(read_my_var(series_file[iter_value][0], str(parameter_name))))) + for j in range(len(series_file[iter_value])): + Zmienna[j] = read_my_var(series_file[iter_value][j], str(parameter_name)) + srednia[iter_value] = Zmienna.mean(0) + STD[iter_value] = Zmienna.std(0) + STD_error_mean[iter_value] = Zmienna.std(0)/sqrt(dl) + error[iter_value] = np.power(1/dl * (moment(Zmienna,4) - (dl-3)/(dl-1)*np.power(STD[iter_value],2)),1/2)/(2*np.sqrt(STD[iter_value])) + #Error from this https://stats.stackexchange.com/questions/156518/what-is-the-standard-error-of-the-sample-standard-deviation + return srednia[iter_value], STD[iter_value], error[iter_value], STD_error_mean[iter_value] + + def czas(iter_value): + for j in range(len(series_file[iter_value])): + time = read_my_var(series_file[iter_value][j], "position") + return time + files = [0 for i in range(len(sciezki))] + series_file = [0 for i in range(len(sciezki))] + for p in range(len(sciezki)): + os.chdir(sciezki[p]) + series_file[p] = [open(file_names, "r") for file_names in glob.glob("*.dat")] + files[p] = glob.glob("*.dat") + + colors = [ 'forestgreen', 'gold', 'forestgreen', 'gold', 'forestgreen', 'gold'] + u_init = np.linspace(-int(len(label)/len(podpisy)), int(len(label)/len(podpisy)), int(len(label)/len(podpisy))) + u = np.tile(u_init, len(podpisy)) + width = 0.20 + colors_list = [ 'thistle', 'orchid','red', 'grey', 'green', 'orange', 'blue', 'yellow'] + colors = colors_list[0:len(etykiety)] *len(podpisy) + multi = len(etykiety) + + + fig1, ax = plt.subplots() + fig1.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1]/srednia[-1]*100, color=colors[p],width =width*width_multiplier, label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\frac{\sigma(acc \hspace{0.5} precip)}{mean(acc \hspace{0.5} precip)}$ [%]") + plt.xticks(X, labels, ha = 'center') + plt.ylim(0, 10.5e2) #piggy/ + # plt.ylim(0, 3.5e2) #no_piggy/ + #plt.text(0.5, 265 , 'G', fontsize=26) + plt.title("Standard deviation of accumulated precipitation to \n mean of accumulated precipitation in a cumulus congestus simulation",weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD#: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax.text(rect.get_x() + rect.get_width()/2., 0.99*height, + '%d' % int(height) + "%", ha='center', va='bottom') + plt.savefig(outfile+'STD_to_mean_'+name+'.png') + + fig2, ax2 = plt.subplots() + fig2.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + STD = licz_srednia("acc_vol_precip", p, sciezki)[1] + error = licz_srednia("acc_vol_precip", p, sciezki)[2] + A = plt.bar(X[p] + u[p]*width/multi, STD[-1], color=colors[p],width =width*width_multiplier, yerr=error[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"$\sigma$ [$m^3$]") + plt.ylim(0, 1.2e-1) #piggy + # plt.ylim(0, 8e-1) #no_piggy + #plt.text(0.5, 0.53 , 'F', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Standard deviation of accumulated precipitation \n in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + for rect in A: + height = rect.get_height() + ax2.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'STD_'+name+'.png') + + fig3, ax3 = plt.subplots() + fig3.set_size_inches(18.5, 10.5) + for p in range( len(sciezki)): + srednia = licz_srednia("acc_vol_precip", p, sciezki)[0] + STD_error_mean = licz_srednia("acc_vol_precip", p, sciezki)[3] + A = plt.bar(X[p] + u[p]*width/multi, srednia[-1], color=colors[p],width =width*width_multiplier, yerr=STD_error_mean[-1], label=(label[p]) if (p < multi) else "") + plt.ylabel(r"Mean accumulated precipitation [$m^3$]") + plt.ylim(0, 25e-2) #piggy + # plt.ylim(0, 65e-2) #no_piggy + #plt.text(0.5, 0.43 , 'E', fontsize=26) + plt.xticks(X, labels, ha = 'center') + plt.title(" Mean of accumulated precipitation in a cumulus congestus simulation", weight='bold') + # plt.legend(title="number of super-droplets per cell: ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + plt.legend(title="SD# ", prop=dict(weight='bold') ,loc='upper left', framealpha = 0.5, frameon = 0, ncol = multi) + + + for rect in A: + height = rect.get_height() + ax3.text(rect.get_x() + rect.get_width()/2., 0.99*height, + f"{height:.2e}", ha='center', va='bottom') + # f"{height:.2e}" + "$m^3$", ha='center', va='bottom') + plt.savefig(outfile+'Mean_'+name+'.png') + + +Rysuj_to(paths, label_list, podpisy, name) diff --git a/NC_vs_AF/precip_rate.py b/NC_vs_AF/precip_rate.py new file mode 100644 index 0000000..8ce296c --- /dev/null +++ b/NC_vs_AF/precip_rate.py @@ -0,0 +1,124 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/' +name = 'no_Piggy_tail_average_by_timesteps_and_files' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/dobre/' + + +def Precipitation_rate(paths, timestep): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + precip_rate= [0 for i in range(nr_files)] + precip_rate_STD= [0 for i in range(nr_files)] + p = 0 + for file in range(nr_files): + filename = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[p] = h5py.File(filename + "/const.h5", "r")["G"][:,:] + precip_rate[p] = (h5py.File(filename + "/timestep" + str(240*timestep).zfill(10) + ".h5", "r")["precip_rate"][:,:]) + p+=1 + rhod = np.mean(rhod,axis=0) + precip_rate = np.mean(precip_rate,axis=0) + precip_rate_STD = np.std(precip_rate,axis=0) + + nx, nz = rhod.shape + hght = np.arange(nz) * 100 + return precip_rate, precip_rate_STD, hght + + + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Precipitation_rate, path_to_file_1) +partial_fun_2 = functools.partial(Precipitation_rate, path_to_file_2) +partial_fun_3 = functools.partial(Precipitation_rate, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + + +mean_p_rate1 = [0 for i in range(91)] +std_p_rate1 = [0 for i in range(91)] +# height1 = [0 for i in range(91)] + +mean_p_rate2 = [0 for i in range(91)] +std_p_rate2 = [0 for i in range(91)] +# height2 = [0 for i in range(91)] + +mean_p_rate3 = [0 for i in range(91)] +std_p_rate3 = [0 for i in range(91)] +# height3 = [0 for i in range(91)] + +# print(np.mean((Class_1_array[50])[0],axis=0)) + + +for i in range(91): + + mean_p_rate1[i] = float(0) if np.all((Class_1_array[i])[0]) == np.nan else np.mean((Class_1_array[i])[0], axis=0) + std_p_rate1[i] = float(0) if np.all((Class_1_array[i])[1]) == np.nan else np.mean((Class_1_array[i])[1], axis=0) + # height1[i] = float(0) if np.all((Class_1_array[i])[2]) == np.nan else np.mean((Class_1_array[i])[2], axis=0) + + mean_p_rate2[i] = float(0) if np.all((Class_2_array[i])[0]) == np.nan else np.mean((Class_2_array[i])[0], axis=0) + std_p_rate2[i] = float(0) if np.all((Class_2_array[i])[1]) == np.nan else np.mean((Class_2_array[i])[1], axis=0) + # height2[i] = float(0) if np.all((Class_2_array[i])[2]) == np.nan else np.mean((Class_2_array[i])[2], axis=0) + + mean_p_rate3[i] = float(0) if np.all((Class_3_array[i])[0]) == np.nan else np.mean((Class_3_array[i])[0], axis=0) + std_p_rate3[i] = float(0) if np.all((Class_3_array[i])[1]) == np.nan else np.mean((Class_3_array[i])[1], axis=0) + # height3[i] = float(0) if np.all((Class_3_array[i])[2]) == np.nan else np.mean((Class_3_array[i])[2], axis=0) + +height = ((Class_1_array[i])[2]) + + + +Mean_precip_rate_1 = np.mean(mean_p_rate1, axis=0) +STD_precip_rate_1 = np.mean(std_p_rate1, axis=0) +Mean_precip_rate_2 = np.mean(mean_p_rate2, axis=0) +STD_precip_rate_2 = np.mean(std_p_rate2, axis=0) +Mean_precip_rate_3 = np.mean(mean_p_rate3, axis=0) +STD_precip_rate_3 = np.mean(std_p_rate3, axis=0) + +plt.figure(figsize=(30,15)) +plt.plot(Mean_precip_rate_1,height, label = 'SD100', linewidth=5) +plt.plot(Mean_precip_rate_2,height, label = 'SD1000', linewidth=5) +plt.plot(Mean_precip_rate_3, height, label = 'SD10000', linewidth=5) +plt.legend() +plt.title(name) +# plt.fill_betweenx(height, mean_p_rate-std_p_rate, mean_p_rate+std_p_rate, alpha=0.2) +plt.savefig(outfile+name+"_mean_"+str(91*240).zfill(10)+'.png') +plt.clf() + diff --git a/NC_vs_AF/precip_rate_new_master.py b/NC_vs_AF/precip_rate_new_master.py new file mode 100644 index 0000000..155c4a7 --- /dev/null +++ b/NC_vs_AF/precip_rate_new_master.py @@ -0,0 +1,223 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/' +name = 'New_master_check_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n5/SD100/tail/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n6/SD100/tail/' +path_to_file_7 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n7/SD100/tail/' +path_to_file_8 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n8/SD100/tail/' +path_to_file_9 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n9/SD100/tail/' +path_to_file_10 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n10/SD100/tail/' +path_to_file_11 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n11/SD100/tail/' + + +def Precipitation_rate(paths, timestep): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + precip_rate= [0 for i in range(nr_files)] + precip_rate_STD= [0 for i in range(nr_files)] + p = 0 + for file in range(nr_files): + filename = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[p] = h5py.File(filename + "/const.h5", "r")["G"][:,:] + precip_rate[p] = (h5py.File(filename + "/timestep" + str(240*timestep).zfill(10) + ".h5", "r")["precip_rate"][:,:]) + p+=1 + rhod = np.mean(rhod,axis=0) + precip_rate = np.mean(precip_rate,axis=0) + precip_rate_STD = np.std(precip_rate,axis=0) + + nx, nz = rhod.shape + hght = np.arange(nz) * 100 + return precip_rate, precip_rate_STD, hght + + + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Precipitation_rate, path_to_file_1) +partial_fun_2 = functools.partial(Precipitation_rate, path_to_file_2) +partial_fun_3 = functools.partial(Precipitation_rate, path_to_file_3) +partial_fun_4 = functools.partial(Precipitation_rate, path_to_file_4) +partial_fun_5 = functools.partial(Precipitation_rate, path_to_file_5) +partial_fun_6 = functools.partial(Precipitation_rate, path_to_file_6) +partial_fun_7 = functools.partial(Precipitation_rate, path_to_file_7) +partial_fun_8 = functools.partial(Precipitation_rate, path_to_file_8) +partial_fun_9 = functools.partial(Precipitation_rate, path_to_file_9) +partial_fun_10 = functools.partial(Precipitation_rate, path_to_file_10) +partial_fun_11 = functools.partial(Precipitation_rate, path_to_file_11) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + Classic_7 = executor.map(partial_fun_7, punkty) + Classic_8 = executor.map(partial_fun_8, punkty) + Classic_9 = executor.map(partial_fun_9, punkty) + Classic_10 = executor.map(partial_fun_10, punkty) + Classic_11 = executor.map(partial_fun_11, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] +Class_7 = [i for i in Classic_7] +Class_8 = [i for i in Classic_8] +Class_9 = [i for i in Classic_9] +Class_10 = [i for i in Classic_10] +Class_11 = [i for i in Classic_11] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) +Class_4_array = np.array(Class_4) +Class_5_array = np.array(Class_5) +Class_6_array = np.array(Class_6) +Class_7_array = np.array(Class_7) +Class_8_array = np.array(Class_8) +Class_9_array = np.array(Class_9) +Class_10_array = np.array(Class_10) +Class_11_array = np.array(Class_11) + +mean_p_rate1 = [0 for i in range(91)] +std_p_rate1 = [0 for i in range(91)] + +mean_p_rate2 = [0 for i in range(91)] +std_p_rate2 = [0 for i in range(91)] + +mean_p_rate3 = [0 for i in range(91)] +std_p_rate3 = [0 for i in range(91)] + +mean_p_rate4 = [0 for i in range(91)] +std_p_rate4 = [0 for i in range(91)] + +mean_p_rate5 = [0 for i in range(91)] +std_p_rate5 = [0 for i in range(91)] + +mean_p_rate6 = [0 for i in range(91)] +std_p_rate6 = [0 for i in range(91)] + +mean_p_rate7 = [0 for i in range(91)] +std_p_rate7 = [0 for i in range(91)] + +mean_p_rate8 = [0 for i in range(91)] +std_p_rate8 = [0 for i in range(91)] + +mean_p_rate9 = [0 for i in range(91)] +std_p_rate9 = [0 for i in range(91)] + +mean_p_rate10 = [0 for i in range(91)] +std_p_rate10 = [0 for i in range(91)] + +mean_p_rate11 = [0 for i in range(91)] +std_p_rate11 = [0 for i in range(91)] + +for i in range(91): + + mean_p_rate1[i] = float(0) if np.all((Class_1_array[i])[0]) == np.nan else np.mean((Class_1_array[i])[0], axis=0) + std_p_rate1[i] = float(0) if np.all((Class_1_array[i])[1]) == np.nan else np.mean((Class_1_array[i])[1], axis=0) + + mean_p_rate2[i] = float(0) if np.all((Class_2_array[i])[0]) == np.nan else np.mean((Class_2_array[i])[0], axis=0) + std_p_rate2[i] = float(0) if np.all((Class_2_array[i])[1]) == np.nan else np.mean((Class_2_array[i])[1], axis=0) + + mean_p_rate3[i] = float(0) if np.all((Class_3_array[i])[0]) == np.nan else np.mean((Class_3_array[i])[0], axis=0) + std_p_rate3[i] = float(0) if np.all((Class_3_array[i])[1]) == np.nan else np.mean((Class_3_array[i])[1], axis=0) + + mean_p_rate4[i] = float(0) if np.all((Class_4_array[i])[0]) == np.nan else np.mean((Class_4_array[i])[0], axis=0) + std_p_rate4[i] = float(0) if np.all((Class_4_array[i])[1]) == np.nan else np.mean((Class_4_array[i])[1], axis=0) + + mean_p_rate5[i] = float(0) if np.all((Class_5_array[i])[0]) == np.nan else np.mean((Class_5_array[i])[0], axis=0) + std_p_rate5[i] = float(0) if np.all((Class_5_array[i])[1]) == np.nan else np.mean((Class_5_array[i])[1], axis=0) + + mean_p_rate6[i] = float(0) if np.all((Class_6_array[i])[0]) == np.nan else np.mean((Class_6_array[i])[0], axis=0) + std_p_rate6[i] = float(0) if np.all((Class_6_array[i])[1]) == np.nan else np.mean((Class_6_array[i])[1], axis=0) + + mean_p_rate7[i] = float(0) if np.all((Class_7_array[i])[0]) == np.nan else np.mean((Class_7_array[i])[0], axis=0) + std_p_rate7[i] = float(0) if np.all((Class_7_array[i])[1]) == np.nan else np.mean((Class_7_array[i])[1], axis=0) + + mean_p_rate8[i] = float(0) if np.all((Class_8_array[i])[0]) == np.nan else np.mean((Class_8_array[i])[0], axis=0) + std_p_rate8[i] = float(0) if np.all((Class_8_array[i])[1]) == np.nan else np.mean((Class_8_array[i])[1], axis=0) + + mean_p_rate9[i] = float(0) if np.all((Class_9_array[i])[0]) == np.nan else np.mean((Class_9_array[i])[0], axis=0) + std_p_rate9[i] = float(0) if np.all((Class_9_array[i])[1]) == np.nan else np.mean((Class_9_array[i])[1], axis=0) + + mean_p_rate10[i] = float(0) if np.all((Class_10_array[i])[0]) == np.nan else np.mean((Class_10_array[i])[0], axis=0) + std_p_rate10[i] = float(0) if np.all((Class_10_array[i])[1]) == np.nan else np.mean((Class_10_array[i])[1], axis=0) + + mean_p_rate11[i] = float(0) if np.all((Class_11_array[i])[0]) == np.nan else np.mean((Class_11_array[i])[0], axis=0) + std_p_rate11[i] = float(0) if np.all((Class_11_array[i])[1]) == np.nan else np.mean((Class_11_array[i])[1], axis=0) + +height = ((Class_1_array[i])[2]) + +Mean_precip_rate_1 = np.mean(mean_p_rate1, axis=0) +STD_precip_rate_1 = np.mean(std_p_rate1, axis=0) +Mean_precip_rate_2 = np.mean(mean_p_rate2, axis=0) +STD_precip_rate_2 = np.mean(std_p_rate2, axis=0) +Mean_precip_rate_3 = np.mean(mean_p_rate3, axis=0) +STD_precip_rate_3 = np.mean(std_p_rate3, axis=0) +Mean_precip_rate_4 = np.mean(mean_p_rate4, axis=0) +STD_precip_rate_4 = np.mean(std_p_rate4, axis=0) +Mean_precip_rate_5 = np.mean(mean_p_rate5, axis=0) +STD_precip_rate_5 = np.mean(std_p_rate5, axis=0) +Mean_precip_rate_6 = np.mean(mean_p_rate6, axis=0) +STD_precip_rate_6 = np.mean(std_p_rate6, axis=0) +Mean_precip_rate_7 = np.mean(mean_p_rate7, axis=0) +STD_precip_rate_7 = np.mean(std_p_rate7, axis=0) +Mean_precip_rate_8 = np.mean(mean_p_rate8, axis=0) +STD_precip_rate_8 = np.mean(std_p_rate8, axis=0) +Mean_precip_rate_9 = np.mean(mean_p_rate9, axis=0) +STD_precip_rate_9 = np.mean(std_p_rate9, axis=0) +Mean_precip_rate_10 = np.mean(mean_p_rate10, axis=0) +STD_precip_rate_10 = np.mean(std_p_rate10, axis=0) +Mean_precip_rate_11 = np.mean(mean_p_rate11, axis=0) +STD_precip_rate_11 = np.mean(std_p_rate11, axis=0) + +plt.figure(figsize=(30,15)) +plt.scatter(Mean_precip_rate_1,height, label = 'P_n1', linewidth=5) +plt.scatter(Mean_precip_rate_2,height, label = 'P_n2', linewidth=5) +plt.scatter(Mean_precip_rate_3, height, label = 'P_n3', linewidth=5) +plt.scatter(Mean_precip_rate_4, height, label = 'P_n4', linewidth=5) +plt.scatter(Mean_precip_rate_5, height, label = 'P_n5', linewidth=5) +plt.scatter(Mean_precip_rate_6, height, label = 'P_n6', linewidth=5) +plt.scatter(Mean_precip_rate_7, height, label = 'P_n7', linewidth=5) +plt.scatter(Mean_precip_rate_8, height, label = 'P_n8', linewidth=5) +plt.scatter(Mean_precip_rate_9, height, label = 'P_n9', linewidth=5) +plt.scatter(Mean_precip_rate_10, height, label = 'P_n10', linewidth=5) +plt.scatter(Mean_precip_rate_11, height, label = 'P_n11', linewidth=5) +plt.legend() +plt.title(name) +# plt.fill_betweenx(height, mean_p_rate-std_p_rate, mean_p_rate+std_p_rate, alpha=0.2) +plt.savefig(outfile+name+"_mean_"+str(91*240).zfill(10)+'.png') +plt.clf() + diff --git a/Rain_distribution/Distribution/Piggy/classic/Srednia_po_czasie_test.py b/Rain_distribution/Distribution/Piggy/classic/Srednia_classic_m_cb.py similarity index 98% rename from Rain_distribution/Distribution/Piggy/classic/Srednia_po_czasie_test.py rename to Rain_distribution/Distribution/Piggy/classic/Srednia_classic_m_cb.py index faa180c..c25ba1f 100644 --- a/Rain_distribution/Distribution/Piggy/classic/Srednia_po_czasie_test.py +++ b/Rain_distribution/Distribution/Piggy/classic/Srednia_classic_m_cb.py @@ -147,7 +147,7 @@ def Positions(paths, timestep): ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') -ax1.step(biny[2:], Average_srednia_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') #lub opcja ze liczba na jednym a na drugim masa fig.suptitle('time= '+str(i*120)+'[s]') diff --git a/Rain_distribution/Distribution/Piggy/classic/Srednia_classic_m_g.py b/Rain_distribution/Distribution/Piggy/classic/Srednia_classic_m_g.py new file mode 100644 index 0000000..cf2d325 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/classic/Srednia_classic_m_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/classic/mask/g/' +name = 'Piggy_Average_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/classic/Srednia_classic_nm_cb.py b/Rain_distribution/Distribution/Piggy/classic/Srednia_classic_nm_cb.py new file mode 100644 index 0000000..060474f --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/classic/Srednia_classic_nm_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/classic/no_mask/cb/' +name = 'Piggy_Average_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/classic/Srednie_classic_nm_g.py b/Rain_distribution/Distribution/Piggy/classic/Srednie_classic_nm_g.py new file mode 100644 index 0000000..73aa5bf --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/classic/Srednie_classic_nm_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/classic/no_mask/g/' +name = 'Piggy_Average_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_m_cb.py b/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_m_cb.py new file mode 100644 index 0000000..59e19cc --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_m_cb.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/compare/mask/cb/' +name = 'Piggy_Average_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_num6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() diff --git a/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_m_g.py b/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_m_g.py new file mode 100644 index 0000000..76da8ab --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_m_g.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/compare/mask/g/' +name = 'Piggy_Average_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_num6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() diff --git a/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_nm_cb.py b/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_nm_cb.py new file mode 100644 index 0000000..69ffc92 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_nm_cb.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/compare/no_mask/cb/' +name = 'Piggy_Average_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_nm_g.py b/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_nm_g.py new file mode 100644 index 0000000..e0abd47 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/mix/Srednie_compare_nm_g.py @@ -0,0 +1,216 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/compare/no_mask/g/' +name = 'Piggy_Average_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_m_cb.py b/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_m_cb.py new file mode 100644 index 0000000..dc3e93e --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_m_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/tail/mask/cb/' +name = 'Piggy_Average_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_m_g.py b/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_m_g.py new file mode 100644 index 0000000..f85c7c0 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_m_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/tail/mask/g/' +name = 'Piggy_Average_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_nm_cb.py b/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_nm_cb.py new file mode 100644 index 0000000..1bee29c --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_nm_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/tail/no_mask/cb/' +name = 'Piggy_Average_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_nm_g.py b/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_nm_g.py new file mode 100644 index 0000000..4c7db7a --- /dev/null +++ b/Rain_distribution/Distribution/Piggy/tail/Srednie_tail_nm_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy/tail/no_mask/g/' +name = 'Piggy_Average_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_m_cb.py b/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_m_cb.py new file mode 100644 index 0000000..8537e34 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_m_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/classic/mask/cb/' +name = 'Piggy_2_Average_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_m_g.py b/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_m_g.py new file mode 100644 index 0000000..f66f4ae --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_m_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/classic/mask/g/' +name = 'Piggy_2_Average_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_nm_cb.py b/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_nm_cb.py new file mode 100644 index 0000000..0ea2a16 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_nm_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/classic/no_mask/cb/' +name = 'Piggy_2_Average_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_nm_g.py b/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_nm_g.py new file mode 100644 index 0000000..2520235 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/classic/Srednie_classic_nm_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/classic/no_mask/g/' +name = 'Piggy_2_Average_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_m_cb.py b/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_m_cb.py new file mode 100644 index 0000000..d482de4 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_m_cb.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/compare/mask/cb/' +name = 'Piggy_2_Average_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_m_g.py b/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_m_g.py new file mode 100644 index 0000000..e5426db --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_m_g.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/compare/mask/g/' +name = 'Piggy_2_Average_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_nm_cb.py b/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_nm_cb.py new file mode 100644 index 0000000..8531b08 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_nm_cb.py @@ -0,0 +1,216 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/compare/no_mask/cb/' +name = 'Piggy_2_Average_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_nm_g.py b/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_nm_g.py new file mode 100644 index 0000000..a330ad9 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/mix/Srednie_compare_nm_g.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/compare/no_mask/g/' +name = 'Piggy_2_Average_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_m_cb.py b/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_m_cb.py new file mode 100644 index 0000000..f7b95bd --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_m_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/tail/mask/cb/' +name = 'Piggy_2_Average_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_m_g.py b/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_m_g.py new file mode 100644 index 0000000..68900a2 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_m_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/tail/mask/g/' +name = 'Piggy_2_Average_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_nm_cb.py b/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_nm_cb.py new file mode 100644 index 0000000..7dcfe94 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_nm_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/tail/no_mask/cb/' +name = 'Piggy_2_Average_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_nm_g.py b/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_nm_g.py new file mode 100644 index 0000000..e2e6bb4 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_2/tail/Srednie_tail_nm_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_2/tail/no_mask/g/' +name = 'Piggy_2_Average_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_2/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py b/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py new file mode 100644 index 0000000..eb08e9d --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/mask/cb/' +name = 'Piggy_3_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py b/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py new file mode 100644 index 0000000..f4797b8 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/mask/g/' +name = 'Piggy_3_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py b/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py new file mode 100644 index 0000000..7bc0c87 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/no_mask/cb/' +name = 'Piggy_3_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py b/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py new file mode 100644 index 0000000..eb7d257 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/no_mask/g/' +name = 'Piggy_3_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_m_cb.py b/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_m_cb.py new file mode 100644 index 0000000..630d54b --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_m_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/mask/cb/' +name = 'Piggy_3_Average_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_m_g.py b/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_m_g.py new file mode 100644 index 0000000..181ba4d --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_m_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/mask/g/' +name = 'Piggy_3_Average_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_nm_cb.py b/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_nm_cb.py new file mode 100644 index 0000000..1ca88e7 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_nm_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/no_mask/cb/' +name = 'Piggy_3_Average_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_nm_g.py b/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_nm_g.py new file mode 100644 index 0000000..8d9698b --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/classic/Srednie_classic_nm_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/no_mask/g/' +name = 'Piggy_3_Average_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py b/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py new file mode 100644 index 0000000..608319e --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/mask/cb/' +name = 'Piggy_3_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py b/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py new file mode 100644 index 0000000..490e25d --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/mask/g/' +name = 'Piggy_3_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py b/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py new file mode 100644 index 0000000..1ec08c7 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/no_mask/cb/' +name = 'Piggy_3_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py b/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py new file mode 100644 index 0000000..975b5bc --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/no_mask/g/' +name = 'Piggy_3_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_m_cb.py b/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_m_cb.py new file mode 100644 index 0000000..7c3fef2 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_m_cb.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/mask/cb/' +name = 'Piggy_3_Average_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_m_g.py b/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_m_g.py new file mode 100644 index 0000000..032b2be --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_m_g.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/mask/g/' +name = 'Piggy_3_Average_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_nm_cb.py b/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_nm_cb.py new file mode 100644 index 0000000..be223ff --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_nm_cb.py @@ -0,0 +1,216 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/no_mask/cb/' +name = 'Piggy_3_Average_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_nm_g.py b/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_nm_g.py new file mode 100644 index 0000000..eabdfb9 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/mix/Srednie_compare_nm_g.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/no_mask/g/' +name = 'Piggy_3_Average_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py b/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py new file mode 100644 index 0000000..5d1fd6f --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/tail/mask/cb/' +name = 'Piggy_3_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py b/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py new file mode 100644 index 0000000..21be110 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/tail/mask/g/' +name = 'Piggy_3_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py b/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py new file mode 100644 index 0000000..064401b --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/tail/no_mask/cb/' +name = 'Piggy_3_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py b/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py new file mode 100644 index 0000000..c415271 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/tail/no_mask/g/' +name = 'Piggy_3_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_m_cb.py b/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_m_cb.py new file mode 100644 index 0000000..28b45c6 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_m_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/tail/mask/cb/' +name = 'Piggy_3_Average_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_m_g.py b/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_m_g.py new file mode 100644 index 0000000..5860e7f --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_m_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/tail/mask/g/' +name = 'Piggy_3_Average_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_nm_cb.py b/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_nm_cb.py new file mode 100644 index 0000000..57e36f9 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_nm_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/tail/no_mask/cb/' +name = 'Piggy_3_Average_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_nm_g.py b/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_nm_g.py new file mode 100644 index 0000000..f05e6e7 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/tail/Srednie_tail_nm_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/tail/no_mask/g/' +name = 'Piggy_3_Average_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_3/test.sh b/Rain_distribution/Distribution/Piggy_3/test.sh new file mode 100644 index 0000000..e5ace65 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_3/test.sh @@ -0,0 +1,4 @@ + +for files in /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/Distribution/Piggy_2/mix/*; do + echo $files + done diff --git a/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py new file mode 100644 index 0000000..eb08e9d --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/mask/cb/' +name = 'Piggy_3_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py b/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py new file mode 100644 index 0000000..f4797b8 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/mask/g/' +name = 'Piggy_3_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py new file mode 100644 index 0000000..7bc0c87 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/no_mask/cb/' +name = 'Piggy_3_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py b/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py new file mode 100644 index 0000000..eb7d257 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py @@ -0,0 +1,160 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/no_mask/g/' +name = 'Piggy_3_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_m_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_m_cb.py new file mode 100644 index 0000000..630d54b --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_m_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/mask/cb/' +name = 'Piggy_3_Average_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_m_g.py b/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_m_g.py new file mode 100644 index 0000000..181ba4d --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_m_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/mask/g/' +name = 'Piggy_3_Average_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_nm_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_nm_cb.py new file mode 100644 index 0000000..1ca88e7 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_nm_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/no_mask/cb/' +name = 'Piggy_3_Average_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_nm_g.py b/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_nm_g.py new file mode 100644 index 0000000..8d9698b --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/classic/Srednie_classic_nm_g.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/classic/no_mask/g/' +name = 'Piggy_3_Average_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py new file mode 100644 index 0000000..608319e --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/mask/cb/' +name = 'Piggy_3_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py b/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py new file mode 100644 index 0000000..490e25d --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/mask/g/' +name = 'Piggy_3_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py new file mode 100644 index 0000000..1ec08c7 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/no_mask/cb/' +name = 'Piggy_3_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py b/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py new file mode 100644 index 0000000..975b5bc --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/no_mask/g/' +name = 'Piggy_3_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_m_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_m_cb.py new file mode 100644 index 0000000..7c3fef2 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_m_cb.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/mask/cb/' +name = 'Piggy_3_Average_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_m_g.py b/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_m_g.py new file mode 100644 index 0000000..032b2be --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_m_g.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/mask/g/' +name = 'Piggy_3_Average_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_nm_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_nm_cb.py new file mode 100644 index 0000000..be223ff --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_nm_cb.py @@ -0,0 +1,216 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/no_mask/cb/' +name = 'Piggy_3_Average_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_nm_g.py b/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_nm_g.py new file mode 100644 index 0000000..eabdfb9 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/mix/Srednie_compare_nm_g.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_3/compare/no_mask/g/' +name = 'Piggy_3_Average_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/Piggy_3/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py new file mode 100644 index 0000000..4d44006 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py @@ -0,0 +1,171 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_new_masters/tail/mask/cb/' +name = 'Piggy_new_masters_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/tail/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='P_n1') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='P_n2') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='P_n3') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='c', linewidth=9, label='P_n4') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='P_n1') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='P_n2') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='P_n3') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='c', linewidth=9, label='P_n4') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py b/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py new file mode 100644 index 0000000..67d2eaf --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py @@ -0,0 +1,172 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_new_masters/tail/mask/g/' +name = 'Piggy_new_masters_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='P_n1') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='P_n2') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='P_n3') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='c', linewidth=9, label='P_n4') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='P_n1') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='P_n2') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='P_n3') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='c', linewidth=9, label='P_n4') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py new file mode 100644 index 0000000..078a1f7 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py @@ -0,0 +1,172 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_new_masters/tail/no_mask/cb/' +name = 'Piggy_new_masters_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='P_n1') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='P_n2') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='P_n3') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='c', linewidth=9, label='P_n4') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='P_n1') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='P_n2') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='P_n3') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='c', linewidth=9, label='P_n4') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py b/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py new file mode 100644 index 0000000..d597c04 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py @@ -0,0 +1,172 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_new_masters/tail/no_mask/g/' +name = 'Piggy_new_masters_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='P_n1') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='P_n2') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='P_n3') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='c', linewidth=9, label='P_n4') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='P_n1') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='P_n2') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='P_n3') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='c', linewidth=9, label='P_n4') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_m_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_m_cb.py new file mode 100644 index 0000000..d0f6630 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_m_cb.py @@ -0,0 +1,186 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_new_masters/tail/mask/cb/' +name = 'Piggy_new_masters_Average_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='P_n1') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='P_n2') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='P_n3') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='c', linewidth=9, label='P_n4') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='P_n1') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='P_n2') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='P_n3') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='c', linewidth=9, label='P_n4') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_m_g.py b/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_m_g.py new file mode 100644 index 0000000..cee02b3 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_m_g.py @@ -0,0 +1,186 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_new_masters/tail/mask/g/' +name = 'Piggy_new_masters_Average_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='P_n1') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='P_n2') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='P_n3') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='c', linewidth=9, label='P_n4') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='P_n1') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='P_n2') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='P_n3') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='c', linewidth=9, label='P_n4') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_nm_cb.py b/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_nm_cb.py new file mode 100644 index 0000000..dffaf1d --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_nm_cb.py @@ -0,0 +1,186 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_new_masters/tail/no_mask/cb/' +name = 'Piggy_new_masters_Average_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='P_n1') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='P_n2') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='P_n3') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='c', linewidth=9, label='P_n4') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='P_n1') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='P_n2') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='P_n3') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='c', linewidth=9, label='P_n4') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_nm_g.py b/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_nm_g.py new file mode 100644 index 0000000..a5f9da6 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/tail/Srednie_tail_nm_g.py @@ -0,0 +1,186 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/Piggy_new_masters/tail/no_mask/g/' +name = 'Piggy_new_masters_Average_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n1/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n2/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n3/SD100/tail/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/Piggy_n4/SD100/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='P_n1') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='P_n2') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='P_n3') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='c', linewidth=9, label='P_n4') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='P_n1') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='P_n2') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='P_n3') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='c', linewidth=9, label='P_n4') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/Piggy_new_masters/test.sh b/Rain_distribution/Distribution/Piggy_new_masters/test.sh new file mode 100644 index 0000000..e5ace65 --- /dev/null +++ b/Rain_distribution/Distribution/Piggy_new_masters/test.sh @@ -0,0 +1,4 @@ + +for files in /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/Distribution/Piggy_2/mix/*; do + echo $files + done diff --git a/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_no_piggy_classic_m_cb.py b/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_no_piggy_classic_m_cb.py new file mode 100644 index 0000000..123a941 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_no_piggy_classic_m_cb.py @@ -0,0 +1,167 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/classic/mask/cb/' +name = 'no_Piggy_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py b/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py new file mode 100644 index 0000000..b1ecab6 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_m_g.py @@ -0,0 +1,168 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/classic/mask/g/' +name = 'no_Piggy_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py b/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py new file mode 100644 index 0000000..9e7289c --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_cb.py @@ -0,0 +1,168 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/classic/no_mask/cb/' +name = 'no_Piggy_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py b/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py new file mode 100644 index 0000000..a0aee49 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/classic/Distribution_from_mom0_and_3_piggy_2_classic_nm_g.py @@ -0,0 +1,168 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/classic/no_mask/g/' +name = 'no_Piggy_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_m_cb.py b/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_m_cb.py new file mode 100644 index 0000000..ca52a3b --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_m_cb.py @@ -0,0 +1,177 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/classic/mask/cb/' +name = 'no_Piggy_Average_classic_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/dobre/' + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_m_g.py b/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_m_g.py new file mode 100644 index 0000000..34e8c00 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_m_g.py @@ -0,0 +1,178 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/classic/mask/g/' +name = 'no_Piggy_Average_classic_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/dobre/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_nm_cb.py b/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_nm_cb.py new file mode 100644 index 0000000..670d93f --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_nm_cb.py @@ -0,0 +1,178 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/classic/no_mask/cb/' +name = 'no_Piggy_Average_classic_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/dobre/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_nm_g.py b/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_nm_g.py new file mode 100644 index 0000000..9d8ab30 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/classic/Srednie_classic_nm_g.py @@ -0,0 +1,179 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/classic/no_mask/g/' +name = 'no_Piggy_Average_classic_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py b/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py new file mode 100644 index 0000000..0cd4257 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/compare/mask/cb/' +name = 'no_Piggy_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py b/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py new file mode 100644 index 0000000..ff52913 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_m_g.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/compare/mask/g/' +name = 'no_Piggy_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py b/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py new file mode 100644 index 0000000..b8982fe --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_cb.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/compare/no_mask/cb/' +name = 'no_Piggy_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py b/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py new file mode 100644 index 0000000..35ec19a --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/mix/Distribution_from_mom0_and_3_piggy_2_compare_nm_g.py @@ -0,0 +1,197 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/compare/no_mask/g/' +name = 'no_Piggy_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax0.step(biny[1:-1], Srednie_num4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax0.step(biny[1:-1], Srednie_num5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax0.step(biny[1:-1], Srednie_num6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100_c') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD100_t') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD1000_c') + ax1.step(biny[2:], Srednie_mass4[i]/biny_diff[0], c='y', linewidth=9, label='SD1000_t') + ax1.step(biny[2:], Srednie_mass5[i]/biny_diff[0], c='r', linewidth=9, label='SD10000_c') + ax1.step(biny[2:], Srednie_mass6[i]/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_m_cb.py b/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_m_cb.py new file mode 100644 index 0000000..b962531 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_m_cb.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/compare/mask/cb/' +name = 'no_Piggy_Average_compare_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_m_g.py b/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_m_g.py new file mode 100644 index 0000000..301ccaf --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_m_g.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/compare/mask/g/' +name = 'no_Piggy_Average_compare_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_nm_cb.py b/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_nm_cb.py new file mode 100644 index 0000000..5b42949 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_nm_cb.py @@ -0,0 +1,216 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/compare/no_mask/cb/' +name = 'no_Piggy_Average_compare_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_nm_g.py b/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_nm_g.py new file mode 100644 index 0000000..fa3166f --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/mix/Srednie_compare_nm_g.py @@ -0,0 +1,217 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/compare/no_mask/g/' +name = 'no_Piggy_Average_compare_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/classic/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + srednia_number = np.nanmean(wynik_number) + srednia_mass = np.nanmean(wynik_mass) + STD = np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +partial_fun_4 = functools.partial(Positions, path_to_file_4) +partial_fun_5 = functools.partial(Positions, path_to_file_5) +partial_fun_6 = functools.partial(Positions, path_to_file_6) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + Classic_4 = executor.map(partial_fun_4, punkty) + Classic_5 = executor.map(partial_fun_5, punkty) + Classic_6 = executor.map(partial_fun_6, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_4 = [i for i in Classic_4] +Class_5 = [i for i in Classic_5] +Class_6 = [i for i in Classic_6] + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) +Srednie_num4 = np.zeros((91, 39)) +Srednie_mass4 = np.zeros((91, 39)) +odchylenie_num4 = np.zeros((91, 39)) +Srednie_num5 = np.zeros((91, 39)) +Srednie_mass5 = np.zeros((91, 39)) +odchylenie_num5 = np.zeros((91, 39)) +Srednie_num6 = np.zeros((91, 39)) +Srednie_mass6 = np.zeros((91, 39)) +odchylenie_num6 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = (((Class_1[i])[0])[j])[0] + odchylenie_num1[i][j] = (((Class_1[i])[0])[j])[1] + Srednie_mass1[i][j] = (((Class_1[i])[0])[j])[2] + Srednie_num2[i][j] = (((Class_2[i])[0])[j])[0] + odchylenie_num2[i][j] = (((Class_2[i])[0])[j])[1] + Srednie_mass2[i][j] = (((Class_2[i])[0])[j])[2] + Srednie_num3[i][j] = (((Class_3[i])[0])[j])[0] + odchylenie_num3[i][j] = (((Class_3[i])[0])[j])[1] + Srednie_mass3[i][j] = (((Class_3[i])[0])[j])[2] + Srednie_num4[i][j] = (((Class_4[i])[0])[j])[0] + odchylenie_num4[i][j] = (((Class_4[i])[0])[j])[1] + Srednie_mass4[i][j] = (((Class_4[i])[0])[j])[2] + Srednie_num5[i][j] = (((Class_5[i])[0])[j])[0] + odchylenie_num5[i][j] = (((Class_5[i])[0])[j])[1] + Srednie_mass5[i][j] = (((Class_5[i])[0])[j])[2] + Srednie_num6[i][j] = (((Class_6[i])[0])[j])[0] + odchylenie_num6[i][j] = (((Class_6[i])[0])[j])[1] + Srednie_mass6[i][j] = (((Class_6[i])[0])[j])[2] + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) +Average_srednia_num4 = np.mean(Srednie_num4, axis=0) +Average_odchylenie_num4 = np.mean(odchylenie_num4, axis=0) +Average_srednia_mass4 = np.mean(Srednie_mass4, axis=0) +Average_srednia_num5 = np.mean(Srednie_num5, axis=0) +Average_odchylenie_num5 = np.mean(odchylenie_num5, axis=0) +Average_srednia_mass5 = np.mean(Srednie_mass5, axis=0) +Average_srednia_nu6 = np.mean(Srednie_num6, axis=0) +Average_odchylenie_num6 = np.mean(odchylenie_num6, axis=0) +Average_srednia_mass6 = np.mean(Srednie_mass6, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax0.step(biny[1:-1], Average_srednia_num4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax0.step(biny[1:-1], Average_srednia_num5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax0.step(biny[1:-1], Average_srednia_num6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100_c') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD100_t') +ax1.step(biny[2:], Average_srednia_masss3/biny_diff[0], c='m', linewidth=9, label='SD1000_c') +ax1.step(biny[2:], Average_srednia_mass4/biny_diff[0], c='y', linewidth=9, label='SD1000_t') +ax1.step(biny[2:], Average_srednia_mass5/biny_diff[0], c='r', linewidth=9, label='SD10000_c') +ax1.step(biny[2:], Average_srednia_mass6/biny_diff[0], c='c', linewidth=9, label='SD10000_t') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py b/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py new file mode 100644 index 0000000..f1d4359 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_cb.py @@ -0,0 +1,168 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/tail/mask/cb/' +name = 'no_Piggy_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py b/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py new file mode 100644 index 0000000..7b539a3 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_m_g.py @@ -0,0 +1,166 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/tail/mask/g/' +name = 'no_Piggy_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/dobre/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py b/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py new file mode 100644 index 0000000..abb2244 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_cb.py @@ -0,0 +1,167 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/tail/no_mask/cb/' +name = 'no_Piggy_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py b/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py new file mode 100644 index 0000000..dccad79 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/tail/Distribution_from_mom0_and_3_piggy_2_tail_nm_g.py @@ -0,0 +1,166 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/tail/no_mask/g/' +name = 'no_Piggy_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/dobre/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax0.step(biny[1:-1], Srednie_num2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax0.step(biny[1:-1], Srednie_num3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass2[i]/biny_diff[0], c='k', linewidth=9, label='SD1000') + ax1.step(biny[2:], Srednie_mass3[i]/biny_diff[0], c='m', linewidth=9, label='SD10000') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_m_cb.py b/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_m_cb.py new file mode 100644 index 0000000..027729d --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_m_cb.py @@ -0,0 +1,178 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/tail/mask/cb/' +name = 'no_Piggy_Average_tail_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1]* rainy_mask[:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_m_g.py b/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_m_g.py new file mode 100644 index 0000000..3ec7eff --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_m_g.py @@ -0,0 +1,178 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/tail/mask/g/' +name = 'no_Piggy_Average_tail_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_nm_cb.py b/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_nm_cb.py new file mode 100644 index 0000000..c65bbb8 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_nm_cb.py @@ -0,0 +1,178 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/tail/no_mask/cb/' +name = 'no_Piggy_Average_tail_no_mask_cb_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,int(min_hght/100)-1] + wynik_mass [file] = dystrybucja_mom3[file][:,int(min_hght/100)-1] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_nm_g.py b/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_nm_g.py new file mode 100644 index 0000000..90bbd7a --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/tail/Srednie_tail_nm_g.py @@ -0,0 +1,178 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/tail/no_mask/g/' +name = 'no_Piggy_Average_tail_no_mask_g_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/dobre/' + + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) +partial_fun_2 = functools.partial(Positions, path_to_file_2) +partial_fun_3 = functools.partial(Positions, path_to_file_3) +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + Classic_2 = executor.map(partial_fun_2, punkty) + Classic_3 = executor.map(partial_fun_3, punkty) + + +Class_1 = [i for i in Classic_1] +Class_2 = [i for i in Classic_2] +Class_3 = [i for i in Classic_3] +Class_1_array = np.array(Class_1) +Class_2_array = np.array(Class_2) +Class_3_array = np.array(Class_3) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) +Srednie_num2 = np.zeros((91, 39)) +Srednie_mass2 = np.zeros((91, 39)) +odchylenie_num2 = np.zeros((91, 39)) +Srednie_num3 = np.zeros((91, 39)) +Srednie_mass3 = np.zeros((91, 39)) +odchylenie_num3 = np.zeros((91, 39)) + + +for i in range(91): + + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + Srednie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[0]) + odchylenie_num2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[1]) + Srednie_mass2[i][j] = float(0) if np.all((((Class_2_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_2_array[i])[0])[j])[2]) + + Srednie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[0]) + odchylenie_num3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[1]) + Srednie_mass3[i][j] = float(0) if np.all((((Class_3_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_3_array[i])[0])[j])[2]) + +Average_srednia_num1 = np.mean(Srednie_num1, axis=0) +Average_odchylenie_num1 = np.mean(odchylenie_num1, axis=0) +Average_srednia_mass1 = np.mean(Srednie_mass1, axis=0) +Average_srednia_num2 = np.mean(Srednie_num2, axis=0) +Average_odchylenie_num2 = np.mean(odchylenie_num2, axis=0) +Average_srednia_mass2 = np.mean(Srednie_mass2, axis=0) +Average_srednia_num3 = np.mean(Srednie_num3, axis=0) +Average_odchylenie_num3 = np.mean(odchylenie_num3, axis=0) +Average_srednia_mass3 = np.mean(Srednie_mass3, axis=0) + +plt.rcParams.update({'font.size': 40}) +fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) +ax0.step(biny[1:-1], Average_srednia_num1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax0.step(biny[1:-1], Average_srednia_num2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax0.step(biny[1:-1], Average_srednia_num3/biny_diff[0], c='m', linewidth=9, label='SD10000') +ax1.step(biny[2:], Average_srednia_mass1/biny_diff[0], c='g', linewidth=9, label='SD100') +ax1.step(biny[2:], Average_srednia_mass2/biny_diff[0], c='k', linewidth=9, label='SD1000') +ax1.step(biny[2:], Average_srednia_mass3/biny_diff[0], c='m', linewidth=9, label='SD10000') + +#lub opcja ze liczba na jednym a na drugim masa +fig.suptitle('time= '+str(i*120)+'[s]') +ax0.set_xscale('log') +ax1.set_xscale('log') +ax0.set_yscale('log') +ax1.set_yscale('log') +# plt.yscale('log') +# plt.xlim((1e-3, 1e-0)) +ax0.set_ylim(bottom=0) +ax1.set_ylim(bottom=0) +ax0.grid(True) +ax0.legend() +ax1.grid(True) +ax1.legend() +# plt.suptitle('Current time {}s '.format(int(timestep/2))) +ax0.set_xlabel(r'r [m]') +ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') +ax1.set_xlabel(r'r [m]') +ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') +plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') +plt.clf() \ No newline at end of file diff --git a/Rain_distribution/Distribution/no_Piggy/test.sh b/Rain_distribution/Distribution/no_Piggy/test.sh new file mode 100644 index 0000000..e5ace65 --- /dev/null +++ b/Rain_distribution/Distribution/no_Piggy/test.sh @@ -0,0 +1,4 @@ + +for files in /home/pzmij/biblioteki/UWLCM_plotting/Rain_distribution/Distribution/Piggy_2/mix/*; do + echo $files + done diff --git a/Rain_distribution/Rain_many_copare_time_line_21_12.py b/Rain_distribution/Rain_many_copare_time_line_21_12.py index 5e4c3c6..446179f 100644 --- a/Rain_distribution/Rain_many_copare_time_line_21_12.py +++ b/Rain_distribution/Rain_many_copare_time_line_21_12.py @@ -138,14 +138,16 @@ def Adia_fraction(timestep, paths): profiler.disable() stats = pstats.Stats(profiler).sort_stats('cumtime') stats.print_stats() -ax0.set_ylim((0,0.5)) -ax1.set_ylim((0, 0.6 )) +ax0.set_ylim((0,1.075)) +ax1.set_ylim((0, 1.2)) ax0.set_xlim((3800,8000)) ax1.set_xlim((3800,8000)) ax0.set_xlabel('X [m]') ax1.set_xlabel('X [m]') ax0.set_ylabel('Mean of $q_r$ [g/kg]') ax1.set_ylabel('STD of $q_r$ [g/kg]') +ax0.set_title("Mean taken based on the qr values \n range from ground lvl to cloud base") +ax1.set_title("Mean taken based on the qr values \n range from ground lvl to cloud base") ax0.legend(title=legend_title) ax1.legend(title=legend_title) fig.suptitle('time range = '+str(time_start) + ' to '+str(time_end) +' s') diff --git a/Rain_distribution/TEST_nP.py b/Rain_distribution/TEST_nP.py new file mode 100644 index 0000000..130c698 --- /dev/null +++ b/Rain_distribution/TEST_nP.py @@ -0,0 +1,147 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/' +name = 'no_Piggy_TEST1_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/zle/' +# path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +# path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +# path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +# path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +# path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = np.nanstd(W_n) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) + +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + + + +Class_1 = [i for i in Classic_1] +Class_1_array = np.array(Class_1) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) + +plt.rcParams.update({'font.size': 40}) +for i in range(91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + print(i,j,(((Class_1_array[i])[0])[j])[0], 'spacjaaaaaaaa', float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0])) + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[0]) + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[1]) + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) == np.nan else np.mean((((Class_1_array[i])[0])[j])[2]) + + + + ax0.step(biny[1:-1], Srednie_num1[i]/biny_diff[0], c='g', linewidth=9, label='SD100') + ax1.step(biny[2:], Srednie_mass1[i]/biny_diff[0], c='m', linewidth=9, label='SD100') + + #lub opcja ze liczba na jednym a na drugim masa + fig.suptitle('time= '+str(i*120)+'[s]') + ax0.set_xscale('log') + ax1.set_xscale('log') + ax0.set_yscale('log') + ax1.set_yscale('log') + # plt.yscale('log') + # plt.xlim((1e-3, 1e-0)) + ax0.set_ylim(bottom=0) + ax1.set_ylim(bottom=0) + ax0.grid(True) + ax0.legend() + ax1.grid(True) + ax1.legend() + # plt.suptitle('Current time {}s '.format(int(timestep/2))) + ax0.set_xlabel(r'r [m]') + ax0.set_ylabel('n(ln r) [# of droplets/ d lnr]') + ax1.set_xlabel(r'r [m]') + ax1.set_ylabel('rr / log(bin size) [(kg/kg) / d lnr]') + plt.savefig(outfile+name+str(i*240).zfill(10)+'.png') + plt.clf() diff --git a/Rain_distribution/TEST_nP2.py b/Rain_distribution/TEST_nP2.py new file mode 100644 index 0000000..52c3906 --- /dev/null +++ b/Rain_distribution/TEST_nP2.py @@ -0,0 +1,120 @@ +from sys import argv, path, maxsize +# path.insert(0,"/home/piotr/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +# path.insert(0,"/home/piotr-pc/Piotr/IGF/local_install/parcel/lib/python3/dist-packages") +path.insert(0,"/home/pzmij/biblioteki/local_folder/16_03/lib/python3/dist-packages") + + + + +import cProfile, pstats +import h5py +import functools +import numpy as np +from itertools import product +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt +from libcloudphxx import common as lcmn +import glob, os +from mpl_toolkits.axes_grid1.inset_locator import inset_axes +import multiprocessing +import concurrent.futures +import threading +import concurrent.futures +plt.rcParams.update({'font.size': 20}) + + +#########parametry do uruchomienia +outfile = '/home/pzmij/2D/PAPER/Wyniki/Distribution/no_Piggy/' +name = 'no_Piggy_TEST1_' +path_to_file_1 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/test/' +# path_to_file_2 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD100/tail/' +# path_to_file_3 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/classic/' +# path_to_file_4 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD1000/tail/' +# path_to_file_5 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/classic/' +# path_to_file_6 = '/home/pzmij/2D/PAPER/Distribution/no_Piggy/SD10000/tail/' + + +def Distro(timestep, paths, pozycja): + files = os.listdir(paths) + nr_files = len(files) + rhod= [0 for i in range(nr_files)] + dz = [0 for i in range(nr_files)] + rl = [0 for i in range(nr_files)] + rl_base = [0 for i in range(nr_files)] + rr = [0 for i in range(nr_files)] + dystrybucja_mom0 = [0 for i in range(nr_files)] + dystrybucja_mom3 = [0 for i in range(nr_files)] + wynik_number = [0 for i in range(nr_files)] + wynik_mass = [0 for i in range(nr_files)] + + for file in range(nr_files): + Name = paths+files[file] + '/'+ files[file]+ "_out_lgrngn" + rhod[file] = h5py.File(Name + "/const.h5", "r")["G"][:,:] + dz[file] = h5py.File(Name + "/const.h5", "r").attrs["dz"] + + filename = Name + "/timestep" + str(int(timestep)*240).zfill(10) + ".h5" + rl[file] = (h5py.File(filename, "r")["cloud_rw_mom3"][:,:]) * 4. / 3. * 3.1416 * 1e3; # kg/kg + rl_base[file] = rl[file] + rr[file] = (h5py.File(filename, "r")["rain_rw_mom3"][:,:]) + dystrybucja_mom0[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom0"][:,:]) + dystrybucja_mom3[file] = (h5py.File(filename, "r")["rw_rng"+str(pozycja).zfill(3)+"_mom3"][:,:]) * rhod[file] * 4. / 3. * 3.1416 * 1e3; # kg/kg + # cloudiness mask - as in RICO paper + cloudy_mask = np.where(rl[file] > 1e-5, 1, 0) + rainy_mask = np.where(rr[file] > 0, 1, 0) + + nx, nz = rr[file].shape + hght = np.arange(nz) * dz[file] + # cloud base + clb_idx = np.argmax(cloudy_mask > 0, axis=1) + hght_2 = hght[clb_idx] + hght_2[hght_2==0] = np.nan + if np.isnan(hght_2).all() == True : + continue + min_hght = np.nanmin(hght_2) + if min_hght ==np.nan: + break + wynik_number[file] = dystrybucja_mom0[file][:,0]#* rainy_mask[:,0] + wynik_mass [file] = dystrybucja_mom3[file][:,0]#* rainy_mask[:,0] + wynik_number[file][wynik_number[file]==0]=np.nan + wynik_mass[file][wynik_mass[file]==0]=np.nan + W_n = np.array(wynik_number) + W_m = np.array(wynik_mass) + srednia_number = np.nanmean(W_n) + srednia_mass = np.nanmean(W_m) + STD = 0 #np.nanstd(wynik_number) + return srednia_number, STD, srednia_mass + +def Positions(paths, timestep): + Results = [0 for i in range(40)] + for i in range(39): + Results[i] = Distro(timestep, paths, i) + Results[i] = np.nan_to_num(Results[i]) + return Results, timestep + + +punkty = np.intc(np.linspace(0,90,91)) +partial_fun_1 = functools.partial(Positions, path_to_file_1) + +with concurrent.futures.ProcessPoolExecutor() as executor: + Classic_1 = executor.map(partial_fun_1, punkty) + + + +Class_1 = [i for i in Classic_1] +Class_1_array = np.array(Class_1) + + +biny = [(1e-6*pow(10, -3+i*0.2)) for i in range(0,41)] +biny_diff = np.diff(np.log(biny[1:])) +Srednie_num1 = np.zeros((91, 39)) +Srednie_mass1 = np.zeros((91, 39)) +odchylenie_num1 = np.zeros((91, 39)) + +plt.rcParams.update({'font.size': 40}) +for i in range(80,91): + fig, (ax0, ax1) = plt.subplots(1, 2,figsize=(40,40)) + for j in range(39): + Srednie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[0]) != np.nan else (((Class_1_array[i])[0])[j])[0] + odchylenie_num1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[1]) != np.nan else (((Class_1_array[i])[0])[j])[1] + Srednie_mass1[i][j] = float(0) if np.all((((Class_1_array[i])[0])[j])[2]) != np.nan else (((Class_1_array[i])[0])[j])[2]