Skip to content

Commit

Permalink
Merge pull request #41 from AgPipeline/develop
Browse files Browse the repository at this point in the history
Merging develop to master - no review
  • Loading branch information
Chris-Schnaufer authored Jan 8, 2021
2 parents 6aba569 + 865792c commit 566af8c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/testing_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ jobs:
run: python3 -m pip install --upgrade --no-cache-dir pip
- name: Fetch/update setuptools
run: python3 -m pip install --upgrade --no-cache-dir setuptools
- name: Install python-apt
run: sudo apt-get install -y python-apt
- name: HACK to fix apt-get update problem w/ different python versions
run: 'cd /usr/lib/python3/dist-packages && sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so'
- name: Update apt-get
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[![license](https://img.shields.io/badge/license-BSD%203-green?logo=Open-Source-Initiative)](https://github.com/AgPipeline/transformer-canopycover/blob/master/LICENSE)

[![Enforcing testing](https://github.com/AgPipeline/transformer-canopycover/workflows/Enforcing%20tests/badge.svg)](https://github.com/AgPipeline/transformer-canopycover/actions?query=workflow%3A%22Enforcing+tests%22)
[![testing](https://github.com/AgPipeline/transformer-canopycover/workflows/Testing%20Docker%20image/badge.svg)](https://github.com/AgPipeline/transformer-canopycover/actions?query=workflow%3A%22Testing+Docker+image%22)

# Transformer Canopy Cover

Calculates canopy cover (the percentage pixels identified as a plant) on a plot level for one or more images that have been processed by the [soilmask transformer](https://github.com/AgPipeline/transformer-soilmask) to mask the soil.
Expand Down
27 changes: 21 additions & 6 deletions canopycover.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import argparse
import copy
import datetime
import logging
import os
import subprocess
import tempfile
from typing import Union
import numpy as np
import dateutil.parser
from agpypeline import entrypoint, algorithm, geoimage
from agpypeline.environment import Environment
from osgeo import gdal, ogr
Expand Down Expand Up @@ -249,6 +249,24 @@ def get_plot_species(plot_name: str, full_md: list, args: argparse.Namespace) ->
return args.species if args.species is not None else optional if optional is not None else "Unknown"


def get_time_stamps(iso_timestamp: str, args: argparse.Namespace) -> list:
"""Returns the date and the local time (offset is stripped) derived from the passed in timestamp
Args:
iso_timestamp: the timestamp string
args: the command line parameters
Return:
A list consisting of the date (YYYY-MM-DD) and a local timestamp (YYYY-MM-DDTHH:MM:SS)
"""
if 'timestamp' in args and args.timestamp:
timestamp = datetime.datetime.fromisoformat(args.timestamp)
elif iso_timestamp:
timestamp = datetime.datetime.fromisoformat(iso_timestamp)
else:
return ['', '']

return [timestamp.strftime('%Y-%m-%d'), timestamp.strftime('%Y-%m-%dT%H:%M:%S')]


class CanopyCover(algorithm.Algorithm):
"""Calculates canopy cover percentage on soil-masked image"""

Expand All @@ -265,6 +283,7 @@ def add_parameters(self, parser: argparse.ArgumentParser) -> None:
# pylint: disable=no-self-use
parser.add_argument('--species', dest="species", type=str, nargs='?',
help="name of the species associated with the canopy cover")
parser.add_argument('--timestamp', help='the timestamp to use in ISO 8601 format (eg:YYYY-MM-DDTHH:MM:SS')

def check_continue(self, environment: Environment, check_md: dict, transformer_md: list, full_md: list) -> tuple:
"""Checks if conditions are right for continuing processing
Expand Down Expand Up @@ -309,11 +328,7 @@ def perform_process(self, environment: Environment, check_md: dict, transformer_
# Disable pylint checks that would reduce readability
# pylint: disable=unused-argument,too-many-locals,too-many-branches,too-many-statements
# Setup local variables
localtime = ""
if check_md['timestamp']:
timestamp = dateutil.parser.parse(check_md['timestamp'])
if timestamp:
localtime = timestamp.strftime("%Y-%m-%dT%H:%M:%S")
(_, localtime) = get_time_stamps(check_md['timestamp'], environment.args)

save_csv_filename = os.path.join(check_md['working_folder'], "canopycover.csv")
save_file = open(save_csv_filename, 'w')
Expand Down

0 comments on commit 566af8c

Please sign in to comment.