Project

General

Profile

« Previous | Next » 

Revision 68

Added submap and extract_plot_map to extract plot subpaths from VegX-VegBank.csv

View differences:

scripts/util/submap
1
#!/usr/bin/env python
2
# Extracts subpaths from a map spreadsheet
3

  
4
import csv
5
import os.path
6
import sys
7

  
8
sys.path.append(os.path.dirname(__file__)+"/../lib")
9

  
10
import opts
11

  
12
def all_not_none(list_):
13
    return reduce(lambda a, b: a and b, map(lambda e: e != None, list_))
14

  
15
def main():
16
    # Get subpath config from env vars
17
    config_names = ['subpath', 'new_root']
18
    env_names = []
19
    configs = map(lambda col: opts.get_env_vars(config_names, col, env_names),
20
        ['left', 'right'])
21
    if not all_not_none(configs): raise SystemExit(
22
        'Usage: '+opts.env_usage(env_names)+' '+sys.argv[0]+' <map >submap')
23
    
24
    # Transform map
25
    for config in configs:
26
        config['prefix'] = config['subpath']+config['new_root']
27
        config['prefix_len'] = len(config['prefix'])
28
    reader = csv.reader(sys.stdin)
29
    col_names = reader.next()[:2]
30
    # TODO: replace col_names with new_roots
31
    writer = csv.writer(sys.stdout)
32
    writer.writerow(col_names)
33
    for row in reader:
34
        if row[0].startswith(configs[0]['prefix']):
35
            assert row[1].startswith(configs[1]['prefix'])
36
            for idx in range(len(configs)):
37
                row[idx] = row[idx][configs[idx]['prefix_len']:]
38
            writer.writerow(row)
39

  
40
main()
0 41

  
mappings/extract_plot_map
1
#!/bin/bash
2
# Extracts plot subpaths from VegX-VegBank.csv
3

  
4
selfDir="$(dirname -- "$0")"
5
cd "$selfDir"
6

  
7
export left_subpath='*ID->' left_new_root='/*s/plotObservation/' \
8
right_subpath= right_new_root=
9

  
10
../scripts/util/submap <VegX-VegBank.csv >VegX-VegBank.plots.csv
0 11

  
mappings/VegX-VegBank.plots.csv
1
VegX/*s/individualOrganismObservation/,VegBank/
2
*UniqueIdentifierID->/*s/plot/country,namedPlace[placeSystem=area|country|territory]/placeName
3
*UniqueIdentifierID->/*s/plot/county,namedPlace[placeSystem=county]/placeName
4
*UniqueIdentifierID->/*s/plot/geospatial/CoordinateUncertaintyInMeters,plot/locationAccuracy
5
*UniqueIdentifierID->/*s/plot/geospatial/DecimalLatitude,plot/realLatitude
6
*UniqueIdentifierID->/*s/plot/geospatial/DecimalLongitude,plot/realLongitude
7
*UniqueIdentifierID->/*s/plot/geospatial/FootprintWKT,plot/dsgpoly
8
*UniqueIdentifierID->/*s/plot/geospatial/maximumDepthInMeters,observation/waterDepth/max
9
*UniqueIdentifierID->/*s/plot/geospatial/maximumElevationInMeters,"plot/{elevation/max,elevationRange/to}"
10
*UniqueIdentifierID->/*s/plot/geospatial/minimumDepthInMeters,observation/waterDepth/min
11
*UniqueIdentifierID->/*s/plot/geospatial/minimumElevationInMeters,"plot/{elevation/min,elevationRange/from}"
12
*UniqueIdentifierID->/*s/plot/plotUniqueIdentifier,plot/authorPlotCode
13
*UniqueIdentifierID->/*s/plot/relatedSpatialItem/relatedItem[relationshipType=parentPlot]/relatedItemID->/*s/plot/plotUniqueIdentifier,plot/PARENT_ID->/plot/authorPlotCode
14
*UniqueIdentifierID->/*s/plot/simpleUserdefined[name=locality]/value,namedPlace/placeDescription
15
*UniqueIdentifierID->/*s/plot/state,namedPlace[placeSystem=region|state|province]/placeName
16
obsStartDate,"stemLocation/taxonInterpretation[PLANTCONCEPT_ID=]/collectionDate,observation/authorObsCode"
17
obsStartDate/_date/day,stemLocation/taxonInterpretation[PLANTCONCEPT_ID=]/collectionDate/_date/day
18
obsStartDate/_date/month,stemLocation/taxonInterpretation[PLANTCONCEPT_ID=]/collectionDate/_date/month
19
obsStartDate/_date/year,stemLocation/taxonInterpretation[PLANTCONCEPT_ID=]/collectionDate/_date/year

Also available in: Unified diff