# Check if collection exits in database and initialize database only if not
# on command fail restart service
function initialize {
  echo "Initialize coverage types"
  python3 manage.py coveragetype import /rgbnir_definition.json --traceback
  echo "Initializing collection '${COLLECTION}'."
  python3 manage.py producttype create "${COLLECTION}"_Product_CS00 --traceback \
    --coverage-type "sar_hh_gray"
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS00 --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS00 "TRUE_COLOR" --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  # CS01
  python3 manage.py producttype create "${COLLECTION}"_Product_CS01 --traceback \
    --coverage-type "sar_hh_gray"
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS01 --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS01 "TRUE_COLOR" --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  # CS02
  python3 manage.py producttype create "${COLLECTION}"_Product_CS02 --traceback \
    --coverage-type "sar_hh_gray"
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS02 --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS02 "TRUE_COLOR" --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  # CS03
  python3 manage.py producttype create "${COLLECTION}"_Product_CS03 --traceback \
    --coverage-type "sar_hh_gray"
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS03 --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS03 "TRUE_COLOR" --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  # CS04
  python3 manage.py producttype create "${COLLECTION}"_Product_CS04 --traceback \
    --coverage-type "sar_hh_gray"
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS04 --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_CS04 "TRUE_COLOR" --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  # DM01
  python3 manage.py producttype create "${COLLECTION}"_Product_DM01 --traceback \
    --coverage-type "RGNirByte"
  python3 manage.py browsetype create "${COLLECTION}"_Product_DM01 --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 0 255 \
    --green-range 0 255 \
    --blue-range 0 255 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_DM01 "TRUE_COLOR" --traceback \
    --red "nir" \
    --green "green" \
    --blue "red" \
    --red-range 0 255 \
    --green-range 0 255 \
    --blue-range 0 255 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_DM01 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 0 255 \
    --green-range 0 255 \
    --blue-range 0 255 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  # EQ02
  python3 manage.py producttype create "${COLLECTION}"_Product_EQ02 --traceback \
    --coverage-type "BGRNir" \
    --coverage-type "RGB"
  python3 manage.py browsetype create "${COLLECTION}"_Product_EQ02 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 0 500 \
    --green-range 0 600 \
    --blue-range 0 500 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EQ02 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 0 500 \
    --green-range 0 600 \
    --blue-range 0 500 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EQ02 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 0 700 \
    --green-range 0 500 \
    --blue-range 0 600 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EQ02 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # EW01
  python3 manage.py producttype create "${COLLECTION}"_Product_EW01 --traceback \
    --coverage-type "grayscale"
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW01 --traceback \
    --red "gray" \
    --red-range 0 1500 \
    --red-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW01 "TRUE_COLOR" --traceback \
    --red "gray" \
    --red-range 0 1500 \
    --red-nodata 0
  # EW02
  python3 manage.py producttype create "${COLLECTION}"_Product_EW02 --traceback \
    --coverage-type "BGRNir" \
    --coverage-type "RGB" \
    --coverage-type "CBGYRReNirNir2"
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW02 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 100 700 \
    --green-range 100 600 \
    --blue-range 100 700 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW02 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 100 700 \
    --green-range 100 600 \
    --blue-range 100 700 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW02 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 100 700 \
    --green-range 100 600 \
    --blue-range 100 700 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW02 "NDVI" --traceback \
    --grey "(nir-blue)/(nir+blue)" --grey-range -1 1
  # EW03
  python3 manage.py producttype create "${COLLECTION}"_Product_EW03 --traceback \
    --coverage-type "BGRNir" \
    --coverage-type "RGB" \
    --coverage-type "CBGYRReNirNir2"
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW03 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 100 700 \
    --green-range 100 600 \
    --blue-range 100 700 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW03 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 100 700 \
    --green-range 100 600 \
    --blue-range 100 700 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW03 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 100 700 \
    --green-range 100 600 \
    --blue-range 100 700 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_EW03 "NDVI" --traceback \
    --grey "(nir-blue)/(nir+blue)" --grey-range -1 1
  python3 manage.py producttype create "${COLLECTION}"_Product_GE01 --traceback \
    --coverage-type "BGRNir" \
    --coverage-type "RGB"
  python3 manage.py browsetype create "${COLLECTION}"_Product_GE01 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 0 600 \
    --green-range 0 700 \
    --blue-range 0 800 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_GE01 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 0 600 \
    --green-range 0 700 \
    --blue-range 0 800 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_GE01 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 0 1000 \
    --green-range 0 600 \
    --blue-range 0 700 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_GE01 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # GY01
  python3 manage.py producttype create "${COLLECTION}"_Product_GY01 --traceback \
    --coverage-type "BGRNir" \
    --coverage-type "RGB"
  python3 manage.py browsetype create "${COLLECTION}"_Product_GY01 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 50 600 \
    --green-range 50 600 \
    --blue-range 50 600 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_GY01 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 50 600 \
    --green-range 50 600 \
    --blue-range 50 600 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_GY01 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 50 800 \
    --green-range 50 600 \
    --blue-range 50 600 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_GY01 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # IK02
  python3 manage.py producttype create "${COLLECTION}"_Product_IK02 --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_IK02 --traceback \
    --red "blue" \
    --green "green" \
    --blue "red" \
    --red-range 0 700 \
    --green-range 0 800 \
    --blue-range 0 900 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_IK02 "TRUE_COLOR" --traceback \
    --red "blue" \
    --green "green" \
    --blue "red" \
    --red-range 0 700 \
    --green-range 0 800 \
    --blue-range 0 900 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_IK02 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "blue" \
    --blue "green" \
    --red-range 0 1000 \
    --green-range 0 700 \
    --blue-range 0 800 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_IK02 "NDVI" --traceback \
    --grey "(nir-blue)/(nir+blue)" --grey-range -1 1
  # RE00
  python3 manage.py producttype create "${COLLECTION}"_Product_RE00 --traceback \
    --coverage-type "BGRReNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_RE00 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1000 8000 \
    --green-range 1000 8000 \
    --blue-range 1000 10000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_RE00 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1000 8000 \
    --green-range 1000 8000 \
    --blue-range 1000 10000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_RE00 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 1000 8000 \
    --green-range 1000 8000 \
    --blue-range 1000 8000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_RE00 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # RS02
  python3 manage.py producttype create "${COLLECTION}"_Product_RS02 --traceback \
    --coverage-type "sar_hh_gray" \
    --coverage-type "sar_hh_vv_gray" \
    --coverage-type "sar_hh_hv_vh_vv_gray"

  python3 manage.py browsetype create "${COLLECTION}"_Product_RS02 --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_RS02 "TRUE_COLOR" --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  # SP04
  python3 manage.py producttype create "${COLLECTION}"_Product_SP04 --traceback \
    --coverage-type "RGBNirByte"
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP04 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 0 255 \
    --green-range 0 255 \
    --blue-range 0 255 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP04 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 0 255 \
    --green-range 0 255 \
    --blue-range 0 255 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP04 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 0 255 \
    --green-range 0 255 \
    --blue-range 0 255 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP04 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # SP05 - nir is blue
  python3 manage.py producttype create "${COLLECTION}"_Product_SP05 --traceback \
    --coverage-type "RGNirByte"
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP05 --traceback \
    --red "red" \
    --green "green" \
    --blue "nir" \
    --red-range 0 120 \
    --green-range 0 120 \
    --blue-range 0 120 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP05 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "nir" \
    --red-range 0 120 \
    --green-range 0 120 \
    --blue-range 0 120 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  # TX01
  python3 manage.py producttype create "${COLLECTION}"_Product_TX01 --traceback \
    --coverage-type "sar_hh_gray" \
    --coverage-type "sar_hh_vv_gray" \
    --coverage-type "sar_hh_hv_vh_vv_gray"
  python3 manage.py browsetype create "${COLLECTION}"_Product_TX01 --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_TX01 "TRUE_COLOR" --traceback \
    --red "gray" \
    --red-range 1 65535 \
    --red-nodata 0
  # DM02
  python3 manage.py producttype create "${COLLECTION}"_Product_DM02 --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_DM02 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 2000 15000 \
    --green-range 1000 7000 \
    --blue-range 1000 7000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_DM02 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 2000 15000 \
    --green-range 1000 7000 \
    --blue-range 1000 7000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_DM02 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 1000 7000 \
    --green-range 2000 15000 \
    --blue-range 1000 7000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_DM02 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # KS03 - bands are alphabetically BGNR, hence shift below
  python3 manage.py producttype create "${COLLECTION}"_Product_KS03 --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_KS03 --traceback \
    --red "nir" \
    --green "green" \
    --blue "red" \
    --red-range 1000 10000 \
    --green-range 1000 8000 \
    --blue-range 1000 12000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_KS03 "TRUE_COLOR" --traceback \
    --red "nir" \
    --green "green" \
    --blue "red" \
    --red-range 1000 10000 \
    --green-range 1000 8000 \
    --blue-range 1000 12000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_KS03 "FALSE_COLOR" --traceback \
    --red "blue" \
    --green "nir" \
    --blue "green" \
    --red-range 1000 10000 \
    --green-range 1000 10000 \
    --blue-range 1000 8000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_KS03 "NDVI" --traceback \
    --grey "(blue-nir)/(blue+nir)" --grey-range -1 1
  # SP06
  python3 manage.py producttype create "${COLLECTION}"_Product_SP06 --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP06  --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 100 1000 \
    --green-range 100 1000 \
    --blue-range 100 1000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP06 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 100 1000 \
    --green-range 100 1000 \
    --blue-range 100 1000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP06 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 100 1200 \
    --green-range 100 1000 \
    --blue-range 100 1000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP06 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # SP07
  python3 manage.py producttype create "${COLLECTION}"_Product_SP07 --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP07  --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 0 900 \
    --green-range 0 900 \
    --blue-range 0 1000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP07 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 0 900 \
    --green-range 0 900 \
    --blue-range 0 1000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP07 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 0 1200 \
    --green-range 0 900 \
    --blue-range 0 900 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SP07 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # PH1A
  python3 manage.py producttype create "${COLLECTION}"_Product_PH1A --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_PH1A  --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1 2000 \
    --green-range 1 2000 \
    --blue-range 1 2000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_PH1A "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1 2000 \
    --green-range 1 2000 \
    --blue-range 1 2000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_PH1A "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 1 2000 \
    --green-range 1 2000 \
    --blue-range 1 2000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_PH1A "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # PH1B
  python3 manage.py producttype create "${COLLECTION}"_Product_PH1B --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_PH1B --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1 2000 \
    --green-range 1 2000 \
    --blue-range 1 2000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_PH1B "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1 2000 \
    --green-range 1 2000 \
    --blue-range 1 2000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_PH1B "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 1 2000 \
    --green-range 1 2000 \
    --blue-range 1 2000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_PH1B "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # SK00
  python3 manage.py producttype create "${COLLECTION}"_Product_SK00 --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_SK00 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1 600 \
    --green-range 1 600 \
    --blue-range 1 600 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SK00 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1 600 \
    --green-range 1 600 \
    --blue-range 1 600 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SK00 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 1 600 \
    --green-range 1 600 \
    --blue-range 1 600 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SK00 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # SW03
  python3 manage.py producttype create "${COLLECTION}"_Product_SW03 --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_SW03 --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1 1000 \
    --green-range 1 1000 \
    --blue-range 1 1000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SW03 "TRUE_COLOR" --traceback \
    --red "red" \
    --green "green" \
    --blue "blue" \
    --red-range 1 1000 \
    --green-range 1 1000 \
    --blue-range 1 1000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SW03 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "red" \
    --blue "green" \
    --red-range 1 1000 \
    --green-range 1 1000 \
    --blue-range 1 1000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_SW03 "NDVI" --traceback \
    --grey "(nir-red)/(nir+red)" --grey-range -1 1
  # PL00 bands go in order b,g,r,nir
  python3 manage.py producttype create "${COLLECTION}"_Product_PL00 --traceback \
    --coverage-type "RGBNir"
  python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 --traceback \
    --red "blue" \
    --green "green" \
    --blue "red" \
    --red-range 1500 15000 \
    --green-range 1500 15000 \
    --blue-range 1500 15000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 "TRUE_COLOR" --traceback \
    --red "blue" \
    --green "green" \
    --blue "red" \
    --red-range 1500 15000 \
    --green-range 1500 15000 \
    --blue-range 1500 15000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 "FALSE_COLOR" --traceback \
    --red "nir" \
    --green "blue" \
    --blue "green" \
    --red-range 1500 20000 \
    --green-range 1500 15000 \
    --blue-range 1500 15000 \
    --red-nodata 0 \
    --green-nodata 0 \
    --blue-nodata 0
  python3 manage.py browsetype create "${COLLECTION}"_Product_PL00 "NDVI" --traceback \
    --grey "(nir-blue)/(nir+blue)" --grey-range -1 1
  python3 manage.py collectiontype create "${COLLECTION}"_Collection --traceback \
    --coverage-type "RGBNir" \
    --coverage-type "RGNirByte" \
    --coverage-type "RGBNirByte" \
    --coverage-type "RGB" \
    --coverage-type "grayscale" \
    --coverage-type "CBGYRReNirNir2" \
    --coverage-type "BGRReNir" \
    --coverage-type "sar_hh_gray" \
    --coverage-type "sar_hh_vv_gray" \
    --coverage-type "sar_hh_hv_vh_vv_gray" \
    --product-type "${COLLECTION}"_Product_PH1A \
    --product-type "${COLLECTION}"_Product_PH1B \
    --product-type "${COLLECTION}"_Product_DM02 \
    --product-type "${COLLECTION}"_Product_DM01 \
    --product-type "${COLLECTION}"_Product_CS00 \
    --product-type "${COLLECTION}"_Product_CS01 \
    --product-type "${COLLECTION}"_Product_CS02 \
    --product-type "${COLLECTION}"_Product_CS03 \
    --product-type "${COLLECTION}"_Product_CS04 \
    --product-type "${COLLECTION}"_Product_EW01 \
    --product-type "${COLLECTION}"_Product_EW02 \
    --product-type "${COLLECTION}"_Product_EW03 \
    --product-type "${COLLECTION}"_Product_EQ02 \
    --product-type "${COLLECTION}"_Product_GE01 \
    --product-type "${COLLECTION}"_Product_GY01 \
    --product-type "${COLLECTION}"_Product_TX01 \
    --product-type "${COLLECTION}"_Product_IK02 \
    --product-type "${COLLECTION}"_Product_RE00 \
    --product-type "${COLLECTION}"_Product_RS02 \
    --product-type "${COLLECTION}"_Product_SP04 \
    --product-type "${COLLECTION}"_Product_SP05 \
    --product-type "${COLLECTION}"_Product_SP06 \
    --product-type "${COLLECTION}"_Product_SP07 \
    --product-type "${COLLECTION}"_Product_SK00 \
    --product-type "${COLLECTION}"_Product_SW03 \
    --product-type "${COLLECTION}"_Product_PL00 \
    --product-type "${COLLECTION}"_Product_KS03
  python3 manage.py collection create "${COLLECTION}" --type "${COLLECTION}"_Collection --traceback
}

id_check=$(python3 manage.py id check "${COLLECTION}")
if [[ $id_check == *"is already in use by a 'Collection'"* ]]; then
  # name is already taken
  echo "Using existing database"
elif [[ $id_check == *"is currently not in use"* ]]; then
  initialize
else
  echo "Restarting service inside init-db by emitting an error"
  set -eo pipefail
  false
fi
