How to use invocation_result method in localstack

Best Python code snippet using localstack_python

version_manager.py

Source:version_manager.py Github

copy

Full Screen

...309 executor.invocation_done()310 self.available_environments.put(executor)311 self.store_logs(invocation_result=invocation_result, executor=executor)312 # Service Endpoint implementation313 def invocation_result(self, invoke_id: str, invocation_result: InvocationResult) -> None:314 LOG.debug("Got invocation result for invocation '%s'", invoke_id)315 self.invocation_response(invoke_id=invoke_id, invocation_result=invocation_result)316 def invocation_error(self, invoke_id: str, invocation_error: InvocationError) -> None:317 LOG.debug("Got invocation error for invocation '%s'", invoke_id)318 self.invocation_response(invoke_id=invoke_id, invocation_result=invocation_error)319 def invocation_logs(self, invoke_id: str, invocation_logs: InvocationLogs) -> None:320 LOG.debug("Got logs for invocation '%s'", invoke_id)321 for log_line in invocation_logs.logs.splitlines():322 LOG.debug("> %s", log_line)323 running_invocation = self.running_invocations.get(invoke_id, None)324 if running_invocation is None:325 raise Exception(f"Cannot map invocation result {invoke_id} to invocation")326 running_invocation.logs = invocation_logs.logs327 def status_ready(self, executor_id: str) -> None:...

Full Screen

Full Screen

full_preprocessing_utils.py

Source:full_preprocessing_utils.py Github

copy

Full Screen

1import numpy as np # linear algebra2import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)3import dicom4import os5import matplotlib.pyplot as plt6from mpl_toolkits.mplot3d.art3d import Poly3DCollection7import scipy8import pandas9from skimage import measure, morphology1011import shutil12import zipfile1314# Load the scans in given folder path15def load_scan(path):16 slices = [dicom.read_file(path + '/' + s) for s in get_dcom_files(path)]17 slices.sort(key=lambda x: float(x.ImagePositionPatient[2]))18 try:19 slice_thickness = np.abs(slices[0].ImagePositionPatient[2] - slices[1].ImagePositionPatient[2])20 except:21 slice_thickness = np.abs(slices[0].SliceLocation - slices[1].SliceLocation)2223 for s in slices:24 s.SliceThickness = slice_thickness2526 return slices272829def get_pixels_hu(slices):30 image = np.stack([s.pixel_array for s in slices])31 # Convert to int16 (from sometimes int16),32 # should be possible as values should always be low enough (<32k)33 image = image.astype(np.int16)3435 # Set outside-of-scan pixels to 036 # The intercept is usually -1024, so air is approximately 037 image[image == -2000] = 03839 # Convert to Hounsfield units (HU)40 for slice_number in range(len(slices)):4142 intercept = slices[slice_number].RescaleIntercept43 slope = slices[slice_number].RescaleSlope4445 if slope != 1:46 image[slice_number] = slope * image[slice_number].astype(np.float64)47 image[slice_number] = image[slice_number].astype(np.int16)4849 image[slice_number] += np.int16(intercept)5051 return np.array(image, dtype=np.int16)525354def resample(image, scan, new_spacing=[1, 1, 1]):55 print('In resample, original image dimensions ', image.shape)56 # Determine current pixel spacing57 spacing = np.array([scan[0].SliceThickness] + scan[0].PixelSpacing, dtype=np.float32)5859 resize_factor = spacing / new_spacing60 new_real_shape = image.shape * resize_factor61 new_shape = np.round(new_real_shape)62 real_resize_factor = new_shape / image.shape63 new_spacing = spacing / real_resize_factor6465 image = scipy.ndimage.interpolation.zoom(image, real_resize_factor, mode='nearest').astype(np.uint8)66 #print(image[50:55,90:92,105:110])67 print('In resample, final image dimensions ', image.shape)686970 return image7172def get_average_pixel_value(patient_dir):73 slices = load_scan(patient_dir)74 image_3d = get_pixels_hu(slices)75 return np.mean(slices)7677def write_3d_image(patient, root_dir):78 slices = load_scan(root_dir + patient)79 image_3d = get_pixels_hu(slices)80 print('Resampling image ' + patient)81 #resampled_image = resample(image_3d, slices)82 print('Done. Writing ' + patient)83 # for i in range(resampled_image.shape[0]):84 # np.savetxt('output/' + patient + '_' + str(i) + '.csv',85 # resampled_image[i,:,:], '%5.0f', delimiter=',')86 #create_zip_file('c:/data/cosmin/kaggle/scan/output/', patient + "_" + str(i))87 #os.remove('c:/data/cosmin/kaggle/scan/output/' + patient + '_' + str(i) + '.csv')88 np.save('output/' + patient , image_3d)8990def get_3d_image(patient, root_dir):91 slices = load_scan(root_dir + patient)92 image_3d = get_pixels_hu(slices)93 return image_3d9495def create_zip_file(directory, file):96 zf = zipfile.ZipFile(file + ".zip", "w",compression=zipfile.ZIP_DEFLATED)97 path = os.path.normpath(os.path.join(directory, file + '.csv'))98 zf.write(path, path)99100101def write_resampled_images(root_dir):102 patients = os.listdir(root_dir)103 index = 0104 for patient in patients:105 write_resampled_image(patient, root_dir)106 index += 1107 print(index)108109110# apply method_to_invoke to all image3d of the patients in the directory111# return mapping patient-id -> invocation result112def apply_to_all_patients(root_dir, method_to_invoke):113 df = load_train_set_outcomes()114 res = pandas.DataFrame(columns=('patient','outcome','invocation_result'))115 patients = os.listdir(root_dir)116 index = 0117 for patient in patients:118 if(df.loc[df['id'] == patient].size == 0):119 continue120 slices = load_scan(root_dir + patient)121 image_3d = get_pixels_hu(slices)122 invocation_result = method_to_invoke(image_3d)123 print(patient)124 patient_outcome = (df.loc[df['id'] == patient]['cancer'] == 1).values[0]125 print(patient_outcome,invocation_result)126 res[index] = [patient, patient_outcome, invocation_result]127 index += 1128 res.to_csv('averages.csv')129 return res130131def get_all_patients(root_dir):132 return os.listdir(root_dir)133134#load patientId->1 or 0 from the input/stage1_labels.csv file135def load_train_set_outcomes():136 df = pandas.read_csv('input/stage1_labels.csv')137 return df138139140def plot_3d(image, threshold=-300):141 # Position the scan upright,142 # so the head of the patient would be at the top facing the camera143 p = image.transpose(2, 1, 0)144145 verts, faces, normals, values = measure.marching_cubes(p, threshold)146147 fig = plt.figure(figsize=(10, 10))148 ax = fig.add_subplot(111, projection='3d')149150 # Fancy indexing: `verts[faces]` to generate a collection of triangles151 mesh = Poly3DCollection(verts[faces], alpha=0.70)152 face_color = [0.45, 0.45, 0.75]153 mesh.set_facecolor(face_color)154 ax.add_collection3d(mesh)155156 ax.set_xlim(0, p.shape[0])157 ax.set_ylim(0, p.shape[1])158 ax.set_zlim(0, p.shape[2])159160 plt.show()161162163def get_dcom_files(path):164 res = []165 files = os.listdir(path)166 for file in files:167 if file.endswith(".dcm"):168 res.append(file) ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful