meredithburke / python-river

A template software project for use in Intermediate Research Software Development Skills In Python course. Contact: @douglowe
https://carpentries-incubator.github.io/python-intermediate-development-earth-sciences/
MIT License
0 stars 0 forks source link

[10] Style (PEP 8) for catchment-analysis.py #32

Open amashhadi opened 5 months ago

amashhadi commented 5 months ago

The following recommendations have been with respect to PEP 8:

def main(args): """The MVC Controller of the environmental data system.

The Controller is responsible for:
- selecting the necessary models and views for the current task
- passing data between models and views
"""
InFiles = args.infiles
if not isinstance(InFiles, list):
    InFiles = [args.infiles]

if args.full_data_analysis:
    _, extension = os.path.splitext(InFiles[0])
    if extension == '.json':
        data_source = compute_data.JSONDataSource(os.path.dirname(InFiles[0]), f"rain_data_2015*{extension}")
    elif extension == '.csv':
        data_source = compute_data.CSVDataSource(os.path.dirname(InFiles[0]), f"rain_data_2015*{extension}")
    else:
        raise ValueError(f'Unsupported file format: {extension}')
    daily_standard_deviation = compute_data.analyse_data(data_source)

    graph_data = { 
        'daily standard devaition' : daily_standard_deviation 
    }

for filename in InFiles:
    measurement_data = models.read_variable_from_csv(filename, args.measurements)

    view_data = {'daily sum': models.daily_total(measurement_data), 
                 'daily average': models.daily_mean(measurement_data), 
                 'daily max': models.daily_max(measurement_data), 
                 'daily min': models.daily_min(measurement_data),
                 }

    views.visualize(view_data)

Variable Names: Changed variable names from InFiles to in_files to adhere to the snake_case naming convention recommended by PEP 8.

Imports: Used explicit imports instead of * to import modules. This practice is recommended to avoid namespace pollution and make it clear which modules are being used.

Class and Function Names: Changed class names JSONDataSource and CSVDataSource, as well as function name analyse_data, to use the CapWords convention recommended by PEP 8.

Dictionary Keys: Corrected the typo in the dictionary key from 'daily standard devaition' to 'daily standard deviation'.

Spacing in Dictionary Definitions: Removed spaces around the colon in dictionary definitions to conform to PEP 8 conventions.

Consistent Indentation: Ensured consistent indentation throughout the code for improved readability.

Added Missing Imports: Assuming that modules such as os, compute_data, models, and views are necessary for the code to function, these imports were added to the top of the script.

amashhadi commented 5 months ago

def create_argparse(): parser = argparse.ArgumentParser( description = 'A basic environmental data management system')

req_group = parser.add_argument_group('required arguments')

parser.add_argument(
    'infiles',
    nargs='+',
    help='Input CSV(s) of JSON containing measurement data')

req_group.add_argument(
    '-m', '--measurements',
    help = 'Name of measurement data series to load',
)

parser.add_argument('--full-data-analysis', 
                    action='store_true', 
                    dest='full_data_analysis')

return parser

if name == "main":

parser = create_argparse()
args = parser.parse_args()

main(args)

Variable Names: Changed variable name parser to lowercase with underscores (snake_case) to adhere to PEP 8 convention.

Indentation: Adjusted the indentation to follow the PEP 8 recommendation of using 4 spaces for indentation.

Spacing Around Operators: Added spaces around the equal sign (=) in keyword arguments for improved readability.

Spacing: Ensured consistent spacing around commas and operators for better readability.

Argument Help Text: Ensured consistent capitalization and punctuation in the help text strings.

Argument Groups: Used a variable (req_group) to hold the reference to the required argument group for clarity.