def process_knmi_dayvalues_selected(): '''Function asks for one or more wmo numbers to download their data''' console.header('START DOWNLOAD STATION(S) KNMI DATA DAY VALUES...', True) done, max = 0, (stations.list) while True: places = cask.ask_for_stations('\nSelect one or more stations ? ', stations.list) if utils.is_quit(places): break st = time.time_ns() for stat in places: daydata.process_data(stat) console.log(' ', True) console.log(vt.process_time('Total processing time is ', st), True) again = cask.ask_again(f'Do you want to download more stations ?', True) if utils.is_quit(again): break console.footer('END DOWNLOAD STATION(S) KNMI DATA DAY VALUES...', True)
def ask_period_stations_type_name( name, space=False ): # Ask start and end date ok, period, places, type, name = False, '', list(), '', name # Ask for period t = f'Give the period for the calculation of {name} statistics' period = ask_for_period( t, space ) if utils.is_quit(period): return ok, period, places, type, name # Ask for one or more stations places = ask_for_stations( '\nSelect one (or more) weather station(s) ?', space ) if not places: return ok, period, places, type, name elif utils.is_quit(places): return ok, period, places, type, name # Ask for a file type type = ask_for_file_type('\nSelect output filetype ? ', config.default_output, space ) if utils.is_quit(type): return ok, period, places, type, name ok = True # Ask for a name if type != 'cmd': fname = f'{name}-{period.replace("*","x")}-{utils.now_for_file()}' fname = ask_for_file_name( '\nSet a name for the output file ? <optional> ', fname, space ) if utils.is_quit(fname): ok = False # Oke quit return ok, period, places, type, fname
def stop(): answ = ask("Exit program? \nPress 'q' to exit...", True) if answ: if utils.is_quit(answ): console.footer('Application stopped...', True ) sys.exit()
def ask_for_yn( txt, default, space=False ): ok = False t = f'{txt}\n' t += '\t1) Yes\n' t += '\t2) No' while True: answ = ask_for_txt( t, default=default, space=space ) if not answ or utils.is_empthy(answ): # 'ie. y, n, no, yes 1, 2' answ = str(default) answ = answ.lower() if utils.is_quit(answ): return config.answer_quit[0] # Return first el for quit elif utils.is_yes(answ): return config.answer_yes[0] elif utils.is_no(answ): return config.answer_no[0] else: try: answi = int(answ) except ValueError: # Input was not a number pass else: # Input is a number if answi == 1: return config.answer_yes[0] elif answi == 2: return config.answer_no[0] console.log(f'Unknown option: {answ} ?\nTry again.', True)
def ask_for_date_with_check_data( stat, txt, space=False ): console.log(f'Loading data {stat.place} ...') ok, data = daydata.read( stat ) if not ok: input(f'Error reading data! {stat.place}') return config.answer_quit[0], np.array([]) sd = int( data[ 0, daydata.YYYYMMDD]) ed = int( data[-1, daydata.YYYYMMDD]) t = f'{txt}\n' t += f'Available range data for - {stat.place} - is from {sd} untill {ed}' while True: answ = ask_for_date(t, space) if utils.is_quit(answ): return config.answer_quit[0] # Return first el for quit, np.array([]) else: try: ymd = int(answ) except Exception as e: pass else: if ymd < sd or ymd > ed: console.log(f'Date {ymd} is out of range for {stat.place}') else: return answ, data
def table_allstats(): '''Function makes calculations for all statistics''' while True: console.header('START CALCULATE ALL STATISTICS...', True) # Ask for all in one ok, period, places, type, name = cask.ask_period_stations_type_name( 'all') if not ok: break console.header(f'CALCULATING ALL STATISTICS...', True) st = time.time_ns() path = allstats.calculate(places, period, name, type) console.log(vt.process_time('Total processing time is ', st), True) if type != 'cmd': fopen = cask.ask_to_open_with_app( f'\nOpen the file (type={type}) with your default application ?' ) if fopen: fio.open_with_app(path, 2, True) # Always ask for going back again = cask.ask_again( f'\nDo you want to make another all statistics table ?') if utils.is_quit(again): break console.footer(f'END CALCULATE ALL STATISTICS...', True)
def ask_for_a_month( txt, space=False ): l = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', 'january', 'februari', 'march', 'april', 'mai', 'june', 'july', 'august', 'september', 'oktober', 'november', 'december', 'jan', 'feb', 'mar', 'apr', 'mai', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec' ] t = f'{txt}\n' t += vt.list_to_col( l, align='center', col=6, col_width='10' ) t += 'To select a month. Type in a month as above.' while True: answ = ask_for_txt( t, default=False, space=space ) if not answ or utils.is_empthy(answ): console.log('Please type in something ...', True) elif utils.is_quit(answ): res = config.answer_quit[0] # Return first el for quit break else: answ = answ.lower() if answ in l: res = vt.month_to_num( answ ) break else: ask( f'Month {answ} unknown !\nPress a key to try again...', True ) return res
def ask_for_a_day( txt, space=False ): days = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ] months = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] l = list() for i in range( len(months) ): m = months[i] mm = f'0{m}' if m < 10 else f'{m}' for d in range(1, days[m-1]+1, 1): dd = f'0{d}' if d < 10 else f'{d}' l.append( f'{mm}{dd}' ) t = f'{txt}\n' t += vt.list_to_col( l, align='left', col=14, col_width=5 ) t += 'To select a day. Type in the day as above.' while True: answ = ask_for_txt( t, default=False, space=space ) if not answ or utils.is_empthy(answ): console.log('Please type in something ...', True) elif utils.is_quit(answ): res = config.answer_quit[0] # Return first el for quit break elif answ in l: res = answ break else: ask( f'Day {answ} unknown !\nPress a key to try again...', True ) return res
def ask_for_one_station( txt, l_map=False, space=False): result = False if l_map == False: l_map = utils.only_existing_stations_in_map() # Update l if len(l_map) != 0: t = f'{txt}\n' t += vt.list_to_col(l, 'left', 3, 25) t += 'To add a station, give a wmo-number or a city name' while True: answ = ask_for_txt( t, default=False, space=space ) if utils.is_empthy(answ): console.log('Please type in something ...', True) elif utils.is_quit(answ): result = config.answer_quit[0] # Return first el for quit break elif stations.name_in_list(answ, l_map) or \ stations.wmo_in_list(answ, l_map): result = stations.find_by_wmo_or_name(answ, l_map) console.log(f'{result.wmo}: {result.place} {result.province} selected', True) break else: ask( f'Station: {answ} unknown !\nPress a key to try again...', True ) else: t = 'No weatherdata found in data map. Download weatherdata first.' console.log(t, True) return result
def ask_again(txt, space=False): t = f'{txt} Press a key...' answ = ask_for_txt( t, default=False, space=space ) if utils.is_quit(answ): return config.answer_quit[0] # Return first el for quit return answ
def ask_for_file_name(txt, default='x-x-x-x', space=False): answ = ask_for_txt( txt, default, space ) if not answ or utils.is_empthy(answ): return str(default) elif utils.is_quit(answ): return config.answer_quit[0] # Return first el for quit return answ
def ask_for_entities( txt, space=False): l, info = [], False ok, t = fio.read(utils.mk_path(config.dir_app, config.knmi_dayvalues_info_txt)) inf = f'INFO:\n{t}' if ok else f'Info file {config.knmi_dayvalues_info_txt} not found...' txt += '\n' + vt.dayvalues_entities( sep=',' ) txt += 'To add one weather entity, type in the enitity name. e.g. TX\n' txt += 'To add one more stations, give entity name separated by a comma. e.g TX, TG, TN\n' while True: t = txt t += inf if config.help_info or info else "Type 'i' for more info..." if len(l) > 0: t += "\nPress 'n' to move to the next !" answ = ask_for_txt( t, default=False, space=space ) if not answ or utils.is_empthy(answ): console.log('Please type in something ...', True) continue # Again else: answ = clear( answ ) if answ == 'i': info = True elif utils.is_quit(answ): return config.answer_quit[0] # Return first el for quit elif answ == 'n' and len(l) > 0: return l elif answ.find(',') != -1: lt = answ.split(',') for e in lt: if e: e = clear(e) # Clean input ok, ent = daydata.is_ent( e ) if ok: l.append(e) else: ok, ent = daydata.is_ent( answ ) if ok: l.append(ent) else: console.log(f"Unknown option {ent} given. Fill in one or more entities separated by an ',' ", True) if len(l) > 0: cnt, kol, t = 1, 10, 'All weather entities who are added are: ' for ent in l: t += ent + ', ' if cnt % kol == 0: t += '\n' t = t[0:-2] # Remove space and comma console.log( t, True ) return l
def year_extremes(): '''Function calculates extremes in a year''' while True: console.header('START CALCULATE EXTREMES IN A YEAR...', True) year = cask.ask_for_a_year('\nSelect a year for the extremes ? ') if utils.is_quit(year): break places = cask.ask_for_stations( '\nSelect one or more weather stations ? ') if utils.is_quit(places): break type = cask.ask_for_file_type('\nSelect output filetype ? ', cfg.default_output) if utils.is_quit(type): break fname = f'yearextremes-{year}-{utils.now_for_file()}' fname = fname.replace('*', 'x').replace(' ', '') fname = cask.ask_for_file_name( '\nGive a name for the file ? <optional>', fname) if utils.is_quit(fname): break st = time.time_ns() path = myearextremes.calculate(places, year, type, fname) console.log(vt.process_time('Total processing time is ', st), True) if type in ['text', 'html']: fopen = cask.ask_to_open_with_app( f'\nOpen the file (type={type}) with your default application ?' ) if fopen: fio.open_with_app(path) # Always ask for going back again = cask.ask_again( f'Do you want to calculate extremes for a year again ?', True) if utils.is_quit(again): break console.footer('END CALCULATE EXTREMES IN A YEAR...', True)
def ask_for_query( txt, space=False ): info = False while True: t = f'{txt}\n' t += 'For example: TX > 35\n' if config.help_info or info: t += 'Possible properties are\n' t += "' gt', '> ' = greater than ie TG > 20 Warm nights\n" t += "' ge', '>=', ' ≥' = greater than and equal ie TX >= 30 Tropical days\n" t += "' lt', '< ' = less than ie TN < 0 Frosty days\n" t += "' le', '<=', ' ≤' = less than equal ie TX <= 0 Icy days\n" t += "' eq', '==' = equal ie DDVEC == 90 A day with a wind from the east\n" t += "' ne', '!=', '<>' = not equal ie RH != 0 A day with rain\n" t += "' or', '||' 'or ' ie SQ > 10 or TX >= 25 Sunny and warm days\n" t += "'and', '&&' 'and' ie RH > 10 and TX < 0 Most propably a day with snow\n" t += '\nPossible entities are\n' t += "'DDVEC' = Vector mean wind direction (degrees) 'FHVEC' = Vector mean windspeed (m/s)\n" t += "'FG' = Daily mean windspeed (in 0.1 m/s) 'FHX' = Maximum hourly mean windspeed (m/s)\n" t += "'FHN' = Minimum hourly mean windspeed (m/s) 'FXX' = Maximum wind gust (m/s)\n" t += "'TG' = Daily mean temperature in (°C) 'TN' = Minimum temperature (°C)\n" t += "'TX' = Maximum temperature (°C) 'T10N' = Minimum temperature at 10 cm (°C)\n" t += "'SQ' = Sunshine duration (hour) 'SP' = % of maximum sunshine duration\n" t += "'Q' = Global radiation (J/cm2) 'DR' = Precipitation duration (hour)\n" t += "'RH' = Daily precipitation amount (mm) 'RHX' = Maximum hourly precipitation (mm)\n" t += "'PG' = Daily mean sea level pressure (hPa) 'PX' = Maximum hourly sea level pressure (hPa)\n" t += "'PN' = Minimum hourly sea level pressure (hPa) 'EV24' = Potential evapotranspiration (mm)\n" t += "'VVN' = Minimum visibility 0: <100m, 1:100-200m, 2:200-300m,..., 49:4900-5000m, 50:5-6 km, \n" t += ' 56:6-7km, 57:7-8km,..., 79:29-30km, 80:30-35km, 81:35-40km,..., 89: >70km)\n' t += "'VVX' = Maximum visibility 0: <100 m, 1:100-200 m, 2:200-300 m,..., 49:4900-5000 m, 50:5-6 km, \n" t += ' 56:6-7km, 57:7-8km,..., 79:29-30km, 80:30-35km, 81:35-40km,..., 89: >70km)\n' t += "'NG' = Mean daily cloud cover (octants) 'UG' = Daily mean relative atmospheric humidity (%)\n" t += "'UX' = Maximum atmospheric humidity (%) 'UN' = Minimum relative atmospheric humidity (%)" else: t += "Type 'i' for more info..." answ = ask_for_txt( t, default=False, space=space ) # TODO MAKE ADVANCED CHECKS if not answ or utils.is_empthy(answ): console.log('Please type in something ...', True) elif answ == 'i': info = True elif utils.is_quit(answ): return config.answer_quit[0] # Return first el for quit # TODO # elif validate.query(answ): # TODO # return answ else: return utils.make_query_txt_only( answ ) return answ # No checking for now
def ask_for_date( txt, space=False): while True: answ = ask_for_txt( txt, default=False, space=space ) if not answ or utils.is_empthy(answ): console.log('Please type in something ...', True) continue elif utils.is_quit(answ): answ = config.answer_quit[0] # Return first el for quit break elif validate.yyyymmdd(answ): break else: console.log(f'Error in date: {answ}\n', True) return answ
def ask_for_period( txt='', space=False ): info = False while True: t= f'{txt} \n' t += 'Period start - end \n' t += 'Default format yyyymmdd-yyyymmdd \n' t += 'For example: 20200510-20200520 \n' if config.help_info or info: t += 'Formats with a wild card * \n' t += ' --- still in development --- \n' t += ' ******** selects all the available data (=8x*)\n' t += ' **** selects (current) year (=4x*)\n' t += ' ** selects (current) month (=2x*)\n' t += ' yyyy**** selects the whole year yyyy\n' t += ' yyyymm** selects the month mm in the year yyyy\n' t += ' ****mm** selects a month mm for every year \n' t += ' ****mmdd selects a monthday mmdd for every year \n' t += ' yyyy****-yyyy**** selects a full year from yyyy untill yyyy \n' t += ' yyyymmdd-yyyy*mmdd selects a day mmdd in a year from start day to endyear\n' t += ' yyyymmdd-yyyy*mmdd* selects a certain period from mmdd=mmdd* in a year from yyyy to yyyy\n' t += 'Examples wildcard * \n' t += ' 2015**** selects the year 2015 \n' t += ' 201101**-202001** selects all januarys from 2011 unto 2020 \n' t += ' ****07** selects all julys from avalaible data \n' t += ' ****1225 selects all 25 decembers from avalaible data' else: t+= "Type 'i' for more info..." answ = ask_for_txt( t, default=False, space=space ) if not answ or utils.is_empthy(answ): console.log('\nPlease type in something...\n', True) elif utils.is_quit(answ): answ = config.answer_quit[0] # Return first el for quit break elif answ == 'i': info = True else: if daydata.check_periode( answ ): # TODO answ = answ.replace(' ', '') break else: err = f'Period of format {answ} is unknown... Press a key... ' ask(err) return answ
def search_for_days(): '''Function searches files for days with specific values. ie > 30 degrees''' while True: console.header('START SEARCHING FOR SPECIFIC DAYS...', True) period = cask.ask_for_period( '\nFor which time periode do you want to search ? ') if utils.is_quit(period): break places = cask.ask_for_stations( '\nSelect one or more weather stations ?') if not places: cask.ask_back_to_main_menu() break elif utils.is_quit(places): break query = cask.ask_for_query('\nType in a query for selecting days ? ') if utils.is_quit(query): break type = cask.ask_for_file_type('\nSelect output filetype ? ', cfg.default_output) if utils.is_quit(type): break fname = f'days-{utils.make_query_txt_only(query)}-{period}-{utils.now_for_file()}' fname = fname.replace('*', 'x').replace(' ', '') fname = cask.ask_for_file_name( '\nGive a name for the file ? <optional>', fname) if utils.is_quit(fname): break st = time.time_ns() path = search4days.calculate(places, period, query, type, fname) console.log(vt.process_time('Total processing time is ', st), True) if type in ['text', 'html']: fopen = cask.ask_to_open_with_app( f'\nOpen the file (type={type}) with your default application ?' ) if fopen: fio.open_with_app(path, 2, True) # Always ask for going back again = cask.ask_again(f'Do you want to search for days again ?', True) if utils.is_quit(again): break console.footer('END SEARCH FOR DAYS...', True)
def get_dayvalues_by_date(): '''Funtion gets day values from data knmi ''' while True: console.header('START: SEARCHING AND PREPARING DAY VALUES...', True) # Ask for station places = cask.ask_for_stations( '\nSelect one or more weather stations ?') # QUESTION: # QUESTION: if not places: break elif utils.is_quit(places): break period = cask.ask_for_period( '\nSelect one date or period(s) for the dayvalues ? ') if utils.is_quit(period): break type = cask.ask_for_file_type('\nSelect output filetype ? ', cfg.default_output) if utils.is_quit(type): break download = cask.ask_for_yn( '\nDo you want to download the data first ?', 'no') if utils.is_quit(download): break download = True if utils.is_yes(download) else False check = cask.ask_type_options( '\nDo you want to add only new files or rewrite it all ? ', ['add', 'rewrite'], 'add') if utils.is_quit(check): break console.log('CHECK-1: ' + str(check)) check = True if check == 'add' else False console.log('CHECK-2: ' + str(check)) st = time.time_ns() path = mdayval.calculate(places, period, type, check, download) console.log(vt.process_time('Total processing time is ', st), True) fopen = cask.ask_to_open_with_app( f'\nOpen the (last made) file (type={type}) with your default application ?' ) if fopen: fio.open_with_app(path) # Always ask for going back t = f'\nDo you want to select another period(s) and or station(s) ?' again = cask.ask_again(t) if utils.is_quit(again): break console.footer('END SEARCHING AND PREPARING DAY VALUES...', True)
def ask_for_int(txt, default=False, space=False): if space: console.log(' ', space) while True: answ = ask_for_txt(txt, default, space) if utils.is_empthy(answ): answ = default break elif utils.is_quit(answ): answ = config.answer_quit[0] # Return first el for quit break else: answ = re.sub( '\D', '', answ ) # Remove non-digits try: answ = int(answ) except ValueError: console.log('Give an real integer...', True) continue else: break if space: console.log(' ', space) return answ
def month_extremes(): '''Function calculates extremes in a month in''' while True: console.header('START CALCULATE EXTREMES IN A MONTH...', True) month = cask.ask_for_a_month( '\nFor which month do you want to calculate the extremes ? ') if utils.is_quit(month): break period = cask.ask_for_period( f'\nFor what time periode do you want to caculate the extremes in the month {month} ? ' ) if utils.is_quit(period): break places = cask.ask_for_stations( '\nSelect one or more weather stations ? ') if utils.is_quit(places): break type = cask.ask_for_file_type('\nSelect output filetype ? ', cfg.default_output) if utils.is_quit(type): break fname = f'monthextremes-{month}-{period}-{utils.now_for_file()}' fname = fname.replace('*', 'x').replace(' ', '') fname = cask.ask_for_file_name( '\nGive a name for the file ? <optional>', fname) if utils.is_quit(fname): break st = time.time_ns() path = mmonthextremes.calculate(places, period, month, type, fname) console.log(vt.process_time('Total processing time is ', st), True) if type in ['text', 'html']: fopen = cask.ask_to_open_with_app( f'\nOpen the file (type={type}) with your default application ?' ) if fopen: fio.open_with_app(path, 2, True) # Always ask for going back again = cask.ask_again( f'Do you want to calculate extremes for a month again ?', True) if utils.is_quit(again): break console.footer('END CALCULATE EXTREMES IN A MONTH...', True)
def ask_type_options(txt, l, default=config.default_output, space=False): t = f'{txt}\n' i, max = 1, len(l) while True: t += f'\t{i}) {l[i-1]}' if i < max: i, t = i + 1, t + '\n' else: break while True: answ = ask_for_txt( t, default=default, space=space ) if not answ or utils.is_empthy(answ): i = 0 while i < max: if l[i] == default: return default elif str(i) == str(default): return l[i] i += 1 if utils.is_quit(answ): return config.answer_quit[0] # Return first el for quit else: try: answi = int(answ) except ValueError: # Input is not a number if answ in l: return answ else: # Input is a number i = 0 while i < max: if i + 1 == answi: return l[i] i += 1 console.log(f'Unknown option: {answ} ?\nTry again.', True)
def ask_for_stations( txt, l_map=False, space=False): result = list() if l_map == False: l_map = utils.only_existing_stations_in_map() # Update l cnt_map = len(l_map) if cnt_map > 0: l = [f'{el.wmo} {el.place}' for el in l_map] t = f'{txt}\n' t += vt.list_to_col( l, 'left', 4, 23 ) t += 'To add one station, give a wmo-number or a city name\n' t += 'To add more stations, give a wmo-number or a city name separated by a comma\n' t += "Press '*' to add all available weather stations" while True: ask_txt = t cnt_result = len(result) if cnt_result > 0: ask_txt += "\nPress 'n' to move to the next !" answ = ask_for_txt( ask_txt + '\n', default=False, space=space ) if not answ or utils.is_empthy(answ): console.log('Please type in something ...', True) elif utils.is_quit(answ): result = config.answer_quit[0] # Return first el for quit break elif answ == '*': result = l_map break elif answ == 'n' and cnt_result > 0: break else: ll = list() # Make a list with stations if answ.find(',') != -1: ll = [clear(e) for e in answ.split(',')] # Clean input else: if stations.name_in_list(answ, l_map): ll.append(answ) elif stations.wmo_in_list(answ, l_map): ll.append(answ) else: console.log(f'Station: {answ} is unknown !') # Add all added stations for s in ll: st = stations.find_by_wmo_or_name(s, l_map) if st != False: all = f'{st.wmo} {st.place} {st.province}' if stations.check_if_station_already_in_list( st, result ) != True: result.append(st) console.log(f'Station: {all} added...') else: console.log(f'Station: {all} already added...') else: console.log(f'Station: {answ} not found...') cnt_result = len(result) # New count if cnt_result == cnt_map: console.log('\nAll available weatherstations added...', True) break elif cnt_result > 0: console.log('\nAll weatherstation(s) who are added are: ', True) for s in result: console.log(f'{s.wmo}: {s.place} {s.province}', True) else: t = 'No weatherdata found in data map. Download weatherdata first.' console.log(t, True) result = False return result
def graph_period(): '''Funtion makes images for a period from the data of the knmi''' while True: console.header('START MAKING A IMAGE GRAPH...', True) period = cask.ask_for_period('What time periode ?') if utils.is_quit(period): break places = cask.ask_for_stations('\nSelect weather station(s) ?') if not places: cask.ask_back_to_main_menu() break elif utils.is_quit(places): break entities = cask.ask_for_entities('\nSelect weather entity(s) ?') if utils.is_quit(entities): break ent_type_graphs = list() for ent in entities: ent_type = ent.upper() # Set to none or defaults graph_type = cfg.plot_graph_type line_width = cfg.plot_line_width marker_size = cfg.plot_marker_size marker_text = cfg.plot_marker_txt min_max_ave_period = cfg.plot_min_max_ave_period climate_ave = cfg.plot_climate_ave climate_ave_marker_txt = cfg.plot_climate_marker_txt climate_periode = cfg.climate_period graph_type = cask.ask_type_options( f'\nWhich type graph do you want to use for {ent_type} ? ', ['line', 'bar'], cfg.plot_graph_type) if utils.is_quit(graph_type): break break if graph_type == 'line': # TODO MAKE OPTIONS FOR EACH ENTITIY COLOR OPTIONS line_width = cask.ask_for_int( f'\nSet the width of the line (in pixels) for {ent_type} ? ', cfg.plot_line_width) # Width line if utils.is_quit(line_width): break break marker_size = cask.ask_for_int( f'\nSet the marker size (in pixels) for {ent_type} ? ', cfg.plot_marker_size) # Dot sizes on day if utils.is_quit(marker_size): break break marker_txt = cask.ask_for_yn( f'\nValues next to the markers for {ent_type} ? ', cfg.plot_marker_txt) if utils.is_quit(marker_txt): break break min_max_ave_period = cask.ask_for_yn( '\nCalculate min, max and average value in period too ? ', cfg.plot_min_max_ave_period) if utils.is_quit(min_max_ave_period): break break climate_ave = cask.ask_for_yn( f'\nCalculate and plot the climate averages for {ent_type} ? ', cfg.plot_climate_ave) if utils.is_quit(climate_ave): break break if utils.is_yes(climate_ave): climate_ave_marker_txt = cask.ask_for_yn( f'\nValues next to the markers for climate averages for {ent_type} ? ', cfg.plot_climate_marker_txt) if utils.is_quit(climate_ave_marker_txt): break break sy, ey = cfg.climate_period.split('-') climate_y_s = cask.ask_for_int( f'\nGive a start year for the calculation of climate averages <yyyy> for {ent_type} ? ', sy) if utils.is_quit(climate_y_s): break break climate_y_e = cask.ask_for_int( f'\nGive an end year for the calculation of climate average <yyyy> for {ent_type} ? ', ey) if utils.is_quit(climate_y_e): break break climate_periode = f'{climate_y_s}-{climate_y_e}' ent_type_graphs.append([ ent_type, graph_type, line_width, marker_size, marker_text, min_max_ave_period, climate_ave, climate_ave_marker_txt, climate_periode ]) console.log('Fill in the parameters for the image', False) title = cask.ask_for_txt('\nGive a title for the graph') ylabel = cask.ask_for_txt('\nGive a y-as label for the graph') default = cask.ask_for_yn( '\nDo you want to use default values ?\nSee file -> config.py...', cfg.plot_default) if utils.is_quit(default): break # Make option list options = { 'plot_width': cfg.plot_width, 'plot_height': cfg.plot_height, 'plot_cummul_val': cfg.plot_cummul_val, 'plot_image_type': cfg.plot_image_type, 'plot_dpi': cfg.plot_dpi } if utils.is_no(default): # Update option list plot_width = cask.ask_for_int( '\nGive the width (in pixels) for the graph.', cfg.plot_width) if utils.is_quit(plot_width): break else: options['plot_width'] = plot_width plot_height = cask.ask_for_int( '\nGive the height (in pixels) for the graph.', cfg.plot_height) if utils.is_quit(plot_height): break else: options['plot_height'] = plot_height plot_cummul_val = cask.ask_for_yn( '\nDo you want cummulative values for the graph ? ', cfg.plot_cummul_val) if utils.is_quit(plot_cummul_val): break else: options[ 'plot_cummul_val'] = plot_cummul_val # Take first yess or no plot_image_type = cask.ask_type_options( '\nWhat type of image ? ', ['png', 'jpg', 'ps', 'pdf', 'svg'], cfg.plot_image_type) if utils.is_quit(plot_image_type): break else: options['plot_image_type'] = plot_image_type plot_dpi = cask.ask_for_int('\nGive the dpi ? ', cfg.plot_dpi) if utils.is_quit(plot_dpi): break else: options['plot_dpi'] = plot_dpi fname = f"graph-{period.replace('*', 'x')}-{utils.now_for_file()}" fname = cask.ask_for_file_name('\nGive a name for the file ? ', fname) if utils.is_quit(fname): break console.header('PREPARING IMAGES...', True) st = time.time_ns() path = vg.plot(places, ent_type_graphs, period, title, ylabel, fname, options) console.log(vt.process_time('Total processing time is ', st), True) fopen = cask.ask_to_open_with_app( f'\nOpen the file (type={options["plot_image_type"]}) with your default application ?' ) if fopen: fio.open_with_app(path) # Always ask for going back again = cask.ask_again(f'\nDo you want to make more images ?') if utils.is_quit(again): break console.footer('END MAKING A IMAGE GRAPH...', True)