Example #1
0
 def load_analyses(self, p, header_idx=1):
     self._path = p
     parser = XLSParser()
     parser.load(p, header_idx)
     self.header_offset = header_idx + 1
     self.parser = parser
     return True
Example #2
0
 def load_analyses(self, p, header_idx=1):
     self._path = p
     parser = XLSParser()
     parser.load(p, header_idx)
     self.header_offset = header_idx + 1
     self.parser = parser
     return True
Example #3
0
    def _import_environment_sheet(self, manager, p, sheet, tag):
        xp = XLSParser()
        xp.load(p, sheet=sheet)
        db = manager.db

        with db.session_ctx():
            # progress = manager.open_progress(xp.nrows)
            for args in xp.itervalues():
                sample = args['sample']
                sample = '{}-{:03d}'.format(tag, int(sample))

                # progress.change_message('Setting environment for {}'.format(sample))
                dbsample = db.get_sample(sample, project='Minna Bluff', verbose=False)
                if dbsample:
                    mapf = args['MapFea'].lower()
                    env = None
                    if 'subaerial' in mapf:
                        env = 'subaerial'
                    elif 'hyaloclastite' in mapf:
                        env = 'subglacial'
                    elif 'quenched' in mapf:
                        env = 'mixed'

                    if env:
                        self.debug('setting sample: {} environment: {}'.format(sample, env))
                        dbsample.environment = env
                else:
                    self.debug('no sample in db for {}'.format(sample))
Example #4
0
    def _import_rock_type(self, manager, p):
        xp = XLSParser()
        xp.load(p)
        db = manager.db
        rock_type_map = {'L': 'Lava',
                         'LAg': 'Lava/Agglutinate',
                         'L(gl)': 'Lava glassy',
                         'B': 'Autobreccia',
                         'B(gl)': 'Hyaloclastite Breccia',
                         'D': 'Dike',
                         'VZI': 'Vent zone intrusion',
                         'T': 'Pyroclastic Tuff or Lapilli Tuff',
                         'S': 'Polymict sediment',
                         'T(gl)': 'Hydrovolcanic tuff  aka hyalotuff'}

        with db.session_ctx():
            progress = manager.open_progress(xp.nrows)
            for args in xp.itervalues(keys=['ID', 'MapCode']):
                sample = args['ID']
                sample = '{}-{}'.format(sample[:4], sample[4:])
                progress.change_message('Setting sample {}'.format(sample))

                dbsample = db.get_sample(sample, project='Minna Bluff', verbose=False)
                if dbsample:
                    # rock_type = rock_type_map[args['MapCode']]
                    rock_type = args['MapCode'].strip()
                    if rock_type in rock_type_map:
                        dbsample.rock_type = rock_type
                    else:
                        dbsample.rock_type = ''
                        # print sample, rock_type
                else:
                    print 'no sample in db for {}'.format(sample)
        progress.close()
Example #5
0
    def _import_lithologies(self, manager, p):
        xp = XLSParser()
        xp.load(p)
        db = manager.db

        with db.session_ctx():
            progress = manager.open_progress(xp.nrows)
            for args in xp.itervalues(keys=['sample', 'lithology']):
                sample = args['sample']

                progress.change_message('Setting sample {}'.format(sample))

                dbsample = db.get_sample(sample, project='Minna Bluff', verbose=False)
                if dbsample:
                    dbsample.lithology = args['lithology']
                else:
                    print 'no sample in db for {}'.format(sample)
        progress.close()
Example #6
0
    def do_loading(self,
                   manager,
                   db,
                   path,
                   dry=True,
                   use_progress=True,
                   quiet=False):
        if not quiet:
            option = self.options
            info = option.edit_traits()
            if not info.result:
                return

            dry = option.dry

        if not os.path.isfile(path):
            self.warning('No file located at {}'.format(path))

        xp = XLSParser()
        xp.load(path)

        add_samples = True

        if manager and use_progress:
            db = manager.db
            progress = manager.open_progress(xp.nrows)
            progress.position = (100, 100)

        added_projects = []
        added_materials = []
        with db.session_ctx(commit=not dry):
            keys = ('sample', 'project', 'material')
            for args in xp.itervalues(keys=keys):
                sample, project, material = args['sample'], args[
                    'project'], args['material']

                # check if project exists
                if project not in added_projects:
                    dbproject = db.get_project(project)
                    if not dbproject:
                        if quiet or self.confirmation_dialog(
                                '"{}" does not exist. Add to database?'.format(
                                    project)):
                            added_projects.append(project)
                            db.add_project(project)
                        else:
                            continue

                # check if material exists
                if material not in added_materials:
                    dbmaterial = db.get_material(material)
                    if not dbmaterial:
                        if quiet or self.confirmation_dialog(
                                '"{}" does not exist. Add to database?'.format(
                                    material)):
                            added_materials.append(material)
                            db.add_material(material)
                        else:
                            continue

                if use_progress:
                    progress.change_message('Setting sample {}'.format(sample))

                if not dry:
                    db.flush()

                dbsample = db.get_sample(sample,
                                         project,
                                         material,
                                         verbose=False)
                if not dbsample:
                    if add_samples:
                        # print 'trying to add sample {} {} {}'.format(sample,project, material)
                        dbsample = db.add_sample(sample, project, material)

            if use_progress:
                progress.close()
Example #7
0
    def do_loading(self, manager, db, path, dry=True, use_progress=True, quiet=False):
        if not quiet:
            option = self.options
            info = option.edit_traits()
            if not info.result:
                return

            dry = option.dry

        if not os.path.isfile(path):
            self.warning('No file located at {}'.format(path))

        xp = XLSParser()
        xp.load(path)

        add_samples = True

        if manager and use_progress:
            db = manager.db
            progress = manager.open_progress(xp.nrows)
            progress.position = (100,100)

        added_projects = []
        added_materials = []
        with db.session_ctx(commit=not dry):
            keys = ('sample', 'project', 'material')
            for args in xp.itervalues(keys=keys):
                sample, project, material = args['sample'], args['project'], args['material']

                # check if project exists
                if project not in added_projects:
                    dbproject = db.get_project(project)
                    if not dbproject:
                        if quiet or self.confirmation_dialog('"{}" does not exist. Add to database?'.format(project)):
                            added_projects.append(project)
                            db.add_project(project)
                        else:
                            continue

                # check if material exists
                if material not in added_materials:
                    dbmaterial = db.get_material(material)
                    if not dbmaterial:
                        if quiet or self.confirmation_dialog('"{}" does not exist. Add to database?'.format(material)):
                            added_materials.append(material)
                            db.add_material(material)
                        else:
                            continue

                if use_progress:
                    progress.change_message('Setting sample {}'.format(sample))

                if not dry:
                    db.flush()

                dbsample = db.get_sample(sample, project, material, verbose=False)
                if not dbsample:
                    if add_samples:
                        # print 'trying to add sample {} {} {}'.format(sample,project, material)
                        dbsample = db.add_sample(sample, project, material)

            if use_progress:
                progress.close()
Example #8
0
    def do_import(self, manager, p):
        # self._import_lithologies(manager,p)
        # self._import_tas(manager, p)
        # self._import_environment(manager, p)
        self._import_rock_type(manager, p)
        return

        xp = XLSParser()
        xp.load(p, header_idx=2)
        overwrite_meta = True
        overwrite_alt_name = True
        add_samples = True
        db = manager.db
        progress = manager.open_progress(xp.nrows)

        self._import_lithologies(manager, db, xp)

        with db.session_ctx():
            ellps = xp.get_value(0, 1)
            zone = xp.get_value(1, 1)

            convert_coordinates = xp.has_key('E') and xp.has_key('N')

            self._ref_system = pyproj.Proj(proj='utm', zone=zone, ellps=ellps.upper())
            self._wgs84 = pyproj.Proj(init='EPSG:4326')

            if convert_coordinates:
                keys = ('sample', 'alt_name', 'project', 'material')
            else:
                keys = ('sample', 'alt_name', 'project', 'material',
                        'lithology',
                        'lat', 'long', 'elevation', 'location', 'igsn', 'note')

            for args in xp.itervalues(keys=keys):
                sample, project, material = args['sample'], args['project'], args['material']

                progress.change_message('Setting sample {}'.format(sample))

                dbsample = db.get_sample(sample, project, material, verbose=False)
                # if not dbsample:
                #     self.info('adding sample {} project={} material={}'.format(sample, project, material))
                #     dbsample=db.add_sample(sample, project, material)
                alt_name = args['alt_name']
                alt_names = None
                if alt_name:
                    head, tail = alt_name.split('-')
                    try:
                        itail = int(tail)
                        padded_alt_name = '{}-{:03d}'.format(head, itail)
                        non_padded_alt_name = '{}-{:01d}'.format(head, itail)
                    except ValueError:
                        padded_alt_name, non_padded_alt_name = '', ''

                    alt_names = (alt_name, padded_alt_name, non_padded_alt_name)

                if not dbsample:
                    if alt_names:
                        for a in alt_names:
                            dbsample = db.get_sample(a, project, material, verbose=False)
                            if dbsample:
                                if overwrite_alt_name:
                                    self.debug('setting name={} alt_name={}, padded_alt_name={}'.format(sample,
                                                                                                        a,
                                                                                                        padded_alt_name))
                                    dbsample.name = sample
                                    dbsample.alt_name = padded_alt_name
                                break

                if not dbsample:
                    if alt_names:
                        for a in alt_names:
                            dbsample = db.get_sample(a, project, material, verbose=False)
                            if dbsample:
                                break

                if not dbsample:
                    if add_samples:
                        if args['lat'] and args['long']:
                            dbsample = db.add_sample(sample, project, material)
                            if alt_name:
                                dbsample.alt_name = padded_alt_name

                if not dbsample:
                    continue

                if overwrite_meta:
                    if convert_coordinates:
                        lon, lat = self._convert_coordinates(args['E'], args['N'])
                    else:
                        lat, lon = args['lat'], args['long']

                    dbsample.lat = lat
                    dbsample.long = lon
                    dbsample.elevation = args['elevation']
                    dbsample.location = args['location']
                    dbsample.igsn = args['igsn']
                    dbsample.note = args['note']
                    dbsample.lithology = args['lithology']

            progress.close()