Exemplo n.º 1
0
    def __init__(self,earth_structure, namespace):
        """
        Class for handling earth models.

        :param earth_structure: An EarthStructure JSON dictionary. 
        """

        add_arguments = namespace['add_arguments']
        short_description = namespace.get('short_description',
                                          'No description')

        parser = URLArgumentParser(short_description)
        add_arguments(parser)
        try:
            args = parser.parse_params(earth_structure["arguments"])
        except SendHelp as helper:
            raise SendHelp
        
        self.reflect_file = str(earth_structure["datafile"])
        
        # Load the image data
        if earth_structure.get('update_model', None):
            response = requests.get(earth_structure["image"])

            if os.path.exists(self.reflect_file):
                os.remove(self.reflect_file)

            image = \
              Image.open(StringIO(response.content)).convert("RGB")
            image.load()
            self.image = np.asarray(image, dtype="int32")

            self.units = args.units
            self.depth = args.depth
            self.reflectivity_method = args.reflectivity_method

            self.property_map = {}

            # Keep only a direct map for legacy. Input data has name
            # attribute we are going to ignore
            mapping = earth_structure["mapping"]

            # Make a lookup table for vp. This is terribly
            # inefficient for memory, but quicker than looping
            # dictionaries. There is for sure a better way
            self.vp_lookup = np.zeros((256,256,256))
            for colour in mapping:
                rock = \
                  rock_properties_type(mapping[colour]["property"])

                rgb = colour.split('(')[1].split(')')[0].split(',')
                self.vp_lookup[int(rgb[0]), int(rgb[1]),
                               int(rgb[2])] = rock.vp
                                             
                self.property_map[colour] = rock
Exemplo n.º 2
0
    def __init__(self, earth_structure, namespace):
        """
        Class for handling earth models.

        :param earth_structure: An EarthStructure JSON dictionary.
        """

        add_arguments = namespace['add_arguments']
        short_description = namespace.get('short_description',
                                          'No description')

        parser = URLArgumentParser(short_description)
        add_arguments(parser)
        try:
            args = parser.parse_params(earth_structure["arguments"])
        except SendHelp:
            raise SendHelp

        self.reflect_file = str(earth_structure["datafile"])

        self.property_map = {}
        # Load the image data
        if earth_structure.get('update_model', None):
            response = requests.get(earth_structure["image"])

            if os.path.exists(self.reflect_file):
                os.remove(self.reflect_file)

            image = Image.open(StringIO(response.content))\
                         .convert("RGB")
            image.load()

            self.image = np.asarray(image, dtype="int32")
            self.units = args.units
            self.depth = args.depth
            self.reflectivity_method = args.reflectivity_method

            # Keep only a direct map for legacy. Input data has name
            # attribute we are going to ignore
            mapping = earth_structure["mapping"]

            # Make a lookup table for vp. This is terribly
            # inefficient for memory, but quicker than looping
            # dictionaries. There is for sure a better way
            self.vp_lookup = np.zeros((256, 256, 256))
            for colour in mapping:
                rock = rock_properties_type(mapping[colour]["property"])
                rock.name = mapping[colour]["name"]

                rgb = colour.split('(')[1].split(')')[0].split(',')
                self.vp_lookup[int(rgb[0]), int(rgb[1]), int(rgb[2])] = rock.vp

                self.property_map[colour] = rock
Exemplo n.º 3
0
def run_script(args):
    
    matplotlib.interactive(False)

    args.reflectivity_method = zoeppritz
    args.title = 'Forward model - spatial cross section'
    args.wavelet = ricker
    args.margin=1
    args.slice='spatial'
    args.trace = 0
    
    model = urllib2.urlopen(args.model["image"]).read()
    model = Image.open(StringIO(model)).convert("RGB")
    model = np.asarray(model)
    
    # decimate the first dimension of the model (into sample rate: dt [ms])
    
    ds = float(args.twt_range[1] - args.twt_range[0]) / float(model.shape[0])
    

    
    x = (np.arange(0, model.shape[0]) * ds) + args.twt_range[0] 
    

    f = interp1d(x, model.astype("float"), axis=0, kind="nearest")


    
    xnew = np.arange(args.twt_range[0],args.twt_range[1], dt * 1000.0)

    xnew = xnew[np.where(xnew < np.amax(x))] 
    
    
    model_new = f(xnew)
    
    mapping = args.model["mapping"]

    for colour in mapping:
        rock = rock_properties_type(mapping[colour]["property"])
        mapping[colour] = rock

    args.ntraces =  model_new.shape[1]
                                             
    return modelr_plot(model_new, mapping, args)