def test_latest_cocos(self): from omas.omas_utils import list_structures, omas_rcparams from omas.omas_physics import generate_cocos_signals with warnings.catch_warnings(): warnings.filterwarnings("ignore", message=".*defining its COCOS transform.*") generate_cocos_signals(list_structures( imas_version=omas_rcparams['default_imas_version']), threshold=0, write=False, verbose=False)
def extract_coordinates(imas_version=omas_rcparams['default_imas_version']): ''' return list of strings with coordinates across all structures :param imas_version: imas version :return: list with coordinate ''' from omas.omas_utils import list_structures from omas.omas_utils import load_structure omas_coordinates = set() for structure in list_structures(imas_version=imas_version): tmp = load_structure(structure, imas_version)[0] coords = [] for item in tmp: if 'coordinates' in tmp[item]: coords.extend(map(i2o, tmp[item]['coordinates'])) coords = list(filter(lambda x: '...' not in x, set(coords))) omas_coordinates.update(coords) return sorted(list(omas_coordinates))
''' Utility to generate the omas/omas_cocos.py file ''' import os, sys sys.path.insert( 0, os.path.split( os.path.split(os.path.split(os.path.abspath(__file__))[0])[0])[0]) from omas.omas_utils import list_structures, omas_rcparams from omas.omas_physics import generate_cocos_signals generate_cocos_signals( list_structures(imas_version=omas_rcparams['default_imas_version']), threshold=0, write=True)
def create_html_documentation( imas_version=omas_rcparams['default_imas_version']): filename = os.path.abspath( os.sep.join([ imas_json_dir, imas_versions.get(imas_version, imas_version), 'omas_doc.html' ])) table_header = "<table border=1, width='100%'>" sub_table_header = '<tr>' \ '<th style="width:25%">Path</th>' \ '<th style="width:25%">Dimensions</th>' \ '<th>Type</th>' \ '<th>Units</th>' \ '<th>Description</th>' \ '</tr>' column_style = 'style="word-wrap:break-word;word-break:break-all"' lines = [] for structure_file in list_structures(imas_version=imas_version): print('Adding to html documentation: ' + structure_file) # load structure information structure = load_structure(structure_file, imas_version=imas_version)[0] # idenfity coordinates in the structure coords = [] for item in structure: if 'coordinates' in structure[item]: coords.extend(structure[item]['coordinates']) coords = list(filter(lambda x: '...' not in x, set(coords))) # generate output lines.append('<!-- %s -->' % structure_file) lines.append(table_header) lines.append(sub_table_header) for item in sorted(structure): if not any([ item.endswith(k) for k in ['_error_index', '_error_lower', '_error_upper'] ]): # uncertain quantities is_uncertain = '' if item + '_error_upper' in structure: is_uncertain = ' (uncertain)' # lifecycle status status = '' if 'lifecycle_status' in structure[item] and structure[item][ 'lifecycle_status'] not in ['active']: color_mapper = {'alpha': 'blue', 'obsolescent': 'red'} status = '</p><p><font color="%s">(%s)</font>' % ( color_mapper.get( structure[item]['lifecycle_status'], 'orange'), structure[item]['lifecycle_status']) # highlight entries that are a coordinate item_with_coordinate_highlight = item if item in coords: item_with_coordinate_highlight = '<strong>%s</strong>' % item try: lines.append( '<tr>' '<td {column_style}><p>{item_with_coordinate_highlight}{status}</p></td>' \ '<td {column_style}><p>{coordinates}</p></td>' \ '<td><p>{data_type}</p></td>' \ '<td><p>{units}</p></td>' \ '<td><p>{description}</p></td>' '</tr>'.format( item_with_coordinate_highlight=item_with_coordinate_highlight, coordinates=re.sub('\[\]', '', re.sub('[\'\"]', '', re.sub(',', ',<br>', str( list(map(str, structure[item].get('coordinates', ''))))))), data_type=structure[item].get('data_type', '') + is_uncertain, units=structure[item].get('units', ''), description=re.sub('\n', '<br>', structure[item].get('documentation', '')), status=status, column_style=column_style )) except Exception: printe(item) raise lines.append('</table>') lines.append('</table><p></p>') with open(filename, 'w') as f: if sys.version_info < (3, 0): f.write('\n'.join(lines).encode('utf-8')) else: f.write('\n'.join(lines))
''' Utility to generate the omas/omas_cocos.py file ''' from omas.omas_utils import list_structures, omas_rcparams from omas.omas_physics import generate_cocos_signals generate_cocos_signals(list_structures(imas_version=omas_rcparams['default_imas_version']), threshold=0, write=True)