Delete a dimension in a NetCDF file - edit

I have a netCDF file with 8 variables and 4 dimensions: latitude (dim: 26), longitude (dim:17), time (dim: a lot) and level (dim:1, pressure level). In order to use it in a specific program I need to have only 3 dimensions: latitude, longitude and time.
Is there an easy way to delete the level dimension in each variable?
I've found ncwa -a old_dim ifile.nc ofile.nc but sometimes it converts the type from short to float. When it keeps the short type the attributes "scale factor" and "add.offset" are deleted. The problem is that I want to keep the short type with scale factor and add offset.

Your method is correct, however, your input data are "packed". Repack the output file with ncpdq after averaging-out the level dimension with ncwa:
ncpdq ofile.nc ofile2.nc
and you are done. See docs here.

Related

What does PACK8/16/32 mean in VkFormat names?

I'm trying to understand the names of the items in the VkFormat enum, and so far I think I get all the structure of the names of all of the (non-block) formats, but I can't figure out what it means when they have a suffix of PACK8, PACK16, PACK32. If I add up the channel sizes, they always add up to 8, 16, or 32, nothing irregular, so I don't understand what it would mean to bit-pack these values, since they seem to be 100% efficient, using all their bits.
As usual, the documentation is not very helpful, just saying the format is packed without saying what that means.
The PACK fields mean exactly what the specification says they mean:
whole texels or attributes are stored in a single data element, rather than individual components occupying a single data element
Though if you find that too confusing, you could just look at the actual format descriptions. Vulkan goes into excruciating detail about them, to the point of needless repetition.
The difference between VK_FORMAT_B8G8R8A8_RGB and VK_FORMAT_B8G8R8A8_RGB_PACK32 is the same difference between a uint8_t[4] and a uint32_t. One is an array ("individual components"), while the other is a single value ("single data element") made up of smaller values.
If you have a uint8_t color[4] array, which stores B8G8R8A8, then color[0] stores the blue component. The order of the components in the array is defined by the order of the components in the format's name.
If you have a uint32_t color value, which stores B8G8R8A8, then (color & 0xFF000000) >> 24 will retrieve the blue component. The highest byte is the first, followed by the next highest and so forth.
The reason the packed-vs-not-packed distinction matters is because of endian issues. Arrays of bytes don't have endian issues. But values packed into 16 or 32-bits do have endian issues. The endian of the packed formats is always assumed to be the native endian of the host.

Method to get non-base units?

Is there a method of using the exponent properties of LabView units for carrying custom units? For example I would find it convenient to use milli-Amperes instead of Amperes in my data wires.
My first attempt at doing so looks like this, but trying to get the value out at the end gives me nothing.
I would find it convenient to use milli-Amperes instead of Amperes in my data wires
For a wire, it's not possible, and it's not a problem, here's why:
I'm afraid what you want make little sense, since you're milli-Amperes instead of Amperes refers to representing your data, while a wire is just raw data. Adding the milli- to a floating point changes the exponent, not the mantissa, so there's no loss or gain of precision in the value that your number carries.
Now if we talk about an indicator which is technically a display of the wire value, you change the unit from "A" to "mA" to have the display you want.
Finally, in your attempt with "set numeric info", the -3 factor added next to Amperes means the unit is A^-3, not mA.
You can use data that don't use units, however than you will loose your automatic check of the units.
For display properties you can tweak the display format to show different outputs:
This format string is constructed as following:
% numeric
^ engineering notation, exponents in multiples of three
# no trailing zeros
_6 six significat digits
e scientific notation (1e1 for instance)
The prefix is the best way to affect the presentation of the value on a specific front panel.
When passing data from VI to VI, the prefix is not passed, and the data uses the base ( Amps, Volts, etc...)
In my example below, the unitless value 3 is assigned units of Amp in mA.vi. The front panel indicator is set to show units of mA.
In Watts.vi I multiply the Amps OUT of mA.vi by a constant of 9V and the result is wired to the indicator x*y.
x*y has units of W and I changed the prefix to k for presentation.
The NI forums have several threads that report certain functions (square and square root specifically) can cause unit errors or broken wires. Most folks don't even know the units capability exists, and most that do have tried and abandoned them. :)

How do I read the position data from a GPS (NMEA) device?

I'm trying to read data from a GPS device (NMEA). I am getting the data successfully. However, as soon as I start using it, it gives me gibbirish. This is what I get from the GPS:
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPRMC,120556.000,A,2546.0985,S,02816.0193,E,0.22,276.44,291013,,,A*7A
$GPGGA,120557.000,2546.0984,S,02816.0191,E,1,11,0.8,1396.3,M,21.5,M,,0000*71
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPGSV,3,1,12,31,50,165,19,14,48,055,27,16,43,304,42,32,36,265,38*76
$GPGSV,3,2,12,29,24,119,31,06,19,355,34,20,14,238,41,25,10,138,19*78
$GPGSV,3,3,12,27,09,351,33,22,06,008,36,03,05,341,36,23,,221,*7F
$GPRMC,120557.000,A,2546.0984,S,02816.0191,E,0.17,274.76,291013,,,A*7D
$GPGGA,120558.000,2546.0982,S,02816.0189,E,1,11,0.8,1396.0,M,21.5,M,,0000*72
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPRMC,120558.000,A,2546.0982,S,02816.0189,E,0.07,220.52,291013,,,A*7B
$GPGGA,120559.000,2546.0981,S,02816.0187,E,1,11,0.8,1395.7,M,21.5,M,,0000*7A
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPRMC,120559.000,A,2546.0981,S,02816.018
The above was received by doing the following:
//inside a 100ms ticker
Dim data As String = GpsPort.ReadExisting()
CommentBox.AppendText(data)
As soon as I do Dim strArr() As String = data.Split("$") then output it using:
CommentBox.AppendText(strArr(0).ToString) // inside the same ticker
the output is:
034.000,2546.0985,S,02816.0298,E,1,11,0.8,1360.6,M,21.5,M,,0000*77
3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
MC,121034.000,A,2546.0985,S,02816.0298,E,0.01,236.13,291013,,,A*75
.000,2546.0983,S,02816.0297,E,1,11,0.8,1359.9,M,21.5,M,,0000*7A
A,A,3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
,121035.000,A,2546.0983,S,02816.0297,E,0.06,283.04,291013,,,A*72
036.000,2546.0982,S,02816.0296,E,1,11,0.8,1359.3,M,21.5,M,,0000*73
3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
MC,121036.000,A,2546.0982,S,02816.0296,E,0.03,190.30,291013,,,A*72
.000,2546.0981,S,02816.0296,E,1,11,0.8,1358.6,M,21.5,M,,0000*75
A,A,3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
3,1,12,31,49,161,28,14,46,052,20,16,45,301,39,32,36,268,35*79
3,2,12,29,23,122,18,06,21,355,27,20,15,240,40,27,11,351,37*78
Can anyone assist me in getting the GPS co-ordinates from the GPGGA strings? Because splitting them clearly doesn't work.
You have to read the data line by line.
Each line is one NMEA sentence.
Once you detect "$GPGGA" (or you also could use the RMC message)
you have this line:
$GPGGA,120557.000,2546.0984,S,02816.0191,E,1,11,0.8,1396.3,M,21.5,M,,0000*71
Now you splitt by delimiter ","
Then this is latitude : 2546.0984,S
And this is longitude 02816.0191,E
read at NMEA spec which format the coordinates are: I think: the first to digits in latitdue are degrees, the rest is minutes: 25° 46.0984 minutes. If "S" multiply the result with -1.
slightly different for longitude:
02816.0191,E
first 3 digits degrees, rest minutes. 27° 16.0191 minutes. multiply with -1 if "W".
Basically, the messages you are seeing are part of a rather complicated message format. Each part means something different and the meanings depend on the message type.
You may want to look at some of the code in this open source project. I wrote this library with a colleague and it parses out those messages from a specific GPS device, but it should work with pretty much any device putting out the same data.

Can I run a GA to optimize wavelet transform?

I am running a wavelet transform (cmor) to estimate damping and frequencies that exists in a signal.cmor has 2 parameters that I can change them to get more accurate results. center frequency(Fc) and bandwidth frequency(Fb). If I construct a signal with few freqs and damping then I can measure the error of my estimation(fig 2). but in actual case I have a signal and I don't know its freqs and dampings so I can't measure the error.so a friend in here suggested me to reconstruct the signal and find error by measuring the difference between the original and reconstructed signal e(t)=|x(t)−x^(t)|.
so my question is:
Does anyone know a better function to find the error between reconstructed and original signal,rather than e(t)=|x(t)−x^(t)|.
can I use GA to search for Fb and Fc? or do you know a better search method?
Hope this picture shows what I mean, the actual case is last one. others are for explanations
Thanks in advance
You say you don't know the error until after running the wavelet transform, but that's fine. You just run a wavelet transform for every individual the GA produces. Those individuals with lower errors are considered fitter and survive with greater probability. This may be very slow, but conceptually at least, that's the idea.
Let's define a Chromosome datatype containing an encoded pair of values, one for the frequency and another for the damping parameter. Don't worry too much about how their encoded for now, just assume it's an array of two doubles if you like. All that's important is that you have a way to get the values out of the chromosome. For now, I'll just refer to them by name, but you could represent them in binary, as an array of doubles, etc. The other member of the Chromosome type is a double storing its fitness.
We can obviously generate random frequency and damping values, so let's create say 100 random Chromosomes. We don't know how to set their fitness yet, but that's fine. Just set it to zero at first. To set the real fitness value, we're going to have to run the wavelet transform once for each of our 100 parameter settings.
for Chromosome chr in population
chr.fitness = run_wavelet_transform(chr.frequency, chr.damping)
end
Now we have 100 possible wavelet transforms, each with a computed error, stored in our set called population. What's left is to select fitter members of the population, breed them, and allow the fitter members of the population and offspring to survive into the next generation.
while not done
offspring = new_population()
while count(offspring) < N
parent1, parent2 = select_parents(population)
child1, child2 = do_crossover(parent1, parent2)
mutate(child1)
mutate(child2)
child1.fitness = run_wavelet_transform(child1.frequency, child1.damping)
child2.fitness = run_wavelet_transform(child2.frequency, child2.damping)
offspring.add(child1)
offspring.add(child2)
end while
population = merge(population, offspring)
end while
There are a bunch of different ways to do the individual steps like select_parents, do_crossover, mutate, and merge here, but the basic structure of the GA stays pretty much the same. You just have to run a brand new wavelet decomposition for every new offspring.

Converting meshes to metaballs

I'm doing a project where I need to convert an existing polygonal mesh into a static shape made from metaballs (blobs). I have voxelized the mesh with binvox to "a .raw file" (according to the description at binvox), but I have no clue of how it stores the data, and therefore don't know how to load it.
Question1: Is there any non PHD way to do so? Create a metaball model from a polygonal mesh.
Question2: Has anyone ever used the said .raw file format from binvox and if you did, how?
RLE Run length Encoding
The binary voxel data
The binary data consists of pairs of bytes. The first byte of each pair is the value byte and is either 0 or 1 (1 signifies the presence of a voxel). The second byte is the count byte and specifies how many times the preceding voxel value should be repeated (so obviously the minimum count is 1, and the maximum is 255).
http://www.cs.princeton.edu/~min/binvox/binvox.html