Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic yaml generation for magnets and screens #101

Merged
merged 42 commits into from
Oct 31, 2023

Conversation

MattKing06
Copy link
Collaborator

Summary of Changes

Created a generate class to convert csv data into yaml files via classes.
Also, write.py will create yaml files for every area (from lcls_elements.csv) and in each file there will be screen and magnet data injected.

The structure of the file should be as such:

<hardware-type>:
  <MAD-name>:
    <control-information>:
      PVs : {}
   <metadata>:
      <metadata-field-1>   :  value
  <MAD-name>:
       ...
<hardware-type-2>:
   ...

The .yaml files now in common/devices/yaml have been created using write.py

MattKing06 and others added 30 commits October 20, 2023 00:48
@MattKing06 MattKing06 self-assigned this Oct 30, 2023
Copy link
Member

@nneveu nneveu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

import meme.names
import numpy as np


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments

]
return areas

def get_areas(self) -> list:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change into property

]
return beampaths

def get_beam_paths(self) -> list:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a property

self, element, pv_information: Optional[Dict[str, str]] = {}
):
sum_l_meters = float(element["SumL (m)"]) if element["SumL (m)"] else -1.0
return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change -1.0 to none or something else?

},
}

def _construct_pv_list_from_control_system_name(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments

)
except RuntimeError as rte:
print(rte)
yaml_magnets.update({magnet["Element"]: {}})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set value to function in next line instead?

machine_areas = [area]
else:
machine_areas = area
for _area in machine_areas:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this loop the same as magnet loop? combine into utility function?

class YAMLWriter:
def __init__(self):
self.generator = YAMLGenerator()
self.machine_areas = self.generator.areas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just use 'areas' instead of 'machine_area'

def _is_area(self, area: str):
return area in self._machine_areas

def _constuct_yaml_contents(self, area: str) -> dict:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments

return None

def write_yaml_file(self, area: Optional[str] = "GUNB") -> None:
if area not in self.machine_areas:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change machine_areas to generator.areas

@nneveu nneveu merged commit 17dd8d7 into slaclab:main Oct 31, 2023
1 check failed
@MattKing06 MattKing06 deleted the 92_automatic_yaml_generation branch November 27, 2023 20:51
Derikka pushed a commit to Derikka/lcls-tools that referenced this pull request Mar 17, 2024
* magnets and screen conversion from csv to dictionary structures working. Can extract by area

* add functionality for extracting multiple areas at once

* add PVs to yaml magnets extraction

* removing unneeded file

* working on adding image pvs to yaml files

* working on image device code

* flake8 and black formatting

* make construction function self, add error handling for MEME timeout

* formatting

* make area a list in screens

* add pv_info to screen construction

* restrict wildcard search in meme

* add areas and beampaths as members of YAMLGenerator

* only construct yaml data if you find a Control System Name

* initial class for writing yaml files by area

* colon?

* unindent loop

* return when no devices found for that area

* only return info if it exists, otherwise return None

* add extra PVs for screen searching

* write yaml when you have either magnet or screen contents

* remove walrus operator for 3.6 :(

* make sum_l_meters a 2 sig fig fp number, make beampaths a list

* remove tuple error

* force float casting

* adding first version of yaml files for magnets and screens

* reformat

* refactoring extract_devices function from extract_magnets and extract_screens

* remove member variable for machine_areas, access only via generator

* tidy up with comments

* removing files without PV information

---------

Co-authored-by: Neveu <nneveu@pc101046.slac.stanford.edu>
Co-authored-by: Neveu <nneveu@stanford.edu>
Co-authored-by: matt <matt@SLACMachine.myguest.virtualbox.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants