For each point in the range of emerald ash borrer select all days when the temperature came close to or fell below the supercooling point of EAB.

More formally: select all days when the temperature fell below -30 degrees celsius.

Inputs:
* the range of emerald ash borrer (csv)
    * `EAB range.txt`
* daily average temperatures on a 0.5 by 0.5 degree grid for a ragne of dates 2003-01-01 through 2019-10-01 (NetCDF)
    * `41fe1db9-74cf-4842-a8ea-f8e55281c9ad.nc`
    * `a45203bd-8884-4178-a068-5d3e5c05e72e.nc`
    * `d6867180-6444-4fd0-bda7-480197f76239.nc`
    
Outputs:
* where, when and how low did the temperature fall for each point in the EAB range (csv)
    * `result.txt`
    
* minimum dayly average temperature for each point on the input grid (csv)
    * `min-temperature-map.txt`
    
Notes:

Daily mean temperature were calculated as an average of temperatures at 00:00, 02:00, 04:00, 06:00, 08:00, 10:00, 12:00, 14:00, 16:00, 18:00, 20:00 and 22:00 UTC.
In the interest of efficient storage and transfer the input does not contain temperature data for the entire Earth.

Running the analysis (the easy way)
===================================

Simply paste the following link into a web browser:
https://mybinder.org/v2/gh/hexagonrecursion/supercooling/master?filepath=supercooling.ipynb

Running the analysis (the hard way)
===================================

1. Install anaconda https://www.anaconda.com/distribution/
2. Use conda to install:
    * Jupyter Lab: https://jupyter.org/install
    * xarray
    * netcdf4
    * dask
    * pandas
3. Start Jupyter Lab
4. Download the following datasets and "upload" them to Jupyter Lab:
    * https://github.com/hexagonrecursion/supercooling/releases/download/1.0/41fe1db9-74cf-4842-a8ea-f8e55281c9ad.nc  
    * https://github.com/hexagonrecursion/supercooling/releases/download/1.0/a45203bd-8884-4178-a068-5d3e5c05e72e.nc  
    * https://github.com/hexagonrecursion/supercooling/releases/download/1.0/d6867180-6444-4fd0-bda7-480197f76239.nc  
5. "Upload" supercooling.ipynb and EAB range.txt to Jupyter Lab
6. Open supercooling.ipynb and click Run -> Run All Cells


Obtaining the temperature data
==============================

The files used in this analysis can be downloaded from here:
* https://github.com/hexagonrecursion/supercooling/releases/download/1.0/41fe1db9-74cf-4842-a8ea-f8e55281c9ad.nc
* https://github.com/hexagonrecursion/supercooling/releases/download/1.0/a45203bd-8884-4178-a068-5d3e5c05e72e.nc
* https://github.com/hexagonrecursion/supercooling/releases/download/1.0/d6867180-6444-4fd0-bda7-480197f76239.nc

They were generated by submitting the following query to https://cds.climate.copernicus.eu/

In short: this query calculates daily mean temperature as an average of temperatures at 00:00, 02:00, 04:00, 06:00, 08:00, 10:00, 12:00, 14:00, 16:00, 18:00, 20:00 and 22:00 UTC.

```python
START_YEAR = 2003
END_YEAR = 2019
AREA = [
    [10, -140, 65, -50],
    [20, 100, 60, 150],
    [30, -20, 75, 70],
]

import cdstoolbox as ct

@ct.application(title=f'Daily means')
@ct.output.download()
@ct.output.download()
@ct.output.download()
def daily_means():
    years = [str(y) for y in range(START_YEAR, END_YEAR + 1)]
    print(years)
    
    result = []
    for area in AREA:
        data = ct.catalogue.retrieve(
        'reanalysis-era5-land',
        {
            'area': area,
            'grid': ['0.5', '0.5'],
            'variable': '2m_temperature',
            'year': years,
            'month': [
                '01', '02', '03', '04', '05', '06',
                '07', '08', '09', '10', '11', '12'
            ],
            'day': [
                '01', '02', '03', '04', '05', '06',
                '07', '08', '09', '10', '11', '12',
                '13', '14', '15', '16', '17', '18',
                '19', '20', '21', '22', '23', '24',
                '25', '26', '27', '28', '29', '30',
                '31'
            ],
            'time': [
                '00:00', '02:00', '04:00',
                '06:00', '08:00', '10:00',
                '12:00', '14:00', '16:00',
                '18:00', '20:00', '22:00',
            ],
        }
        )
    
        daily_means = ct.climate.daily_mean(data)
        del data
    
        result.append(daily_means)

    return result[0], result[1], result[2]
```

If you intend to replicate the retrieval of the temperature data note that:
1. The query will take a long time (hours) because the data needs to be retrieved from tape
2. The file names will likely differ
3. At the time of writing the query does not return the whole date range specified by the query: only 2003-01-01 through 2019-10-01. In the future the full range may be returned.

Copyright
=========

The followig files were generated using Copernicus Climate Change Service Information 2020; see https://apps.ecmwf.int/datasets/licences/copernicus/:
* `41fe1db9-74cf-4842-a8ea-f8e55281c9ad.nc`
* `a45203bd-8884-4178-a068-5d3e5c05e72e.nc`
* `d6867180-6444-4fd0-bda7-480197f76239.nc`

The followig files were autohored by Copyright (c) 2020 Andrey Bienkowski <hexagonrecursion@gmail.com>:
* `supercooling.ipynb`
* `README.txt`
* `environment.yml`
* `postBuild`

MIT License

Copyright (c) 2020 Andrey Bienkowski <hexagonrecursion@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

For the file `EAB range.txt` see the `Source of information` column of `EAB range.txt`
