def init_data( self, **kwargs ): project_dataset: xa.Dataset = DataManager.instance().loadCurrentProject("points") reduced_data: xa.DataArray = project_dataset.reduction reduced_data.attrs['dsid'] = project_dataset.attrs['dsid'] self._embedding = ReductionManager.instance().umap_init( reduced_data, **kwargs ) self._points = self._embedding self.initialize_markers()
def prepare_inputs(self, *args): self.dm.select_current_mode() self.update_gui_parameters() self.set_progress(0.02) file_name = f"raw" if self.reduce_method == "None" else f"{self.reduce_method}-{self.model_dims}" if self.subsample > 1: file_name = f"{file_name}-ss{self.subsample}" output_file = os.path.join(self.datasetDir, file_name + ".nc") input_vars = self.get_input_mdata() np_embedding: np.ndarray = self.getInputFileData( input_vars['embedding'], self.subsample) dims = np_embedding.shape mdata_vars = list(input_vars['directory']) xcoords = OrderedDict(samples=np.arange(dims[0]), bands=np.arange(dims[1])) xdims = OrderedDict({dims[0]: 'samples', dims[1]: 'bands'}) data_vars = dict(embedding=xa.DataArray(np_embedding, dims=xcoords.keys(), coords=xcoords, name=input_vars['embedding'])) data_vars.update({ vid: self.getXarray(vid, xcoords, self.subsample, xdims) for vid in mdata_vars }) pspec = input_vars['plot'] data_vars.update({ f'plot-{vid}': self.getXarray(pspec[vid], xcoords, self.subsample, xdims, norm=pspec.get('norm', '')) for vid in ['x', 'y'] }) self.set_progress(0.1) if self.reduce_method != "None": reduced_spectra = ReductionManager.instance().reduce( data_vars['embedding'], self.reduce_method, self.model_dims, self.reduce_nepochs) coords = dict(samples=xcoords['samples'], model=np.arange(self.model_dims)) data_vars['reduction'] = xa.DataArray(reduced_spectra, dims=['samples', 'model'], coords=coords) self.set_progress(0.8) dataset = xa.Dataset(data_vars, coords=xcoords, attrs={'type': 'spectra'}) dataset.attrs["colnames"] = mdata_vars print(f"Writing output to {output_file}") dataset.to_netcdf(output_file, format='NETCDF4', engine='netcdf4') self.updateDatasetList() self.set_progress(1.0)
def prepare_inputs(input_vars, ssample=None): dataManager = DataManager.instance() subsample = dataManager.subsample if ssample is None else ssample np_embedding = dataManager.getInputFileData(input_vars['embedding'], subsample) dims = np_embedding.shape mdata_vars = list(input_vars['directory']) xcoords = OrderedDict(samples=np.arange(dims[0]), bands=np.arange(dims[1])) xdims = OrderedDict({dims[0]: 'samples', dims[1]: 'bands'}) data_vars = dict(embedding=xa.DataArray(np_embedding, dims=xcoords.keys(), coords=xcoords, name=input_vars['embedding'])) data_vars.update( {vid: getXarray(vid, xcoords, subsample, xdims) for vid in mdata_vars}) pspec = input_vars['plot'] data_vars.update({ f'plot-{vid}': getXarray(pspec[vid], xcoords, subsample, xdims, norm=pspec.get('norm', '')) for vid in ['x', 'y'] }) reduction_method = dataManager.config.value("input.reduction/method", 'None') ndim = int(dataManager.config.value("input.reduction/ndim", 32)) epochs = int(dataManager.config.value("input.reduction/epochs", 1)) if reduction_method != "None": reduced_spectra = ReductionManager.instance().reduce( data_vars['embedding'], reduction_method, ndim, epochs) coords = dict(samples=xcoords['samples'], model=np.arange(ndim)) data_vars['reduction'] = xa.DataArray(reduced_spectra, dims=['samples', 'model'], coords=coords) dataset = xa.Dataset(data_vars, coords=xcoords, attrs={'type': 'spectra'}) dataset.attrs["colnames"] = mdata_vars projId = dataManager.config.value('project/id') file_name = f"raw" if reduction_method == "None" else f"{reduction_method}-{ndim}" if subsample > 1: file_name = f"{file_name}-ss{subsample}" outputDir = os.path.join(dataManager.config.value('data/cache'), projId) mode = 0o777 os.makedirs(outputDir, mode, True) output_file = os.path.join(outputDir, file_name + ".nc") print(f"Writing output to {output_file}") dataset.to_netcdf(output_file, format='NETCDF4', engine='netcdf4')
def getConfigPanel(self): from astrolab.reduction.embedding import ReductionManager rm = ReductionManager.instance() nepochs_selector: ip.IntSlider = ip.IntSlider( min=50, max=500, description='UMAP nepochs:', value=rm.nepochs, continuous_update=False, layout=ip.Layout(width="auto")) alpha_selector: ip.FloatSlider = ip.FloatSlider( min=0.1, max=0.8, step=0.01, description='UMAP alpha:', value=rm.alpha, readout_format=".2f", continuous_update=False, layout=ip.Layout(width="auto")) init_selector: ip.Select = ip.Select(options=["random", "spectral"], description='UMAP init method:', value="random", layout=ip.Layout(width="auto")) def apply_handler(*args): from astrolab.gui.application import Astrolab rm.nepochs = nepochs_selector.value rm.alpha = alpha_selector.value rm.init = init_selector.value Astrolab.instance().save_config() apply: ip.Button = ip.Button(description="Apply", layout=ip.Layout(flex='1 1 auto'), border='1px solid dimgrey') apply.on_click(apply_handler) configPanel: ip.VBox = ip.VBox( [nepochs_selector, alpha_selector, init_selector, apply], layout=ip.Layout(width="100%", height="100%"), border='2px solid firebrick') return configPanel
def reembed(self, **kwargs ): t0 = time.time() self._embedding = ReductionManager.instance().umap_embedding( **kwargs ) self.update_plot() print(f"PointCloudManager: completed embed in {time.time()-t0} sec")
def init_data( self, **kwargs ): project_dataset = DataManager.instance().loadCurrentProject() reduced_data: xa.DataArray = project_dataset.reduction reduced_data.attrs['dsid'] = 'swift' self._embedding = ReductionManager.instance().umap_init( reduced_data, **kwargs )