def _cli(ctx, input, output, codebook): ctx.obj = dict( component=Decoder, input=input, output=output, intensities=IntensityTable.load(input), codebook=Codebook.from_json(codebook), )
def _cli(ctx, input, output, codebook): """pixel-wise spot detection and decoding""" print('Detecting Spots ...') ctx.obj = dict( component=PixelSpotDecoder, image_stack=ImageStack.from_path_or_url(input), output=output, codebook=Codebook.from_json(codebook), )
def _cli(ctx, input, output, blobs_stack, reference_image_from_max_projection, codebook): print('Detecting Spots ...') ctx.obj = dict( component=SpotFinder, image_stack=ImageStack.from_path_or_url(input), output=output, blobs_stack=blobs_stack, reference_image_from_max_projection= reference_image_from_max_projection, codebook=None, ) if codebook is not None: ctx.obj["codebook"] = Codebook.from_json(codebook)
def _cli(cls, args, print_help=False): """Runs the decoder component based on parsed arguments.""" if args.decoder_algorithm_class is None or print_help: cls.decoder_group.print_help() cls.decoder_group.exit(status=2) instance = args.decoder_algorithm_class(**vars(args)) # load intensities and codebook intensities = IntensityTable.load(args.input) codebook = Codebook.from_json(args.codebook) # decode and save output intensities = instance.run(intensities, codebook) intensities.save(args.output)
def from_json(cls, json_url: str, strict: bool = None, config: Optional[Union[str, Dict]] = None) -> "Experiment": """ Construct an `Experiment` from an experiment.json file format specifier Parameters ---------- json_url : str file path or web link to an experiment.json file strict : bool if true, then all JSON loaded by this method will be passed to the appropriate validator config : str or dict configuration property that will be passed to starfish.util.config.Config STARISH_CONFIG : This parameter is read from the environment to permit setting configuration values either directly or via a file. Keys read include: - cache.allow_caching STARFISH_STRICT_LOADING : This parameter is read from the environment. If set, then all JSON loaded by this method will be passed to the appropriate validator. The `strict` parameter to this method has priority over the environment variable. Returns ------- Experiment : Experiment object serving the requested experiment data """ if strict is None: strict = "STARFISH_STRICT_LOADING" in os.environ if strict: valid = validate_sptx.validate(json_url) if not valid: raise Exception("validation failed") config_obj = Config(config) # STARFISH_CONFIG is assumed allow_caching = config_obj.lookup(["cache", "allow_caching"], True) backend, name, baseurl = resolve_path_or_url(json_url, allow_caching) with backend.read_contextmanager(name) as fh: experiment_document = json.load(fh) version = cls.verify_version(experiment_document['version']) _, codebook_name, codebook_baseurl = resolve_url( experiment_document['codebook'], baseurl, allow_caching) codebook_absolute_url = pathjoin(codebook_baseurl, codebook_name) codebook = Codebook.from_json(codebook_absolute_url) extras = experiment_document['extras'] fovs: MutableSequence[FieldOfView] = list() fov_tilesets: MutableMapping[str, TileSet] = dict() if version < Version("5.0.0"): primary_image: Collection = Reader.parse_doc( experiment_document['primary_images'], baseurl) auxiliary_images: MutableMapping[str, Collection] = dict() for aux_image_type, aux_image_url in experiment_document[ 'auxiliary_images'].items(): auxiliary_images[aux_image_type] = Reader.parse_doc( aux_image_url, baseurl) for fov_name, primary_tileset in primary_image.all_tilesets(): fov_tilesets[FieldOfView.PRIMARY_IMAGES] = primary_tileset for aux_image_type, aux_image_collection in auxiliary_images.items( ): aux_image_tileset = aux_image_collection.find_tileset( fov_name) if aux_image_tileset is not None: fov_tilesets[aux_image_type] = aux_image_tileset fov = FieldOfView(fov_name, image_tilesets=fov_tilesets) fovs.append(fov) else: images: MutableMapping[str, Collection] = dict() all_fov_names: MutableSet[str] = set() for image_type, image_url in experiment_document['images'].items(): image = Reader.parse_doc(image_url, baseurl) images[image_type] = image for fov_name, _ in image.all_tilesets(): all_fov_names.add(fov_name) for fov_name in all_fov_names: for image_type, image_collection in images.items(): image_tileset = image_collection.find_tileset(fov_name) if image_tileset is not None: fov_tilesets[image_type] = image_tileset fov = FieldOfView(fov_name, image_tilesets=fov_tilesets) fovs.append(fov) return Experiment(fovs, codebook, extras, src_doc=experiment_document)
def loaded_codebook(simple_codebook_json): return Codebook.from_json(simple_codebook_json, n_ch=2, n_round=2)
def from_json(cls, json_url: str) -> "Experiment": """ Construct an `Experiment` from an experiment.json file format specifier. Loads configuration from StarfishConfig. Parameters ---------- json_url : str file path or web link to an experiment.json file Returns ------- Experiment : Experiment object serving the requested experiment data """ config = StarfishConfig() if config.strict: valid = validate_sptx.validate(json_url) if not valid: raise Exception("validation failed") backend, name, baseurl = resolve_path_or_url(json_url, config.slicedimage) with backend.read_contextmanager(name) as fh: experiment_document = json.load(fh) version = cls.verify_version(experiment_document['version']) _, codebook_name, codebook_baseurl = resolve_url( experiment_document['codebook'], baseurl, config.slicedimage) codebook_absolute_url = pathjoin(codebook_baseurl, codebook_name) codebook = Codebook.from_json(codebook_absolute_url) extras = experiment_document['extras'] fovs: MutableSequence[FieldOfView] = list() fov_tilesets: MutableMapping[str, TileSet] if version < Version("5.0.0"): primary_image: Collection = Reader.parse_doc( experiment_document['primary_images'], baseurl, config.slicedimage) auxiliary_images: MutableMapping[str, Collection] = dict() for aux_image_type, aux_image_url in experiment_document[ 'auxiliary_images'].items(): auxiliary_images[aux_image_type] = Reader.parse_doc( aux_image_url, baseurl, config.slicedimage) for fov_name, primary_tileset in primary_image.all_tilesets(): fov_tilesets = dict() fov_tilesets[FieldOfView.PRIMARY_IMAGES] = primary_tileset for aux_image_type, aux_image_collection in auxiliary_images.items( ): aux_image_tileset = aux_image_collection.find_tileset( fov_name) if aux_image_tileset is not None: fov_tilesets[aux_image_type] = aux_image_tileset fov = FieldOfView(fov_name, image_tilesets=fov_tilesets) fovs.append(fov) else: images: MutableMapping[str, Collection] = dict() all_fov_names: MutableSet[str] = set() for image_type, image_url in experiment_document['images'].items(): image = Reader.parse_doc(image_url, baseurl, config.slicedimage) images[image_type] = image for fov_name, _ in image.all_tilesets(): all_fov_names.add(fov_name) for fov_name in all_fov_names: fov_tilesets = dict() for image_type, image_collection in images.items(): image_tileset = image_collection.find_tileset(fov_name) if image_tileset is not None: fov_tilesets[image_type] = image_tileset fov = FieldOfView(fov_name, image_tilesets=fov_tilesets) fovs.append(fov) return Experiment(fovs, codebook, extras, src_doc=experiment_document)
def load(self, input_parameter: str) -> Codebook: return Codebook.from_json(input_parameter)
def from_json(cls, json_url: str, strict: bool=None) -> "Experiment": """ Construct an `Experiment` from an experiment.json file format specifier Parameters ---------- json_url : str file path or web link to an experiment.json file strict : bool if true, then all JSON loaded by this method will be passed to the appropriate validator Returns ------- Experiment : Experiment object serving the requested experiment data Environment variables --------------------- STARFISH_STRICT_LOADING : If set, then all JSON loaded by this method will be passed to the appropriate validator. The `strict` parameter to this method has priority over the environment variable. """ if strict is None: strict = "STARFISH_STRICT_LOADING" in os.environ if strict: valid = validate_sptx.validate(json_url) if not valid: raise Exception("validation failed") backend, name, baseurl = resolve_path_or_url(json_url) with backend.read_contextmanager(name) as fh: experiment_document = json.load(fh) cls.verify_version(experiment_document['version']) _, codebook_name, codebook_baseurl = resolve_url(experiment_document['codebook'], baseurl) codebook_absolute_url = pathjoin(codebook_baseurl, codebook_name) codebook = Codebook.from_json(codebook_absolute_url) extras = experiment_document['extras'] primary_image: Collection = Reader.parse_doc(experiment_document['primary_images'], baseurl) auxiliary_images: MutableMapping[str, Collection] = dict() for aux_image_type, aux_image_url in experiment_document['auxiliary_images'].items(): auxiliary_images[aux_image_type] = Reader.parse_doc(aux_image_url, baseurl) fovs: MutableSequence[FieldOfView] = list() for fov_name, primary_tileset in primary_image.all_tilesets(): aux_image_tilesets_for_fov: MutableMapping[str, TileSet] = dict() for aux_image_type, aux_image_collection in auxiliary_images.items(): aux_image_tileset = aux_image_collection.find_tileset(fov_name) if aux_image_tileset is not None: aux_image_tilesets_for_fov[aux_image_type] = aux_image_tileset fov = FieldOfView( fov_name, primary_image_tileset=primary_tileset, auxiliary_image_tilesets=aux_image_tilesets_for_fov, ) fovs.append(fov) return Experiment(fovs, codebook, extras, src_doc=experiment_document)