def draw(self): cpoints = tuple( map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y1), (self.x2, self.y2), (self.x1, self.y2)))) qpoints = list( map(lambda p: QtCore.QPoint(p[0], p[1]), (cpoints + (cpoints[0], )))) qpoly = QPolygon(qpoints) cr = self.setup_cr() cr.drawPolygon(qpoly) if self.editing: self.draw_edit(cr) elif self.showcap: self.draw_caps(cr, self.cap, cpoints) if self.drawdims: fontsize = self.scale_font() cr.setFont(QFont(self.font, pointSize=fontsize)) cx1, cy1 = cpoints[0] cx2, cy2 = cpoints[2] # draw label on X dimension cx = cx1 + (cx2 - cx1) // 2 cy = cy2 + -4 cr.drawText(cx, cy, "%d" % (self.x2 - self.x1)) # draw label on Y dimension cy = cy1 + (cy2 - cy1) // 2 cx = cx2 + 4 cr.drawText(cx, cy, "%d" % (self.y2 - self.y1))
def draw(self): cpoints = tuple(map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y1), (self.x2, self.y2), (self.x1, self.y2)))) qpoints = list(map(lambda p: QtCore.QPoint(p[0], p[1]), (cpoints + (cpoints[0],)))) qpoly = QPolygon(qpoints) cr = self.setup_cr() cr.drawPolygon(qpoly) if self.cap: self.draw_caps(cr, self.cap, cpoints) if self.drawdims: fontsize = self.scale_font() cr.setFont(QFont(self.font, pointSize=fontsize)) cx1, cy1 = cpoints[0] cx2, cy2 = cpoints[2] # draw label on X dimension cx = cx1 + (cx2 - cx1) // 2 cy = cy2 + -4 cr.drawText(cx, cy, "%d" % (self.x2 - self.x1)) # draw label on Y dimension cy = cy1 + (cy2 - cy1) // 2 cx = cx2 + 4 cr.drawText(cx, cy, "%d" % (self.y2 - self.y1))
def correct_wcs(self): # small local function to strip comment and blank lines def _flt(line): line = line.strip() if line.startswith('#'): return False if len(line) == 0: return False return True # extract image and reference coords from text widgets txt1 = self.w.report.get_text() lines1 = filter(_flt, txt1.split('\n')) txt2 = self.w.correct.get_text() lines2 = filter(_flt, txt2.split('\n')) assert len(lines1) == len(lines2), \ Exception("Number of lines don't match in reports") img_coords = list(map(lambda l: map(float, l.split(',')[3:5]), lines1)) #print "img coords:", img_coords ref_coords = list(map(lambda l: map(float, l.split(',')[0:2]), lines2)) #print "ref coords:", ref_coords image = self.fitsimage.get_image() self.fv.nongui_do(self._calc_match, image, img_coords, ref_coords)
def draw_ccds(self, ctr_ra_deg, ctr_dec_deg): image = self.fitsimage.get_image() if image is None: return ctr_x, ctr_y = image.radectopix(ctr_ra_deg, ctr_dec_deg) self.ctr_x, self.ctr_y = ctr_x, ctr_y l = [] ctr_pt = self.dc.Point(ctr_x, ctr_y, 50, linewidth=4, color="orange", style="plus", coord="data") l.append(ctr_pt) self.ctr_pt = ctr_pt paths = self.get_paths(ctr_ra_deg, ctr_dec_deg, info) start, stop, dither_positions = self.get_dither_positions() dither = list(map(lambda pt: image.radectopix(pt[0], pt[1]), dither_positions)) dither = numpy.array(dither) ## only_ccds_in_dithers = self.w.only_dithers.get_state() crdmap = self.fitsimage.get_coordmap("data") for key, path in paths: points = list(map(lambda pt: image.radectopix(pt[0], pt[1]), path)) points = numpy.array(points) if "color" in info[key]: color = info[key]["color"] else: color = "lightgreen" p = self.dc.Polygon(points, color=color, showcap=False) # hack to be able to check containment before object is on # the canvas p.crdmap = crdmap ## # exclude this ccd if not involved in the dither ## if only_ccds_in_dithers and not self._ccd_in_dither(dither, p): ## continue # annotate with the CCD name pcx, pcy = p.get_center_pt() name = sdo_map[key] t = self.dc.Text(pcx, pcy, text=name, color=color, fontsize=12, coord="data") l.append(self.dc.CompoundObject(p, t)) # l.append(p) obj = self.dc.CompoundObject(*l) self.canvas.deleteObjectByTag("ccd_overlay") self.canvas.add(obj, tag="ccd_overlay", redraw=False) # rotate for pa obj.rotate(-self.pa_deg, xoff=ctr_x, yoff=ctr_y) self.ccd_overlay = obj self.canvas.update_canvas() self.logger.debug("canvas rotated")
def draw(self): cpoints = tuple(map(lambda p: self.canvascoords(p[0], p[1]), self.points)) cr = self.setup_cr() qpoints = list(map(lambda p: QtCore.QPoint(p[0], p[1]), (cpoints + (cpoints[0],)))) qpoly = QPolygon(qpoints) cr.drawPolygon(qpoly) if self.cap: self.draw_caps(cr, self.cap, cpoints)
def unmarshall(obj): # take care of compound types if isinstance(obj, list): return list(map(unmarshall, obj)) if isinstance(obj, tuple): return tuple(map(unmarshall, obj)) if isinstance(obj, dict): return dict(zip(obj.keys(), map(unmarshall, obj.values()))) if isinstance(obj, xmlrpclib.Binary): obj = obj.data return obj
def draw(self): cpoints = tuple( map(lambda p: self.canvascoords(p[0], p[1]), self.points)) cr = self.setup_cr() qpoints = list( map(lambda p: QtCore.QPoint(p[0], p[1]), (cpoints + (cpoints[0], )))) qpoly = QPolygon(qpoints) cr.drawPolygon(qpoly) if self.cap: self.draw_caps(cr, self.cap, cpoints)
def draw(self): cpoints = tuple(map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y2), (self.x2, self.y1)))) qpoints = list(map(lambda p: QtCore.QPoint(p[0], p[1]), (cpoints + (cpoints[0],)))) qpoly = QPolygon(qpoints) cr = self.setup_cr() cr.drawPolygon(qpoly) if self.editing: self.draw_edit(cr) elif self.showcap: self.draw_caps(cr, self.cap, cpoints)
def get_cpoints(self, viewer, points=None): if points is None: points = self.get_points() if hasattr(self, 'rot_deg') and self.rot_deg != 0.0: # rotate vertices according to rotation x, y = self.get_center_pt() rpoints = tuple(map(lambda p: self.crdmap.rotate_pt(p[0], p[1], self.rot_deg, xoff=x, yoff=y), points)) else: rpoints = points cpoints = tuple(map(lambda p: self.canvascoords(viewer, p[0], p[1]), rpoints)) return cpoints
def unmarshall(rtnval): typ = type(rtnval) # take care of compound types if isinstance(rtnval, list): return list(map(unmarshall, rtnval)) if isinstance(rtnval, tuple): return tuple(map(unmarshall, rtnval)) if isinstance(rtnval, dict): return dict(zip(rtnval.keys(), map(unmarshall, rtnval.values()))) if isinstance(rtnval, xmlrpclib.Binary): rtnval = rtnval.data return rtnval
def get_cpoints(self, viewer, points=None): if points is None: points = self.get_points() if hasattr(self, 'rot_deg') and self.rot_deg != 0.0: # rotate vertices according to rotation x, y = self.get_center_pt() rpoints = tuple( map( lambda p: self.crdmap.rotate_pt( p[0], p[1], self.rot_deg, xoff=x, yoff=y), points)) else: rpoints = points cpoints = tuple( map(lambda p: self.canvascoords(viewer, p[0], p[1]), rpoints)) return cpoints
def draw_polygon(self, cpoints): qpoints = list(map(lambda p: QtCore.QPoint(p[0], p[1]), cpoints)) p = cpoints[0] qpoints.append(QtCore.QPoint(p[0], p[1])) qpoly = QPolygon(qpoints) self.cr.drawPolygon(qpoly)
def set_minmax(self, i, length): subset = self.get_subset_from_starlist(i, i + length) values = list(map(lambda star: float(star[self.mag_field]), subset)) if len(values) > 0: self.mag_max = max(values) self.mag_min = min(values) self.cbar.set_range(self.mag_min, self.mag_max)
def draw(self): cpoints = map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y1), (self.x2, self.y2), (self.x1, self.y2))) cr = self.setup_cr() pen = cr.get_pen(self.color) brush = None if self.fill: if self.fillcolor: brush = cr.get_brush(self.fillcolor) else: brush = cr.get_brush(self.color) cr.canvas.polygon(list(chain.from_iterable(cpoints)), pen, brush) if self.cap: self.draw_caps(cr, self.cap, cpoints) if self.drawdims: fontsize = self.scale_font() font = cr.get_font(self.font, fontsize, self.color) cx1, cy1 = cpoints[0] cx2, cy2 = cpoints[2] # draw label on X dimension cx = cx1 + (cx2 - cx1) // 2 cy = cy2 + -4 text = "%d" % (self.x2 - self.x1) cr.canvas.text((cx, cy), text, font) cy = cy1 + (cy2 - cy1) // 2 cx = cx2 + 4 text = "%d" % (self.y2 - self.y1) cr.canvas.text((cx, cy), text, font)
def contains_pts(self, pts): if len(self.objects) == 0: x_arr, y_arr = np.asarray(pts).T return np.full(x_arr.shape, False, dtype=np.bool) return reduce(self._contains_reduce, map(lambda obj: obj.contains_pts(pts), self.objects))
def drop_event(self, widget, event): dropdata = event.mimeData() formats = list(map(str, list(dropdata.formats()))) self.logger.debug("available formats of dropped data are %s" % ( formats)) if "text/thumb" in formats: if six.PY2: thumbstr = str(dropdata.data("text/thumb")) else: thumbstr = str(dropdata.data("text/thumb"), encoding='ascii') data = [ thumbstr ] self.logger.debug("dropped thumb(s): %s" % (str(data))) elif dropdata.hasUrls(): urls = list(dropdata.urls()) data = [ str(url.toString()) for url in urls ] self.logger.debug("dropped filename(s): %s" % (str(data))) elif "text/plain" in formats: data = [ dropdata.text() ] self.logger.debug("dropped filename(s): %s" % (str(data))) else: # No format that we understand--just pass it along ## data = dropdata.data(formats[0]) ## self.logger.debug("dropped data of len %d" % (len(data))) event.setAccepted(False) return event.setAccepted(True) #event.acceptProposedAction() self.make_ui_callback('drag-drop', data)
def drop_event(self, widget, event): dropdata = event.mimeData() formats = list(map(str, list(dropdata.formats()))) self.logger.debug("available formats of dropped data are %s" % (formats)) if "text/thumb" in formats: if six.PY2: thumbstr = str(dropdata.data("text/thumb")) else: thumbstr = str(dropdata.data("text/thumb"), encoding='ascii') data = [thumbstr] self.logger.debug("dropped thumb(s): %s" % (str(data))) elif dropdata.hasUrls(): urls = list(dropdata.urls()) data = [str(url.toString()) for url in urls] self.logger.debug("dropped filename(s): %s" % (str(data))) elif "text/plain" in formats: data = [dropdata.text()] self.logger.debug("dropped filename(s): %s" % (str(data))) else: # No format that we understand--just pass it along ## data = dropdata.data(formats[0]) ## self.logger.debug("dropped data of len %d" % (len(data))) event.setAccepted(False) return event.setAccepted(True) #event.acceptProposedAction() self.make_ui_callback('drag-drop', data)
def browse(self, path): self.logger.debug("path: %s" % (path)) if os.path.isdir(path): dirname = path globname = None else: dirname, globname = os.path.split(path) dirname = os.path.abspath(dirname) # check validity of leading path name if not os.path.isdir(dirname): self.fv.show_error("Not a valid path: %s" % (dirname)) return if not globname: globname = '*' path = os.path.join(dirname, globname) # Make a directory listing self.logger.debug("globbing path: %s" % (path)) filelist = list(glob.glob(path)) filelist.sort(key=str.lower) filelist.insert(0, os.path.join(dirname, '..')) self.jumpinfo = list(map(self.get_info, filelist)) self.curpath = path if self.do_scanfits: self.scan_fits() self.makelisting(path)
def pixtoradec(self, idxs, coords='data'): # Starlink's WCS needs pixels referenced from 1 if coords == 'data': idxs = numpy.array(list(map(lambda x: x+1, idxs))) else: idxs = numpy.array(idxs) try: # pixel to sky coords (in the WCS specified transform) arrs = [ [idxs[i]] for i in range(len(idxs)) ] res = self.wcs.tran(arrs, 1) if self.coordsys not in ('pixel', 'raw'): # whatever sky coords to icrs coords res = self.icrs_trans.tran(res, 1) # TODO: what if axes are inverted? ra_rad, dec_rad = res[0][0], res[1][0] ra_deg, dec_deg = math.degrees(ra_rad), math.degrees(dec_rad) #print ra_deg, dec_deg except Exception as e: self.logger.error("Error calculating pixtoradec: %s" % (str(e))) raise WCSError(e) return ra_deg, dec_deg
def set_minmax(self, i, length): subset = self.get_subset_from_starlist(i, i+length) values = list(map(lambda star: float(star[self.mag_field]), subset)) self.mag_max = max(values) self.mag_min = min(values) self.cbar.set_range(self.mag_min, self.mag_max)
def get_image(self): fi = self.fitsimage # clear previous image self.fig.clf() ax = self.fig.add_subplot(111) ax.autoscale(True, tight=True) x0, y0, x1, y1 = tuple(map(int, fi.get_datarect())) #extent = (x0, x1, y0, y1) image = fi.get_image() arr = image.cutout_data(x0, y0, x1, y1) extent = self.get_wcs_extent(image, x0, y0, x1, y1) # get cut levels loval, hival = fi.get_cut_levels() # make the equivalent color map for matplotlib cm = self.make_mpl_colormap(fi) # add the image to the figure interp = 'nearest' img = ax.imshow(arr, interpolation=interp, origin="lower", vmin=loval, vmax=hival, cmap=cm, aspect="equal", extent=extent) # add a colorbar self.fig.colorbar(img, orientation='vertical') # force an update of the figure self.fig.canvas.draw()
def draw(self): cpoints = list(map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y1), (self.x2, self.y2), (self.x1, self.y2)))) cr = self.setup_cr(closed=True, transform=None) cr.update_patch(self) xy = numpy.array(cpoints) p = patches.Polygon(xy, **cr.kwdargs) cr.axes.add_patch(p) if self.cap: self.draw_caps(cr, self.cap, cpoints) if self.drawdims: fontsize = self.scale_font() font = cr.get_font(self.font, fontsize, self.color) cx1, cy1 = cpoints[0] cx2, cy2 = cpoints[2] # draw label on X dimension cx = cx1 + (cx2 - cx1) / 2 cy = cy2 + -4 text = "%d" % (self.x2 - self.x1) cr.axes.text(cx, cy, text, fontdict=font) cy = cy1 + (cy2 - cy1) / 2 cx = cx2 + 4 text = "%d" % (self.y2 - self.y1) cr.axes.text(cx, cy, text, fontdict=font)
def pixtoradec(self, idxs, coords='data'): # Starlink's WCS needs pixels referenced from 1 if coords == 'data': idxs = numpy.array(list(map(lambda x: x + 1, idxs))) else: idxs = numpy.array(idxs) try: # pixel to sky coords (in the WCS specified transform) arrs = [[idxs[i]] for i in range(len(idxs))] res = self.wcs.tran(arrs, 1) if self.coordsys not in ('pixel', 'raw'): # whatever sky coords to icrs coords res = self.icrs_trans.tran(res, 1) # TODO: what if axes are inverted? ra_rad, dec_rad = res[0][0], res[1][0] ra_deg, dec_deg = math.degrees(ra_rad), math.degrees(dec_rad) #print ra_deg, dec_deg except Exception as e: self.logger.error("Error calculating pixtoradec: %s" % (str(e))) raise WCSError(e) return ra_deg, dec_deg
def draw(self): cpoints = tuple( map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y2), (self.x2, self.y1)))) qpoints = list( map(lambda p: QtCore.QPoint(p[0], p[1]), (cpoints + (cpoints[0], )))) qpoly = QPolygon(qpoints) cr = self.setup_cr() cr.drawPolygon(qpoly) if self.editing: self.draw_edit(cr) elif self.showcap: self.draw_caps(cr, self.cap, cpoints)
def calc_offsets(self, points): ref_x, ref_y = self.refobj.get_reference_pt() #return map(lambda x, y: x - ref_x, y - ref_y, points) def _cvt(pt): x, y = pt return x - ref_x, y - ref_y return map(_cvt, points)
def _getlines(self, obj): if obj.kind == 'compound': return self._append_lists(list(map(self._getlines, obj.objects))) elif obj.kind == 'line': return [obj] else: return []
def draw(self): cr = self.setup_cr() cpoints = list(map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y1), (self.x2, self.y2), (self.x1, self.y2)))) (cx0, cy0) = cpoints[-1] cr.move_to(cx0, cy0) for cx, cy in cpoints: cr.line_to(cx, cy) #cr.move_to(cx, cy) cr.close_path() cr.stroke_preserve() self.draw_fill(cr) if self.cap: self.draw_caps(cr, self.cap, cpoints) if self.drawdims: cr.select_font_face(self.font) fontsize = self.scale_font() cr.set_font_size(fontsize) cx1, cy1 = cpoints[0] cx2, cy2 = cpoints[2] # draw label on X dimension cx = cx1 + (cx2 - cx1) // 2 cy = cy2 + -4 cr.move_to(cx, cy) cr.show_text("%d" % (self.x2 - self.x1)) cy = cy1 + (cy2 - cy1) // 2 cx = cx2 + 4 cr.move_to(cx, cy) cr.show_text("%d" % (self.y2 - self.y1))
def draw(self): cpoints = list( map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y1), (self.x2, self.y2), (self.x1, self.y2)))) cr = self.setup_cr() pen = self.get_pen(cr) brush = self.get_brush(cr) cr.canvas.polygon(list(chain.from_iterable(cpoints)), pen, brush) if self.editing: self.draw_edit(cr) elif self.showcap: self.draw_caps(cr, self.cap, cpoints) if self.drawdims: fontsize = self.scale_font() alpha = getattr(self, 'alpha', 1.0) font = cr.get_font(self.font, fontsize, self.color, alpha=alpha) cx1, cy1 = cpoints[0] cx2, cy2 = cpoints[2] # draw label on X dimension cx = cx1 + (cx2 - cx1) // 2 cy = cy2 + -4 text = "%d" % (self.x2 - self.x1) cr.canvas.text((cx, cy), text, font) cy = cy1 + (cy2 - cy1) // 2 cx = cx2 + 4 text = "%d" % (self.y2 - self.y1) cr.canvas.text((cx, cy), text, font)
def draw(self): cpoints = list(map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y1), (self.x2, self.y2), (self.x1, self.y2)))) cr = self.setup_cr() pen = self.get_pen(cr) brush = self.get_brush(cr) cr.canvas.polygon(list(chain.from_iterable(cpoints)), pen, brush) if self.editing: self.draw_edit(cr) elif self.showcap: self.draw_caps(cr, self.cap, cpoints) if self.drawdims: fontsize = self.scale_font() alpha = getattr(self, 'alpha', 1.0) font = cr.get_font(self.font, fontsize, self.color, alpha=alpha) cx1, cy1 = cpoints[0] cx2, cy2 = cpoints[2] # draw label on X dimension cx = cx1 + (cx2 - cx1) // 2 cy = cy2 + -4 text = "%d" % (self.x2 - self.x1) cr.canvas.text((cx, cy), text, font) cy = cy1 + (cy2 - cy1) // 2 cx = cx2 + 4 text = "%d" % (self.y2 - self.y1) cr.canvas.text((cx, cy), text, font)
def draw(self): cpoints = tuple(map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y1), (self.x2, self.y2), (self.x1, self.y2)))) cr = self.setup_cr() #cr.draw_polygon(cpoints) if self.editing: self.draw_edit(cr) elif self.showcap: self.draw_caps(cr, self.cap, cpoints) if self.drawdims: fontsize = self.scale_font() #cr.set_font(Font(self.font, pointSize=fontsize)) cx1, cy1 = cpoints[0] cx2, cy2 = cpoints[2] # draw label on X dimension cx = cx1 + (cx2 - cx1) // 2 cy = cy2 + -4 #cr.draw_text(cx, cy, "%d" % (self.x2 - self.x1)) # draw label on Y dimension cy = cy1 + (cy2 - cy1) // 2 cx = cx2 + 4
def draw_polygon(self, cpoints): qpoints = list( map(lambda p: QtCore.QPoint(p[0], p[1]), (cpoints + (cpoints[0], )))) qpoly = QPolygon(qpoints) self.cr.drawPolygon(qpoly)
def get_llur(self): points = numpy.array(list(map(lambda obj: obj.get_llur(), self.objects))) t_ = points.T x1, y1 = min(t_[0].min(), t_[0].min()), min(t_[1].min(), t_[3].min()) x2, y2 = max(t_[0].max(), t_[0].max()), min(t_[1].max(), t_[3].max()) return (x1, y1, x2, y2)
def get_shape_view(self, shape_obj, avoid_oob=True): """ Calculate a bounding box in the data enclosing `shape_obj` and return a view that accesses it and a mask that is True only for pixels enclosed in the region. If `avoid_oob` is True (default) then the bounding box is clipped to avoid coordinates outside of the actual data. """ x1, y1, x2, y2 = map(int, shape_obj.get_llur()) if avoid_oob: # avoid out of bounds indexes wd, ht = self.get_size() x1, x2 = max(0, x1), min(x2, wd - 1) y1, y2 = max(0, y1), min(y2, ht - 1) # calculate pixel containment mask in bbox yi = np.mgrid[y1:y2 + 1].reshape(-1, 1) xi = np.mgrid[x1:x2 + 1].reshape(1, -1) pts = np.asarray((xi, yi)).T contains = shape_obj.contains_pts(pts) view = np.s_[y1:y2 + 1, x1:x2 + 1] return (view, contains)
def transform_non_affine(self, xy): #print "transform in:", xy if self.viewer == None: return xy res = np.array(list(map(self._transform_xy, xy))) #print "transform out:", res return res
def transform_non_affine(self, xy): #print "transform in:", xy if self.viewer is None: return xy res = np.array(list(map(self._transform_xy, xy))) #print "transform out:", res return res
def get_points(self): """Get the set of points that is used to draw the object. Points are returned in *data* coordinates. """ points = list( map(lambda pt: self.crdmap.to_data(pt[0], pt[1]), self.points)) return points
def pixtosystem(self, idxs, system=None, coords='data'): c = self.pixtocoords(idxs, system=system, coords=coords) if not self.new_coords: # older astropy return (self._deg(c.lonangle), self._deg(c.latangle)) else: r = c.frame.data return tuple(map(self._deg, [getattr(r, component) for component in r.components[:2]]))
def get_points(self): """Get the set of points that is used to draw the object. Points are returned in *data* coordinates. """ points = list(map(lambda pt: self.crdmap.to_data(pt[0], pt[1]), self.points)) return points
def transform_non_affine(self, xy): #print "transform in:", xy if self.fitsimage == None: return xy res = np.array(map(self._transform_xy, xy)) #print "transform out:", res return res
def draw(self): cpoints = tuple(map(lambda p: self.canvascoords(p[0], p[1]), self.points)) cr = self.setup_cr() #cr.draw_polygon(cpoints) if self.cap: self.draw_caps(cr, self.cap, cpoints)
def marshall(obj): typ = type(obj) # take care of compound types if isinstance(obj, list): return list(map(marshall, obj)) if isinstance(obj, tuple): return tuple(map(marshall, obj)) if isinstance(obj, dict): return dict(zip(obj.keys(), map(marshall, obj.values()))) # check if object is a large binary object if isinstance(obj, Blob): return xmlrpclib.Binary(obj.buf) if not typ in base_types: obj = undefined return obj
def pixtosystem(self, idxs, system=None, coords='data'): c = self.pixtocoords(idxs, system=system, coords=coords) if not self.new_coords: # older astropy return (self._deg(c.lonangle), self._deg(c.latangle)) else: r = c.frame.data return tuple( map(self._deg, [getattr(r, component) for component in r.components[:2]]))
def marshall(res): typ = type(res) # take care of compound types if isinstance(res, list): return list(map(marshall, res)) if isinstance(res, tuple): return tuple(map(marshall, res)) if isinstance(res, dict): return dict(zip(res.keys(), map(marshall, res.values()))) # base types if isinstance(res, bytes): return xmlrpclib.Binary(res) if not typ in base_types: res = undefined return res
def draw(self): cpoints = tuple(map(lambda p: self.canvascoords(p[0], p[1]), self.points)) cr = self.setup_cr() for i in range(len(cpoints) - 1): cx1, cy1 = cpoints[i] cx2, cy2 = cpoints[i+1] #cr.draw_line(cx1, cy1, cx2, cy2) if self.cap: self.draw_caps(cr, self.cap, cpoints)
def draw(self): cpoints = tuple( map(lambda p: self.canvascoords(p[0], p[1]), self.points)) cr = self.setup_cr() #cr.draw_polygon(cpoints) if self.editing: self.draw_edit(cr) elif self.showcap: self.draw_caps(cr, self.cap, cpoints)
def drop_event(self, widget, event): dropdata = event.mimeData() formats = list(map(str, list(dropdata.formats()))) self.logger.debug("available formats of dropped data are %s" % ( formats)) if dropdata.hasUrls(): urls = list(dropdata.urls()) paths = [ str(url.toString()) for url in urls ] event.acceptProposedAction() self.logger.debug("dropped filename(s): %s" % (str(paths))) self.make_callback('drag-drop', paths)
def drop_event(self, widget, event): dropdata = event.mimeData() formats = map(str, list(dropdata.formats())) self.logger.debug("available formats of dropped data are %s" % (formats)) if dropdata.hasUrls(): urls = list(dropdata.urls()) paths = [str(url.toString()) for url in urls] event.acceptProposedAction() self.logger.debug("dropped filename(s): %s" % (str(paths))) self.make_callback('drag-drop', paths)
def draw(self): cpoints = tuple(map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y2), (self.x2, self.y1)))) cr = self.setup_cr() #cr.draw_polygon(cpoints) if self.editing: self.draw_edit(cr) elif self.showcap: self.draw_caps(cr, self.cap, cpoints)
def draw(self): cpoints = tuple(map(lambda p: self.canvascoords(p[0], p[1]), self.points)) cr = self.setup_cr() cr.pen().setCapStyle(QtCore.Qt.RoundCap) for i in range(len(cpoints) - 1): cx1, cy1 = cpoints[i] cx2, cy2 = cpoints[i+1] cr.drawLine(cx1, cy1, cx2, cy2) if self.cap: self.draw_caps(cr, self.cap, cpoints)
def set_geometry(self, geometry): # translation of X window geometry specification WxH+X+Y coords = geometry.replace('+', ' +') coords = coords.replace('-', ' -') coords = coords.split() if 'x' in coords[0]: # spec includes dimensions dim = coords[0] coords = coords[1:] else: # spec is position only dim = None if dim is not None: # user specified dimensions dim = list(map(int, dim.split('x'))) self.set_size(*dim) if len(coords) > 0: # user specified position coords = list(map(int, coords)) self.set_pos(*coords)
def draw(self): cpoints = self.get_cpoints() qpoints = list(map(lambda p: QtCore.QPoint(p[0], p[1]), (cpoints + (cpoints[0],)))) qpoly = QPolygon(qpoints) cr = self.setup_cr() cr.drawPolygon(qpoly) if self.editing: self.draw_edit(cr) elif self.showcap: self.draw_caps(cr, self.cap, cpoints)
def draw(self): cpoints = list(map(lambda p: self.canvascoords(p[0], p[1]), ((self.x1, self.y1), (self.x2, self.y2), (self.x2, self.y1)))) cr = self.setup_cr() pen = self.get_pen(cr) brush = self.get_brush(cr) cr.canvas.polygon(list(chain.from_iterable(cpoints)), pen, brush) if self.cap: self.draw_caps(cr, self.cap, cpoints)
def pixtoradec(self, idxs, coords='data'): if coords == 'fits': # Via astWCS.NUMPY_MODE, we've forced pixels referenced from 0 idxs = tuple(map(lambda x: x-1, idxs)) try: ra_deg, dec_deg = self.wcs.pix2wcs(idxs[0], idxs[1]) except Exception as e: self.logger.error("Error calculating pixtoradec: %s" % (str(e))) raise common.WCSError(e) return ra_deg, dec_deg
def pixtoradec(self, idxs, coords='data'): if coords == 'fits': # Via astWCS.NUMPY_MODE, we've forced pixels referenced from 0 idxs = tuple(map(lambda x: x-1, idxs)) try: ra_deg, dec_deg = self.wcs.pix2wcs(idxs[0], idxs[1]) except Exception as e: self.logger.error("Error calculating pixtoradec: %s" % (str(e))) raise WCSError(e) return ra_deg, dec_deg