forked from official-apps/SeismicHazardForecasting
		
	add non-parallel processing and set as default; fix colourbar
This commit is contained in:
		@@ -439,22 +439,40 @@ verbose: {verbose}")
 | 
			
		||||
 | 
			
		||||
        PGA = np.zeros(shape=(nx * ny))
 | 
			
		||||
 | 
			
		||||
        # use dask parallel computing
 | 
			
		||||
        start = timer()
 | 
			
		||||
        pbar = ProgressBar()
 | 
			
		||||
        pbar.register()
 | 
			
		||||
        # iter = range(0,len(distances))
 | 
			
		||||
        iter = indices
 | 
			
		||||
        iml_grid_raw = []  # raw ground motion grids
 | 
			
		||||
        for imt in products:
 | 
			
		||||
            logger.info(f"Estimating {imt}")
 | 
			
		||||
 | 
			
		||||
            imls = [dask.delayed(compute_IMT_exceedance)(rx_lat[i], rx_lon[i], distances[i].flatten(), fr, p, lambdas,
 | 
			
		||||
                                                         forecast_len, lambdas_perc, m_range, m_pdf, m_cdf, model,
 | 
			
		||||
                                                         log_level=logging.DEBUG, imt=imt, IMT_min=0.0, IMT_max=2.0,
 | 
			
		||||
                                                         rx_label=i) for i in iter]
 | 
			
		||||
            iml = dask.compute(*imls)
 | 
			
		||||
            iml_grid_raw.append(list(iml))
 | 
			
		||||
        start = timer()
 | 
			
		||||
 | 
			
		||||
        use_pp = False
 | 
			
		||||
 | 
			
		||||
        if use_pp:         # use dask parallel computing
 | 
			
		||||
            pbar = ProgressBar()
 | 
			
		||||
            pbar.register()
 | 
			
		||||
            # iter = range(0,len(distances))
 | 
			
		||||
            iter = indices
 | 
			
		||||
            iml_grid_raw = []  # raw ground motion grids
 | 
			
		||||
            for imt in products:
 | 
			
		||||
                logger.info(f"Estimating {imt}")
 | 
			
		||||
 | 
			
		||||
                imls = [dask.delayed(compute_IMT_exceedance)(rx_lat[i], rx_lon[i], distances[i].flatten(), fr, p, lambdas,
 | 
			
		||||
                                                            forecast_len, lambdas_perc, m_range, m_pdf, m_cdf, model,
 | 
			
		||||
                                                            log_level=logging.DEBUG, imt=imt, IMT_min=0.0, IMT_max=2.0,
 | 
			
		||||
                                                            rx_label=i, rtol=0.1, use_cython=False) for i in iter]
 | 
			
		||||
                iml = dask.compute(*imls)
 | 
			
		||||
                iml_grid_raw.append(list(iml))
 | 
			
		||||
 | 
			
		||||
        else:
 | 
			
		||||
            iml_grid_raw = []
 | 
			
		||||
            iter = indices
 | 
			
		||||
            for imt in products:
 | 
			
		||||
                iml = []
 | 
			
		||||
                for i in iter:
 | 
			
		||||
                    iml_i = compute_IMT_exceedance(rx_lat[i], rx_lon[i], distances[i].flatten(), fr, p, lambdas, forecast_len, 
 | 
			
		||||
                                                    lambdas_perc, m_range, m_pdf, m_cdf, model, imt=imt, IMT_min = 0.0,
 | 
			
		||||
                                                    IMT_max = 2.0, rx_label = i, rtol = 0.1, use_cython=False)
 | 
			
		||||
                    iml.append(iml_i)
 | 
			
		||||
                    logger.info(f"Estimated {imt} at rx {i} is {iml_i}")
 | 
			
		||||
                iml_grid_raw.append(iml)
 | 
			
		||||
        
 | 
			
		||||
        end = timer()
 | 
			
		||||
        logger.info(f"Ground motion exceedance computation time: {round(end - start, 1)} seconds")
 | 
			
		||||
 | 
			
		||||
@@ -530,7 +548,7 @@ verbose: {verbose}")
 | 
			
		||||
            tick_positions = np.linspace(vmin, vmax, num_ticks)
 | 
			
		||||
            ax.set_yticks(tick_positions)
 | 
			
		||||
            ax.set_yticklabels([f"{tick:.2f}" for tick in tick_positions])  # format tick labels
 | 
			
		||||
            ax.set_title(imt, pad=15)
 | 
			
		||||
            ax.set_title(products[j], pad=15)
 | 
			
		||||
            fig.subplots_adjust(left=0.25, right=0.75, bottom=0.05, top=0.95)  # Adjust Layout
 | 
			
		||||
            fig.savefig("colorbar_" + str(j) + ".svg", bbox_inches='tight')
 | 
			
		||||
            plt.close(fig)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user