def _import2dimage(self, hdu): """Import 2d image data from hdu.""" p = self.params if (p.datacol is not None or p.symerrcol is not None or p.poserrcol is not None or p.negerrcol is not None): print "Warning: ignoring columns as import 2D dataset" header = hdu.header data = hdu.data try: # try to read WCS for image, and work out x/yrange wcs = [ header[i] for i in ('CRVAL1', 'CRPIX1', 'CDELT1', 'CRVAL2', 'CRPIX2', 'CDELT2') ] rangex = ((data.shape[1] - wcs[1]) * wcs[2] + wcs[0], (0 - wcs[1]) * wcs[2] + wcs[0]) rangey = ((0 - wcs[4]) * wcs[5] + wcs[3], (data.shape[0] - wcs[4]) * wcs[5] + wcs[3]) rangex = (rangex[1], rangex[0]) except KeyError: # no / broken wcs rangex = None rangey = None return datasets.Dataset2D(data, xrange=rangex, yrange=rangey)
def SetData2D(self, name, data, xrange=None, yrange=None): """Create a 2D dataset.""" data = datasets.Dataset2D(data, xrange=xrange, yrange=yrange) op = operations.OperationDatasetSet(name, data) self.document.applyOperation(op) if self.verbose: print "Set 2d dataset '%s'" % name
def setInDocument(self, document, linkedfile=None): """Set the data in the document. Returns list containing name of dataset read """ ds = datasets.Dataset2D(self.data, xrange=self.params.xrange, yrange=self.params.yrange) ds.linked = linkedfile fullname = self.params.prefix + self.name + self.params.suffix document.setData(fullname, ds) return [fullname]
def do(self, document): """Make new dataset.""" # keep backup of old if exists self.olddataset = document.data.get(self.datasetname, None) # make new dataset ds = self.makeDSClass() ds.document = document if not self.link: # unlink if necessary ds = datasets.Dataset2D(ds.data, xrange=ds.xrange, yrange=ds.yrange) document.setData(self.datasetname, ds) return ds
def doImport(self, document): """Do import.""" pluginnames = [p.name for p in plugins.importpluginregistry] plugin = plugins.importpluginregistry[pluginnames.index( self.params.plugin)] # if the plugin is a class, make an instance # the old API is for the plugin to be instances if isinstance(plugin, type): plugin = plugin() # strip out parameters for plugin itself p = self.params # stick back together the plugin parameter object plugparams = plugins.ImportPluginParams(p.filename, p.encoding, p.pluginpars) results = plugin.doImport(plugparams) # make link for file LF = None if p.linked: LF = linked.LinkedFilePlugin(p) customs = [] # convert results to real datasets names = [] for d in results: if isinstance(d, plugins.Dataset1D): ds = datasets.Dataset(data=d.data, serr=d.serr, perr=d.perr, nerr=d.nerr) elif isinstance(d, plugins.Dataset2D): ds = datasets.Dataset2D(data=d.data, xrange=d.rangex, yrange=d.rangey) elif isinstance(d, plugins.DatasetText): ds = datasets.DatasetText(data=d.data) elif isinstance(d, plugins.DatasetDateTime): ds = datasets.DatasetDateTime(data=d.data) elif isinstance(d, plugins.Constant): customs.append(['constant', d.name, d.val]) continue elif isinstance(d, plugins.Function): customs.append(['function', d.name, d.val]) continue else: raise RuntimeError("Invalid data set in plugin results") # set any linking if linked: ds.linked = LF # construct name name = p.prefix + d.name + p.suffix # actually make dataset document.setData(name, ds) names.append(name) # add constants, functions to doc, if any self.addCustoms(document, customs) self.outdatasets = names self.outcustoms = list(customs)