Re: Possible bug

From: Deepak Chandan <dchandan_at_nyahnyahspammersnyahnyah>
Date: Sat Jul 30 2011 - 16:56:16 MDT

Hi Mary,
Sure, I'll do that. I am busy at the moment attending a deadline, however, as soon as I am done with that, I'll get the necessary codes to you.

Sincerely,
Deepak

On 2011-07-29, at 5:56 PM, Mary Haley wrote:

> Deepak,
>
> I'm not sure what's going on here, but out of curiosity, what happens if you comment out the Ngl.end() call?
>
> If possible, can you provide me with a pared down script that I can run here?
>
> --Mary
>
> On Jul 29, 2011, at 11:08 AM, Deepak Chandan wrote:
>
>> Hi all,
>> I have an object-oriented system of plotting routines that I use for my research. It has plot objects (of different types) that have associated properties which are used in processing, including creating plots. To plot the objects I call a pyngl script (given below) that plots the data using information stored in the object. Now, the problem I am having is that between two calls to this pyngl routine, I am getting the following error:
>>
>> fatal:["Error.c":411]:ErrorInitialize:Only one instance of ErrorClass is supported
>> fatal:Unable to initialize layer-Can't Create
>> fatal:Error Creating ErrorClass object
>> fatal:Unable to initialize layer-Can't Create
>> fatal:Unable to initialize layer-Can't Create
>> fatal:_NhlCreate:Unable to access "default" App object
>> fatal:PID #-4 can't be found in NhlSetValues
>> fatal:_NhlCreate:Unable to access "default" App object
>> fatal:_NhlCreate:Invalid Parent id #-4
>> fatal:NhlGetValues:PID #-4 is invalid
>> fatal:NhlGetValues:PID #-4 is invalid
>> Python(39345,0xac7512c0) malloc: *** mmap(size=4294918144) failed (error code=12)
>> *** error: can't allocate region
>> *** set a breakpoint in malloc_error_break to debug
>> Bus error: 10
>>
>> For example, suppose I am working in IPython, I create a plot object:
>> $$> p = obsplot(id=90834) #where id is the ID number of a particular computation
>> $$> p.plot()
>> This works; now if I create another object and plot it, I get the above error from the plot script. I cannot understand why this should happen. Maybe someone can help me out here. I am working on a Mac, current version 10.7, (although this problem was present in the previous version 10.6.7 as well). My PyNIO and PyNGL version numbers are 1.4.0 and 1.3.1 respectively. Python version is 2.7.2 and bumpy version is 1.5.1. Using print statements, I have figured that the problem originates at the Ngl.open_wks statement in the code.
>>
>> Thank you for looking into this.
>>
>> Sincerely,
>> Deepak Chandan
>>
>>
>> The plotting script is:
>>
>> =============================== CODE BEGIN ======================================
>> def nclplot2d(obj, *args, **kwargs):
>> import os
>> import Nio
>> import Ngl
>> import numpy as np
>> keys = kwargs.keys()
>>
>> file1 = Nio.open_file(os.path.join(obj._datadir, obj._datafile), "r")
>> data = file1.variables["gdata"][:]*obj._unitsfactor
>> lon = file1.variables["lon"][:]
>> lat = file1.variables["lat"][:]
>> mmax = data.max()
>> mmin = data.min()
>> allm = max(abs(mmax), abs(mmin))
>> digits = 0
>> digits = countdigits(int(allm), digits)
>> lbfmt = "@.%d;1f" % (digits)
>> if not "wks" in keys:
>> wks_type = "pdf"
>> else:
>> wks_type = kwargs["wks"]
>> if not ("proj" in keys):
>> proj = obj._projection
>> else:
>> proj = kwargs["proj"]
>> obj._projection = proj
>> if not ("clbrpos" in keys):
>> clbrpos = "Horizontal"
>> else:
>> clbrpos = kwargs["clbrpos"]
>> if not ("cntrnum" in keys):
>> cntrnum = obj._cntrnum
>> else:
>> cntrnum = kwargs["cntrnum"]
>> obj._cntrnum = cntrnum
>> if not ("stride" in keys):
>> if cntrnum <= 10:
>> stride = 1
>> elif 10 < cntrnum <=20:
>> stride = 2
>> elif 20 < cntrnum <= 30:
>> stride = 3
>> else:
>> stride = kwargs["kwargs"]
>> if not ("langle" in keys):
>> langle = 0
>> else:
>> langle = kwargs["langle"]
>>
>>
>> if clbrpos == "Horizontal":
>> lbw = 0.6
>> lbh = 0.1
>> side = "Bottom"
>> else:
>> lbw = 0.1
>> lbh = 0.6
>> side = "Right"
>>
>> wrkstn = Ngl.open_wks(wks_type, os.path.join(obj._figdir, obj._figfile))
>> BlueOrangeYellow = np.array([[256,256,256],[5, 35, 80],[5, 37, 83],[5, 39, 86], [5, 40, 89], [5, 42, 92],\
>> [6, 44, 95],[6, 46, 98],[6, 48, 100],[6, 49, 103],[6, 51, 106], [6, 53, 109],\
>> [6, 55, 112], [6, 57, 115], [7, 59, 118], [7, 60, 121], [7, 62, 124], [7, 64, 127],\
>> [7, 66, 130], [7, 68, 133], [7, 69, 136], [7, 71, 138], [7, 73, 141], [8, 75, 144],\
>> [8, 77, 147], [8, 78, 150], [8, 82, 156], [10, 84, 158], [12, 87, 159], [15, 89, 161],\
>> [17, 92, 163], [19, 94, 164], [21, 97, 166], [24, 99, 168], [26, 102, 169], [28, 104, 171],\
>> [30, 107, 173], [33, 109, 174], [35, 112, 176], [37, 114, 178], [39, 116, 179],\
>> [41, 119, 181], [44, 121, 182], [46, 124, 184], [48, 126, 186], [50, 129, 187], [53, 131, 189],\
>> [55, 134, 191], [57, 136, 192], [59, 139, 194], [62, 141, 196], [66, 146, 199], [68, 147, 200],\
>> [69, 149, 200], [71, 150, 201], [72, 152, 201], [74, 153, 202], [76, 155, 202], [77, 156, 203],\
>> [79, 157, 204], [81, 159, 204], [82, 160, 205], [84, 162, 205], [85, 163, 206], [87, 165, 207],\
>> [89, 166, 207], [90, 167, 208], [92, 169, 208], [93, 170, 209], [95, 172, 209], [97, 173, 210],\
>> [98, 174, 211], [100, 176, 211],[102, 177, 212], [103, 179, 212], [105, 180, 213], [106, 182, 213],\
>> [108, 183, 214], [110, 184, 215], [113, 186, 215], [115, 187, 216], [118, 189, 216], [120, 190, 217],\
>> [122, 192, 218], [125, 193, 218], [127, 194, 219], [129, 196, 220], [132, 197, 220], [134, 199, 221],\
>> [137, 200, 221], [139, 202, 222], [141, 203, 223], [144, 204, 223], [146, 206, 224], [149, 207, 224],\
>> [151, 209, 225], [153, 210, 226], [156, 211, 226], [158, 213, 227], [160, 214, 228], [163, 216, 228],\
>> [165, 217, 229], [170, 220, 230], [172, 221, 231], [174, 222, 232], [176, 223, 233], [178, 224, 234],\
>> [179, 225, 235], [181, 226, 236], [183, 227, 237], [185, 228, 238], [187, 229, 239], [189, 230, 240],\
>> [191, 231, 241], [193, 232, 242], [195, 233, 243], [196, 233, 243], [198, 234, 244], [200, 235, 245],\
>> [202, 236, 246], [204, 237, 247], [206, 238, 248], [208, 239, 249], [210, 240, 250], [211, 241, 251],\
>> [213, 242, 252], [215, 243, 253], [219, 245, 255], [255, 255, 200], [255, 254, 197], [255, 253, 193],\
>> [255, 252, 190], [255, 251, 187], [255, 250, 184], [255, 249, 180], [255, 248, 177], [255, 247, 174],\
>> [255, 246, 171], [255, 245, 167], [255, 244, 164], [255, 243, 161], [255, 243, 158], [255, 242, 154],\
>> [255, 241, 151], [255, 240, 148], [255, 239, 144], [255, 238, 141], [255, 237, 138], [255, 236, 135],\
>> [255, 235, 131], [255, 234, 128], [255, 233, 125], [255, 232, 122], [255, 230, 115], [255, 229, 113],\
>> [254, 227, 111], [254, 226, 109], [253, 225, 108], [253, 224, 106], [252, 222, 104], [252, 221, 102],\
>> [251, 220, 100], [251, 219, 98], [250, 217, 97], [250, 216, 95], [249, 215, 93], [249, 214, 91],\
>> [248, 212, 89], [248, 211, 87], [247, 210, 85], [247, 208, 84], [246, 207, 82], [246, 206, 80],\
>> [245, 205, 78], [245, 203, 76], [244, 202, 74], [244, 201, 73], [243, 200, 71], [242, 197, 67],\
>> [242, 194, 65], [241, 191, 63], [241, 188, 62], [240, 185, 60], [240, 182, 58], [239, 179, 56],\
>> [239, 176, 54], [238, 173, 53], [238, 170, 51], [237, 167, 49], [237, 164, 47], [236, 161, 45],\
>> [236, 159, 44], [236, 156, 42], [235, 153, 40], [235, 150, 38], [234, 147, 36], [234, 144, 34],\
>> [233, 141, 33], [233, 138, 31], [232, 135, 29], [232, 132, 27], [231, 129, 25], [231, 126, 24],\
>> [230, 123, 22], [230, 120, 20], [229, 118, 19], [228, 116, 18], [227, 114, 18], [225, 112, 17],\
>> [224, 110, 16], [223, 108, 15], [222, 107, 15], [221, 105, 14], [220, 103, 13], [218, 101, 12],\
>> [217, 99, 12], [216, 97, 11], [215, 95, 10], [214, 93, 9], [213, 91, 8], [212, 89, 8], [210, 87, 7],\
>> [209, 85, 6], [208, 83, 5], [207, 82, 5], [206, 80, 4], [205, 78, 3], [203, 76, 2], [202, 74, 2],\
>> [200, 70, 0], [198, 69, 1], [195, 68, 2], [193, 67, 3], [190, 65, 4], [188, 64, 4], [185, 63, 5],\
>> [183, 62, 6], [180, 61, 7], [178, 60, 8], [175, 58, 9], [173, 57, 10], [170, 56, 11], [168, 55, 12],\
>> [165, 54, 12], [163, 53, 13], [160, 52, 14], [158, 50, 15], [155, 49, 16], [153, 48, 17],\
>> [150, 47, 18], [148, 46, 19], [145, 45, 19], [143, 43, 20], [140, 42, 21], [135, 40, 23]],'f')
>>
>> BlueOrangeYellow = BlueOrangeYellow/256.
>> rlist = Ngl.Resources()
>> rlist.wkColorMap = BlueOrangeYellow
>> Ngl.set_values(wrkstn,rlist)
>> resources = Ngl.Resources()
>> resources.nglSpreadColors = True
>>
>> resources.sfXCStartV = min(lon)
>> resources.sfXCEndV = max(lon)
>> resources.sfYCStartV = max(lat)
>> resources.sfYCEndV = min(lat)
>>
>> resources.tiMainString = obj._title
>> resources.tiMainFont = "Helvetica" # Font for title
>> resources.tiMainFontHeightF = 0.012
>> # resources.tiXAxisString = "Longitude"
>> # resources.tiYAxisString = "Latitude"
>> # resources.tiXAxisFont = "Helvetica" # Font for X axis label
>> # resources.tiYAxisFont = "Helvetica" # Font for Y axis label
>> # resources.tiXAxisFontHeightF =
>> # resources.tiYAxisFontHeightF =
>>
>>
>> resources.cnFillOn = True
>> resources.cnLinesOn = False
>> resources.cnLineLabelsOn = False
>> resources.cnLevelSelectionMode = "ManualLevels"
>> resources.cnMaxLevelCount = cntrnum
>> resources.cnMinLevelValF = -1.*allm
>> resources.cnMaxLevelValF = 1.*allm
>> resources.cnLevelSpacingF = (2*allm)/cntrnum
>> resources.cnLineLabelFormat = lbfmt
>>
>> resources.lbAutoManage = False
>> resources.lbOrientation = clbrpos
>> resources.lbLabelFont = "Helvetica"
>> # resources.lbLabelPosition = "Center"
>> resources.lbLabelFontHeightF = .010
>> resources.lbLabelAngleF = langle
>> resources.lbLabelStride = stride
>> resources.pmLabelBarSide = side
>> resources.pmLabelBarWidthF = lbw
>> resources.pmLabelBarHeightF = lbh
>>
>> resources.lbTitleString = obj._clbrtitle
>> resources.lbTitlePosition = "Top"
>> resources.lbTitleDirection = "Across"
>> resources.lbTitleFont = "Helvetica-Bold"
>> resources.lbTitleFontHeightF = .011
>>
>> resources.mpProjection = proj
>> resources.mpCenterLonF = obj._clon
>> resources.mpCenterLatF = 0.
>> resources.mpDataBaseVersion = "MediumRes"
>> resources.mpGridAndLimbOn = True
>> resources.mpPerimOn = False
>> resources.mpGridLatSpacingF = 30.
>> resources.mpGridLonSpacingF = 30.
>> resources.mpFillOn = False
>>
>>
>> contour = Ngl.contour_map(wrkstn, data, resources)
>> del contour
>> del resources
>> del rlist
>> del wrkstn
>>
>> file1.close()
>> Ngl.end()
>> from pyPdf import PdfFileWriter, PdfFileReader
>> output = PdfFileWriter()
>> input1 = PdfFileReader(file(os.path.join(obj._figdir, obj._figfile)+"."+wks_type, "rb"))
>> output.addPage(input1.getPage(0).rotateCounterClockwise(90))
>> outputStream = file("/Users/dchandan/temp/ps2pdf.temp.pdf", "wb")
>> output.write(outputStream)
>> outputStream.close()
>> import shutil
>> shutil.copy2("/Users/dchandan/temp/ps2pdf.temp.pdf", os.path.join(obj._figdir, obj._figfile)+"."+wks_type)
>> os.remove("/Users/dchandan/temp/ps2pdf.temp.pdf")
>>
>> ============================= CODE END =======================================
>>
>>
>> The plot code that calls the above nclplot2d routine is:
>>
>> def plot(self, *args, **kwargs):
>> from nclplot2d import nclplot2d
>> nclplot2d(self, *args, **kwargs)
>>
>>
>>
>> _______________________________________________
>> pyngl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
>
Received on Sat Jul 30 16:56:22 2011

This archive was generated by hypermail 2.1.8 : Mon Sep 12 2011 - 16:03:35 MDT