def test_readDirect_sites_nonexistant_list(self): with assert_raises(WSFileError): IO.read_sites('this_is_not_a_file.lst')
def test_readDirect_raw_data_nonexistant_data(self): sites = IO.read_sites(badlist) with assert_raises(WSFileError): IO.read_raw_data(site_names=sites)
def main_data(args): defaults = { 'azimuth': 0.0, 'flag_outliers': 'y', 'outlier_errmap': 10, 'lowTol': 2.0, 'highTol': 10.0, 'use_TF': 'y', 'period_choice': 'n', 'cTol': 0.5, 'hfreq_errmap': 20, 'XXYY_errmap': 10, 'no_period_errmap': 50 } if set(('dbg', 'debug', '-dbg', '-debug')).intersection(set([x.lower() for x in args])): DEBUG = True WSDS.DEBUG = True if set(('i', '-i')).intersection(set([x.lower() for x in args])): interactive = True else: interactive = False # Get list file list_file = WSIO.verify_input('Enter list file name:', expected='read') try: site_names = WSIO.read_sites(list_file) except WSFileError as e: # Error is raised if something is wrong with the file. print(e.message) print('Exiting...') return dataset = WSDS.Dataset(listfile=list_file) # Get desired azimuth azimuth = WSIO.verify_input('Desired azimuth (deg. from True North)', expected=float, default=defaults['azimuth']) flag_outliers = WSIO.verify_input('Adjust error map for outliers?', default=defaults['flag_outliers'], expected='yn') if flag_outliers == 'y': dataset.data.OUTLIER_MAP = WSIO.verify_input( 'Set outlier error map', default=defaults['outlier_errmap'], expected=int) else: dataset.data.OUTLIER_MAP = 1 dataset.data.HIGHFREQ_MAP = WSIO.verify_input( 'Error map on high frequencies (>1000Hz)', default=defaults['hfreq_errmap'], expected=int) dataset.data.XXYY_MAP = WSIO.verify_input('XXYY error map', default=defaults['XXYY_errmap'], expected=int) dataset.data.NO_PERIOD_MAP = WSIO.verify_input( 'Missing period error map', default=defaults['no_period_errmap'], expected=int) lowTol = WSIO.verify_input( 'High frequency (>1Hz) matching tolerance %-age', default=defaults['lowTol'], expected=float) lowTol /= 100 highTol = WSIO.verify_input( 'High frequency (>=10s) matching tolerance %-age', default=defaults['highTol'], expected=float) highTol /= 100 raw_data = dataset.raw_data num_TF = 0 for site in raw_data.sites.values(): if 'TZXR' in site.components: num_TF += 1 print('{} sites out of {} have tipper data'.format(num_TF, len(site_names))) use_TF = WSIO.verify_input('Would you like to include TF data?', default=defaults['use_TF'], expected='yn') if use_TF: defaults.update({'inv_type': 5}) else: defaults.update({'inv_type': 1}) dType = WSIO.verify_input( 'Which periods would you like to choose from?\n' 'Options are MTU-5, MTU-A, both, freqset, all, or program selected ' '(5/A/b/o/m/n)', default=defaults['period_choice'], expected='5aboamn') # if dType == 'n': cTol = WSIO.verify_input( 'Required fraction of sites containing each period?', default=defaults['cTol'], expected=float) if cTol > 1: cTol /= 100 period_set = raw_data.narrow_period_list(periods=MTU_data_types( data=raw_data, dType=dType), high_tol=highTol, low_tol=lowTol, count_tol=cTol) sorted_periods = sorted(period_set.keys()) # Can set this up later to only run if -i is set (or set that as the default) # Want user to be able to decide between interactive (plotting) mode, and just # straight command line input. chosen = pick_periods(sorted_periods, period_set, interactive) for ii, p in enumerate(chosen): if p < 0: chosen[ii] = -1 / p else: chosen[ii] = p inv_type = int( WSIO.verify_input('Inversion Type?', default=defaults['inv_type'], expected='12345')) # Still have to make sure this method also applies the error map properly. dataset.get_data_from_raw( lTol=lowTol, hTol=highTol, periods=chosen, components=WSIO.get_components(invType=inv_type)[0]) dataset.data.set_error_map() if azimuth != 0: dataset.rotate_sites(azimuth) while True: outdata = WSIO.verify_input('Output file name?', default='.data', expected='write') if outdata: if outdata[-5:] != '.data': outdata = ''.join([outdata, '.data']) dataset.write_data(outfile=outdata, overwrite=True) break return dataset