[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[IDV #PHU-486914]: question



Greetings Tilly,

Thanks for the update. I think this is a case of the first bit being labeled as 
0 or 1. For indexing by bit, the first bit is labeled as 0. So, the 17th bit 
would be the bit named 16, since the first is 0. It could be that the 
description of you flag bit patterned was based on the first bit having a value 
of 1 (so the first bit is 1, the second 2, ...), which is not the standard way 
of naming bits.

I say if it works for you, then go for it :-)  When this get put into the IDV, 
however, we will base it on the first bit being 0.

Cheers!

Sean

> Dear Sean,
> One more remark, it appeared that I was looking at the wrong bit.
> To make the code working right for me I had to create the bitmask by using 
> bit_mask = 1 << (n)
> Instead of (n -1)
> I don't know whether that has to do with definitions or whatever but I wanted 
> to let you know.
> 
> Kind regards,
> Tilly
> 
> 
> -----Oorspronkelijk bericht-----
> Van: Unidata IDV Support [mailto:address@hidden]
> Verzonden: donderdag 6 oktober 2011 16:57
> Aan: Driesenaar, Tilly (KNMI)
> CC: address@hidden; Driesenaar, Tilly (KNMI)
> Onderwerp: [IDV #PHU-486914]: question
> 
> Ah yes, my approach was a little bit too simple. I've attached a .py file 
> that uses my code, but has been appropriately modified by Jeff McWhirter to 
> handle indexing into your variable (Thanks Jeff!). Use the contents of the 
> python file in your Jython Library and you should be good to go. 
> extractBitField(data, N) is the function you should use when you want to find 
> the bits for your data.
> 
> Let me know if this works :-)
> 
> Sean
> 
> 
> > Dear Sean,
> > I created your function in the local Jython library and then created
> > another function
> >
> > KNMIQC(QC):
> > ff=getBit(QC,17)
> > return ff
> >
> > and then I made a formula for this last one (by rightclicking the
> > function) Then I tried to display this formula with input the quality flag 
> > field in a netCDF file.
> > But then I get the error:
> > TypeError: unsupported operand type(s) for &: 'int' and 
> > 'ucar.visad.data.GeoGridFlatField'
> >
> > Probably I have to do something more to do this mask comparison for all 
> > gridpoints in the field?
> >
> > Kind regards,
> > Tilly
> >
> > -----Oorspronkelijk bericht-----
> > Van: Unidata IDV Support [mailto:address@hidden]
> > Verzonden: woensdag 5 oktober 2011 23:18
> > Aan: Driesenaar, Tilly (KNMI)
> > CC: address@hidden; Driesenaar, Tilly (KNMI)
> > Onderwerp: [IDV #PHU-486914]: question
> >
> > Sorry, replace "bitNumber" with "n" in the line before the if statement.
> >
> > Sean
> >
> > > Greetings Tilly,
> > >
> > > Add this function to your local Jython library (click "Edit" -> 
> > > "Formulas" -> "Jython Library", and select "Local Jython" -> "User's 
> > > Library"), and give it a try:
> > >
> > > def getBit(flag, n):
> > > """
> > > return the value of the nth bit of the given flag """
> > > bit_mask = 1 << (bitNumber -1)
> > > if ((bit_mask & flag) == 0):
> > > return 0
> > > else:
> > > return 1
> > >
> > > (note: if the formatting of this function does not come out right in
> > > my message, be sure to add four spaces to everything after the first
> > > line [def getBit(flag, n):], and an additional four spaces to the
> > > "return" lines)
> > >
> > > Cheers!
> > >
> > > Sean
> > >
> > >
> > > > Dear Sean
> > > > Thank you for your help!
> > > > I'm dealing with a 32 bit integer.
> > > > Cheers,
> > > > Tilly
> > > >
> > > > -----Oorspronkelijk bericht-----
> > > > Van: Unidata IDV Support [mailto:address@hidden]
> > > > Verzonden: vrijdag 23 september 2011 18:59
> > > > Aan: Driesenaar, Tilly (KNMI)
> > > > Onderwerp: [IDV #PHU-486914]: question
> > > >
> > > > Greetings Tilly!
> > > >
> > > > What kind of interger is QCF (16 bit, 32 bit?)? In Jython 2.6, the bin 
> > > > operator will be supported, so things will be much easier. However, you 
> > > > will need to create a bitmask and use the bit-wise operator & to 
> > > > extract the information you need. If I knew what kind of int you were 
> > > > dealing with, I could give you an example to extract out the 17th bit.
> > > >
> > > > Cheers!
> > > >
> > > > Sean
> > > >
> > > > > Dear IDV support desk
> > > > >
> > > > >
> > > > >
> > > > > I would like to plot the information in an integer quality flag in 
> > > > > IDV.
> > > > >
> > > > > The flag consists of several masks, e.g. the first, or second or
> > > > > 17th bit are set .
> > > > >
> > > > > In python I would use any of the following commands to extract
> > > > > information from this integer quality flag (say QCF).
> > > > >
> > > > > (As you can see I'm especially interested in the 17th bit (or
> > > > > mask value
> > > > > 2**17) )
> > > > >
> > > > >
> > > > >
> > > > > bin(int(QCF))[-18]  (look at the value of the 17th bit )
> > > > >
> > > > > or
> > > > >
> > > > > (int(QCF)/2**17)%2  (so divide by mask value and do modulo 2)
> > > > >
> > > > >
> > > > >
> > > > > How do I get this into an IDV formula?
> > > > >
> > > > > I tried (QCF/2**17)%2 , but that doesn't seem to evaluate in the
> > > > > right way.
> > > > >
> > > > >
> > > > >
> > > > > Kind regards,
> > > > >
> > > > > Tilly Driesenaar
> > > > >
> > > > > KNMI
> > > > >
> > > > > The Netherlands
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > Ticket Details
> > > > ===================
> > > > Ticket ID: PHU-486914
> > > > Department: Support IDV
> > > > Priority: Normal
> > > > Status: Closed
> > > >
> > > >
> > >
> >
> >
> > Ticket Details
> > ===================
> > Ticket ID: PHU-486914
> > Department: Support IDV
> > Priority: Normal
> > Status: Open
> >
> >
> 
> 
> Ticket Details
> ===================
> Ticket ID: PHU-486914
> Department: Support IDV
> Priority: Normal
> Status: Open
> 


Ticket Details
===================
Ticket ID: PHU-486914
Department: Support IDV
Priority: Normal
Status: Closed