Skip to content
Snippets Groups Projects
Socet2ISIS.ipynb 35 KiB
Newer Older
  • Learn to ignore specific revisions
  •    "execution_count": 56,
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
       "outputs": [],
    
        "import sys\n",
        "from functools import singledispatch\n",
    
        "import warnings\n",
    
        "\n",
        "import pandas as pd\n",
    
        "import math\n",
        "import pyproj\n",
    
        "from plio.examples import get_path\n",
    
        "from plio.io.io_bae import read_gpf, read_ipf\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "from collections import defaultdict\n",
    
        "import plio.io.io_controlnetwork as cn\n",
        "import plio.io.isis_serial_number as sn"
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
      {
       "cell_type": "code",
    
       "execution_count": 85,
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
       "metadata": {},
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
       "outputs": [],
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
       "source": [
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "# Reads a .atf file and outputs all of the \n",
        "# .ipf, .gpf, .sup, .prj, and path to locate the \n",
        "# .apf file (should be the same as all others) \n",
        "def read_atf(atf_file):\n",
        "    with open(atf_file) as f:\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        \n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        # Extensions of files we want\n",
        "        files_ext = ['.prj', '.sup', '.ipf', '.gpf']\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        files_dict = []\n",
        "        files = defaultdict(list)\n",
        "\n",
        "        for line in f:\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "            ext = os.path.splitext(line)[-1].strip()\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "            \n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "            # Check is needed for split as all do not have a space\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "            if ext in files_ext:\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "                \n",
        "                # If it is the .prj file, it strips the directory away and grabs file name\n",
        "                if ext == '.prj':\n",
        "                    files[ext].append(line.strip().split(' ')[1].split('\\\\')[-1])\n",
        "                \n",
        "                # If the ext is in the list of files we care about, it addes to the dict\n",
        "                files[ext].append(line.strip().split(' ')[-1])\n",
        "            \n",
        "            else:\n",
        "                \n",
        "                # Adds to the dict even if not in files we care about\n",
        "                files[ext.strip()].append(line)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        \n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        # Gets the base filepath\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        files['basepath'] = os.path.dirname(os.path.abspath(atf_file))\n",
        "        \n",
        "        # Creates a dict out of file lists for GPF, PRJ, IPF, and ATF\n",
        "        files_dict = (dict(files_dict))\n",
        "        \n",
        "        # Sets the value of IMAGE_IPF to all IPF images\n",
        "        files_dict['IMAGE_IPF'] = files['.ipf']\n",
        "        \n",
        "        # Sets the value of IMAGE_SUP to all SUP images\n",
        "        files_dict['IMAGE_SUP'] = files['.sup']\n",
        "        \n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        # Sets value for GPF file\n",
        "        files_dict['GP_FILE'] = files['.gpf'][0]\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        # Sets value for PRJ file\n",
        "        files_dict['PROJECT'] = files['.prj'][0]\n",
    
        "        \n",
        "        # Sets the value of PATH to the path of the ATF file\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        files_dict['PATH'] = files['basepath']\n",
    
        "        return files_dict\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "\n",
    
        "# converts columns l. and s. to isis\n",
    
        "# no transform applied\n",
    
        "def line_sample_size(record, path):\n",
        "    with open(os.path.join(path, record['ipf_file'] + '.sup')) as f:\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        for i, line in enumerate(f):\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "            if i == 2:\n",
        "                img_index = line.split('\\\\')\n",
        "                img_index = img_index[-1].strip()\n",
        "                img_index = img_index.split('.')[0]\n",
        "                \n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "            if i == 3:\n",
    
        "                line_size = line.split(' ')\n",
        "                line_size = line_size[-1].strip()\n",
        "                assert int(line_size) > 0, \"Line number {} from {} is a negative number: Invalid Data\".format(line_size, record['ipf_file'])\n",
        "                \n",
        "            if i == 4:\n",
        "                sample_size = line.split(' ')\n",
        "                sample_size = sample_size[-1].strip()\n",
        "                assert int(sample_size) > 0, \"Sample number {} from {} is a negative number: Invalid Data\".format(sample_size, record['ipf_file'])\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "                break\n",
    
        "                \n",
        "        \n",
        "        line_size = int(line_size)/2.0 + record['l.'] + 1\n",
        "        sample_size = int(sample_size)/2.0 + record['s.'] + 1\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        return sample_size, line_size, img_index\n",
    
        "    \n",
        "# converts known to ISIS keywords\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "def known(record):\n",
        "    if record['known'] == 0:\n",
        "        return 'Free'\n",
        "    \n",
        "    elif record['known'] == 1 or record['known'] == 2 or record['known'] == 3:\n",
        "        return 'Constrained'\n",
        "    \n",
        "# converts +/- 180 system to 0 - 360 system\n",
        "def to_360(num):\n",
        "    return num % 360\n",
        "\n",
        "# ocentric to ographic latitudes\n",
    
        "# transform but unsure how to handle\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "def oc2og(dlat, dMajorRadius, dMinorRadius):\n",
        "    try:    \n",
        "        dlat = math.radians(dlat)\n",
        "        dlat = math.atan(((dMajorRadius / dMinorRadius)**2) * (math.tan(dlat)))\n",
        "        dlat = math.degrees(dlat)\n",
        "    except:\n",
        "        print (\"Error in oc2og conversion\")\n",
        "    return dlat\n",
        "\n",
        "# ographic to ocentric latitudes\n",
    
        "# transform but unsure how to handle\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "def og2oc(dlat, dMajorRadius, dMinorRadius):\n",
        "    try:\n",
        "        dlat = math.radians(dlat)\n",
        "        dlat = math.atan((math.tan(dlat) / ((dMajorRadius / dMinorRadius)**2)))\n",
        "        dlat = math.degrees(dlat)\n",
        "    except:\n",
        "        print (\"Error in og2oc conversion\")\n",
        "    return dlat\n",
        "\n",
    
        "# gets eRadius and pRadius from a .prj file\n",
        "def get_axis(file):\n",
    
        "    with open(file) as f:\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        from collections import defaultdict\n",
        "\n",
        "        files = defaultdict(list)\n",
        "        \n",
        "        for line in f:\n",
        "            \n",
        "            ext = line.strip().split(' ')\n",
        "            files[ext[0]].append(ext[-1])\n",
        "            \n",
        "        eRadius = float(files['A_EARTH'][0])\n",
        "        pRadius = eRadius * (1 - float(files['E_EARTH'][0]))\n",
        "        \n",
        "        return eRadius, pRadius\n",
        "    \n",
        "# function to convert lat_Y_North to ISIS_lat\n",
    
        "def lat_ISIS_coord(record, semi_major, semi_minor):\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    ocentric_coord = og2oc(record['lat_Y_North'], semi_major, semi_minor)\n",
        "    coord_360 = to_360(ocentric_coord)\n",
        "    return coord_360\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "\n",
        "# function to convert long_X_East to ISIS_lon\n",
    
        "def lon_ISIS_coord(record, semi_major, semi_minor):\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    ocentric_coord = og2oc(record['long_X_East'], semi_major, semi_minor)\n",
        "    coord_360 = to_360(ocentric_coord)\n",
        "    return coord_360\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "def body_fix(record, semi_major, semi_minor, inverse=False):\n",
        "    \"\"\"\n",
        "    Parameters\n",
        "    ----------\n",
        "    record : ndarray\n",
        "             (n,3) where columns are x, y, height or lon, lat, alt\n",
        "    \"\"\"\n",
        "    \n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    ecef = pyproj.Proj(proj='geocent', a=semi_major, b=semi_minor)\n",
        "    lla = pyproj.Proj(proj='latlon', a=semi_major, b=semi_minor)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    if inverse:\n",
        "        lon, lat, height = pyproj.transform(ecef, lla, record[0], record[1], record[2])\n",
        "        return lon, lat, height\n",
        "    else:\n",
        "        y, x, z = pyproj.transform(lla, ecef, record[0], record[1], record[2])\n",
        "        return y, x, z\n",
        "\n",
        "def ignore_toggle(record):\n",
        "    if record['stat'] == 0:\n",
        "        return True\n",
        "    else:\n",
        "        return False\n",
        "\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "# TODO: Does isis cnet need a convariance matrix for sigmas? Even with a static matrix of 1,1,1,1 \n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "def compute_sigma_covariance_matrix(lat, lon, rad, latsigma, lonsigma, radsigma, semimajor_axis):\n",
        "    \n",
        "    \"\"\"\n",
        "    Given geospatial coordinates, desired accuracy sigmas, and an equitorial radius, compute a 2x3\n",
        "    sigma covariange matrix.\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    Parameters\n",
        "    ----------\n",
        "    lat : float\n",
        "          A point's latitude in degrees\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    lon : float\n",
        "          A point's longitude in degrees\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    rad : float\n",
        "          The radius (z-value) of the point in meters\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    latsigma : float\n",
        "               The desired latitude accuracy in meters (Default 10.0)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    lonsigma : float\n",
        "               The desired longitude accuracy in meters (Default 10.0)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    radsigma : float\n",
        "               The desired radius accuracy in meters (Defualt: 15.0)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    semimajor_axis : float\n",
        "                     The semi-major or equitorial radius in meters (Default: 1737400.0 - Moon)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    Returns\n",
        "    -------\n",
        "    rectcov : ndarray\n",
        "              (2,3) covariance matrix\n",
        "    \"\"\"\n",
        "    \n",
        "    lat = math.radians(lat)\n",
        "    lon = math.radians(lon)\n",
        "    \n",
        "    # SetSphericalSigmasDistance\n",
        "    scaled_lat_sigma = latsigma / semimajor_axis\n",
        "\n",
        "    # This is specific to each lon.\n",
        "    scaled_lon_sigma = lonsigma * math.cos(lat) / semimajor_axis\n",
        "    \n",
        "    # SetSphericalSigmas\n",
        "    cov = np.eye(3,3)\n",
        "    cov[0,0] = scaled_lat_sigma ** 2\n",
        "    cov[1,1] = scaled_lon_sigma ** 2\n",
        "    cov[2,2] = radsigma ** 2\n",
        "    \n",
        "    # Approximate the Jacobian\n",
        "    j = np.zeros((3,3))\n",
        "    cosphi = math.cos(lat)\n",
        "    sinphi = math.sin(lat)\n",
        "    coslambda = math.cos(lon)\n",
        "    sinlambda = math.sin(lon)\n",
        "    rcosphi = rad * cosphi\n",
        "    rsinphi = rad * sinphi\n",
        "    j[0,0] = -rsinphi * coslambda\n",
        "    j[0,1] = -rcosphi * sinlambda\n",
        "    j[0,2] = cosphi * coslambda\n",
        "    j[1,0] = -rsinphi * sinlambda\n",
        "    j[1,1] = rcosphi * coslambda\n",
        "    j[1,2] = cosphi * sinlambda\n",
        "    j[2,0] = rcosphi\n",
        "    j[2,1] = 0.\n",
        "    j[2,2] = sinphi\n",
        "    mat = j.dot(cov)\n",
        "    mat = mat.dot(j.T)\n",
        "    rectcov = np.zeros((2,3))\n",
        "    rectcov[0,0] = mat[0,0]\n",
        "    rectcov[0,1] = mat[0,1]\n",
        "    rectcov[0,2] = mat[0,2]\n",
        "    rectcov[1,0] = mat[1,1]\n",
        "    rectcov[1,1] = mat[1,2]\n",
        "    rectcov[1,2] = mat[2,2]\n",
        "    \n",
    
        "    return np.array(rectcov)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "#     return np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]])\n",
        "\n",
        "\n",
        "def compute_cov_matrix(record, semimajor_axis):\n",
        "    cov_matrix = compute_sigma_covariance_matrix(record['lat_Y_North'], record['long_X_East'], record['ht'], record['sig0'], record['sig1'], record['sig2'], semimajor_axis)\n",
        "    return cov_matrix.ravel().tolist()\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "# applys transformations to columns\n",
    
        "def apply_two_isis_transformations(atf_dict, df):\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    prj_file = os.path.join(atf_dict['PATH'], atf_dict['PROJECT'])\n",
    
        "    eRadius, pRadius = get_axis(prj_file)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    lla = np.array([[df['long_X_East']], [df['lat_Y_North']], [df['ht']]])\n",
        "    \n",
        "    ecef = body_fix(lla, semi_major = eRadius, semi_minor = pRadius, inverse=False)\n",
        "    \n",
    
        "    df['s.'], df['l.'], df['image_index'] = (zip(*df.apply(line_sample_size, path = atf_dict['PATH'], axis=1)))\n",
        "    df['known'] = df.apply(known, axis=1)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "    df['long_X_East'] = ecef[0][0]\n",
        "    df['lat_Y_North'] = ecef[1][0]\n",
        "    df['ht'] = ecef[2][0]    \n",
        "    df['aprioriCovar'] = df.apply(compute_cov_matrix, semimajor_axis = eRadius, axis=1)\n",
    
        "#     df['ignore'] = df.apply(ignore_toggle, axis=1)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "        \n",
    
        "def socet2isis(prj_file):\n",
        "    # Read in and setup the atf dict of information\n",
        "    atf_dict = read_atf(prj_file)\n",
        "    \n",
        "    # Get the gpf and ipf files using atf dict\n",
        "    gpf_file = os.path.join(atf_dict['PATH'], atf_dict['GP_FILE']);\n",
        "    ipf_list = [os.path.join(atf_dict['PATH'], i) for i in atf_dict['IMAGE_IPF']]\n",
        "    \n",
        "    # Read in the gpf file and ipf file(s) into seperate dataframes\n",
        "    gpf_df = read_gpf(gpf_file)\n",
        "    ipf_df = read_ipf(ipf_list)\n",
        "\n",
        "    # Check for differences between point ids using each dataframes\n",
        "    # point ids as a reference\n",
        "    gpf_pt_idx = pd.Index(pd.unique(gpf_df['point_id']))\n",
        "    ipf_pt_idx = pd.Index(pd.unique(ipf_df['pt_id']))\n",
        "\n",
        "    point_diff = ipf_pt_idx.difference(gpf_pt_idx)\n",
        "\n",
        "    if len(point_diff) != 0:\n",
        "        warnings.warn(\"The following points found in ipf files missing from gpf file: \\n\\n{}. \\\n",
        "                      \\n\\nContinuing, but these points will be missing from the control network\".format(list(point_diff)))\n",
        "        \n",
        "    # Merge the two dataframes on their point id columns\n",
        "    socet_df = ipf_df.merge(gpf_df, left_on='pt_id', right_on='point_id')\n",
        "    \n",
        "    # Apply the transformations\n",
    
        "#     apply_two_isis_transformations(atf_dict, socet_df)\n",
    
        "    \n",
        "    # Define column remap for socet dataframe\n",
    
        "#     column_map = {'pt_id': 'id', 'l.': 'y', 's.': 'x',\n",
        "#                   'res_l': 'lineResidual', 'res_s': 'sampleResidual', 'known': 'Type',\n",
        "#                   'lat_Y_North': 'aprioriY', 'long_X_East': 'aprioriX', 'ht': 'aprioriZ',\n",
        "#                   'sig0': 'aprioriLatitudeSigma', 'sig1': 'aprioriLongitudeSigma', 'sig2': 'aprioriRadiusSigma',\n",
        "#                   'sig_l': 'linesigma', 'sig_s': 'samplesigma'}\n",
    
        "    \n",
        "    # Rename the columns using the column remap above\n",
    
        "#     socet_df.rename(columns = column_map, inplace=True)\n",
    
        "    \n",
        "    # Return the socet dataframe to be converted to a control net\n",
        "    return socet_df\n",
        "\n",
        "# creates a dict of serial numbers with the cub being the key\n",
        "def serial_numbers(images, path, extension):\n",
        "    serial_dict = dict()\n",
        "    \n",
        "    for image in images:\n",
    
    Adam Paquette's avatar
    Adam Paquette committed
        "        snum = sn.generate_serial_number(os.path.join(path, image + extension))\n",
        "        snum = snum.replace('Mars_Reconnaissance_Orbiter', 'MRO')\n",
        "        serial_dict[image] = snum\n",
    
        "    return serial_dict"
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 86,
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
       "metadata": {
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "scrolled": true
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
       "outputs": [],
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
       "source": [
    
        "# Setup stuffs for the cub information namely the path and extension\n",
    
        "path = '/home/acpaquette/repos/plio/test_cubes'\n",
        "targetname = 'Mars'\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "# Extension of your cub files\n",
    
        "extension = '.8bit.cub'\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "\n",
        "# Path to atf file\n",
    
        "atf_file = ('/home/acpaquette/repos/plio/plio/examples/SocetSet/Relative.atf')\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "socet_df = socet2isis(atf_file)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "\n",
    
        "# images = pd.unique(socet_df['ipf_file'])\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "\n",
    
        "# serial_dict = serial_numbers(images, path, extension)\n",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
        "\n",
        "# creates the control network\n",
    
    379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
        "# cn.to_isis('/home/acpaquette/repos/plio/plio/examples/SocetSet/cn.net', socet_df, serial_dict, targetname = targetname)"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": 116,
       "metadata": {},
       "outputs": [],
       "source": [
        "return_df = cn.from_isis(\"/home/acpaquette/repos/plio/plio/examples/SocetSet/cn.net\")\n",
        "\n",
        "columns = []\n",
        "column_index = []\n",
        "\n",
        "for i, column in enumerate(list(return_df.columns)):\n",
        "    if column not in columns:\n",
        "        column_index.append(i)\n",
        "        columns.append(column)\n",
        "\n",
        "return_df = return_df.iloc[:, column_index]"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": 117,
       "metadata": {},
       "outputs": [],
       "source": [
        "column_map = {'pt_id': 'id', 'l.': 'y', 's.': 'x',\n",
        "              'res_l': 'lineResidual', 'res_s': 'sampleResidual', 'known': 'Type',\n",
        "              'lat_Y_North': 'aprioriY', 'long_X_East': 'aprioriX', 'ht': 'aprioriZ',\n",
        "              'sig0': 'aprioriLatitudeSigma', 'sig1': 'aprioriLongitudeSigma', 'sig2': 'aprioriRadiusSigma',\n",
        "              'sig_l': 'linesigma', 'sig_s': 'samplesigma'}\n",
        "\n",
        "column_map = {k: v for v, k in column_map.items()}\n",
        "return_df.rename(columns = column_map, inplace=True)\n",
        "return_df.drop(['chooserName', 'datetime', 'referenceIndex', 'jigsawRejected', 'editLock', 'aprioriSurfPointSource', 'aprioriSurfPointSourceFile','aprioriRadiusSource', 'aprioriRadiusSourceFile'] , axis = 1, inplace=True)"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": 129,
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/html": [
           "<div>\n",
           "<style scoped>\n",
           "    .dataframe tbody tr th:only-of-type {\n",
           "        vertical-align: middle;\n",
           "    }\n",
           "\n",
           "    .dataframe tbody tr th {\n",
           "        vertical-align: top;\n",
           "    }\n",
           "\n",
           "    .dataframe thead th {\n",
           "        text-align: right;\n",
           "    }\n",
           "</style>\n",
           "<table border=\"1\" class=\"dataframe\">\n",
           "  <thead>\n",
           "    <tr style=\"text-align: right;\">\n",
           "      <th></th>\n",
           "      <th>lat_Y_North</th>\n",
           "      <th>long_X_East</th>\n",
           "      <th>ht</th>\n",
           "    </tr>\n",
           "  </thead>\n",
           "  <tbody>\n",
           "    <tr>\n",
           "      <th>0</th>\n",
           "      <td>139525.230749</td>\n",
           "      <td>3.390974e+06</td>\n",
           "      <td>4506.496945</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>1</th>\n",
           "      <td>139525.230749</td>\n",
           "      <td>3.390974e+06</td>\n",
           "      <td>4506.496945</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>2</th>\n",
           "      <td>139489.278045</td>\n",
           "      <td>3.390969e+06</td>\n",
           "      <td>4516.454802</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>3</th>\n",
           "      <td>139489.278045</td>\n",
           "      <td>3.390969e+06</td>\n",
           "      <td>4516.454802</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>4</th>\n",
           "      <td>139823.489797</td>\n",
           "      <td>3.390990e+06</td>\n",
           "      <td>4536.274914</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>5</th>\n",
           "      <td>139823.489797</td>\n",
           "      <td>3.390990e+06</td>\n",
           "      <td>4536.274914</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>6</th>\n",
           "      <td>139772.738004</td>\n",
           "      <td>3.390936e+06</td>\n",
           "      <td>4518.050219</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>7</th>\n",
           "      <td>139772.738004</td>\n",
           "      <td>3.390936e+06</td>\n",
           "      <td>4518.050219</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>8</th>\n",
           "      <td>139575.914815</td>\n",
           "      <td>3.390952e+06</td>\n",
           "      <td>3816.666542</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>9</th>\n",
           "      <td>139575.914815</td>\n",
           "      <td>3.390952e+06</td>\n",
           "      <td>3816.666542</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>10</th>\n",
           "      <td>139614.756296</td>\n",
           "      <td>3.390953e+06</td>\n",
           "      <td>3791.232717</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>11</th>\n",
           "      <td>139614.756296</td>\n",
           "      <td>3.390953e+06</td>\n",
           "      <td>3791.232717</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>12</th>\n",
           "      <td>139912.041374</td>\n",
           "      <td>3.390914e+06</td>\n",
           "      <td>3875.608660</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>13</th>\n",
           "      <td>139912.041374</td>\n",
           "      <td>3.390914e+06</td>\n",
           "      <td>3875.608660</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>14</th>\n",
           "      <td>139909.452033</td>\n",
           "      <td>3.390930e+06</td>\n",
           "      <td>3845.361327</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>15</th>\n",
           "      <td>139909.452033</td>\n",
           "      <td>3.390930e+06</td>\n",
           "      <td>3845.361327</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>16</th>\n",
           "      <td>139669.826849</td>\n",
           "      <td>3.391120e+06</td>\n",
           "      <td>3270.672620</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>17</th>\n",
           "      <td>139669.826849</td>\n",
           "      <td>3.391120e+06</td>\n",
           "      <td>3270.672620</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>18</th>\n",
           "      <td>139694.517017</td>\n",
           "      <td>3.391205e+06</td>\n",
           "      <td>3289.744506</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>19</th>\n",
           "      <td>139694.517017</td>\n",
           "      <td>3.391205e+06</td>\n",
           "      <td>3289.744506</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>20</th>\n",
           "      <td>139968.793338</td>\n",
           "      <td>3.391126e+06</td>\n",
           "      <td>3274.711397</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>21</th>\n",
           "      <td>139968.793338</td>\n",
           "      <td>3.391126e+06</td>\n",
           "      <td>3274.711397</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>22</th>\n",
           "      <td>139979.200780</td>\n",
           "      <td>3.391138e+06</td>\n",
           "      <td>3298.297228</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>23</th>\n",
           "      <td>139979.200780</td>\n",
           "      <td>3.391138e+06</td>\n",
           "      <td>3298.297228</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>24</th>\n",
           "      <td>139688.031217</td>\n",
           "      <td>3.391041e+06</td>\n",
           "      <td>4253.956077</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>25</th>\n",
           "      <td>139688.031217</td>\n",
           "      <td>3.391041e+06</td>\n",
           "      <td>4253.956077</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>26</th>\n",
           "      <td>139686.910823</td>\n",
           "      <td>3.391089e+06</td>\n",
           "      <td>4216.743792</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>27</th>\n",
           "      <td>139686.910823</td>\n",
           "      <td>3.391089e+06</td>\n",
           "      <td>4216.743792</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>28</th>\n",
           "      <td>139786.205284</td>\n",
           "      <td>3.390979e+06</td>\n",
           "      <td>3579.127600</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>29</th>\n",
           "      <td>139786.205284</td>\n",
           "      <td>3.390979e+06</td>\n",
           "      <td>3579.127600</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>30</th>\n",
           "      <td>139785.010997</td>\n",
           "      <td>3.391002e+06</td>\n",
           "      <td>3546.549796</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>31</th>\n",
           "      <td>139785.010997</td>\n",
           "      <td>3.391002e+06</td>\n",
           "      <td>3546.549796</td>\n",
           "    </tr>\n",
           "  </tbody>\n",
           "</table>\n",
           "</div>"
          ],
          "text/plain": [
           "      lat_Y_North   long_X_East           ht\n",
           "0   139525.230749  3.390974e+06  4506.496945\n",
           "1   139525.230749  3.390974e+06  4506.496945\n",
           "2   139489.278045  3.390969e+06  4516.454802\n",
           "3   139489.278045  3.390969e+06  4516.454802\n",
           "4   139823.489797  3.390990e+06  4536.274914\n",
           "5   139823.489797  3.390990e+06  4536.274914\n",
           "6   139772.738004  3.390936e+06  4518.050219\n",
           "7   139772.738004  3.390936e+06  4518.050219\n",
           "8   139575.914815  3.390952e+06  3816.666542\n",
           "9   139575.914815  3.390952e+06  3816.666542\n",
           "10  139614.756296  3.390953e+06  3791.232717\n",
           "11  139614.756296  3.390953e+06  3791.232717\n",
           "12  139912.041374  3.390914e+06  3875.608660\n",
           "13  139912.041374  3.390914e+06  3875.608660\n",
           "14  139909.452033  3.390930e+06  3845.361327\n",
           "15  139909.452033  3.390930e+06  3845.361327\n",
           "16  139669.826849  3.391120e+06  3270.672620\n",
           "17  139669.826849  3.391120e+06  3270.672620\n",
           "18  139694.517017  3.391205e+06  3289.744506\n",
           "19  139694.517017  3.391205e+06  3289.744506\n",
           "20  139968.793338  3.391126e+06  3274.711397\n",
           "21  139968.793338  3.391126e+06  3274.711397\n",
           "22  139979.200780  3.391138e+06  3298.297228\n",
           "23  139979.200780  3.391138e+06  3298.297228\n",
           "24  139688.031217  3.391041e+06  4253.956077\n",
           "25  139688.031217  3.391041e+06  4253.956077\n",
           "26  139686.910823  3.391089e+06  4216.743792\n",
           "27  139686.910823  3.391089e+06  4216.743792\n",
           "28  139786.205284  3.390979e+06  3579.127600\n",
           "29  139786.205284  3.390979e+06  3579.127600\n",
           "30  139785.010997  3.391002e+06  3546.549796\n",
           "31  139785.010997  3.391002e+06  3546.549796"
          ]
         },
         "execution_count": 129,
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "return_df[['lat_Y_North', 'long_X_East', 'ht']]"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": 128,
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/html": [
           "<div>\n",
           "<style scoped>\n",
           "    .dataframe tbody tr th:only-of-type {\n",
           "        vertical-align: middle;\n",
           "    }\n",
           "\n",
           "    .dataframe tbody tr th {\n",
           "        vertical-align: top;\n",
           "    }\n",
           "\n",
           "    .dataframe thead th {\n",
           "        text-align: right;\n",
           "    }\n",
           "</style>\n",
           "<table border=\"1\" class=\"dataframe\">\n",
           "  <thead>\n",
           "    <tr style=\"text-align: right;\">\n",
           "      <th></th>\n",
           "      <th>lat_Y_North</th>\n",
           "      <th>long_X_East</th>\n",
           "      <th>ht</th>\n",
           "    </tr>\n",
           "  </thead>\n",
           "  <tbody>\n",
           "    <tr>\n",
           "      <th>0</th>\n",
           "      <td>0.095708</td>\n",
           "      <td>2.356167</td>\n",
           "      <td>-2342.889214</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>1</th>\n",
           "      <td>0.095708</td>\n",
           "      <td>2.356167</td>\n",
           "      <td>-2342.889214</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>2</th>\n",
           "      <td>0.095920</td>\n",
           "      <td>2.355564</td>\n",
           "      <td>-2349.638414</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>3</th>\n",
           "      <td>0.095920</td>\n",
           "      <td>2.355564</td>\n",
           "      <td>-2349.638414</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>4</th>\n",
           "      <td>0.096339</td>\n",
           "      <td>2.361186</td>\n",
           "      <td>-2314.316425</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>5</th>\n",
           "      <td>0.096339</td>\n",
           "      <td>2.361186</td>\n",
           "      <td>-2314.316425</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>6</th>\n",
           "      <td>0.095954</td>\n",
           "      <td>2.360368</td>\n",
           "      <td>-2370.502882</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>7</th>\n",
           "      <td>0.095954</td>\n",
           "      <td>2.360368</td>\n",
           "      <td>-2370.502882</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>8</th>\n",
           "      <td>0.081058</td>\n",
           "      <td>2.357037</td>\n",
           "      <td>-2363.989968</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>9</th>\n",
           "      <td>0.081058</td>\n",
           "      <td>2.357037</td>\n",
           "      <td>-2363.989968</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>10</th>\n",
           "      <td>0.080518</td>\n",
           "      <td>2.357691</td>\n",
           "      <td>-2360.922571</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>11</th>\n",
           "      <td>0.080518</td>\n",
           "      <td>2.357691</td>\n",
           "      <td>-2360.922571</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>12</th>\n",
           "      <td>0.082311</td>\n",
           "      <td>2.362733</td>\n",
           "      <td>-2388.123298</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>13</th>\n",
           "      <td>0.082311</td>\n",
           "      <td>2.362733</td>\n",
           "      <td>-2388.123298</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>14</th>\n",
           "      <td>0.081668</td>\n",
           "      <td>2.362678</td>\n",
           "      <td>-2371.973499</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>15</th>\n",
           "      <td>0.081668</td>\n",
           "      <td>2.362678</td>\n",
           "      <td>-2371.973499</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>16</th>\n",
           "      <td>0.069458</td>\n",
           "      <td>2.358505</td>\n",
           "      <td>-2193.309629</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>17</th>\n",
           "      <td>0.069458</td>\n",
           "      <td>2.358505</td>\n",
           "      <td>-2193.309629</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>18</th>\n",
           "      <td>0.069861</td>\n",
           "      <td>2.358862</td>\n",
           "      <td>-2106.769773</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>19</th>\n",
           "      <td>0.069861</td>\n",
           "      <td>2.358862</td>\n",
           "      <td>-2106.769773</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>20</th>\n",
           "      <td>0.069543</td>\n",
           "      <td>2.363543</td>\n",
           "      <td>-2174.971745</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>21</th>\n",
           "      <td>0.069543</td>\n",
           "      <td>2.363543</td>\n",
           "      <td>-2174.971745</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>22</th>\n",
           "      <td>0.070044</td>\n",
           "      <td>2.363710</td>\n",
           "      <td>-2162.103231</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>23</th>\n",
           "      <td>0.070044</td>\n",
           "      <td>2.363710</td>\n",
           "      <td>-2162.103231</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>24</th>\n",
           "      <td>0.090342</td>\n",
           "      <td>2.358866</td>\n",
           "      <td>-2269.610862</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>25</th>\n",
           "      <td>0.090342</td>\n",
           "      <td>2.358866</td>\n",
           "      <td>-2269.610862</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>26</th>\n",
           "      <td>0.089550</td>\n",
           "      <td>2.358814</td>\n",
           "      <td>-2222.328983</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>27</th>\n",
           "      <td>0.089550</td>\n",
           "      <td>2.358814</td>\n",
           "      <td>-2222.328983</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>28</th>\n",
           "      <td>0.076012</td>\n",
           "      <td>2.360565</td>\n",
           "      <td>-2328.281125</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>29</th>\n",
           "      <td>0.076012</td>\n",
           "      <td>2.360565</td>\n",
           "      <td>-2328.281125</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>30</th>\n",
           "      <td>0.075320</td>\n",
           "      <td>2.360529</td>\n",
           "      <td>-2305.362047</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>31</th>\n",
           "      <td>0.075320</td>\n",
           "      <td>2.360529</td>\n",
           "      <td>-2305.362047</td>\n",
           "    </tr>\n",
           "  </tbody>\n",
           "</table>\n",
           "</div>"
          ],
          "text/plain": [
           "    lat_Y_North  long_X_East           ht\n",
           "0      0.095708     2.356167 -2342.889214\n",
           "1      0.095708     2.356167 -2342.889214\n",
           "2      0.095920     2.355564 -2349.638414\n",
           "3      0.095920     2.355564 -2349.638414\n",
           "4      0.096339     2.361186 -2314.316425\n",
           "5      0.096339     2.361186 -2314.316425\n",
           "6      0.095954     2.360368 -2370.502882\n",
           "7      0.095954     2.360368 -2370.502882\n",
           "8      0.081058     2.357037 -2363.989968\n",
           "9      0.081058     2.357037 -2363.989968\n",
           "10     0.080518     2.357691 -2360.922571\n",
           "11     0.080518     2.357691 -2360.922571\n",
           "12     0.082311     2.362733 -2388.123298\n",
           "13     0.082311     2.362733 -2388.123298\n",
           "14     0.081668     2.362678 -2371.973499\n",
           "15     0.081668     2.362678 -2371.973499\n",
           "16     0.069458     2.358505 -2193.309629\n",
           "17     0.069458     2.358505 -2193.309629\n",
           "18     0.069861     2.358862 -2106.769773\n",
           "19     0.069861     2.358862 -2106.769773\n",
           "20     0.069543     2.363543 -2174.971745\n",
           "21     0.069543     2.363543 -2174.971745\n",
           "22     0.070044     2.363710 -2162.103231\n",
           "23     0.070044     2.363710 -2162.103231\n",
           "24     0.090342     2.358866 -2269.610862\n",
           "25     0.090342     2.358866 -2269.610862\n",
           "26     0.089550     2.358814 -2222.328983\n",
           "27     0.089550     2.358814 -2222.328983\n",
           "28     0.076012     2.360565 -2328.281125\n",
           "29     0.076012     2.360565 -2328.281125\n",
           "30     0.075320     2.360529 -2305.362047\n",
           "31     0.075320     2.360529 -2305.362047"
          ]
         },
         "execution_count": 128,
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "socet_df[['lat_Y_North', 'long_X_East', 'ht']]"
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
    
       "source": []
    
      }
     ],
     "metadata": {
      "kernelspec": {
       "display_name": "Python 3",
       "language": "python",
       "name": "python3"
      },
      "language_info": {
       "codemirror_mode": {
        "name": "ipython",
        "version": 3
       },
       "file_extension": ".py",
       "mimetype": "text/x-python",
       "name": "python",
       "nbconvert_exporter": "python",
       "pygments_lexer": "ipython3",
    
    Tyler Thatcher's avatar
    Tyler Thatcher committed
       "version": "3.6.4"