def hLineTest(self): self.logger.info("hLineTest") hline = HLine(240, Yaml().load("{ azimuth: 240, elevation: 60 }")) t1 = round(hline.getElevationAtAzimuth(240)) self.logger.debug(t1) assert t1 == 60 t2 = hline.getElevationAtAzimuth(200) self.logger.debug(t2) assert t2 < 55 and t2 > 50 hline2 = HLine(240, Yaml().load("{ azimuth: 200, elevation: 53 }")) t3 = hline2.getElevationAtAzimuth(240) assert round(t3) == 60 t4 = hline2.getElevationAtAzimuth(60) assert t4 < 0 # two measurements back and forth hline3 = HLine(150, Yaml().load("{ azimuth: 145, elevation: 62.5 }")) hline4 = HLine(150, Yaml().load("{ azimuth: 198.3, elevation: 52.4 }")) t5 = hline3.getElevationAtAzimuth(198.3) t6 = hline4.getElevationAtAzimuth(145) #self.logger.info("t5:" + str(t5)) #self.logger.info("t6:" + str(t6)) assert round(t5) == 52 assert round(t6) == 63
def lineTest(self): self.logger.info("lineTest") line1 = Line( 60, Yaml().load(""" - { azimuth: 120, elevation: 35.82 } - { azimuth: 110, elevation: 49 } """)) line = Line( 240, Yaml().load(""" - { azimuth: 197.28, elevation: 39.54 } - { azimuth: 227, elevation: 59 } """)) line3 = Line( 240, Yaml().load(""" - { azimuth: 197.28, elevation: 39.54 } - { azimuth: 199.52, elevation: 41.56 } """)) line4 = Line( 240, Yaml().load(""" - { azimuth: 197.28, elevation: 39.54, angle: -35 } """)) # gäste line5 = Line( 240, Yaml().load(""" - { azimuth: 174.88, elevation: 30.3 } - { azimuth: 189.58, elevation: 53.66 } """)) self.logger.debug(line.getElevationAtAzimuth(240)) self.logger.debug(line.getElevationAtAzimuth(224)) self.logger.debug(line.getElevationAtAzimuth(227)) self.logger.debug(line.getElevationAtAzimuth(200)) self.logger.debug(line.getElevationAtAzimuth(199.52)) self.logger.debug(line.getElevationAtAzimuth(180)) self.logger.debug(line.getElevationAtAzimuth(170)) self.logger.debug(line.getElevationAtAzimuth(160)) self.logger.debug(line.getElevationAtAzimuth(150)) self.logger.debug(line.getElevationAtAzimuth(290)) self.logger.debug(line.getElevationAtAzimuth(300)) self.logger.debug(line.getElevationAtAzimuth(310)) self.logger.debug(line.getElevationAtAzimuth(320)) self.logger.debug(line.getElevationAtAzimuth(330)) self.logger.debug(line.getElevationAtAzimuth(175)) self.logger.debug(line5.getElevationAtAzimuth(181.68)) assert round(line.getElevationAtAzimuth(240)) == 62 assert round(line.getElevationAtAzimuth(224)) == 58 assert round(line.getElevationAtAzimuth(227)) == 59 assert round(line.getElevationAtAzimuth(199.52)) == 42 assert round(line.getElevationAtAzimuth(174)) == 0
def readYaml(file): from java.io import FileInputStream from org.yaml.snakeyaml import Yaml input = FileInputStream(file) yaml = Yaml() data = yaml.load(input) return data
def getFormatData(type): from org.yaml.snakeyaml import Yaml from java.io import ByteArrayInputStream formatData = loadResource('template.yaml') input = java.io.ByteArrayInputStream(formatData) yaml = Yaml() data = yaml.load(input) return data[type]
def genNEFYaml(fileName): input = 'nef : ' + fileName + '\n' input += yamlStr print input yaml = Yaml() data = yaml.load(input) return data
def dailySchedulesTest(self, rules): self.logger.info("dailySchedulesTest") schedules = DailySchedules( Yaml().load(""" weekend: - kids_evening - kids_open workday: - kids_open vacation: - kids_open """), rules) return schedules
def sunExposureTest(self): self.logger.info("sunExposureTest") se = SunExposure(Yaml().load(""" orientation: 240 sun_openings: - azimuth: 160 below: - { azimuth: 240, elevation: 60 } above: - { elevation: 5 } - azimuth: 240 below: - { azimuth: 240, elevation: 60 } above: - { elevation: 3 } - azimuth: 330 """)) assert se.isSunlit(159, 9) == False assert se.isSunlit(161, 15) == True assert se.isSunlit(161, 6) == True assert se.isSunlit(161, 4) == False assert se.isSunlit(241, 58) == True assert se.isSunlit(241, 62) == False assert se.isSunlit(241, 4) == True assert se.isSunlit(325, 4) == True assert se.isSunlit(331, 4) == False se2 = SunExposure(Yaml().load(""" orientation: 240 sun_openings: - azimuth: 160 - azimuth: 330 """)) assert se2.isSunlit(200, 9) == True
def genYaml(): input = ''' molecule : entities : - sequence : GPGAST type : nv ptype : protein anneal: steps : 1000 highTemp : 1000.0 ''' yaml = Yaml() data = yaml.load(input) return data
def calendarTest(self, schedules): self.logger.info("calendarTest") calendar = Calendar( Yaml().load(""" - desc: "Sommerferien" timerange: {from: "12.06.2017", to: "16.08.2017" } daily_schedule: vacation - desc: "Weekend" cron: "? * 7,1 *" daily_schedule: weekend - desc: "Workdays" cron: "? * 2-6 *" daily_schedule: workday """), schedules).getDailyScheduleName()
def rulesTest(self): self.logger.info("rulesTest") rules = Rules( Yaml().load(""" kids_evening: triggers: - cron: '0 30 19' action: MANUAL items: - shutter_living kids_open: triggers: - cron: '0 30 20' - channel_event: {channel: 'astro:sun:local:nauticDusk#event', event: 'START'} action: SUN items: - shutter_living """), {'shutter_automation': 'shutter_automation'}) return rules
def dumpYamlWin(yamlFile): yaml = Yaml() win = {} win['geometry'] = nw.geometry() win['title'] = "Test" win['grid'] = nw.getGrid() win['sconfig'] = nw.sconfig() (rows, cols) = win['grid'] spectra = [] win['spectra'] = spectra nCharts = nw.nCharts() for iSpectrum in range(nCharts): nw.active(iSpectrum) sd = {} spectra.append(sd) iRow = iSpectrum / cols iCol = iSpectrum % cols sd['grid'] = [iRow, iCol] sd['lim'] = nw.lim() sd['cconfig'] = nw.cconfig() sd['datasets'] = [] datasets = nw.datasets() for dataset in datasets: dset = {} dset['name'] = dataset dset['config'] = nw.config(dataset) dset['dims'] = nw.getDims(dataset) sd['datasets'].append(dset) sd['peaklists'] = [] peakLists = nw.peakLists() for peakList in peakLists: pset = {} pset['name'] = peakList pset['config'] = nw.pconfig(peakList) sd['peaklists'].append(pset) print win yamlDump = yaml.dump(win) with open(yamlFile, 'w') as fOut: fOut.write(yamlDump)
import de.embl.cba.metadata.MetaData as MetaData; import de.embl.cba.metadata.MetadataCreator as MetadataCreator; import ij.IJ as IJ; import org.yaml.snakeyaml.DumperOptions as DumperOptions; import org.yaml.snakeyaml.Yaml as Yaml; import java.io.FileInputStream as FileInputStream; outputPath = "/Volumes/cba/exchange/OeyvindOedegaard/yaml_project/test.yaml"; yaml = Yaml(); md = yaml.load( FileInputStream( "/Volumes/cba/exchange/OeyvindOedegaard/yaml_project/test.yaml" ) ); metaDict = md.metadata print( metaDict[ MetadataCreator.IMAGE_DIMENSIONS ] );
def __init__(self): self.logger = logging.getLogger(logger_name + ".Config") self.shutterConfig = Yaml().load(open(shuttersFile)) self.scheduleConfig = Yaml().load(open(scheduleFile)) self.logger.info("Config loaded")
def sunExposureRuleTest(self): testExposureConfig = Yaml().load(""" shutter_living: orientation: 240 sun_openings: - azimuth: 160 - azimuth: 330 """) testExposure = {} for shutter in testExposureConfig: testExposure[shutter] = SunExposure(testExposureConfig[shutter]) ser = SunExposureRule(testExposure, "astro_sun_azimuth", "astro_sun_elevation", "weather_sunny", "shutter_automation", True) # values for DOWN = 100, STOP = 50, UP = 0 shutterName = "shutter_living" shutterItem = ir.get(shutterName) sunlitStateItem = ir.get(prefix_sunlit + shutterName) autoStateItem = ir.get(prefix_auto + shutterName) isSunnyItem = ir.get("weather_sunny") events.postUpdate(isSunnyItem.getName(), "OFF") events.sendCommand(shutterItem.getName(), "DOWN") events.postUpdate(sunlitStateItem.getName(), sunlitStateFalse) events.postUpdate(autoStateItem.getName(), autoStateSun) # sunlit: true, state: SUN, weather: cloudy time.sleep(1) ser._execute(240, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "100" # sunlit: true, state: SUN, weather: sunny events.postUpdate(isSunnyItem.getName(), "ON") time.sleep(1) ser._execute(240, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "50" # sunlit: true, state: SUN, weather: cloudy events.postUpdate(isSunnyItem.getName(), "OFF") time.sleep(1) ser._execute(240, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "50" # sunlit: false, state: SUN, weather: cloudy ser._execute(60, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "0" # sunlit: true, state: DOWN, weather: sunny events.postUpdate(isSunnyItem.getName(), "ON") events.postUpdate(autoStateItem.getName(), autoStateDown) events.sendCommand(shutterItem.getName(), "DOWN") time.sleep(1) ser._execute(240, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "100" # sunlit: false, state: DOWN, weather: sunny ser._execute(60, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "100" # sunlit: true, state: UP, weather: sunny events.postUpdate(autoStateItem.getName(), autoStateUp) events.sendCommand(shutterItem.getName(), "UP") time.sleep(1) ser._execute(240, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "0" # sunlit: false, state: UP, weather: sunny ser._execute(60, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "0" # sunlit: true, state: MANUAL, weather: sunny events.postUpdate(autoStateItem.getName(), autoStateManual) events.postUpdate(sunlitStateItem.getName(), sunlitStateUnknown) events.sendCommand(shutterItem.getName(), "UP") time.sleep(1) ser._execute(240, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "0" # sunlit: true, state: SUN, weather: sunny, sunlitstat: unknown events.postUpdate(autoStateItem.getName(), autoStateSun) time.sleep(1) ser._execute(240, 30, True) time.sleep(1) assert shutterItem.getState().toString() == "0" assert sunlitStateItem.getState().toString() == sunlitStateTrue
def parseArgs(): parser = OptionParser() parser.add_option("-p", "--pdbs", dest="pdbPath", default="") parser.add_option("-o", "--outDir", dest="outDir", default="analysis") parser.add_option("-y", "--yaml", dest="yamlFile", default=None) #Will now be used to add addition files to parse that are not included in the yaml file parser.add_option("-c", "--convert", action='store_true', dest="modifyFileType", default=False) # not used! parser.add_option("-s", "--shifts", dest="shiftFile", default=None) parser.add_option("-d", "--distances", dest="disFile", default=None) parser.add_option("-r", "--range", dest="resRange", default="") (options, args) = parser.parse_args() outDir = os.path.join(homeDir, options.outDir) if not os.path.exists(outDir): os.mkdir(outDir) pdbFilePath = options.pdbPath if pdbFilePath == "": pdbFiles = args else: pdbFiles = getFiles(pdbFilePath) changeRange = (options.resRange != '') range = options.resRange if (options.yamlFile != None): input = FileInputStream(options.yamlFile) yaml = Yaml() data = yaml.load(input) else: data = {'ribose': True} if options.shiftFile != None: shift = {} if changeRange: shift['range'] = range arr = options.shiftFile.split(' ') if len(arr) == 1: shift['type'] = 'nv' shift['file'] = arr[0] else: shift['file'] = arr[0] if arr[1] == 's': shift['type'] = 'str3' elif arr[1] == 'n': shift['type'] = 'nv' data['shifts'] = shift else: if changeRange: data['shifts']['range'] = range if options.disFile != None: dis = {} if changeRange: dis['range'] = range arr = options.disFile.split(' ') if len(arr) == 1: dis['type'] = 'nv' dis['file'] = arr[0] else: dis['file'] = arr[0] if arr[1] == 'a': dis['type'] = 'amber' elif arr[1] == 'n': dis['type'] = 'nv' if 'distances' in data: included = checkIncluded(data['distances'], dis) if not included: data['distances'].append(dis) else: print dis[ 'file'] + ' is already included in yaml file. Ignoring Duplicate.' else: data['distances'] = [dis] else: if changeRange: for dict in data['distances']: dict['range'] = range outFiles = loadPDBModels(pdbFiles, data, outDir) summary(outFiles)
def loadYamlWin(yamlFile, createNewStage=True): with open(yamlFile) as fIn: inputData = fIn.read() yaml = Yaml() if createNewStage > 0: nw.new() pathComps = os.path.split(yamlFile) title = pathComps[1] if title.endswith('_fav.yaml'): title = title[0:-9] elif title.endswith('.yaml'): title = title[0:-5] nw.setTitle(title) data = yaml.load(inputData) if 'geometry' in data: (x, y, w, h) = data['geometry'] nw.geometry(x, y, w, h) if 'grid' in data: (rows, cols) = data['grid'] nw.grid(rows, cols) if 'sconfig' in data: sconfig = data['sconfig'] nw.sconfig(sconfig) spectra = data['spectra'] for v in spectra: print v datasets = v['datasets'] if 'grid' in v: (iRow, iCol) = v['grid'] else: iRow = 0 iCol = 0 activeWin = iRow * cols + iCol print 'g', iRow, iCol, activeWin nw.active(activeWin) if 'cconfig' in v: cconfig = v['cconfig'] nw.cconfig(cconfig) datasetValues = [] for dataset in datasets: print dataset name = dataset['name'] datasetValues.append(name) print 'dv', datasetValues nw.cmd.datasets(datasetValues) if 'lim' in v: lim = v['lim'] nw.lim(lim) for dataset in datasets: name = dataset['name'] if 'config' in dataset: cfg = dataset['config'] nw.config(datasets=[name], pars=cfg) if 'dims' in dataset: dims = dataset['dims'] nw.setDims(dataset=name, dims=dims) if 'peaklists' in v: peakLists = v['peaklists'] peakListValues = [] for peakList in peakLists: print peakList name = peakList['name'] peakListValues.append(name) print 'dv', peakListValues nw.cmd.peakLists(peakListValues) for peakList in peakLists: name = peakList['name'] if 'config' in peakList: cfg = peakList['config'] nw.pconfig(peakLists=[name], pars=cfg) nw.drawAll()
def horizonTest(self): self.logger.info("horizonTest") horizon = Horizon(240, Yaml().load("{ elevation: 53 }")) assert horizon.getElevationAtAzimuth(60) == 53 assert horizon.getElevationAtAzimuth(200) == 53
def readYamlString(yamlString): from org.yaml.snakeyaml import Yaml yaml = Yaml() data = yaml.load(yamlString) return data
import de.embl.cba.metadata.MetaData as MetaData import de.embl.cba.metadata.MetadataCreator as MetadataCreator import ij.IJ as IJ import org.yaml.snakeyaml.DumperOptions as DumperOptions import org.yaml.snakeyaml.Yaml as Yaml import java.io.FileWriter as FileWriter file = "/Volumes/cba/exchange/OeyvindOedegaard/yaml_project/01_TestFiles/20180627_LSM780M2_208_ibidi1_fcs_B_Posx96.lsm" metadataCreator = MetadataCreator(file) metadata = metadataCreator.getMetadata() dumperOptions = DumperOptions() dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK) outputPath = "/Volumes/cba/exchange/OeyvindOedegaard/yaml_project/test.yaml" yaml = Yaml(dumperOptions) writer = FileWriter(outputPath) yaml.dump(metadata, writer) writer.flush() writer.close() IJ.open(outputPath)
def __init__(self): self.logger = LoggerFactory.getLogger(logger_name + ".Config") self.gardenaConfig = Yaml().load(open(gardena_config_file)) self.logger.info("Config loaded")
def _readTemplate(self, file2read): ''' evaluate if the template has a yaml format ''' if not self.isYamlTemplate: initialFile = file2read logger.debug('[%s._readTemplate] Looking for file: "%s"' % (self.__class__.__name__, initialFile)) if not os.path.exists(file2read): # check both .yaml & .yml extension file2read = '%s.yaml' % (file2read) logger.debug('[%s._readTemplate] Looking for file: "%s"' % (self.__class__.__name__, file2read)) if os.path.exists(file2read): self.isYamlTemplate = True else: file2read = '%s.yml' % (file2read) logger.debug('[%s._readTemplate] Looking for file: "%s"' % (self.__class__.__name__, file2read)) if os.path.exists(file2read): self.isYamlTemplate = True else: logger.error( '[%s._readTemplate] Template File "%s" doesn\'t exist (even with yaml extension)' % (self.__class__.__name__, initialFile)) raise MySyntaxError( '[%s._readTemplate] Template File "%s" doesn\'t exist (even with yaml extension)' % (self.__class__.__name__, initialFile)) # So the template file exists try: logger.debug('[%s._readTemplate] Reading template file "%s"' % (self.__class__.__name__, file2read)) lines = open(file2read, 'r').readlines() except: logger.error( '[%s._readTemplate] failure opening template file "%s"' % (self.__class__.__name__, file2read)) raise MySyntaxError( '[%s._readTemplate] failure opening template file "%s"' % (self.__class__.__name__, file2read)) # Shebang testing for Yaml format if not self.isYamlTemplate and (lines[0].find('#!yaml') >= 0 or lines[0].find('#!yml') >= 0): self.isYamlTemplate = True if not self.isYamlTemplate: logger.error( '[%s._readTemplate] compatibility issue ! template must be YAML data', (self.__class__.__name__)) raise SyntaxError( '[%s._readTemplate] compatibility issue ! template must be YAML data', (self.__class__.__name__)) # Yaml format: load the string to Yaml if we don't have already if not self.yamlTemplate: yaml = Yaml(Constructor(), Representer(), DumperOptions(), CustomResolver()) try: self.yamlTemplate = yaml.load(''.join(lines).strip()) except (MarkedYAMLException, YAMLException, ParserException, ReaderException, ScannerException), e: logger.error('Error while parsing YAML-file "%s":\n%s' % (file2read, e)) raise MySyntaxError('Error while parsing YAML-file "%s":\n%s' % (file2read, e)) logger.trace("_readTemplate - Loaded Yaml : '''%s'''" % (self.yamlTemplate))