def extract(self, log_file_path: Path) -> None: '''Extract one or more plots from a log file.''' # define the output from a single plot; a log file may contain more than # one plot plot_begin = r'Starting plotting progress (.+?)' plot_end = r'Renamed final file' pattern = plot_begin + plot_end if log_file_path in self._files: return with open(log_file_path, 'r') as f: log_data = f.read() data_replace = log_data.replace('\n', ' ') plots = re.findall(pattern, data_replace) self._config.logger.debug(f'number of plots {len(plots)}') # process each plot in the log file for index, result in enumerate(plots, 1): self._config.logger.debug(f'results len {len(result)}') plot = Plot(self._config, log_file_path, index) if plot.extract(result): plot_id = plot.parameters.plot_id if plot_id not in self._plot_ids: self._plots.append(plot) self._plot_ids.append(plot_id) self._files.append(log_file_path)
def create_widgets(self): self.lid = Lid(self) self.com = Com(self) self.log = Log(self) self.lpg_meter = Meter('A', self) self.co_meter = Meter('B', self) self.lpg_plot = Plot('A', self) self.co_plot = Plot('B', self)
def __init__(self, x, y, model): self.__x = x self.__y = y self.__model = model #Creating status plot widget rectPlot[Constants.X] = rectPlot[Constants.X] + self.__x + Constants.SIDE_MENU_TEXT_LEFT_MARGIN rectPlot[Constants.Y] = rectPlot[Constants.Y] + self.__y plotStatusStyle = dict(plotGenericStyle) plotStatusStyle['rect'] = pygame.Rect(rectPlot) self.__plotStatus = Plot(plotStatusStyle) # We get the initial data to populate the screen self.getData()
def main(choice): try: assert LooseVersion(tf.__version__) in [LooseVersion('1.0.0'), LooseVersion( '1.0.1')], 'This project requires TensorFlow version 1.0 You are using {}' \ .format(tf.__version__) print('TensorFlow Version: {}'.format(tf.__version__)) print('*****Author: Satyaki Sanyal*****') print('***This project must only be used for educational purpose***') if choice == 1: if not tf.test.gpu_device_name(): print('*** ERROR: No GPU found. Please use a GPU to train your neural network. ***') else: print('Default GPU Device: {}'.format(tf.test.gpu_device_name())) Main().main() elif choice == 2: Translate().translate() elif choice == 3: Plot().plot() else: print('*** Error: Wrong choice ***') except Exception as exc: print('*** Error: ' + str(exc) + ' ***')
def main(): while True: try: ip = int( input( 'Enter 1. to analyse tweets, 2. to visualise tweets, 3. Exit \n>> ' )) if ip == 1: from src import twitter elif ip == 2: Plot.plot() elif ip == 3: print('*** Thank you ***') break else: print('*** Input not recognized. Try Again! ***') except Exception as e: print('***** EXCEPTION FACED: ' + str(e) + ' *****')
def create_plot(self, filename): """ This method does the following (which is too much): 1. Update the DB to "in progress" (not done) 2. Verify that the file exist in GCS (not done) 3. Download the file from GCS. 4. Do convertion from json file to packets. 5. Plot per packet. 6. Upload plots to a new bucket (we will use the only bucket I have with a dirname of the json file for all of it's packet plots). 7. Update the DB to "success" (not done) Also need to update the DB to "fail" if any other step failed (not done) @note: need to send data to SQL DB upon start (in progress) and change it to in_progress / success / failed later. I did not get any open DB in GCP so this part will not be done! @note: need to return status and failed parts of the process: file or problematic packets, depands on the implementation of the the TODOs """ download_source_file = BACKET_PREFIX.format(filename) download_destination_file = os.path.join(LOCAL_PLOT_DIRECTORY, filename) # Download file from GCS json_file = storage_client.download(download_source_file, download_destination_file) # Get packets packets = iter(json_to_packets(json_file)) # Create plot from packets # TODO: @oran - we need to send each packet or batch of packets to other services to # deal with big files or we might have mem issues - I used iter above but it should # have been done in the helpers.py and not in the above line - too late!. # Let's assume it's ok for a POC. is_success, plots_dir = Plot(LOCAL_PLOT_DIRECTORY).create_plots( json_file, packets) if not is_success: logger.warning( 'Not all packets where successfuly parsed in this file: %s', filename) # Zipping the directory # TOOD: @oran - what happends if one package is corrupted? - need to deal with this case: # either fail all or return the problematic package. # (I prefer to fail it with a good log) - we should have all the failed processes in # the db, so we can add another script to scan and fix them or decide what to do with # them if we can't fix them. For example a status api would have easily helped us to # write code to deal with this issue with some logic. upload_source_file = ziper.zipdir(plots_dir) # Uploading file to GCS upload_destination_file = os.path.join( BACKET_PREFIX_PLOTS.format(upload_source_file), BACKET_PREFIX.format(filename)) storage_client.upload(upload_source_file, upload_destination_file)
class StatisticsView(object): def __init__(self, x, y, model): self.__x = x self.__y = y self.__model = model #Creating status plot widget rectPlot[Constants.X] = rectPlot[Constants.X] + self.__x + Constants.SIDE_MENU_TEXT_LEFT_MARGIN rectPlot[Constants.Y] = rectPlot[Constants.Y] + self.__y plotStatusStyle = dict(plotGenericStyle) plotStatusStyle['rect'] = pygame.Rect(rectPlot) self.__plotStatus = Plot(plotStatusStyle) # We get the initial data to populate the screen self.getData() def getData(self): self.__model.getLast7DaysPrs(self.update) def update(self, data): self.__plotStatus.update(data) def draw(self, mainSurface, visible): self.__plotStatus.draw(mainSurface, visible) def clean(self): self.__plotStatus.clean()
def plot_custom(curves=None, points=None, ax=None, T_unit='K', P_unit='Pa', scale_log=True, legend=True, title=True, title_text=''): """ Allow the creation of a custom plot Parameters ---------- curves : tuple tuple with two arrays (x array, y array) with pint units points : tuple tuple with two values (x value, y value) with pint units ax : matplotlib axis, optional axis where the plot will be shown. If None, one will be created T_unit : str pint unit of the temperature P_unit : str pint unit of the pressure scale_log : bool, default=True if the y-axis will have a log scale legend : bool, default=True if a legend will be shown title : bool, default=True if the plot will have a title title_text : str, default='' title text """ if ax is None: fig, ax = plt.subplots(figsize=(10, 8), facecolor=(1.0, 1.0, 1.0)) ax.set_axisbelow(True) graph = Plot(ax=ax, x_label='Temperature', y_label='Pressure', x_unit=T_unit, y_unit=P_unit, legend=legend, scale_log=scale_log, title=title, title_text=title_text) if curves: for curve in curves: graph.plot_arrays(curve['data_tuple'], label=curve['label'], **curve['kwargs']) if points: for point in points: graph.plot_point(point['data_tuple'], label=point['label'], **point['kwargs'])
def plot(self, ax=None, T_unit='K', P_unit='Pa', scale_log=True, legend=True, title=True, title_text='', clapeyron_lv=False, points=True): """ Plots the phase diagram Parameters ---------- ax : matplotlib axis, optional axis where the plot will be shown. If None, one will be created T_unit : str pint unit of the temperature P_unit : str pint unit of the pressure scale_log : bool, default=True if the y-axis will have a log scale legend : bool, default=True if a legend will be shown title : bool, default=True if the plot will have a title title_text : str, default='' title text clapeyron_lv : bool, default=False if the Clapeyron liquid-vapour curve will be plotted along the Antoine one points: bool, default=True if Triple Point and Critical Point will be shown """ if ax is None: fig, ax = plt.subplots(figsize=(10, 8), facecolor=(1.0, 1.0, 1.0)) ax.set_axisbelow(True) if title_text == '': title_text = f'Calculated phase diagram - {self.format_formula()}' graph = Plot(ax=ax, x_label='Temperature', y_label='Pressure', x_unit=T_unit, y_unit=P_unit, legend=legend, scale_log=scale_log, title=title, title_text=title_text) linewidth = 3 marker_size = 100 graph.plot_arrays(self.clapeyron_sl(), limit=self.critical_point.pressure, label='Clapeyron S-L', linewidth=linewidth, zorder=1) graph.plot_arrays(self.clapeyron_sv(), label='Clapeyron S-V', linewidth=linewidth, zorder=1) graph.plot_arrays(self.antoine_lv(), label='Antoine L-V', linewidth=linewidth, zorder=1) if clapeyron_lv: graph.plot_arrays(self.clapeyron_lv(), label='Clapeyron L-V', linewidth=linewidth, linestyle='--', zorder=1) if points: graph.plot_point(self.triple_point, label='Triple Point', color='red', s=marker_size, zorder=2) graph.plot_point(self.critical_point, label='Critical Point', color='purple', s=marker_size, zorder=2)
#!/usr/bin/python from src.functions import Functions from src.constants import Constants from src.algorithm import Algorithm from src.plot import Plot # testine animacija Constants.n = 10 Constants.tau = 0.01 u_initial = Functions.u_exact_range(0) func_points, time_points = Algorithm.run(u_initial) p = Plot() p.set_data(func_points, time_points) p.animate(5.0)
data = { 'hdi': os.path.join(data_dir, 'hdi.xlsx'), 'gdp': os.path.join(data_dir, 'gdp.xlsx'), 'mortality': os.path.join(data_dir, 'mortality_rates.xlsx'), 'incidence': os.path.join(data_dir, 'incidence_rates.xlsx'), 'hdi_vs_gdp': os.path.join(data_dir, 'hdi_vs_gdp.xlsx') } target_columns = { 'hdi': 'HDI', 'incidence': 'Incidence Rate', 'mortality': 'Mortality Rate', 'gdp': 'GDP per capita' } plots = { key: Plot(value, target_columns.get(key)) for key, value in data.items() } features_options = [{ 'label': 'GDP per capita', 'value': 'gdp' }, { 'label': 'HDI', 'value': 'hdi' }, { 'label': 'Mortality Rate', 'value': 'mortality' }] countries_options = [{ 'label': 'Oman',