komanawa.basgra_nz_py.basgra_python#

This is a place to create a python wrapper for the BASGRA fortran model in fortarn_BASGRA_NZ

Author: Matt Hanson Created: 12/08/2020 9:32 AM

Functions#

get_fortran_basgra(supply_pet[, recomplile, verbose, ...])

get the callable fortran BASGRA function

get_month_day_to_nonleap_doy([key_doy])

param key_doy:

bool, if true the keys are doy, else keys are (month, dayofmonth)

run_basgra_nz(params, matrix_weather, days_harvest, ...)

python wrapper for the fortran BASGRA code changes to the fortran code may require changes to this function runs the model for the period of the weather data

Module Contents#

get_fortran_basgra(supply_pet, recomplile=False, verbose=False, binname='gfortran-12')[source]#

get the callable fortran BASGRA function

Parameters:
  • supply_pet – bool if True use the PET version, if False use the peyman version

  • recomplile – bool if True force recompile the fortran code

  • verbose – bool if True print the fortran compilation output

  • version – str the version of gfortran to use, only tested on 11.4.0

Returns:

get_month_day_to_nonleap_doy(key_doy=False)[source]#
Parameters:

key_doy – bool, if true the keys are doy, else keys are (month, dayofmonth)

Returns:

dictionary if not inverse: {(m,d}:doy} if inverse: {doy: (m,d)}

run_basgra_nz(params, matrix_weather, days_harvest, doy_irr, verbose=False, supply_pet=True, auto_harvest=False, run_365_calendar=False, binname='gfortran-12', recompile=False, compile_verbose=False)[source]#

python wrapper for the fortran BASGRA code changes to the fortran code may require changes to this function runs the model for the period of the weather data

Parameters:
  • params – dictionary, see input_output_keys.py, Komanawa-Solutions-Ltd/BASGRA_NZ_PY for more details

  • matrix_weather – pandas dataframe of weather data, maximum entries set in _max_weather_size in line 24 of this file (currently 36600) see documentation for input columns at Komanawa-Solutions-Ltd/BASGRA_NZ_PY , note expected DOY will change depending on expect_no_leap_days

  • days_harvest – days harvest dataframe must be same length as matrix_weather entries see documentation for input columns at Komanawa-Solutions-Ltd/BASGRA_NZ_PY , note expected DOY will change depending on expect_no_leap_days

  • doy_irr – a list of the days of year to irrigate on, must be integers acceptable values: (0-366)

  • verbose – boolean, if True the fortran function prints a number of statements for debugging purposes(depreciated)

  • supply_pet – boolean, if True BASGRA expects pet to be supplied, if False the parameters required to calculate pet from the peyman equation are expected, the version must match the DLL if dll_path != ‘default’

  • auto_harvest – boolean, if True then assumes data is formated correctly for auto harvesting, if False, then assumes data is formatted for manual harvesting (e.g. previous version) and re-formats internally

  • run_365_calendar – boolean, if True then run on a 365 day calender This expects that all leap days will be removed from matrix_weather and days_harvest. DOY is expected to be between 1 and 365. This means that datetime objects defined by year and doy will be incorrect. instead use get_month_day_to_nonleap_doy to map DOY to datetime via month and day. This is how the index of the returned datetime will be passed. For example for date 2024-03-01 (2024 is a leap year) the dayofyear via a datetime object will be 61, but if expect_no_leap_days=True basgra expects day of year to be 60. the index of the results will be a datetime object of equivalent to 2024-03-01, so the output doy will not match the index doy and there will be no value on 2020-02-29. default False

  • binname – str, the name of the gfortran compiler to use, default ‘gfortran-12’

  • recompile – bool, if True force recompile the fortran code

  • compile_verbose – bool, if True print the fortran compilation output

Returns:

pd.DataFrame(index=datetime index, columns = out_cols)