def find_bird4(sppsci, spplist):
	#pass scientific name, list of requested 4-letter codes - cycle through spplist and return matching 4-letter bird code
	result = ''
	for n, b in enumerate(spplist): #loop through passed bird4 list
		if sppsci == bird_codes.lookup_bird(b)['SCINAME']: #check if sciname matches passed value
			result = b
	return result
Пример #2
0
def find_bird4(sppsci, spplist):
    #pass scientific name, list of requested 4-letter codes - cycle through spplist and return matching 4-letter bird code
    result = ''
    for n, b in enumerate(spplist):  #loop through passed bird4 list
        if sppsci == bird_codes.lookup_bird(
                b)['SCINAME']:  #check if sciname matches passed value
            result = b
    return result
Пример #3
0
def load_cmd_args():
    print nl + '-looping through command line arguments'
    ############################
    #TEMPORARY - use to simulate command line arguments
    ######INPUT DATA HERE#############################
    temp_argv = 'C:\\data\\@projects\\eBird_obs\\20150825_parse_ebird_records.py J:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=RUBL st=NC'
    # temp_argv = 'C:\\data\\@projects\\eBird_obs\\20150825_parse_ebird_records.py J:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=LOSH st=NC'
    # temp_argv = 'C:\\data\\@projects\\eBird_obs\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=NOBO st=NC,SC,VA,GA,TN'
    # temp_argv = 'C:\\data\\@projects\\eBird_obs\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=KEWA,SWWA,CERW,WOTH,YBCU st=NC'
    # temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=YCPA'
    # temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2003,2004 spp=YCPA'
    # temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2003-2015 spp=BACS,YCPA'
    # temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2010-2015 spp=RUBL'
    # temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2003,2004 spp=BACS,YCPA'
    # temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2003,2004 spp=BACS,YCPA st=NC'
    temp_argv = temp_argv.split(' ')

    global bstall
    global byrsall
    global bsppall
    global rootdir
    global fn

    # try:
    for argn, arg in enumerate(temp_argv):  #for testing
        # for argn, arg in enumerate(sys.argv):
        if argn >= 1:  #parse values
            if "=" in arg:
                #format should be: argname=[val1,val2,val3]
                flag = arg.split('=')
                params[flag[0]] = flag[1].split(',')
            else:  #assume it is a filename
                fn = arg
        elif argn == 0:
            dirfilesep = arg.rfind('\\') + 1
            rootdir = arg[:dirfilesep]
            sourcefile = arg[dirfilesep:]

    if len(fn) == 0:  #no filename passed, use default
        fn = 'E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt'

    #################################
    #populate scientific names in parameters
    print nl + '-populating species'
    if len(params['spp']) == 0:
        params['sppsci'].append('all')
        bsppall = True
    else:
        for i in params['spp']:
            params['sppsci'].append(bird_codes.lookup_bird(i)['SCINAME'])

    print str(params['sppsci'])

    #################################
    #populate all years in parameters
    print nl + '-populating years'
    yr_in = params['yrs']

    if len(params['yrs']) == 0:
        params['yrsall'].append('all')
        byrsall = True
    elif '-' in yr_in[0]:  #should represent a range of years
        print 'range detected'
        yr_range = yr_in[0].split('-')
        for y in range(int(yr_range[0]), int(yr_range[1]) + 1):
            params['yrsall'].append(y)
    else:  #one year or comma separated list
        for y in yr_in:
            params['yrsall'].append(y)

    print str(params['yrsall'])

    #################################
    #populate all states in parameters
    print nl + '-populating states'
    if len(params['st']) == 0:
        params['stall'].append('all')
        bstall = True
    else:
        for i in params['st']:
            if i in us_state_abbr:
                params['stall'].append(us_states[i][0])
            else:
                params['stall'].append(i)

    print str(params['stall'])

    #################################
    #check to see if minimum parameters present

    if bstall and byrsall and bsppall:
        print '----------------------------------' + nl + 'You must specify at least one criteria to produce results.' + nl + '----------------------------------'
        error_text()
def load_cmd_args():
	print nl+'-looping through command line arguments'
	############################
	#TEMPORARY - use to simulate command line arguments
	######INPUT DATA HERE#############################
	temp_argv = 'C:\\data\\@projects\\eBird_obs\\20150825_parse_ebird_records.py J:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=RUBL st=NC'
	# temp_argv = 'C:\\data\\@projects\\eBird_obs\\20150825_parse_ebird_records.py J:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=LOSH st=NC'
	# temp_argv = 'C:\\data\\@projects\\eBird_obs\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=NOBO st=NC,SC,VA,GA,TN'
	# temp_argv = 'C:\\data\\@projects\\eBird_obs\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=KEWA,SWWA,CERW,WOTH,YBCU st=NC'
	# temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt spp=YCPA'
	# temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2003,2004 spp=YCPA'
	# temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2003-2015 spp=BACS,YCPA'
	# temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2010-2015 spp=RUBL'
	# temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2003,2004 spp=BACS,YCPA'
	# temp_argv = 'C:\\data\\@projects\\eBird\\20150825_parse_ebird_records.py E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt yrs=2003,2004 spp=BACS,YCPA st=NC'
	temp_argv = temp_argv.split(' ')

	global bstall
	global byrsall
	global bsppall
	global rootdir
	global fn

	# try:
	for argn, arg in enumerate(temp_argv): #for testing
	# for argn, arg in enumerate(sys.argv): 
		if argn>=1: #parse values
			if "=" in arg:
				#format should be: argname=[val1,val2,val3]
				flag = arg.split('=')
				params[flag[0]]= flag[1].split(',')
			else: #assume it is a filename
				fn = arg
		elif argn==0:
			dirfilesep = arg.rfind('\\')+1
			rootdir = arg[:dirfilesep]
			sourcefile = arg[dirfilesep:] 

	if len(fn)==0: #no filename passed, use default
		fn = 'E:\\ebird_data\\ebd_relMay-2015\\ebd_relMay-2015.txt'

	#################################
	#populate scientific names in parameters
	print nl + '-populating species'
	if len(params['spp'])==0:
		params['sppsci'].append('all')
		bsppall = True
	else:
		for i in params['spp']:
			params['sppsci'].append(bird_codes.lookup_bird(i)['SCINAME'])

	print str(params['sppsci'])

	#################################
	#populate all years in parameters
	print nl + '-populating years'
	yr_in = params['yrs']

	if len(params['yrs'])==0:
		params['yrsall'].append('all')
		byrsall = True
	elif '-' in yr_in[0]: #should represent a range of years
		print 'range detected'
		yr_range = yr_in[0].split('-')
		for y in range(int(yr_range[0]),int(yr_range[1])+1):
			params['yrsall'].append(y)
	else: #one year or comma separated list
		for y in yr_in:
			params['yrsall'].append(y)

	print str(params['yrsall'])

	#################################
	#populate all states in parameters
	print nl + '-populating states'
	if len(params['st'])==0:
		params['stall'].append('all')
		bstall = True
	else:
		for i in params['st']:
			if i in us_state_abbr:
				params['stall'].append(us_states[i][0])
			else:
				params['stall'].append(i)


	print str(params['stall'])

	#################################
	#check to see if minimum parameters present

	if bstall and byrsall and bsppall:
		print '----------------------------------'+nl+'You must specify at least one criteria to produce results.'+nl+'----------------------------------'
		error_text()