示例#1
0
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)
示例#2
0
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)
示例#3
0
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)
示例#4
0
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)
示例#5
0
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)
示例#6
0
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)
示例#7
0
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)