spatialdata-js-util 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spatialdata_js_util/__init__.py +107 -0
- spatialdata_js_util/cli.py +803 -0
- spatialdata_js_util/codecs/__init__.py +67 -0
- spatialdata_js_util/codecs/backends.py +250 -0
- spatialdata_js_util/codecs/chunks.py +40 -0
- spatialdata_js_util/codecs/encoding.py +154 -0
- spatialdata_js_util/codecs/htj2k_wasm.py +266 -0
- spatialdata_js_util/codecs/names.py +26 -0
- spatialdata_js_util/codecs/probe/multicomponent.j2c +0 -0
- spatialdata_js_util/codecs/probe/multicomponent.json +3 -0
- spatialdata_js_util/codecs/probe/multicomponent.npy +0 -0
- spatialdata_js_util/codecs/vendor/__init__.py +1 -0
- spatialdata_js_util/codecs/vendor/encode-plane.mjs +164 -0
- spatialdata_js_util/codecs/vendor/openjph/index.mjs +131 -0
- spatialdata_js_util/codecs/vendor/openjph/wasm/libopenjph.mjs +2 -0
- spatialdata_js_util/codecs/vendor/openjph/wasm/libopenjph.wasm +0 -0
- spatialdata_js_util/codecs/vendor/openjph/wasm/libopenjph_simd.mjs +2 -0
- spatialdata_js_util/codecs/vendor/openjph/wasm/libopenjph_simd.wasm +0 -0
- spatialdata_js_util/codecs/zarr_codec.py +149 -0
- spatialdata_js_util/errors.py +5 -0
- spatialdata_js_util/images.py +849 -0
- spatialdata_js_util/index_permutations.py +311 -0
- spatialdata_js_util/points.py +445 -0
- spatialdata_js_util/points_zarr.py +799 -0
- spatialdata_js_util/provenance.py +17 -0
- spatialdata_js_util/pyramids.py +318 -0
- spatialdata_js_util/runners.py +458 -0
- spatialdata_js_util/store.py +305 -0
- spatialdata_js_util/tables.py +310 -0
- spatialdata_js_util/tui/__init__.py +0 -0
- spatialdata_js_util/tui/app.py +112 -0
- spatialdata_js_util/tui/models.py +45 -0
- spatialdata_js_util/tui/screens.py +1255 -0
- spatialdata_js_util/tui/widgets.py +50 -0
- spatialdata_js_util/verify.py +338 -0
- spatialdata_js_util-0.1.0.dist-info/METADATA +412 -0
- spatialdata_js_util-0.1.0.dist-info/RECORD +40 -0
- spatialdata_js_util-0.1.0.dist-info/WHEEL +5 -0
- spatialdata_js_util-0.1.0.dist-info/entry_points.txt +7 -0
- spatialdata_js_util-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
async function Module(moduleArg={}){var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import("node:module");var require=createRequire(import.meta.url)}var programArgs=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");if(_scriptName.startsWith("file:")){scriptDirectory=require("node:path").dirname(require("node:url").fileURLToPath(_scriptName))+"/"}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}programArgs=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");class EmscriptenEH{}class EmscriptenSjLj extends EmscriptenEH{}class CppException extends EmscriptenEH{constructor(excPtr){super();this.excPtr=excPtr}}var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["w"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what=`Aborted(${what})`;err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("libopenjph_simd.wasm")}return new URL("libopenjph_simd.wasm",import.meta.url).href}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var HEAP16;var HEAP32;var HEAP64;var HEAP8;var HEAPF32;var HEAPF64;var HEAPU16;var HEAPU32;var HEAPU64;var HEAPU8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);function getValue(ptr,type="i8"){if(type.endsWith("*"))type="*";switch(type){case"i1":return HEAP8[ptr];case"i8":return HEAP8[ptr];case"i16":return HEAP16[ptr>>1];case"i32":return HEAP32[ptr>>2];case"i64":return HEAP64[ptr>>3];case"float":return HEAPF32[ptr>>2];case"double":return HEAPF64[ptr>>3];case"*":return HEAPU32[ptr>>2];default:abort(`invalid type for getValue: ${type}`)}}var noExitRuntime=true;function setValue(ptr,value,type="i8"){if(type.endsWith("*"))type="*";switch(type){case"i1":HEAP8[ptr]=value;break;case"i8":HEAP8[ptr]=value;break;case"i16":HEAP16[ptr>>1]=value;break;case"i32":HEAP32[ptr>>2]=value;break;case"i64":HEAP64[ptr>>3]=BigInt(value);break;case"float":HEAPF32[ptr>>2]=value;break;case"double":HEAPF64[ptr>>3]=value;break;case"*":HEAPU32[ptr>>2]=value;break;default:abort(`invalid type for setValue: ${type}`)}}var stackRestore=val=>__emscripten_stack_restore(val);var stackSave=()=>_emscripten_stack_get_current();var exceptionCaught=[];var uncaughtExceptionCount=0;var ___cxa_begin_catch=ptr=>{var info=new ExceptionInfo(ptr);if(!info.get_caught()){info.set_caught(true);uncaughtExceptionCount--}info.set_rethrown(false);exceptionCaught.push(info);return ___cxa_get_exception_ptr(ptr)};var exceptionLast=null;var ___cxa_end_catch=()=>{_setThrew(0,0);var info=exceptionCaught.pop();___cxa_decrement_exception_refcount(info.excPtr);exceptionLast=null};class ExceptionInfo{constructor(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24}set_type(type){HEAPU32[this.ptr+4>>2]=type}get_type(){return HEAPU32[this.ptr+4>>2]}set_destructor(destructor){HEAPU32[this.ptr+8>>2]=destructor}get_destructor(){return HEAPU32[this.ptr+8>>2]}set_caught(caught){caught=caught?1:0;HEAP8[this.ptr+12]=caught}get_caught(){return HEAP8[this.ptr+12]!=0}set_rethrown(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13]=rethrown}get_rethrown(){return HEAP8[this.ptr+13]!=0}init(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor)}set_adjusted_ptr(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr}get_adjusted_ptr(){return HEAPU32[this.ptr+16>>2]}}var setTempRet0=val=>__emscripten_tempret_set(val);var findMatchingCatch=args=>{var thrown=exceptionLast?.excPtr;if(!thrown){setTempRet0(0);return 0}var info=new ExceptionInfo(thrown);info.set_adjusted_ptr(thrown);var thrownType=info.get_type();if(!thrownType){setTempRet0(0);return thrown}for(var caughtType of args){if(caughtType===0||caughtType===thrownType){break}var adjusted_ptr_addr=info.ptr+16;if(___cxa_can_catch(caughtType,thrownType,adjusted_ptr_addr)){setTempRet0(caughtType);return thrown}}setTempRet0(thrownType);return thrown};var ___cxa_find_matching_catch_2=()=>findMatchingCatch([]);var ___cxa_find_matching_catch_3=arg0=>findMatchingCatch([arg0]);var ___cxa_throw=(ptr,type,destructor)=>{var info=new ExceptionInfo(ptr);info.init(type,destructor);___cxa_increment_exception_refcount(ptr);exceptionLast=new CppException(ptr);uncaughtExceptionCount++;throw exceptionLast};var ___resumeException=ptr=>{if(!exceptionLast){exceptionLast=new CppException(ptr)}throw exceptionLast};var __abort_js=()=>abort("");var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var _fd_close=fd=>52;var INT53_MAX=9007199254740992;var INT53_MIN=-9007199254740992;var bigintToI53Checked=num=>num<INT53_MIN||num>INT53_MAX?NaN:Number(num);function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);return 70}var printCharBuffers=[null,[],[]];var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer));buffer.length=0}else{buffer.push(curr)}};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):"";var _fd_write=(fd,iov,iovcnt,pnum)=>{var num=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j<len;j++){printChar(fd,HEAPU8[ptr+j])}num+=len}HEAPU32[pnum>>2]=num;return 0};var _llvm_eh_typeid_for=type=>type;var wasmTableMirror=[];var getWasmTableEntry=funcPtr=>{var func=wasmTableMirror[funcPtr];if(!func){wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr)}return func};var getCFunc=ident=>{var func=Module["_"+ident];return func};var writeArrayToMemory=(array,buffer)=>{HEAP8.set(array,buffer)};var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;i++}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var ccall=(ident,returnType,argTypes,args,opts)=>{var toC={string:str=>{var ret=0;if(str!==null&&str!==undefined&&str!==0){ret=stringToUTF8OnStack(str)}return ret},array:arr=>{var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}};function convertReturnValue(ret){if(returnType==="string"){return UTF8ToString(ret)}if(returnType==="boolean")return Boolean(ret);return ret}var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i<args.length;i++){var converter=toC[argTypes[i]];if(converter){if(stack===0)stack=stackSave();cArgs[i]=converter(args[i])}else{cArgs[i]=args[i]}}}var ret=func(...cArgs);function onDone(ret){if(stack!==0)stackRestore(stack);return convertReturnValue(ret)}ret=onDone(ret);return ret};var cwrap=(ident,returnType,argTypes,opts)=>{var numericArgs=!argTypes||argTypes.every(type=>type==="number"||type==="boolean");var numericRet=returnType!=="string";if(numericRet&&numericArgs&&!opts){return getCFunc(ident)}return(...args)=>ccall(ident,returnType,argTypes,args,opts)};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])programArgs=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}Module["ccall"]=ccall;Module["cwrap"]=cwrap;Module["setValue"]=setValue;Module["getValue"]=getValue;Module["writeArrayToMemory"]=writeArrayToMemory;var _create_j2c_data,_init_j2c_data,_get_j2c_num_components,_get_j2c_width,_get_j2c_height,_get_j2c_bit_depth,_get_j2c_is_signed,_get_j2c_downsampling_x,_get_j2c_downsampling_y,_parse_j2c_data,_pull_j2c_line,_get_curr_comp,_restrict_input_resolution,_enable_resilience,_release_j2c_data,_enc_create,_enc_destroy,_enc_encode,_enc_get_data,_enc_get_size,_free,_malloc,_setThrew,__emscripten_tempret_set,__emscripten_stack_restore,__emscripten_stack_alloc,_emscripten_stack_get_current,___cxa_increment_exception_refcount,___cxa_decrement_exception_refcount,___cxa_can_catch,___cxa_get_exception_ptr,memory,__indirect_function_table,wasmMemory,wasmTable;function assignWasmExports(wasmExports){_create_j2c_data=Module["_create_j2c_data"]=wasmExports["x"];_init_j2c_data=Module["_init_j2c_data"]=wasmExports["z"];_get_j2c_num_components=Module["_get_j2c_num_components"]=wasmExports["A"];_get_j2c_width=Module["_get_j2c_width"]=wasmExports["B"];_get_j2c_height=Module["_get_j2c_height"]=wasmExports["C"];_get_j2c_bit_depth=Module["_get_j2c_bit_depth"]=wasmExports["D"];_get_j2c_is_signed=Module["_get_j2c_is_signed"]=wasmExports["E"];_get_j2c_downsampling_x=Module["_get_j2c_downsampling_x"]=wasmExports["F"];_get_j2c_downsampling_y=Module["_get_j2c_downsampling_y"]=wasmExports["G"];_parse_j2c_data=Module["_parse_j2c_data"]=wasmExports["H"];_pull_j2c_line=Module["_pull_j2c_line"]=wasmExports["I"];_get_curr_comp=Module["_get_curr_comp"]=wasmExports["J"];_restrict_input_resolution=Module["_restrict_input_resolution"]=wasmExports["K"];_enable_resilience=Module["_enable_resilience"]=wasmExports["L"];_release_j2c_data=Module["_release_j2c_data"]=wasmExports["M"];_enc_create=Module["_enc_create"]=wasmExports["N"];_enc_destroy=Module["_enc_destroy"]=wasmExports["O"];_enc_encode=Module["_enc_encode"]=wasmExports["P"];_enc_get_data=Module["_enc_get_data"]=wasmExports["Q"];_enc_get_size=Module["_enc_get_size"]=wasmExports["R"];_free=Module["_free"]=wasmExports["S"];_malloc=Module["_malloc"]=wasmExports["T"];_setThrew=wasmExports["U"];__emscripten_tempret_set=wasmExports["V"];__emscripten_stack_restore=wasmExports["W"];__emscripten_stack_alloc=wasmExports["X"];_emscripten_stack_get_current=wasmExports["Y"];___cxa_increment_exception_refcount=wasmExports["Z"];___cxa_decrement_exception_refcount=wasmExports["_"];___cxa_can_catch=wasmExports["$"];___cxa_get_exception_ptr=wasmExports["aa"];memory=wasmMemory=wasmExports["v"];__indirect_function_table=wasmTable=wasmExports["y"]}var wasmImports={g:___cxa_begin_catch,n:___cxa_end_catch,c:___cxa_find_matching_catch_2,a:___cxa_find_matching_catch_3,d:___cxa_throw,b:___resumeException,r:__abort_js,q:_emscripten_resize_heap,t:_fd_close,s:_fd_seek,l:_fd_write,o:invoke_i,e:invoke_ii,m:invoke_iii,h:invoke_iiii,j:invoke_v,i:invoke_vi,k:invoke_vii,f:invoke_viiii,u:invoke_viiiiii,p:_llvm_eh_typeid_for};function invoke_ii(index,a1){var sp=stackSave();try{return getWasmTableEntry(index)(a1)}catch(e){stackRestore(sp);if(!(e instanceof EmscriptenEH))throw e;_setThrew(1,0)}}function invoke_v(index){var sp=stackSave();try{getWasmTableEntry(index)()}catch(e){stackRestore(sp);if(!(e instanceof EmscriptenEH))throw e;_setThrew(1,0)}}function invoke_vi(index,a1){var sp=stackSave();try{getWasmTableEntry(index)(a1)}catch(e){stackRestore(sp);if(!(e instanceof EmscriptenEH))throw e;_setThrew(1,0)}}function invoke_iiii(index,a1,a2,a3){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3)}catch(e){stackRestore(sp);if(!(e instanceof EmscriptenEH))throw e;_setThrew(1,0)}}function invoke_viiii(index,a1,a2,a3,a4){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4)}catch(e){stackRestore(sp);if(!(e instanceof EmscriptenEH))throw e;_setThrew(1,0)}}function invoke_i(index){var sp=stackSave();try{return getWasmTableEntry(index)()}catch(e){stackRestore(sp);if(!(e instanceof EmscriptenEH))throw e;_setThrew(1,0)}}function invoke_viiiiii(index,a1,a2,a3,a4,a5,a6){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6)}catch(e){stackRestore(sp);if(!(e instanceof EmscriptenEH))throw e;_setThrew(1,0)}}function invoke_iii(index,a1,a2){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2)}catch(e){stackRestore(sp);if(!(e instanceof EmscriptenEH))throw e;_setThrew(1,0)}}function invoke_vii(index,a1,a2){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2)}catch(e){stackRestore(sp);if(!(e instanceof EmscriptenEH))throw e;_setThrew(1,0)}}async function run(){preRun();var setStatus=Module["setStatus"];if(setStatus){setStatus("Running...");await new Promise(resolve=>setTimeout(resolve,1));setTimeout(setStatus,1,"")}if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}var wasmExports;wasmExports=await createWasm();await run();
|
|
2
|
+
;return Module}export default Module;
|
|
Binary file
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""zarr-python v3 codec shim for the image codecs this package writes.
|
|
2
|
+
|
|
3
|
+
Registered through the ``zarr.codecs`` entry points declared in
|
|
4
|
+
``pyproject.toml``, so installing the distribution is enough to make
|
|
5
|
+
``zarr.open`` — and therefore ``spatialdata.read_zarr`` — decode stores written
|
|
6
|
+
by this package. No import or `register_codecs()` call is required; the explicit
|
|
7
|
+
`register_codecs()` below exists only for environments running from a source
|
|
8
|
+
tree without installed metadata.
|
|
9
|
+
|
|
10
|
+
The stores we write put a single array->bytes codec in the array metadata::
|
|
11
|
+
|
|
12
|
+
"codecs": [{"name": "experimental.openjph_htj2k", "configuration": {}}]
|
|
13
|
+
|
|
14
|
+
so each chunk file is a bare codestream covering the whole chunk. Chunks have
|
|
15
|
+
singleton non-spatial axes (e.g. ``[1, 1, 1, 1024, 1024]``), which is why decode
|
|
16
|
+
reshapes the ``(components, y, x)`` result onto the full chunk shape.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from dataclasses import dataclass
|
|
22
|
+
from typing import TYPE_CHECKING, Any
|
|
23
|
+
|
|
24
|
+
import numpy as np
|
|
25
|
+
from zarr.abc.codec import ArrayBytesCodec
|
|
26
|
+
from zarr.core.buffer import Buffer, NDBuffer
|
|
27
|
+
|
|
28
|
+
from .encoding import decode_image_chunk, encode_image_chunk
|
|
29
|
+
from .names import CODEC_HTJ2K_LEGACY, CODEC_HTJ2K_OPENJPH, CODEC_JPEG2K
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
from zarr.core.array_spec import ArraySpec
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _spatial_dims(shape: tuple[int, ...]) -> tuple[int, int, int]:
|
|
36
|
+
"""Split a chunk shape into ``(components, height, width)``.
|
|
37
|
+
|
|
38
|
+
Leading axes are collapsed into the component count, matching the planar
|
|
39
|
+
``(components, y, x)`` layout the encoders use.
|
|
40
|
+
"""
|
|
41
|
+
if len(shape) < 2:
|
|
42
|
+
raise ValueError(f"Image codec chunks must be at least 2D, got shape {shape}")
|
|
43
|
+
height, width = int(shape[-2]), int(shape[-1])
|
|
44
|
+
components = int(np.prod(shape[:-2])) if len(shape) > 2 else 1
|
|
45
|
+
return components, height, width
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(frozen=True)
|
|
49
|
+
class _ImageCodec(ArrayBytesCodec):
|
|
50
|
+
"""Base for the array->bytes image codecs; subclasses set `codec_name`."""
|
|
51
|
+
|
|
52
|
+
#: zarr v3 codec `name`; overridden per subclass.
|
|
53
|
+
codec_name = ""
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def from_dict(cls, data: dict[str, Any]) -> "_ImageCodec":
|
|
57
|
+
# `configuration` is empty for these codecs but is accepted (and
|
|
58
|
+
# ignored) so that metadata written by other tools still loads.
|
|
59
|
+
return cls()
|
|
60
|
+
|
|
61
|
+
def to_dict(self) -> dict[str, Any]:
|
|
62
|
+
return {"name": self.codec_name, "configuration": {}}
|
|
63
|
+
|
|
64
|
+
def compute_encoded_size(self, input_byte_length: int, _chunk_spec: "ArraySpec") -> int:
|
|
65
|
+
raise NotImplementedError(
|
|
66
|
+
f"{self.codec_name} is a compressor; encoded size is not known ahead of time."
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
async def _decode_single(self, chunk_bytes: Buffer, chunk_spec: "ArraySpec") -> NDBuffer:
|
|
70
|
+
components, height, width = _spatial_dims(tuple(chunk_spec.shape))
|
|
71
|
+
decoded = decode_image_chunk(
|
|
72
|
+
chunk_bytes.to_bytes(),
|
|
73
|
+
self.codec_name,
|
|
74
|
+
components=components,
|
|
75
|
+
height=height,
|
|
76
|
+
width=width,
|
|
77
|
+
)
|
|
78
|
+
dtype = chunk_spec.dtype.to_native_dtype()
|
|
79
|
+
chunk = np.ascontiguousarray(decoded, dtype=dtype).reshape(tuple(chunk_spec.shape))
|
|
80
|
+
return chunk_spec.prototype.nd_buffer.from_numpy_array(chunk)
|
|
81
|
+
|
|
82
|
+
async def _encode_single(self, chunk_array: NDBuffer, chunk_spec: "ArraySpec") -> Buffer | None:
|
|
83
|
+
components, height, width = _spatial_dims(tuple(chunk_spec.shape))
|
|
84
|
+
volume = chunk_array.as_numpy_array().reshape(components, height, width)
|
|
85
|
+
encoded = encode_image_chunk(volume, self.codec_name, self._encode_options())
|
|
86
|
+
return chunk_spec.prototype.buffer.from_bytes(bytes(encoded))
|
|
87
|
+
|
|
88
|
+
def _encode_options(self) -> dict[str, Any]:
|
|
89
|
+
"""Encode settings used when zarr writes through this codec.
|
|
90
|
+
|
|
91
|
+
Lossless, because a codec instantiated from array metadata carries no
|
|
92
|
+
quality configuration — the writer in `images.py` is the supported way to
|
|
93
|
+
choose a lossy preset.
|
|
94
|
+
"""
|
|
95
|
+
return {"reversible": True}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclass(frozen=True)
|
|
99
|
+
class Htj2kCodec(_ImageCodec):
|
|
100
|
+
"""HTJ2K (High-Throughput JPEG 2000) via OpenJPH."""
|
|
101
|
+
|
|
102
|
+
codec_name = CODEC_HTJ2K_OPENJPH
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass(frozen=True)
|
|
106
|
+
class LegacyHtj2kCodec(_ImageCodec):
|
|
107
|
+
"""HTJ2K under the pre-OpenJPH label; decode-compatible with `Htj2kCodec`.
|
|
108
|
+
|
|
109
|
+
Read-only by design. The label is registered so existing stores still open,
|
|
110
|
+
but new chunks should carry the current name — writing more of them would
|
|
111
|
+
spread a codec id we are trying to retire.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
codec_name = CODEC_HTJ2K_LEGACY
|
|
115
|
+
|
|
116
|
+
async def _encode_single(self, chunk_array: NDBuffer, chunk_spec: "ArraySpec") -> Buffer | None:
|
|
117
|
+
raise NotImplementedError(
|
|
118
|
+
f"{CODEC_HTJ2K_LEGACY} is a legacy label kept for reading existing stores; "
|
|
119
|
+
f"write with {CODEC_HTJ2K_OPENJPH} instead."
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@dataclass(frozen=True)
|
|
124
|
+
class Jpeg2kCodec(_ImageCodec):
|
|
125
|
+
"""JPEG 2000 via `imagecodecs`."""
|
|
126
|
+
|
|
127
|
+
codec_name = CODEC_JPEG2K
|
|
128
|
+
|
|
129
|
+
def _encode_options(self) -> dict[str, Any]:
|
|
130
|
+
return {"reversible": True}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
CODEC_CLASSES: dict[str, type[_ImageCodec]] = {
|
|
134
|
+
CODEC_HTJ2K_OPENJPH: Htj2kCodec,
|
|
135
|
+
CODEC_HTJ2K_LEGACY: LegacyHtj2kCodec,
|
|
136
|
+
CODEC_JPEG2K: Jpeg2kCodec,
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def register_codecs() -> None:
|
|
141
|
+
"""Register the image codecs with zarr explicitly.
|
|
142
|
+
|
|
143
|
+
Installing this distribution already registers them via entry points. Call
|
|
144
|
+
this only when running from a source checkout with no installed metadata.
|
|
145
|
+
"""
|
|
146
|
+
from zarr.registry import register_codec
|
|
147
|
+
|
|
148
|
+
for name, codec_cls in CODEC_CLASSES.items():
|
|
149
|
+
register_codec(name, codec_cls)
|