Пример #1
0
def process_rainfall_data(data):

    dataseries = []

    # take first 10 results
    for i, result in enumerate(data):
        field_data = json_to_dataframe(result['hasMonthlyTotalRainfall']['hasDatapoint'])
        field_data = convert_year_month_columns_to_date(field_data)
        field_data["resultIndex"] = i
        dataseries.append(field_data)

    all_fields_data = pandas.concat(dataseries)

    # plot series for all fields
    box_plot_multiple_timeseries_by_freq(all_fields_data, ['month', 'year'], labels=['Monthly', 'Yearly'], title='Rainfall')
    plot_multiple_timeseries_by_year(all_fields_data, title='Yearly rainfall per field')

    # plot series for first field
    monthly_rainfall_for_first_field = all_fields_data[all_fields_data.resultIndex == 0]
    plot_timeseries(monthly_rainfall_for_first_field, title='3 years of rainfall for first field')

    # pretty print first field
    monthly_rainfall_for_first_field = monthly_rainfall_for_first_field[['year', 'month', 'value']].copy()
    print('\nMonthly rainfall for first field')
    print(monthly_rainfall_for_first_field.to_string(index=False))
Пример #2
0
def process_field_forecasts_temperature(field_finder_response):

    # Get daily maximum temperatures
    field_forecasts_url = get_api_url(field_finder_response, 'field-forecasts')
    print(f"\nField Forecasts URL: {field_forecasts_url}")

    forecast_result = get_data(field_forecasts_url)
    daily_forecast_maximum_temperature = json_to_dataframe(forecast_result['hasForecastDailyMaximumTemperature']['hasDatapoint'])
    daily_forecast_maximum_temperature = daily_forecast_maximum_temperature[['dateTime', 'value']].copy()
    daily_forecast_maximum_temperature = convert_dateTime_columns_to_datetime(daily_forecast_maximum_temperature)

    plot_timeseries(daily_forecast_maximum_temperature, title='Daily Maximum Temperature')

    print('\nDaily Maximum Temperature')
    print(daily_forecast_maximum_temperature.to_string(index=False))
Пример #3
0
def process_field_trends_rainfall(field_finder_response):
    # Monthly Rainfall
    field_trends_url = get_api_url(field_finder_response, 'field-trends')
    print(f"\nField Trends URL: {field_trends_url}")

    trends_result = get_data(field_trends_url)
    monthly_rainfall = json_to_dataframe(trends_result['hasMonthlyTotalRainfall']['hasDatapoint'])
    monthly_rainfall = monthly_rainfall[['year', 'month', 'value']].copy()
    monthly_rainfall = convert_year_month_columns_to_date(monthly_rainfall)

    plot_timeseries(monthly_rainfall, title='Monthly rainfall for last 3 years')


    # the data can be output as csv by using to_csv function instead
    print('\nMonthly rainfall for last 3 years')
    print(monthly_rainfall.to_string(index=False))