예제 #1
0
def _get_data( msa_or_conus_name ):
    if msa_or_conus_name.lower( ) == 'conus':
        data_conus = COVID19Database.data_conus( )
        return core.get_incident_data( data_conus )
    if msa_or_conus_name.lower( ) in COVID19Database.data_msas_2019( ):
        data_msas_2019 = COVID19Database.data_msas_2019( )
        return core.get_incident_data( data_msas_2019[ msa_or_conus_name.lower( ) ] )
    raise ValueError("Error, the chosen MSA name %s not one of the %d defined." % (
        msa_or_conus_name.lower( ), len( COVID19Database.data_msas_2019( ) ) ) )
예제 #2
0
def _get_data_state_or_territory( statename ):
    mapping_state_rname_conus = COVID19Database.mapping_state_rname_conus( )
    mapping_state_rname_nonconus = COVID19Database.mapping_state_rname_nonconus( )
    data_states = COVID19Database.data_states( )
    data_nonconus_states_territories = COVID19Database.data_nonconus_states_territories( )
    if statename in mapping_state_rname_conus:
        data_state = data_states[
            mapping_state_rname_conus[ statename ] ]
        return core.get_incident_data( data_state )
    if statename in mapping_state_rname_nonconus:
        data_state = data_nonconus_states_territories[
            mapping_state_rname_nonconus[ statename ] ]
        return core.get_incident_data( data_state )
    raise ValueError("Error, the chosen state or territory, %s, not in one of the %d defined." % (
        statename, len( mapping_state_rname_conus ) + len( mapping_state_rname_nonconus ) ) )
예제 #3
0
def main():
    all_state_territory_choices = sorted(
        chain.from_iterable(
            map(lambda arr: arr.keys(),
                (COVID19Database.mapping_state_rname_conus(),
                 COVID19Database.mapping_state_rname_nonconus()))))

    parser = ArgumentParser()
    parser.add_argument(
        '-d',
        '--dirname',
        dest='dirname',
        type=str,
        action='store',
        default=os.getcwd(),
        help=
        'The directory into which to store the resulting files. Default is %s.'
        % os.getcwd())
    parser.add_argument(
        '--info',
        dest='do_info',
        action='store_true',
        default=False,
        help='If chosen, then print out INFO level logging statements.')
    parser.add_argument(
        '-n',
        dest='name',
        type=str,
        action='store',
        default='New York',
        help=
        'Make movies or other summary data for a state. Default is "New York".',
        choices=all_state_territory_choices)
    parser.add_argument(
        '-M',
        '--maxnum',
        dest='maxnum',
        type=int,
        action='store',
        default=None,
        metavar='MAXNUM',
        help=' '.join([
            'The limit of cases/deaths to visualize.',
            'Default is a plausible amount for the chosen state.',
            'You should use a limit larger (by at least 2, no more than 10) than',
            'the maximum number of cases recorded for a county in that state.'
        ]))
    parser.add_argument('-y',
                        '--yes',
                        dest='do_yes',
                        action='store_true',
                        default=False,
                        help='If chosen, then do not confirm --maxnum.')
    #
    subparsers = parser.add_subparsers(help=' '.join([
        'Choose one of three options:',
        '(m) make a movie of the COVID-19 cumulative stats for the state;',
        '(s) dumps summary plots of last incident date,',
        'and cumulative covid-19 stats, of a state;',
        'and (mcd) make a movie of either "CASES" or "DEATHS" in the state.'
    ]),
                                       dest='choose_option')
    #
    ## make summary movie (m)
    parser_moviestate = subparsers.add_parser(
        'm',
        help=
        'Make a movie of the COVID-19 cases and deaths trend for the specific state.'
    )
    #
    ## make summary plots of last day, and COVID-19 cases/deaths in pandas dataframe up to last day.
    parser_sumstate = subparsers.add_parser(
        's',
        help=' '.join([
            'Make a summary plot, and incident data file,',
            'of COVID-19 cases and deaths trend,', 'for the specific state.'
        ]))
    #
    ## make a movie of cases OR deaths (mcd)
    parser_movcasedeath = subparsers.add_parser(
        'mcd',
        help=
        'Make a large-sized movie of either "CASES" or "DEATHS" for given state.'
    )
    parser_movcasedeath.add_argument(
        '-d',
        '--disp',
        dest='movcasedeath_display',
        type=str,
        action='store',
        default='cases',
        metavar='DISP',
        choices=('cases', 'deaths'),
        help=
        'Whether to display the "cases" or "death" trends of the given state. Default is "cases".'
    )
    parser_movcasedeath.add_argument(
        '-s',
        '--saveimages',
        dest='movcasedeath_saveimages',
        action='store_true',
        default=False,
        help=
        'If chosen, then save the images used to create the movie into a ZIP archive.'
    )
    #
    ##
    args = parser.parse_args()
    logger = logging.getLogger()
    if args.do_info: logger.setLevel(logging.INFO)
    statename = args.name.strip()
    mapping_state_rname_conus = COVID19Database.mapping_state_rname_conus()
    mapping_state_rname_nonconus = COVID19Database.mapping_state_rname_nonconus(
    )
    data_states = COVID19Database.data_states()
    data_nonconus_states_territories = COVID19Database.data_nonconus_states_territories(
    )
    if statename in mapping_state_rname_conus:
        data_state = data_states[mapping_state_rname_conus[statename]]
    else:
        data_state = data_nonconus_states_territories[
            mapping_state_rname_nonconus[statename]]

    inc_data = core.get_incident_data(data_state)
    maxnum = args.maxnum
    if maxnum is None:
        max_cases = core.get_max_cases_county(inc_data)['cases']
        maxnum = find_plausible_maxnum(max_cases)
    if maxnum < 1:
        print('Error, maximum number for visualization %d < 1.' % maxnum)
        return
    _summarize_data(inc_data, maxnum)

    #
    ## quad movie summary
    if args.choose_option == 'm':
        if args.do_yes: status = args.do_yes
        else: status = _try_continue()
        if not status: return
        movie_name = viz.create_summary_movie_frombeginning(
            inc_data, dirname=args.dirname)
    #
    ## cumulative COVID-19 stats up to last day
    elif args.choose_option == 's':
        if args.do_yes: status = args.do_yes
        else: status = _try_continue()
        if not status: return
        viz.get_summary_demo_data(inc_data,
                                  maxnum_colorbar=maxnum,
                                  dirname=args.dirname)
    #
    ## movie of only either COVID-19 cases or deaths
    elif args.choose_option == 'mcd':
        if args.do_yes: status = args.do_yes
        else: status = _try_continue()
        if not status: return
        #
        viz.create_summary_cases_or_deaths_movie_frombeginning(
            inc_data,
            type_disp=args.movcasedeath_display,
            dirname=args.dirname,
            save_imgfiles=args.movcasedeath_saveimages)
def main():
    parser = ArgumentParser()
    parser.add_argument(
        '-d',
        '--dirname',
        dest='dirname',
        type=str,
        action='store',
        default=os.getcwd(),
        help=
        'The directory into which to store the resulting files. Default is %s.'
        % os.getcwd())
    parser.add_argument(
        '--info',
        dest='do_info',
        action='store_true',
        default=False,
        help='If chosen, then print out INFO level logging statements.')
    #
    subparsers = parser.add_subparsers(help=' '.join([
        'Choose one of three options:', '(M) summarizes stats from metros;',
        '(m) make a movie of a metro region;',
        'and (s) dumps summary plots of last incident date,',
        'and cumulative covid-19 stats, of a metro region.'
    ]),
                                       dest='choose_option')
    #
    ## list of metros (M)
    parser_showmetros = subparsers.add_parser(
        'M',
        help=
        'If chosen, then list all the metropolitan areas through which we can look.'
    )
    parser_showmetros.add_argument(
        '-f',
        '--format',
        help=
        'Format of the table that displays MSA summary. Default is "simple".',
        type=str,
        action='store',
        choices=['simple', 'github', 'rst', 'rst-simple', 'json'],
        default='simple')
    parser_showmetros.add_argument(
        '--metros',
        help=
        'If chosen, list of selected metros for which to summarize COVID-19 data.',
        type=str,
        action='store')
    parser_showmetros.add_argument(
        '--topN',
        dest='topN',
        type=int,
        action='store',
        help=
        'If defined, will be the top N (N must be an integer greater than 0) population metros to get data on.'
    )
    #
    ## make summary movie (m)
    parser_moviemetro = subparsers.add_parser(
        'm',
        help=
        'Make a movie of the COVID-19 cases and deaths trend for the specific Metropolitan Statistical Area (MSA).'
    )
    parser_moviemetro.add_argument(
        '-n',
        '--name',
        dest='name',
        type=str,
        action='store',
        default='bayarea',
        help='Make a movie of this metropolitan area. Default is "bayarea"')
    parser_moviemetro.add_argument(
        '-M',
        '--maxnum',
        dest='maxnum',
        type=int,
        action='store',
        default=None,
        metavar='MAXNUM',
        help=' '.join([
            'The limit of cases/deaths to visualize.',
            'Default is a plausible amount for the chosen MSA or CONUS.',
            'You should use a limit larger (by at least 2, no more than 10) than',
            'the maximum number of cases recorded for a county in that MSA or CONUS.'
        ]))
    parser_moviemetro.add_argument(
        '--conus',
        dest='do_conus',
        action='store_true',
        default=False,
        help=
        'If chosen, then make a movie of the COVID-19 cases and deaths trends for the Continental US (CONUS).'
    )
    parser_moviemetro.add_argument(
        '-y',
        '--yes',
        dest='do_yes_moviemetro',
        action='store_true',
        default=False,
        help='If chosen, then do not confirm --maxnum.')
    #
    ## make summary plots of last day, and COVID-19 cases/deaths in pandas dataframe up to last day.
    parser_summmetro = subparsers.add_parser(
        's',
        help=' '.join([
            'Make a summary plot, and incident data file,',
            'of COVID-19 cases and deaths trend,',
            'for the specific Metropolitan Statistical Area (MSA).'
        ]))
    parser_summmetro.add_argument(
        '-n',
        '--name',
        dest='summmetro_name',
        type=str,
        action='store',
        default='bayarea',
        metavar='NAME',
        help=' '.join([
            'Create a summary plot and incident data file of this metropolitan area.',
            'Default is "bayarea".'
        ]))
    parser_summmetro.add_argument(
        '-M',
        '--maxnum',
        dest='summmetro_maxnum',
        type=int,
        action='store',
        default=None,
        metavar='MAXNUM',
        help=' '.join([
            'The limit of cases/deaths to visualize.',
            'Default is a plausible amount for the chosen MSA or CONUS.',
            'You should use a limit larger (by at least 2, no more than 10) than',
            'the maximum number of cases recorded for a county in that MSA or CONUS.'
        ]))
    parser_summmetro.add_argument(
        '--conus',
        dest='do_conus_summmetro',
        action='store_true',
        default=False,
        help=
        'If chosen, then make a movie of the COVID-19 cases and deaths trends for the Continental US (CONUS).'
    )
    parser_summmetro.add_argument(
        '-y',
        '--yes',
        dest='do_yes_summmetro',
        action='store_true',
        default=False,
        help='If chosen, then do not confirm --maxnum.')
    #
    ## make a movie of cases OR deaths
    parser_movcasedeath = subparsers.add_parser(
        'mcd',
        help=
        'Make a large-sized movie of either "CASES" or "DEATHS" for given MSA or CONUS.'
    )
    parser_movcasedeath.add_argument(
        '-n',
        '--name',
        dest='movcasedeath_name',
        type=str,
        action='store',
        default='bayarea',
        metavar='NAME',
        help=' '.join([
            'Create a summary plot and incident data file of this metropolitan area.',
            'Default is "bayarea".'
        ]))
    parser_movcasedeath.add_argument(
        '-d',
        '--disp',
        dest='movcasedeath_display',
        type=str,
        action='store',
        default='cases',
        metavar='DISP',
        choices=('cases', 'deaths'),
        help=
        'Whether to display the "cases" or "death" trends of the MSA or CONUS. Default is "cases".'
    )
    parser_movcasedeath.add_argument(
        '-M',
        '--maxnum',
        dest='movcasedeath_maxnum',
        type=int,
        action='store',
        default=None,
        metavar='MAXNUM',
        help=' '.join([
            'The limit of cases/deaths to visualize.',
            'Default is a plausible amount for the chosen MSA or CONUS.',
            'You should use a limit larger (by at least 2, no more than 10) than',
            'the maximum number of cases recorded for a county in that MSA or CONUS.'
        ]))
    parser_movcasedeath.add_argument(
        '-s',
        '--saveimages',
        dest='movcasedeath_saveimages',
        action='store_true',
        default=False,
        help=
        'If chosen, then save the images used to create the movie into a ZIP archive.'
    )
    parser_movcasedeath.add_argument(
        '--conus',
        dest='do_conus_movcasedeath',
        action='store_true',
        default=False,
        help=
        'If chosen, then make a movie of the COVID-19 cases and deaths trends for the Continental US (CONUS).'
    )
    parser_movcasedeath.add_argument(
        '-y',
        '--yes',
        dest='do_yes_movcasedeath',
        action='store_true',
        default=False,
        help='If chosen, then do not confirm --maxnum.')
    #
    ##
    args = parser.parse_args()
    logger = logging.getLogger()
    if args.do_info: logger.setLevel(logging.INFO)
    #
    ## just show the metros
    if args.choose_option == 'M':
        metros = None
        if args.metros is not None:
            metros = set(
                list(map(lambda tok: tok.strip(), args.metros.split(','))))
        if args.topN is not None:
            assert (args.topN >= 1)
            metros = list(
                map(
                    lambda entry: entry['prefix'],
                    sorted(COVID19Database.data_msas_2019().values(),
                           key=lambda entry: entry['population'])[::-1]
                    [:args.topN]))
            # logging.info('top %d metros: %s.' % ( args.topN, metros ) )
        if args.format != 'json':
            core.display_tabulated_metros(form=args.format,
                                          selected_metros=metros)
        else:
            json_data = core.display_tabulated_metros(form=args.format,
                                                      selected_metros=metros)
            print('%s' % json.dumps(json_data, indent=1))
        return
    elif args.choose_option == 'm':
        #
        ## now create the following stuff...
        if not args.do_conus:
            msaname = args.name.strip()
            data_msas_2019 = COVID19Database.data_msas_2019()
            if msaname not in data_msas_2019:
                print(
                    'Error, the chosen MSA name %s not one of the %d defined.'
                    % (msaname, len(data_msas_2019)))
                return
            data = data_msas_2019[msaname]
        else:
            data = COVID19Database.data_conus()
        inc_data = core.get_incident_data(data)
        maxnum = args.maxnum
        if maxnum is None: maxnum = _get_default_maxnum(inc_data)
        if maxnum < 1:
            print('Error, maximum number for visualization %d < 1.' % maxnum)
            return
        _summarize_data(inc_data, maxnum)
        if args.do_yes_moviemetro: status = args.do_yes_moviemetro
        else: status = _try_continue()
        if status:
            movie_name = viz.create_summary_movie_frombeginning(
                inc_data, dirname=args.dirname)
            return

    elif args.choose_option == 's':
        #
        ## now create the following stuff...
        if not args.do_conus_summmetro:
            msaname = args.summmetro_name.strip()
            data_msas_2019 = COVID19Database.data_msas_2019()
            if msaname not in data_msas_2019:
                print(
                    'Error, the chosen MSA name %s not one of the %d defined.'
                    % (msaname, len(data_msas_2019)))
                return
            data = data_msas_2019[msaname]
        else:
            data = COVID19Database.data_conus()
        inc_data = core.get_incident_data(data)
        maxnum = args.summmetro_maxnum
        if maxnum is None: maxnum = _get_default_maxnum(inc_data)
        if maxnum < 1:
            print('Error, maximum number for visualization %d < 1.' % maxnum)
            return

        _summarize_data(inc_data, maxnum)
        if args.do_yes_summmetro: status = args.do_yes_summmetro
        else: status = _try_continue()
        if status:
            viz.get_summary_demo_data(inc_data, dirname=args.dirname)
            return
    elif args.choose_option == 'mcd':
        #
        ## now create the following stuff...
        if not args.do_conus_movcasedeath:
            msaname = args.movcasedeath_name.strip()
            data_msas_2019 = COVID19Database.data_msas_2019()
            if msaname not in data_msas_2019:
                print(
                    'Error, the chosen MSA name %s not one of the %d defined.'
                    % (msaname, len(data_msas_2019)))
                return
            data = data_msas_2019[msaname]
        else:
            data = COVID19Database.data_conus()
        inc_data = core.get_incident_data(data)
        maxnum = args.movcasedeath_maxnum
        if maxnum is None: maxnum = _get_default_maxnum(inc_data)
        if maxnum < 1:
            print('Error, maximum number for visualization %d < 1.' % maxnum)
            return

        _summarize_data(inc_data, maxnum)
        if args.do_yes_movcasedeath: status = args.do_yes_movcasedeath
        else: status = _try_continue()
        if status:
            viz.create_summary_cases_or_deaths_movie_frombeginning(
                inc_data,
                type_disp=args.movcasedeath_display,
                dirname=args.dirname,
                save_imgfiles=args.movcasedeath_saveimages)
            return
def main():
    rank = MPI.COMM_WORLD.Get_rank()
    time0 = _get_min_time0()
    parser = ArgumentParser()
    parser.add_argument('-r',
                        '--region',
                        metavar='region',
                        type=str,
                        required=True,
                        help='region as JSON file.')
    parser.add_argument(
        '-d',
        '--dirname',
        dest='dirname',
        type=str,
        action='store',
        default=os.getcwd(),
        help=
        'The name of the directory to which to put all this stuff. Default is %s.'
        % os.getcwd())
    parser.add_argument('-i',
                        '--info',
                        dest='do_info',
                        action='store_true',
                        default=False,
                        help='If chosen, then turn on INFO logging.')
    args = parser.parse_args()
    assert (os.path.isdir(args.dirname))
    assert (os.path.isfile(os.path.expanduser(args.region)))
    assert (os.path.basename(os.path.expanduser(
        args.region)).endswith('.json'))
    #
    ## I do four things
    ntasks = 4
    nprocs = min(MPI.COMM_WORLD.Get_size(), ntasks)
    if rank >= ntasks: return
    #
    ## check on whether to turn on INFO logging
    logger = logging.getLogger()
    if args.do_info: logger.setLevel(logging.INFO)
    #
    ## get incident data for the region
    region_filename = os.path.abspath(os.path.expanduser(args.region))
    region_data = _get_region_data(region_filename)
    inc_data = core.get_incident_data(region_data)
    #
    ## now do the thing...
    all_tuples_to_process = list(range(4))
    tuples_to_process = all_tuples_to_process[rank::nprocs]
    for thing_to_do in tuples_to_process:
        if thing_to_do == 0: _summarize(inc_data, args.dirname, time0)
        elif thing_to_do == 1: _movie(inc_data, args.dirname, time0)
        elif thing_to_do == 2:
            _movie_casedeaths(inc_data, args.dirname, time0, type_disp='cases')
        elif thing_to_do == 3:
            _movie_casedeaths(inc_data,
                              args.dirname,
                              time0,
                              type_disp='deaths')
    MPI.COMM_WORLD.Barrier()

    if rank != 0: return
    logging.info(
        'processed all FOUR operations on %s (%s) in %0.3f seconds.' %
        (inc_data['prefix'], inc_data['region name'], time.time() - time0))