.. include:: /global.inc .. include:: /banner.rst Calculating using the CFT ========================= This topic guide explains how to send data to the CFT's calculation modules. .. note:: * :download:`calculate.py <../examples/calculate.py>` has Python examples of these methods * :ref:`Data schemas` are available for reference * This version of the API has significant changes to these methods; see :doc:`changelog` * The CFT now contains two calculation engines for irrigation. 1) Using the volume of water, pumping depth and pumping distance. 2) Using the volume of water only. Method 2, using volume only, uses factors provided by IPCC in 2013 based on geographical location, irrigation method and the power source. * The CFT has updated its machinery module, please see updated :ref:`Data schemas` The expected data has not changed much, except when using a baler type machine. To find out if you are using one, please check the :ref:`machine` to see if you need to add an additional field ``number_of_bales`` to your machinery data. .. note:: As of version 2.2, a new section called 'Disaggregation Totals' has been added to the calculate response. When using either the Dairy or Crop Calculate endpoints, a new field named ``disaggregation_totals`` has been introduced. This field provides an breakdown of the total emissions attributable to each Constituent gas. No changes to your input JSON are required to receive this new field, as it's now a default output. Here's an example of what the new ``disaggregation_totals`` field will look like in the response from within the ``summary`` field .. code-block:: json { "disaggregation_totals": [ { "CO2": { "metric_tonnes_CO2": [ "423.83", "tonnes CO2" ], "metric_tonnes_CO2e": [ "423.83", "tonnes CO2e" ] } "N2O": { "metric_tonnes_N2O": [ "0.36", "tonnes N2O" ], "metric_tonnes_CO2e": [ "97.15", "tonnes CO2e" ] }, "CH4": { "metric_tonnes_CH4": [ "12.07", "tonnes CH4" ], "metric_tonnes_CO2e": [ "336.82", "tonnes CO2e" ] }, } ] } All URLs start with ``/api/v1/``. .. contents:: Contents :local: Crop assessment --------------- .. _calculate-crop-assessment-endpoint: .. http:post:: /crop_product/calculate/ Calculate emissions for a crop product, without saving it to the database **Example request** .. sourcecode:: http POST /crop_product/calculate/ HTTP/1.1 Host: app.coolfarmtool.org Accept: application/json Content-Type: application/json .. literalinclude:: /../../api/v1/samples/crop_product-calculate-input.json **Example response** .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json .. literalinclude:: /../../api/v1/samples/crop_product-calculate-output.json :reqheader X-Api-App-Authorisation: app key; see :doc:`authentication` :statuscode 400: missing or incorrect form data .. _crop-type-rice: Crop type Rice '''''''''''''' .. http:post:: /crop_product/calculate/ Calculate emissions for a rice crop product, without saving it to the database **Example request** .. note:: When calculating a rice crop product please note two additional fields: Flooding is a required parameter but optional to provide (if not provided a default value will be used) The time under cultivation may be entered directly in number of days. If it is not provided the IPCC 2019 default number of days based on farm location and region will be applied. Green manure is an optional parameter and may be provided as shown below .. code-block:: js "flooding": { "time_under_cultivation": { "value": 123, "unit": "d" }, "before_cultivation": "Not flooded pre-season (for < 180 days)", "during_cultivation": "Continuously flooded" }, "green_manure": { "amount": { "value": 6.6, "unit": "tonne / ha" } } .. sourcecode:: http POST /crop_product/calculate/ HTTP/1.1 Host: app.coolfarmtool.org Accept: application/json Content-Type: application/json .. literalinclude:: /../../api/v1/samples/crop_product_rice-calculate-input.json **Example response** .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json .. literalinclude:: /../../api/v1/samples/crop_product_rice-calculate-output.json :reqheader X-Api-App-Authorisation: app key; see :doc:`authentication` :statuscode 400: missing or incorrect form data Local region calculations ''''''''''''''''''''''''' .. http:post:: /crop_product/calculate/ The crop calculate API endpoint provides the flexibility to perform calculations using factors and methods specific to a local region. This allows for more accurate and tailored results based on regional characteristics. .. note:: This functionality is restricted to farms located in specific regions. Currently, it is only available for farms located in Australia. To enable local region calculations, include the following optional keys in the API request: .. code-block:: { "farm": { ... "local_calculations": true, "local_climate": "Dry" } ... }, * ``local_calculations`` (`Boolean`): Set this key to ``true`` to enable local region calculations (Default: ``false``). * ``local_climate`` (`String`): Specify the local climate of the farm using this key. Choose from the available options based on your region. For example, you can set it to ``Dry`` or ``Wet``. Please ensure that you provide the accurate local climate information to obtain precise calculations based on the specific region. Dairy assessment ---------------- .. http:post:: /dairy_product/calculate/ Calculate emissions for a dairy product, without saving it to the database **Example request** .. sourcecode:: http POST /dairy_product/calculate/ HTTP/1.1 Host: app.coolfarmtool.org Accept: application/json Content-Type: application/json .. literalinclude:: /../../api/v1/samples/dairy_product-calculate-input.json **Example response** .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json { "total_emissions": [ { "CH4": "0.00", "CO2": "1344.73", "N2O": "0.00", "name": "energy", "total_CO2e": "1344.73" }, { "CH4": "2267.14", "CO2": "0.00", "N2O": "0.00", "name": "enteric", "total_CO2e": "56678.61" }, { "CH4": "0.00", "CO2": "26461.58", "N2O": "0.00", "name": "feed", "total_CO2e": "26461.58" }, { "CH4": "0.00", "CO2": "6939.96", "N2O": "0.00", "name": "grazing", "total_CO2e": "6939.96" }, { "CH4": "0.00", "CO2": "10480.26", "N2O": "0.00", "name": "manure", "total_CO2e": "10480.26" }, { "CH4": "0.00", "CO2": "2716.00", "N2O": "0.00", "name": "transport", "total_CO2e": "2716.00" } ], "summary": { "emissions_total": [ "100560.4049907536020612299397", "kg CO2e" ] } } :reqheader X-Api-App-Authorisation: app key; see :doc:`authentication` :statuscode 400: missing or incorrect form data Feed '''' The Cool farm tool allows 2 types of format for the feed section. Feed approach 1: Dry Matter Intake (if you know the DMI values) ``````````````````````````````````````````````````````````````` .. sourcecode:: json { "general": { "grazing_area": { "value": 60, "unit": "ha" }, "feed_approach": "dmi" }, "feed_components": [ { "herd_section": "Dairy calves", "item": "Oats", "region": "Global (world)", "dry_matter": { "value": 10, "unit": "kg" }, "certified": false }, { "herd_section": "Meat calves", "item": "Grass fresh managed - on farm", "region": "Global (world)", "dry_matter": { "value": 1.37, "unit": "kg" }, "certified": false }, { "herd_section": "Meat calves", "item": "Maize / corn grain", "region": "Global (world)", "dry_matter": { "value": 5, "unit": "kg" }, "certified": false }, { "herd_section": "Milk cows", "item": "Sorghum", "region": "Global (world)", "dry_matter": { "value": 15, "unit": "kg" }, "certified": false } ] } Feed approach 2: Average feed (the tool will estimate the DMI) `````````````````````````````````````````````````````````````` .. sourcecode:: json { "general": { "grazing_area": { "value": 60, "unit": "ha" }, "feed_approach": "average" }, "feed_components": [ { "item": "Oat hay", "region": "Global (world)", "percentage": 60 }, { "item": "Straw", "region": "Global (world)", "percentage": 40 } ] } Calculate a crop assessment first ````````````````````````````````` You can also use the crop API to first calculate a crop assessment that then can be used as a feed item within the Dairy API for both feed approach 1 and 2. See :ref:`calculate a crop assessment `. You will need to choose an existing feed item to use as the base for manure and enteric fermentation properties. List of the available :ref:`feed types` **Example for feed approach 1** .. sourcecode:: json { "feed_components": [ { "herd_section": "Meat calves", "crop_product": { "type": "Soyabean", "product_dry": { "value": 5, "unit": "tonne" }, "feed_type": "Soybean", "emissions_total": { "value": 22469.393582158074, "unit": "kg CO2e" } }, "dry_matter": { "value": 5, "unit": "kg" }, "certified": false } ] } **Example for feed approach 2** .. sourcecode:: json { "feed_components": [ { "item": "Oat hay", "region": "Global (world)", "percentage": 60 }, { "crop_product": { "type": "Maize", "product_dry": { "value": 2, "unit": "tonne" }, "feed_type": "Maize silage", "emissions_total": { "value": 267.5460271629662, "unit": "kg CO2e" } }, "region": "Global (world)", "percentage": 40 } ] } Water assessment ---------------- .. _calculate-water-assessment-endpoint: .. http:post:: /crop_product/water/calculate/ Calculate water assessment for a crop, without saving it to the database **Example request** .. sourcecode:: http POST /crop_product/water/calculate/ HTTP/1.1 Host: app.coolfarmtool.org Accept: application/json Content-Type: application/json .. literalinclude:: /../../api/v1/samples/water_product-calculate-input.json **Example response** .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json .. literalinclude:: /../../api/v1/samples/water_product-calculate-output.json :reqheader X-Api-App-Authorisation: app key; see :doc:`authentication` :statuscode 400: missing or incorrect form data Irrigation events ````````````````` **Calculating the number of weeks between irrigation dates** To enter the correct number of irrigation events follow the formula below to calculate the correct number of weeks/irrigation events between the irrigation start date and irrigation end date. Number of days between irrigation start date and irrigation end date (knowing that "start" = 5th, "middle" = 15th and "end" = 25th day of the month and last day not included) divided by 7 and rounded to the highest integer number. See the example below: * irrigation start date: start April 2016 -> 2016-04-05 * irrigation end date: middle May 2016 -> 2016-05-15 * days between: 40 * 40 / 7 = 5.71428 -> So rounded to highest integer is **6 weeks** **Water source** To select an irrigation water source enter the *"water_source"* key under the irrigation key. This value will be used as the default for all irrigation events. In order to enter a different water source for a specific irrigation event just add two fields to override the default value as per the example below: .. sourcecode:: json { "water_added": { "value": 12000, "unit": "litre" }, "allocation": 100, "has_source_pump": false, "water_source": 3 } JSON export ----------- From the web interface on a crop or dairy assessment, you can generate a JSON file compatible with the API. This can be used to test and debug the API. To find the JSON export functionality, go to the ‘more’ page of an assessment.