-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
6,712 additions
and
3,584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
} | ||
} | ||
} | ||
|
||
}, | ||
"features": { | ||
"ghcr.io/devcontainers/features/github-cli:1": {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import ast | ||
import csv | ||
import inspect | ||
import re | ||
|
||
from pyscope.observatory import Observatory | ||
|
||
|
||
class HeaderCSVGenerator: | ||
"""Generates a CSV file containing the header information for the Observatory class. | ||
The CSV file contains the following columns: | ||
- Header Key: The key of the header | ||
- Header Value: The value of the header | ||
- Header Description: The description of the header | ||
The CSV file is generated by parsing the Observatory class for the info dictionaries | ||
and then combining them into a master dictionary. The master dictionary is then | ||
output to a CSV file. | ||
""" | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def get_info_dicts(self): | ||
descriptors = inspect.getmembers( | ||
Observatory, predicate=inspect.isdatadescriptor | ||
) | ||
info = [] | ||
for descriptor in descriptors: | ||
if "info" in descriptor[0]: | ||
info.append(descriptor) | ||
|
||
source_list = [] | ||
for descriptor in info: | ||
source_list.append(inspect.getsource(descriptor[1].fget)) | ||
|
||
# Split source into lines, remove tabs | ||
source_lines = [] | ||
for source in source_list: | ||
source_lines.append(source.split("\n")) | ||
|
||
# Remove leading whitespace | ||
stripped_lines = [] | ||
for source in source_lines: | ||
for line in source: | ||
stripped_lines.append(line.lstrip()) | ||
|
||
# Return parts of source_list that contain 'info = {...}' | ||
info_dict = [] | ||
for property in source_list: | ||
# Use regex to find info = {[^}]} and add it to info_dict | ||
info_dict.append(re.findall(r"info = {[^}]*}", property)[0]) | ||
|
||
# Remove 'info = ' from each string | ||
for i, property in enumerate(info_dict): | ||
info_dict[i] = property[7:] | ||
|
||
# Encase any references to self. in quotes | ||
for i, property in enumerate(info_dict): | ||
info_dict[i] = re.sub(r"self\.([a-zA-Z0-9_.\[\]]+)", r'"\1"', property) | ||
|
||
# Find references to str() | ||
for i, property in enumerate(info_dict): | ||
info_dict[i] = re.sub(r"(str\(([a-zA-Z\"\_\.\[\]]+)\))", r"\2", property) | ||
|
||
# Replace any references to self.etc. with None | ||
for i, property in enumerate(info_dict): | ||
# Use regex "\(\s+(.*?\],)"gm | ||
# info_dict[i] = re.sub(r'\(\\n\s+(.*?\],)', 'None', property) | ||
group = re.findall(r"\(\n\s+([\s\S]*?\],)", property) | ||
# replace the group with None | ||
if group: | ||
info_dict[i] = property.replace(group[0], "None,") | ||
|
||
# Enclose any parts with (sep="dms") in quotes | ||
for i, property in enumerate(info_dict): | ||
info_dict[i] = re.sub( | ||
r"(\"\S+\(sep=\"dms\"\))", | ||
lambda m: '"' + m.group(1).replace('"', " ") + '"', | ||
property, | ||
) | ||
|
||
# Remove any parts matching \% i(?=\)) (or replace with "") | ||
for i, property in enumerate(info_dict): | ||
info_dict[i] = re.sub(r"( \% i(?=\)))", "", property) | ||
|
||
# Enclose in quotes any parts matching 'not \"\S+\" is None' | ||
for i, property in enumerate(info_dict): | ||
info_dict[i] = re.sub( | ||
r"(not \"\S+\" is None)", | ||
lambda m: '"' + m.group(1).replace('"', " ") + '"', | ||
property, | ||
) | ||
|
||
# Pass each info_dict through ast.literal_eval to convert to dictionary | ||
info_dict_parsed = [] | ||
for info in info_dict: | ||
info_dict_parsed.append(ast.literal_eval(info)) | ||
|
||
return info_dict_parsed | ||
|
||
def generate_csv(self, filename): | ||
info_dicts = self.get_info_dicts() | ||
# Add each dictionary to make a master dictionary | ||
master_dict = {} | ||
for info in info_dicts: | ||
master_dict.update(info) | ||
# Output to csv in the format key, value, description | ||
# key is the key of the dictionary | ||
# value is the first part of the tuple (the value) | ||
# description is the second part of the tuple (the description) | ||
with open(filename, "w", newline="") as csv_file: | ||
writer = csv.writer(csv_file) | ||
# Write header | ||
writer.writerow(["Header Key", "Header Value", "Header Description"]) | ||
for key, value in master_dict.items(): | ||
writer.writerow([key, value[0], value[1]]) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Header | ||
====== | ||
|
||
This is a page listing all potential header keywords for an `Observatory` object. | ||
|
||
.. Note:: | ||
This is auto-generated from the `info` dictionaries in the `Observatory` class. Some | ||
of the information is not available for all observatories, and some header values may | ||
contain nonsense due to the auto-generation script. | ||
|
||
.. csv-table:: Sample Header | ||
:file: observatory_info.csv | ||
:widths: 4, 6, 10 | ||
:header-rows: 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ User Guide | |
:maxdepth: 2 | ||
|
||
examples | ||
header | ||
logging | ||
config | ||
help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.