示例#1
0
def test_axis_segfault():
    from cdms2 import MV2

    # Contributed by Lawson Hanson
    month = 'January'
    year = '2012'
    miss_value = -9999.0

    data = ['34.006348', '28.314002', '29.269668', '33.698551', '34.177242']

    Rad_global_month = MV2.zeros([len(data)], MV2.float)
    time_day = MV2.zeros([len(data)], MV2.float)
    tim = cdms.createAxis(time_day)
    tim.designateTime()
    tim.id = "time"
    tim.units = 'days since 2012-01-01'

    for i in range(len(time_day)):
        Rad_global_month[i] = data[i]
        tim[i] = float(i)

    # Create a temporary file
    fd, f = tempfile.mkstemp('.nc')
    os.close(fd)
    try:
        out = cdms.open(f, 'w')

        rad_total_month = cdms.createVariable(Rad_global_month,
                                              id='accum_swfcdown_' + month,
                                              axis=[tim],
                                              typecode='f')
        rad_total_month.setAxisList([tim])

        print rad_total_month, tim
        print len(rad_total_month), len(tim)

        out.write(rad_total_month)
    finally:
        out.close()
        os.remove(f)
示例#2
0
def test_axis_segfault():
    from cdms2 import MV2

    # Contributed by Lawson Hanson
    month = 'January'
    year  = '2012'
    miss_value = -9999.0

    data = ['34.006348', '28.314002', '29.269668', '33.698551', '34.177242']

    Rad_global_month = MV2.zeros([len(data)],MV2.float)
    time_day = MV2.zeros([len(data)],MV2.float)
    tim = cdms.createAxis(time_day)
    tim.designateTime()
    tim.id = "time"
    tim.units = 'days since 2012-01-01'

    for i in range(len(time_day)):
        Rad_global_month[i] = data[i]
        tim[i] = float(i)
        
    # Create a temporary file
    fd, f = tempfile.mkstemp('.nc')
    os.close(fd)
    try:
        out = cdms.open(f,'w')
            
        rad_total_month = cdms.createVariable(Rad_global_month,id = 'accum_swfcdown_'+month,axis=[tim],typecode='f')
        rad_total_month.setAxisList([tim]) 

        print rad_total_month,tim
        print len(rad_total_month),len(tim)

        out.write(rad_total_month)
    finally:
        out.close()
        os.remove(f)
示例#3
0
x.Graph[1].Set[0].line.linewidth = 2
# Let's set the colors
x.Graph[0].Set[0].line.color = 'red'
x.Graph[0].Set[1].line.color = 4  # color 4 is blue
# Let's set the second's set style to dash
x.Graph[1].Set[0].line.linestyle = 'dot'
x.Graph[0].Set[1].line.linestyle = 'dash'
x.Graph[0].Set[0].line.linestyle = 2  # 2 is dash

# Now let's set the name for each set, to be used in the legend
x.Graph[0].Set[0].legend = 'Year 1'
x.Graph[0].Set[1].legend = 'Year 2'
x.Graph[1].Set[0].legend = 'Year 2-1'
# ok one last trick, in order to have the 0 line plotted
# let's create a dummy array with zeros in it:
zero = MV.zeros((2), MV.Float)
zero = MV.asVariable(zero)
zero.setdimattribute(0, 'values', [-1., 1.])
# add a dataset and assign it graph 1 black color
x.add_set(1, 'black')

# Finally just for fun let's place a big red "Sample" accross it
x.add_string(0.5, 0.5, 'Sample', color='red', char_size=9, rot=55, just=14)

# And plot these babies:
x.plot([z1, z2, z3,
        zero])  # You MUST pass a list of slab, even if only one slab
# or you can plot then 1 by 1
# first let's clear
x('kill G0.S0')
x('kill G0.S1')
示例#4
0
x.Graph[1].Set[0].line.linewidth = 2
# Let's set the colors
x.Graph[0].Set[0].line.color = 'red'
x.Graph[0].Set[1].line.color = 4  # color 4 is blue
# Let's set the second's set style to dash
x.Graph[1].Set[0].line.linestyle = 'dot'
x.Graph[0].Set[1].line.linestyle = 'dash'
x.Graph[0].Set[0].line.linestyle = 2  # 2 is dash

# Now let's set the name for each set, to be used in the legend
x.Graph[0].Set[0].legend = 'Year 1'
x.Graph[0].Set[1].legend = 'Year 2'
x.Graph[1].Set[0].legend = 'Year 2-1'
# ok one last trick, in order to have the 0 line plotted
# let's create a dummy array with zeros in it:
zero = MV.zeros((2), MV.Float)
zero = MV.asVariable(zero)
zero.setdimattribute(0, 'values', [-1., 1.])
# add a dataset and assign it graph 1 black color
x.add_set(1, 'black')

# Finally just for fun let's place a big red "Sample" accross it
x.add_string(0.5, 0.5, 'Sample', color='red', char_size=9, rot=55, just=14)

# And plot these babies:
# You MUST pass a list of slab, even if only one slab
x.plot([z1, z2, z3, zero])
# or you can plot then 1 by 1
# first let's clear
x('kill G0.S0')
x('kill G0.S1')