小编moa*_*eep的帖子

Matplotlib更新滑块小部件范围

我正在尝试编写一小段代码,以使用matplotlib交互地删除图像系列中的选定切片。我创建了一个按钮“删除”,该按钮存储了一些在选择按钮“更新”时要删除的索引。但是,我目前无法重置滑块控件的范围,即从valmax中删除已删除的切片的数量。这个问题的pythonic解决方案是什么?

这是我的代码:

import dicom
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button

frame = 0
#store indices of slices to be deleted
delete_list = []


def main():

    data = np.random.rand(16,256,256)
    nframes = data.shape[0]

    raw_dicom_stack = []
    for x in range (nframes):
        raw_dicom_stack.append(data[x,:,:])

    #yframe = 0

    # Visualize it
    viewer = VolumeViewer(raw_dicom_stack, nframes)
    viewer.show()

class VolumeViewer(object):
    def __init__(self, raw_dicom_stack, nframes):

        global delete_list

        self.raw_dicom_stack = raw_dicom_stack
        self.nframes = nframes
        self.delete_list = delete_list

        # Setup the axes.
        self.fig, …
Run Code Online (Sandbox Code Playgroud)

python widget slider matplotlib

4
推荐指数
2
解决办法
3613
查看次数

linux打印到STDOUT并使用单个命令重定向到文件

有没有办法将命令的输出回显到终端并使用单个文件重定向到文件,而不是在csh中使用2个单独的命令(由于历史原因,我必须使用csh来实现此目的).目前我这样做

echo "Hello World!"
echo "Hello World!" > textfile

echo "next line blah blah"
echo "next line blah blah" >> textfile
Run Code Online (Sandbox Code Playgroud)

linux csh

4
推荐指数
1
解决办法
2942
查看次数

Linux - 数字排序然后覆盖文件

我有一个通用格式的csv文件

date,  
2013.04.04,
2013.04.04,
2012.04.02,
2013.02.01,
2013.04.05,
2013.04.02,
Run Code Online (Sandbox Code Playgroud)

我运行的脚本会将数据添加到此文件中,该文件不一定按日期顺序排列.如何将文件排序为日期顺序(忽略标题)并覆盖现有文件而不是写入STDOUT

我用过awk

awk 'NR == 1; NR > 1 {print $0 | "sort -n"}' file > file_sorted
mv file_sorted file
Run Code Online (Sandbox Code Playgroud)

有没有更有效的方法来做到这一点,而无需创建额外的文件和移动?

linux sorting awk

4
推荐指数
1
解决办法
3639
查看次数

R - ggplot2在线性区域外推回归线

我有以下数据框(附).我已经为各种准直器/头部组合绘制了CR与A.

(p <- ggplot(df,aes(x=A,y=CR,col=Head))+geom_point()+geom_line() +facet_grid(Collimator~Head, scales="fixed")+scale_x_continuous("Activity [MBq]", expand = c(0,0))+ylim(0,80000)+ ylab("Count Rate [cps]") + theme_bw()+theme(legend.position = "none"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在理想世界中,上述情节将是线性的.实际上,由于系统死区时间增加,CR将开始因A而下降.我想在每个方面添加的是直线拟合,它仅通过前2个数据点 - 这是在死区时间开始之前.

有一个简单的方法来做到这一点ggplot2.我可以使用geom_smooth(method = "lm")其他一些选项吗?

structure(list(A0 = c(76L, 274L, 786L, 1060L, 1294L, 2092L, 2639L, 
3437L, 4223L, 76L, 274L, 786L, 1060L, 1294L, 2092L, 2639L, 3437L, 
4223L, 76L, 274L, 786L, 1060L, 1294L, 2092L, 2639L, 3437L, 4223L, 
76L, 274L, 786L, 1060L, 1294L, 2092L, 2639L, 3437L, 4223L, 76L, 
274L, 786L, 1060L, 1294L, 2092L, 2639L, 3437L, 4223L, 76L, 274L, 
786L, 1060L, 1294L, 2092L, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

4
推荐指数
2
解决办法
1102
查看次数

从 3d 数组中删除图像帧

我是一个Python新用户,想做一些简单的图像处理。本质上,我将拥有动态医学图像 - 不同时间点的一系列 2D 图像,我希望将其存储为 3D 数组。由于扫描技术的性质,在某些成像帧期间可能会偶尔出现患者运动,这使得数据无法使用。我想删除这些帧并重新创建数组 - 新维度(n-1, 256, 256)。删除框架后我想更新图像显示。实现这一目标的最佳方法是什么?这是我到目前为止的框架代码:

import dicom
import numpy as np
import pylab 
from matplotlib.widgets import Slider, Button

ds = dicom.read_file("/home/moadeep/Dropbox/FS1.dcm")
#data = ds.pixel_array
data = np.random.rand(16,256,256)
nframes = data.shape[0]

ax = pylab.subplot(111)
pylab.subplots_adjust(left=0.25, bottom=0.25)

frame = 0
l = pylab.imshow(data[frame,:,:]) #shows 1024x256 imagge, i.e. 0th frame*

axcolor = 'lightgoldenrodyellow'
axframe = pylab.axes([0.35, 0.1, 0.5, 0.03], axisbg=axcolor)

#add slider to scroll image frames
sframe = Slider(axframe, 'Frame', 0, nframes, valinit=0,valfmt='%1d'+'/'+str(nframes))

ax_delete = pylab.axes([0.8,0.025,0.1,0.04], axisbg=axcolor) …
Run Code Online (Sandbox Code Playgroud)

python numpy image matplotlib dicom

3
推荐指数
1
解决办法
1847
查看次数

使用awk / sed更改第一列中的日期格式

我有一个shell脚本,该脚本每天早晨自动运行,将当天的结果附加到文本文件中。该文件的第一列应为今天的日期,然后是结果,以逗号分隔。我使用命令date +%x以所需的格式(dd / mm / yy)获取日期。但是,在一台计算机上,+%x返回mm / dd / yyyy(知道为什么会这样吗?)。然后,我按日期顺序对文件中的数据进行排序。

这是一个这样的文本文件的片段

29/11/12,9654.80,194.32,2.01,7.19,-7.89,7.65,7.57,3.98,9625.27,160.10,1.66,4.90,-4.79,6.83,4.84,3.54                
03/12/12,5184.22,104.63,2.02,6.88,-6.49,7.87,6.67,4.10,5169.52,93.81,1.81,5.29,-5.45,7.87,5.37,4.10                
04/12/12,5183.65,103.18,1.99,6.49,-6.80,8.40,6.66,4.38,5166.04,95.44,1.85,6.04,-6.49,8.40,6.28,4.38                
11/07/2012,5183.65,102.15,1.97,6.78,-6.36,8.92,6.56,4.67,5169.48,96.67,1.87,5.56,-6.10,8.92,5.85,4.67                
07/11/2012,5179.39,115.57,2.23,7.64,-6.61,8.83,7.09,4.62,5150.17,103.52,2.01,7.01,-6.08,8.16,6.51,4.26                
11/26/2012,5182.66,103.30,1.99,7.07,-5.76,7.38,6.37,3.83,5162.81,95.47,1.85,6.34,-5.40,6.65,5.84,3.44                
11/30/2012,5180.82,95.19,1.84,6.51,-5.40,7.91,5.92,4.12,5163.98,91.82,1.78,5.58,-5.07,7.05,5.31,3.65     
Run Code Online (Sandbox Code Playgroud)

是否可以使用awk或sed将后四行的日期格式更改为正确的日期格式?我只希望将mm / dd / yyyy格式的日期格式更改为dd / mm / yy。

linux awk sed

3
推荐指数
1
解决办法
6339
查看次数

只读xls中的某些列

我有一张带有几张纸的excel电子表格.格式如下:

Date        A       B       C       D       E       F                       Reference   Ref Date    Half life
03/01/13    6.29    5.28    8.15    4.93    11.67   6.4                     8.88        01/01/99    30.23
04/01/13    6.39    5.39    8.22    5.04    11.75   6.4                 
07/01/13    6.34    5.32    8.17    4.92    11.82   6.4                 
08/01/13    6.33    5.3 8.16    4.96    11.68   6.4                 
09/01/13    6.29    5.29    8.13    4.93    11.73   6.4                 
10/01/13    6.29    5.32    8.17    4.95    11.61   6.4                 
11/01/13    6.21    5.27    8.12    4.95    11.57   6.4                 
14/01/13    6.28    5.28    8.09    4.92    11.65   6.4                 
15/01/13    6.25    5.26    8.06    4.9 11.59   6.4                 
16/01/13 …
Run Code Online (Sandbox Code Playgroud)

xls r

3
推荐指数
2
解决办法
1万
查看次数

Linux/awk将包含十进制的文件转换为十六进制

我有一个文本文件,其中包含许多十进制的RGB颜色代码.例如

000,000,000
000,003,025
000,007,048
000,010,069
000,014,089
000,017,108
000,020,125
000,024,140
000,027,155
Run Code Online (Sandbox Code Playgroud)

我想将每一行转换为十六进制格式(所需的输出):

00,00,00
00,03,15
00,07,30
00,08,45
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用printf "%.2x,%.2x,%.2x\n" 000 010 69printf "%.2x,%.2x,%.2x\n" 000 010 069不起作用,因为069不可转换.

我认为awk这将是一个合理的工具,但我想我会面临转换小数的相同问题,如069等.

perl -le '$hex = sprintf("%.2x,%.2x,%.2x",005,69,255); print $hex' 与069也有同样的问题

linux perl awk

3
推荐指数
2
解决办法
4050
查看次数

ggplot2在bland altman plot中为每个facet添加geom行

我有以下数据框架

structure(list(Lightbox = c(84L, 67L, 80L, 63L, 76L, 66L, 79L, 
81L, 77L, 82L, 84L, 67L, 80L, 63L, 76L, 66L, 79L, 81L, 77L, 82L, 
84L, 67L, 80L, 63L, 76L, 66L, 79L, 81L, 77L, 82L, 84L, 67L, 80L, 
63L, 76L, 66L, 79L, 81L, 77L, 82L, 84L, 67L, 80L, 63L, 76L, 66L, 
79L, 81L, 77L, 82L), variable = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
3L, 3L, 3L, 3L, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

3
推荐指数
1
解决办法
1994
查看次数

Perl搜索目录中第一次出现的模式

我有一个目录,其中包含该格式的图像头文件列表

image1.hd
image2.hd
image3.hd
image4.hd
Run Code Online (Sandbox Code Playgroud)

我想Image type:=4在目录中搜索正则表达式,并找到第一次出现此模式的文件号.我可以用bash中的几个管道来做到这一点:

 grep -l 'Image type:=4' image*.hd | sed ' s/.*image\(.*\).hd/\1/' | head -n1
Run Code Online (Sandbox Code Playgroud)

在这种情况下返回1.

此模式匹配将用于perl脚本.我知道我可以用

my $number = `grep -l 'Image type:=4' image*.hd | sed ' s/.*image\(.*\).hd/\1/' | head -n1`
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,最好使用纯perl吗?这是我用perl得到的最好的东西.这非常麻烦:

my $tmp;
#want to find the planar study in current study
  foreach (glob "$DIR/image*.hd"){
    $tmp = $_;
    open FILE, "<", "$_" or die $!;
    while (<FILE>)
      {
    if (/Image type:=4/){
      $tmp =~ s/.*image(\d+).hd/$1/;
    }
      }
    close FILE;
    last;
  }
 print "$tmp\n"; …
Run Code Online (Sandbox Code Playgroud)

perl grep

1
推荐指数
1
解决办法
543
查看次数

标签 统计

linux ×4

awk ×3

r ×3

ggplot2 ×2

matplotlib ×2

perl ×2

python ×2

csh ×1

dicom ×1

grep ×1

image ×1

numpy ×1

sed ×1

slider ×1

sorting ×1

widget ×1

xls ×1