Author Topic: extracting the 2D sonar data from 998CX SI recordings?  (Read 9467 times)

0 Members and 1 Guest are viewing this topic.

Offline adriank

  • Newbie
  • *
  • Joined: Jul 2009
  • Location: Australia
  • Posts: 18
  • Unit(s): 997cSI and 998c SI
extracting the 2D sonar data from 998CX SI recordings?
« on: November 11, 2013, 10:44:05 PM »
Hi

Is there a way of extracting the 2D sonar data from 998CX SI recordings? I'd really like to run some analyses using the raw data.

Cheers

Adrian


Offline peterv6i

  • Full Member
  • ***
  • Joined: Oct 2013
  • Location: Izola, Slovenia, EU
  • Posts: 132
  • Unit(s): 998ci
  • Software: 4.500
  • Accessories: 998ci
Re: extracting the 2D sonar data from 998CX SI recordings?
« Reply #1 on: March 21, 2014, 04:40:59 AM »
...

Offline peterv6i

  • Full Member
  • ***
  • Joined: Oct 2013
  • Location: Izola, Slovenia, EU
  • Posts: 132
  • Unit(s): 998ci
  • Software: 4.500
  • Accessories: 998ci
Re: extracting the 2D sonar data from 998CX SI recordings?
« Reply #2 on: February 10, 2015, 03:11:54 AM »
Have you done this?
Look at the source here it's quite simple example...


Code: [Select]
import java.io.DataInputStream;
import java.io.File;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import com.data.Ping;
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Peter
 */
public class Main {

    private static final double RAD_CONVERSION = 180 / Math.PI;
    private static final double EARTH_RADIUS = 6356752.3142;
    private static File datafile = null;
    private static File seconddatafile = null;
    private static int blocksize = 0;
    private static List<Integer> index = null;
    private static List<Integer> secondindex = null;
    private static int timestamp;
    private static int longitude;
    private static int latitude;

    //output picture height (modify this)
    static int height = 1024;

    //modify this to obtain different color (RGB value)
    static Color barva = new Color(179, 255, 153);

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            File file = new File("C:/Documents and Settings/Peter/Desktop/peter/RECORD/maona.dat");
            String name = initFromDAT(file);
            String dirname = name.substring(0, name.length() - 4);
            String path = file.getParent() != null ? file.getParent() + "/" + dirname : dirname;

            System.out.println("name: " + name);
            System.out.println("dirname: " + dirname);
            System.out.println("path: " + path);

            index = getIDXData(new File(String.format("%s/B002.idx", path)));
            datafile = new File(String.format("%s/B002.SON", path));

            secondindex = getIDXData(new File(String.format("%s/B003.idx", path)));
            seconddatafile = new File(String.format("%s/B003.SON", path));

            System.out.println("Index length: " + getLength() + " pings");

            Ping[] pingRange = getPingRange(0, (int) getLength() - 1);
            for (int i = 0; i < pingRange.length; i++) {
                System.out.println("ping range: " + i);
                System.out.println("speed: " + pingRange[i].getSpeed());
                System.out.println("lat: " + pingRange[i].getLatitude());
                System.out.println("lon: " + pingRange[i].getLongitude());
                byte[] soundings = pingRange[i].getSoundings();
               

                System.out.println("===================================");
            }

            //shranimo sliko
           
           
            BufferedImage image = new BufferedImage((int)getLength() - 1, height, BufferedImage.TYPE_INT_RGB);
            for (int loop = 0; loop < (int)getLength() - 1; loop++) {
                byte[] soundings = pingRange[loop].getSoundings();

                //gremo čez podatke iz zapisa
                for (int i = 0; i < height; i++) {
                    int mapped = (int) ((i * soundings.length) / (double) height);
                    byte sounding = soundings[mapped];
                 
                    int color = (barva.getRGB() & sounding) | (barva.getRGB() & (sounding << 8))
                            | (barva.getRGB() & (sounding << 16));


                    //set pixel color
                    image.setRGB(loop, i, color);
                }

            }
            File outputfile = new File("c:/image.jpg");
            ImageIO.write(image, "jpg", outputfile);



        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

   

    static long getLength() {
        return index.size();
    }

    public int getTimeStamp() {
        return this.timestamp;
    }

    static double getLongitude() {
        return toLongitude(longitude);
    }

    static double getLatitude() {
        return toLatitude(latitude);
    }

    static List<Integer> getIDXData(File idxfile) throws FileNotFoundException,
            IOException {
        DataInputStream stream = new DataInputStream(new FileInputStream(idxfile));
        try {
            List<Integer> index = new ArrayList<Integer>();

            while (stream.available() > 0) {
                int time = stream.readInt(); //no need
                int offset = stream.readInt();
                index.add(offset);
            }

            return index;
        } finally {
            stream.close();
        }
    }

    /**
     *
     * @param file
     * @return
     * @throws FileNotFoundException
     * @throws IOException
     */
    static String initFromDAT(File file) throws FileNotFoundException, IOException {

        System.out.println("File: " + file.toString());
        DataInputStream stream = new DataInputStream(new FileInputStream(file));
        try {
            stream.skipBytes(20);
            timestamp = stream.readInt();
            longitude = stream.readInt();
            latitude = stream.readInt();

            System.out.println("timestamp: " + timestamp);
            System.out.println("longitude: " + longitude + " " + toLongitude(longitude));
            System.out.println("latitude: " + latitude + " " + toLatitude(latitude));


            byte[] namebytes = new byte[10];
            stream.read(namebytes, 0, 10);
            String filename = new String(namebytes);
            stream.skipBytes(2); //skip null character \0000

            int ks = stream.readInt(); //don't know what this is
            int tk = stream.readInt(); //don't know what this is
            blocksize = stream.readInt();
            return filename;
        } finally {
            stream.close();
        }
    }

    /**
     * Convert Lowrance/Humminbird mercator meter format into WGS84.
     * Used this article as a reference: http://www.oziexplorer3.com/eng/eagle.html
     * @return
     */
    static double toLongitude(int mercator) {
        return mercator / EARTH_RADIUS * RAD_CONVERSION;
    }

    static double toLatitude(int mercator) {
        double temp = mercator / EARTH_RADIUS;
        temp = Math.exp(temp);
        temp = (2 * Math.atan(temp)) - (Math.PI / 2);
        return temp * RAD_CONVERSION;
    }

    static void reverseBytes(byte[] array) {
        int lastindex = array.length - 1;
        for (int loop = 0; loop < array.length / 2; loop++) {
            byte temp = array[loop];
            array[loop] = array[lastindex - loop];
            array[lastindex - loop] = temp;
        }
    }

    static Ping[] getPingRange(int offset, int length) throws IOException {

        //With side images soundings needs to be combined into one array.
        //Assumption is that both channels have same amount of samples.
        HumminbirdPing[] firstChannel = getPingRangeFromFile(offset, length, datafile, index);
        HumminbirdPing[] secondChannel = getPingRangeFromFile(offset, length, seconddatafile, secondindex);

        for (int loop = 0; loop < firstChannel.length; loop++) {
            HumminbirdPing first = firstChannel[loop];
            HumminbirdPing second = secondChannel[loop];

            //združi oba kanala v en array in vrne rezultat
            byte[] firstsoundings = first.getSoundings();
            byte[] secondsoundings = second.getSoundings();
            reverseBytes(firstsoundings);

            byte[] soundings = new byte[firstsoundings.length + secondsoundings.length];
            System.arraycopy(firstsoundings, 0, soundings, 0, firstsoundings.length);
            System.arraycopy(secondsoundings, 0, soundings, firstsoundings.length, secondsoundings.length);
            first.setSoundings(soundings);
        }


        return firstChannel;

    }

    static HumminbirdPing[] getPingRangeFromFile(int offset, int length, File file, List<Integer> index) throws IOException {
        RandomAccessFile raf = new RandomAccessFile(file, "r");

        try {
            HumminbirdPing[] pings = new HumminbirdPing[length];
            for (int loop = 0; loop < length; loop++) {
                raf.seek(index.get(offset + loop));
                HumminbirdPing ping = new HumminbirdPing(raf, blocksize);
                pings[loop] = ping;
            }
            return pings;
        } finally {
            raf.close();
        }
    }

    static class HumminbirdPing implements Ping {

        private int time;
        private int longitude;
        private int latitude;
        private short speed;
        private short heading;
        private byte[] soundings;

        public HumminbirdPing(RandomAccessFile stream, int blocksize) throws IOException {
         
           /*
            System.out.println("block size: " + blocksize);
            byte[] vrstica = stream.readLine().getBytes();
            for (int x=0; x < vrstica.length; x++)
            {
                System.out.print(vrstica[x]+"|");
            }
            System.out.println("-----------");
           */

            stream.skipBytes(10);
            time = stream.readInt();
            stream.skipBytes(1);
            longitude = stream.readInt();
            stream.skipBytes(1);
            latitude = stream.readInt();
            stream.skipBytes(3);
            heading = stream.readShort();
            stream.skipBytes(3);
            speed = stream.readShort();
            stream.skipBytes(5);
            int freq = stream.readInt();
            stream.skipBytes(10);
            int son = stream.readInt();
            stream.skipBytes(1);

            //vrnemo zapis, ki ga izrisujemo
            System.out.println(blocksize-58);
            soundings = new byte[blocksize - 58];
            stream.read(soundings, 0, blocksize - 58);
        }

        public byte[] getSoundings() {
            return soundings;
        }

        public void setSoundings(byte[] soundings) {
            this.soundings = soundings;
        }

        public float getLowLimit() {
            // Humminbird file does not provide this
            return 0;
        }

        public float getTemp() {
            // Humminbird file does not provide this
            return 0;
        }

        public float getDepth() {
            // Humminbird file does not provide this
            return 0;
        }

        public int getTimeStamp() {
            return this.time;
        }

        public float getSpeed() {
            return this.speed * 3.6f;
        }

        public float getTrack() {
            return this.heading / 10.0f;
        }

        public double getLongitude() {
            return toLongitude(longitude);
        }

        public double getLatitude() {
            return toLatitude(latitude);
        }
    }
}


Code: [Select]
package com.data;

/**
 *
 * @author Peter
 */
public interface Ping {
byte[] getSoundings();
float getLowLimit();
float getTemp();
float getDepth();
int getTimeStamp();
float getSpeed();
float getTrack();
double getLongitude();
double getLatitude();
}


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo

 

Related Topics

  Subject / Started by Replies Last post
4 Replies
6891 Views
Last post December 24, 2009, 11:42:04 PM
by soretoe
9 Replies
14057 Views
Last post May 01, 2013, 10:25:56 AM
by matt@reefmaster
3 Replies
3082 Views
Last post November 13, 2013, 08:50:14 AM
by Humminbird_Greg
1 Replies
3513 Views
Last post April 15, 2014, 11:52:51 PM
by slabbacks
1 Replies
5559 Views
Last post June 06, 2015, 01:17:27 PM
by CamoHunter
6 Replies
3712 Views
Last post September 30, 2015, 02:56:16 PM
by Martins
9 Replies
8113 Views
Last post October 14, 2016, 09:18:15 PM
by rnvinc
3 Replies
7434 Views
Last post October 17, 2017, 08:00:10 PM
by ckd022


anything
SimplePortal 2.3.3 © 2008-2010, SimplePortal