def upload_test_imzml(storage: Storage, sm_config, ds_config): """Create an ImzML file, upload it into storage, and return an imzml_reader for it""" with make_test_imzml(ds_config) as (imzml_path, ibd_path): imzml_content = open(imzml_path, 'rb').read() ibd_content = open(ibd_path, 'rb').read() bucket, prefix = sm_config['lithops']['sm_storage']['imzml'] storage.put_cloudobject(imzml_content, bucket, f'{prefix}/test_ds/test.imzML') storage.put_cloudobject(ibd_content, bucket, f'{prefix}/test_ds/test.ibd') return f'cos://{bucket}/{prefix}/test_ds'
def make_lithops_imzml_reader( storage: Storage, mz_precision='f', polarity='positive', ds_config=TEST_DS_CONFIG, ): """Create an ImzML file, upload it into storage, and return an imzml_reader for it""" mz_dtype = {'f': np.float32, 'd': np.float64}[mz_precision] with TemporaryDirectory() as tmpdir: with ImzMLWriter(f'{tmpdir}/test.imzML', polarity=polarity, mz_dtype=mz_dtype) as writer: for coords, (mzs, ints) in zip(MOCK_COORDINATES, MOCK_SPECTRA): writer.addSpectrum(mzs, ints, coords) imzml_content = open(f'{tmpdir}/test.imzML', 'rb').read() ibd_content = open(f'{tmpdir}/test.ibd', 'rb').read() imzml_cobj = storage.put_cloudobject(imzml_content) ibd_cobj = storage.put_cloudobject(ibd_content) return LithopsImzMLReader(storage, imzml_cobj, ibd_cobj)
BUCKET_NAME = 'lithops-sample-data' # change-me def my_function(obj_id, storage): print(obj_id) data = storage.get_cloudobject(obj_id) return data.decode() if __name__ == '__main__': obj_key = 'cloudobject1.txt' storage = Storage() obj_id = storage.put_cloudobject('Hello World!', BUCKET_NAME, obj_key) print(obj_id) fexec = FunctionExecutor() fexec.call_async(my_function, obj_id) print(fexec.get_result()) obj_key = 'cloudobject2.txt' storage = fexec.storage obj_id = storage.put_cloudobject('Hello World!', BUCKET_NAME, obj_key) print(obj_id) fexec.call_async(my_function, obj_id) print(fexec.get_result())