<commit_before># Import library
from __future__ import print_function
import numpy as np
import pandas as pd
import os
import sys
from distutils.util import strtobool
# Library to help read header in binary WAC FILE
import pvl
from pvl import load as load_label

# Helper to catch images from URLs
import urllib
import requests


class BinaryTable(object):

    ''' Class which is able to read PDS image file for LOLA/WAC images.

    LOLA - All information can be found at
    http://pds-geosciences.wustl.edu/lro/lro-l-lola-3-rdr-v1/lrolol_1xxx/aareadme.txt
    In particular, HEADER in a separate file .LBL that contains all the informations.
    Read manually

    WAC - All information can be found at
    http://lroc.sese.asu.edu/data/LRO-L-LROC-5-RDR-V1.0/LROLRC_2001/AAREADME.TXT
    In particular, HEADER in the binary file that contain all the information -
    Read with the module pvl

    This class has a method able to download the images, though it might be better to download
    them before as it takes a lot of time, especially for larger resolution.

    Both are NASA PDS FILE - Meaning, they are binary table whose format depends on
    the file. All the information can be found in the Header whose reference are above.
    Line usualy index latitude while sample on the line refers to longitude.

    THIS CLASS SUPPORT ONLY CYLINDRICAL PROJECTION.
    PROJECTION : [WAC : 'EQUIRECTANGULAR', LOLA : '"SIMPLE"']
    FURTHER WORK IS NEEDED FOR IT TO BECOMES MORE GENERAL.

    parameter:
    - fname : name of the binary file without the extension
    - self.PDS_FILE : Path where the binary images are download. It should
    consit of two folder, LOLA and LROC_WAC.
    - self.LOLApath : path for LOLA images
    - self.WACpath : path for WAC images

    method:
    - self._Category() : Identify WAC or LOLA Image according to name formating
    - self._Load_Info_LBL : Load the Header of the file (using pvl for WAC and the .LBL
    file for LOLA) and return all the specification as attribute of the class.
    - self.Lat_id : From line return lat
    - self.Long_id : From sample, return long
    - self.Sample_id : From long, return sample
    - self.Line_id : From lat, return line
    - self.Array : Read the binary file where it should and return the values in an
    array
    - self.Extract_All() : Extract the whole image in the file
    - self.Extract_Grid() : Extract only part of the image centered around the structure
    -self.Lamber_Window, self.cylindrical_Window : Return longmin,longmax,latmin,latmax in
    both configuration.

    '''
    racine = '/Users/thorey/Documents/These/Projet/FFC/CraterInspector'

    def __init__(self, fname):
        ''' Parameter
        self.fname : name of the file
        self._Category : Identify weither its WAC/LOLA image
        self._Load_Info_LBL : Load corresponding information
        '''

        self.fname = fname.upper()
        self.PDS_FILE = os.path.join(BinaryTable.racine, 'PDS_FILE')
        self.LOLApath = os.path.join(self.PDS_FILE, 'LOLA')
        self.WACpath = os.path.join(self.PDS_FILE, 'LROC_WAC')
        self._Category()
        self._maybe_download()
        self._Load_Info_LBL()

        assert self.MAP_PROJECTION_TYPE in ['"SIMPLE', 'EQUIRECTANGULAR'],\
            "Only cylindrical projection is possible - %s NOT IMPLEMENTED" % (
                self.MAP_PROJECTION_TYPE)

    def _Category(self):

        if self.fname.split('_')[0] == 'WAC':
            self.Grid = 'WAC'
            self.img = os.path.join(self.WACpath, self.fname + '.IMG')
            self.lbl = ''
        elif self.fname.split('_')[0] == 'LDEM':
            self.Grid = 'LOLA'
            self.img = os.path.join(self.LOLApath, self.fname + '.IMG')
            self.lbl = os.path.join(self.LOLApath, self.fname + '.LBL')
        else:
            raise ValueError("%s : This type of image is not recognized. Possible\
                             images are from %s only" % (self.fname, ', '.join(('WAC', 'LOLA'))))
<commit_msg>fixup! Update to install via pip<commit_after># Import library
from __future__ import print_function
import numpy as np
import pandas as pd
import os
import sys
from distutils.util import strtobool
# Library to help read header in binary WAC FILE
import pvl
from pvl import load as load_label

# Helper to catch images from URLs
import urllib
import requests


class BinaryTable(object):

    ''' Class which is able to read PDS image file for LOLA/WAC images.

    LOLA - All information can be found at
    http://pds-geosciences.wustl.edu/lro/lro-l-lola-3-rdr-v1/lrolol_1xxx/aareadme.txt
    In particular, HEADER in a separate file .LBL that contains all the informations.
    Read manually

    WAC - All information can be found at
    http://lroc.sese.asu.edu/data/LRO-L-LROC-5-RDR-V1.0/LROLRC_2001/AAREADME.TXT
    In particular, HEADER in the binary file that contain all the information -
    Read with the module pvl

    This class has a method able to download the images, though it might be better to download
    them before as it takes a lot of time, especially for larger resolution.

    Both are NASA PDS FILE - Meaning, they are binary table whose format depends on
    the file. All the information can be found in the Header whose reference are above.
    Line usualy index latitude while sample on the line refers to longitude.

    THIS CLASS SUPPORT ONLY CYLINDRICAL PROJECTION.
    PROJECTION : [WAC : 'EQUIRECTANGULAR', LOLA : '"SIMPLE"']
    FURTHER WORK IS NEEDED FOR IT TO BECOMES MORE GENERAL.

    parameter:
    - fname : name of the binary file without the extension
    - self.PDS_FILE : Path where the binary images are download. It should
    consit of two folder, LOLA and LROC_WAC.
    - self.LOLApath : path for LOLA images
    - self.WACpath : path for WAC images

    method:
    - self._Category() : Identify WAC or LOLA Image according to name formating
    - self._Load_Info_LBL : Load the Header of the file (using pvl for WAC and the .LBL
    file for LOLA) and return all the specification as attribute of the class.
    - self.Lat_id : From line return lat
    - self.Long_id : From sample, return long
    - self.Sample_id : From long, return sample
    - self.Line_id : From lat, return line
    - self.Array : Read the binary file where it should and return the values in an
    array
    - self.Extract_All() : Extract the whole image in the file
    - self.Extract_Grid() : Extract only part of the image centered around the structure
    -self.Lamber_Window, self.cylindrical_Window : Return longmin,longmax,latmin,latmax in
    both configuration.

    '''
    racine = '/Users/thorey/Documents/These/Projet/FFC/CraterInspector'

    def __init__(self, fname):
        ''' Parameter
        self.fname : name of the file
        self._Category : Identify weither its WAC/LOLA image
        self._Load_Info_LBL : Load corresponding information
        '''

        self.fname = fname.upper()
        self.PDS_FILE = os.path.join(__file__, 'PDS_FILE')
        self.LOLApath = os.path.join(self.PDS_FILE, 'LOLA')
        self.WACpath = os.path.join(self.PDS_FILE, 'LROC_WAC')

        self._Category()
        self._maybe_download()
        self._Load_Info_LBL()

        assert self.MAP_PROJECTION_TYPE in ['"SIMPLE', 'EQUIRECTANGULAR'],\
            "Only cylindrical projection is possible - %s NOT IMPLEMENTED" % (
                self.MAP_PROJECTION_TYPE)

    def _Category(self):

        if self.fname.split('_')[0] == 'WAC':
            self.Grid = 'WAC'
            self.img = os.path.join(self.WACpath, self.fname + '.IMG')
            self.lbl = ''
        elif self.fname.split('_')[0] == 'LDEM':
            self.Grid = 'LOLA'
            self.img = os.path.join(self.LOLApath, self.fname + '.IMG')
            self.lbl = os.path.join(self.LOLApath, self.fname + '.LBL')
        else:
            raise ValueError("%s : This type of image is not recognized. Possible\
                             images are from %s only" % (self.fname, ', '.join(('WAC', 'LOLA'))))

{'fraction_non_alphanumeric': 0.08515392254220457, 'fraction_numerical': 0.0029791459781529296, 'mean_word_length': 2.6891025641025643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1276796', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2475, 'n_words': 871}