def _handler(self, request, response): climdex_input, freq, func, loglevel, output_file = process_inputs_alpha( request.inputs, temp_pctl_inputs, self.workdir) log_handler( self, response, "Starting Process", logger, log_level=loglevel, process_step="start", ) robjects.r("library(climdex.pcic)") vectors = [] counter = 1 total = len(climdex_input) for input in climdex_input: log_handler( self, response, f"Loading climdexInput from R data file {counter}/{total}", logger, log_level=loglevel, process_step="load_rdata", ) cis = load_cis(input) log_handler( self, response, f"Processing climdex.{func} for file {counter}/{total}", logger, log_level=loglevel, process_step="process", ) for ci_name, ci in cis.items(): try: robjects.r.assign("ci", ci) mothly_pct = robjects.r(f"climdex.{func}(ci, '{freq}')") except RRuntimeError as e: raise ProcessError(msg=f"{type(e).__name__}: {str(e)}") vector_name = f"{func}{counter}_{ci_name}" robjects.r.assign(vector_name, mothly_pct) vectors.append(vector_name) counter += 1 log_handler( self, response, f"Saving {func} as R data file", logger, log_level=loglevel, process_step="save_rdata", ) output_path = os.path.join(self.workdir, output_file) robjects.r["save"](*vectors, file=output_path) log_handler( self, response, "Building final output", logger, log_level=loglevel, process_step="build_output", ) response.outputs["rda_output"].file = output_path # Clear R global env robjects.r("rm(list=ls())") log_handler( self, response, "Process Complete", logger, log_level=loglevel, process_step="complete", ) return response
def _handler(self, request, response): ( base_range, cal, date_fields, date_format, loglevel, max_missing_days, min_base_data_fraction_present, n, northern_hemisphere, output_file, prec_column, prec_file, prec_name, prec_qtiles, quantiles, tavg_column, tavg_file, tavg_name, temp_qtiles, tmax_column, tmax_file, tmax_name, tmin_column, tmin_file, tmin_name, vector_name, ) = process_inputs_alpha(request.inputs, raw_inputs, self.workdir) validate_vectors([ base_range, date_fields, temp_qtiles, prec_qtiles, max_missing_days, ]) log_handler( self, response, "Starting Process", logger, log_level=loglevel, process_step="start", ) climdex = get_package("climdex.pcic") robjects.r("library(PCICt)") log_handler( self, response, "Prepare parameters for climdexInput.raw", logger, log_level=loglevel, process_step="prepare_params", ) params = self.prepare_parameters( request, tmax_name, tmin_name, prec_name, tavg_name, tmax_column, tmin_column, prec_column, tavg_column, date_fields, date_format, cal, prec_file, tavg_file, tmax_file, tmin_file, ) log_handler( self, response, "Processing climdexInput.raw", logger, log_level=loglevel, process_step="process", ) try: ci = climdex.climdexInput_raw( **params, base_range=robjects.r(base_range), n=n, northern_hemisphere=northern_hemisphere, quantiles=robjects.r(quantiles), temp_qtiles=robjects.r(temp_qtiles), prec_qtiles=robjects.r(prec_qtiles), max_missing_days=robjects.r(max_missing_days), min_base_data_fraction_present=min_base_data_fraction_present, ) except RRuntimeError as e: raise ProcessError(msg=f"{type(e).__name__}: {str(e)}") log_handler( self, response, "Saving climdexInput as R data file", logger, log_level=loglevel, process_step="save_rdata", ) output_path = os.path.join(self.workdir, output_file) r_valid_name(vector_name) save_python_to_rdata(vector_name, ci, output_path) log_handler( self, response, "Building final output", logger, log_level=loglevel, process_step="build_output", ) response.outputs["climdexInput"].file = output_path # Clear R global env robjects.r("rm(list=ls())") return response
def _handler(self, request, response): ( center_mean_on_last_day, climdex_input, freq, loglevel, num_days, output_file, ) = process_inputs_alpha(request.inputs, rxnday_inputs, self.workdir) log_handler( self, response, "Starting Process", logger, log_level=loglevel, process_step="start", ) robjects.r("library(climdex.pcic)") vectors = [] counter = 1 total = len(climdex_input) for input in climdex_input: log_handler( self, response, f"Loading climdexInput from R data file {counter}/{total}", logger, log_level=loglevel, process_step="load_rdata", ) cis = load_cis(input) log_handler( self, response, f"Processing Monthly Maximum {num_days}-day Precipitation for file {counter}/{total}", logger, log_level=loglevel, process_step="process", ) for ci_name, ci in cis.items(): try: robjects.r.assign("ci", ci) rxnday = self.rxnday_func(ci, num_days, freq, center_mean_on_last_day) except RRuntimeError as e: raise ProcessError(msg=f"{type(e).__name__}: {str(e)}") vector_name = f"rx{num_days}day{counter}_{ci_name}" robjects.r.assign(vector_name, rxnday) vectors.append(vector_name) counter += 1 log_handler( self, response, f"Saving rx{num_days}day vector to R data file", logger, log_level=loglevel, process_step="save_rdata", ) output_path = os.path.join(self.workdir, output_file) robjects.r["save"](*vectors, file=output_path) log_handler( self, response, "Building final output", logger, log_level=loglevel, process_step="build_output", ) response.outputs["rda_output"].file = output_path # Clear R global env robjects.r("rm(list=ls())") log_handler( self, response, "Process Complete", logger, log_level=loglevel, process_step="complete", ) return response
def _handler(self, request, response): climdex_input, loglevel, output_file = process_inputs_alpha( request.inputs, sdii_inputs, self.workdir) log_handler( self, response, "Starting Process", logger, log_level=loglevel, process_step="start", ) climdex = get_package("climdex.pcic") vectors = [] counter = 1 total = len(climdex_input) for input in climdex_input: log_handler( self, response, f"Loading climdexInput from R data file {counter}/{total}", logger, log_level=loglevel, process_step="load_rdata", ) cis = load_cis(input) log_handler( self, response, f"Processing the mean daily diurnal temperature range for file {counter}/{total}", logger, log_level=loglevel, process_step="process", ) for ci_name, ci in cis.items(): try: robjects.r.assign("ci", ci) sdii = climdex.climdex_sdii(ci) except RRuntimeError as e: raise ProcessError(msg=f"{type(e).__name__}: {str(e)}") vector_name = f"sdii{counter}_{ci_name}" robjects.r.assign(vector_name, sdii) vectors.append(vector_name) counter += 1 log_handler( self, response, "Saving dtr vector to R data file", logger, log_level=loglevel, process_step="save_rdata", ) output_path = os.path.join(self.workdir, output_file) robjects.r["save"](*vectors, file=output_path) log_handler( self, response, "Building final output", logger, log_level=loglevel, process_step="build_output", ) response.outputs["rda_output"].file = output_path # Clear R global env robjects.r("rm(list=ls())") log_handler( self, response, "Process Complete", logger, log_level=loglevel, process_step="complete", ) return response
def _handler(self, request, response): ci_name, climdex_single_input, loglevel, output_file = process_inputs_alpha( request.inputs, avail_indices_inputs, self.workdir) log_handler( self, response, "Starting Process", logger, log_level=loglevel, process_step="start", ) climdex = get_package("climdex.pcic") log_handler( self, response, "Loading climdexInput from R data file", logger, log_level=loglevel, process_step="load_rdata", ) ci = get_robj(climdex_single_input, ci_name) log_handler( self, response, "Processing climdex_get_available_indices", logger, log_level=loglevel, process_step="process", ) try: robjects.r.assign("ci", ci) avail_indices = climdex.climdex_get_available_indices(ci, False) except RRuntimeError as e: raise ProcessError(msg=f"{type(e).__name__}: {str(e)}") avail_processes = self.available_processes(avail_indices) log_handler( self, response, "Building final output", logger, log_level=loglevel, process_step="build_output", ) response.outputs["avail_processes"].data = avail_processes # Clear R global env robjects.r("rm(list=ls())") log_handler( self, response, "Process Complete", logger, log_level=loglevel, process_step="complete", ) return response
def _handler(self, request, response): ( data_file, data_vector, loglevel, output_file, quantiles_vector, vector_name, ) = process_inputs_alpha(request.inputs, quantile_inputs, self.workdir) validate_vectors([quantiles_vector]) r_valid_name(vector_name) log_handler( self, response, "Starting Process", logger, log_level=loglevel, process_step="start", ) climdex = get_package("climdex.pcic") log_handler( self, response, "Loading R data file", logger, log_level=loglevel, process_step="load_rdata", ) if data_file: data = self.unpack_data_file(data_file, data_vector) else: data = robjects.r(data_vector) log_handler( self, response, "Processing climdex.quantile", logger, log_level=loglevel, process_step="process", ) try: quantiles = robjects.r(quantiles_vector) quantile_vector = climdex.climdex_quantile(data, quantiles) except RRuntimeError as e: raise ProcessError(msg=f"{type(e).__name__}: {str(e)}") log_handler( self, response, "Saving quantile as R data file", logger, log_level=loglevel, process_step="save_rdata", ) output_path = os.path.join(self.workdir, output_file) save_python_to_rdata(vector_name, quantile_vector, output_path) log_handler( self, response, "Building final output", logger, log_level=loglevel, process_step="build_output", ) response.outputs["rda_output"].file = output_path response.outputs["output_vector"].data = str(quantile_vector) # Clear R global env robjects.r("rm(list=ls())") log_handler( self, response, "Process Complete", logger, log_level=loglevel, process_step="complete", ) return response
def _handler(self, request, response): climdex_input, loglevel, output_file, threshold = process_inputs_alpha( request.inputs, rmm_inputs, self.workdir) log_handler( self, response, "Starting Process", logger, log_level=loglevel, process_step="start", ) climdex = get_package("climdex.pcic") vectors = [] counter = 1 total = len(climdex_input) for input in climdex_input: log_handler( self, response, f"Loading climdexInput from R data file {counter}/{total}", logger, log_level=loglevel, process_step="load_rdata", ) cis = load_cis(input) log_handler( self, response, f"Processing the annual count of days where daily precipitation is more than {threshold}mm per day for file {counter}/{total}", logger, log_level=loglevel, process_step="process", ) for ci_name, ci in cis.items(): try: robjects.r.assign("ci", ci) count_days = self.threshold_func(threshold, ci) except RRuntimeError as e: raise ProcessError(msg=f"{type(e).__name__}: {str(e)}") vector_name = f"r{threshold}mm{counter}_{ci_name}" robjects.r.assign(vector_name, count_days) vectors.append(vector_name) counter += 1 log_handler( self, response, f"Saving climdex.r{threshold}mm outputs to R data file", logger, log_level=loglevel, process_step="save_rdata", ) output_path = os.path.join(self.workdir, output_file) robjects.r["save"](*vectors, file=output_path) log_handler( self, response, "Building final output", logger, log_level=loglevel, process_step="build_output", ) response.outputs["rda_output"].file = output_path # Clear R global env robjects.r("rm(list=ls())") log_handler( self, response, "Process Complete", logger, log_level=loglevel, process_step="complete", ) return response