utilising cygwin, python & octave to obtain daily & hourly ... · pdf...

64
[email protected] 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months, years, and stations from climate.weather.gc.ca

Upload: truonghanh

Post on 18-Mar-2018

221 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

[email protected] 1

Utilising Cygwin, Python & Octave to obtain daily & hourly climate datafor multiple months, years, and stations from climate.weather.gc.ca

Page 2: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

outline

• Why?• MSc students’ requests• (my current research)

• Environment Canada historical climate / weather data via:

• web

• Cygwin

• Python

• Octave

• raster GIS data

Page 3: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

3student wanted data for Mt.Fromme, BC

Page 4: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

4

results for North Vancouver……hmmm…

Page 5: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

5

Mt.Fromme restoration

Page 6: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

6

results for Grouse

!?

Page 7: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

7

EnvironmentCanadaweather stationsas of 2012 in this dataset(not all active)

Page 8: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

8

Mt.Fromme restoration

Page 9: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

9

Nurdles (pellets used to make #2-HDPE, #4-LDPE & #5-PP plastics) on Victoria beaches & waterfronts

Page 10: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

10

Nurdles on Victoria beaches & waterfronts

Nurdles were observed at red sites on map;10 Litre samples of beach surface debris, plastics, wood, etc, were collected at 5 sites and nurdles measured in milliLitres

Page 11: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

11

High tide and high windsMonNov13, 1pm

Willows Beach

Page 12: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

12

Page 13: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

13

!?

!?

Page 14: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

14

Page 15: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

15

Google maps to obtain Lat / Long

Page 16: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

16

Page 17: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

17

If hourly needed, only by 1 year and 1 month and 1 dayat a time…

If daily needed, only by 1 year and 1 month at a time

If monthly needed, only by 1 year at a time

via the web…

Page 18: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

18

Page 19: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

19

for Daily (data).csv output provides entire month……but not multiple months or multiple years

Page 20: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

20

for Daily or Hourly (data)b/c .csv does not provide……multiple months or multiple years

Page 21: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

21

Cygwin and script

Page 22: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

22

EC instructions to install CygwinCygwin: Unix-like environment and command-line interface for Windows…

Page 23: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

23

I got mixed up confusionMan, it’s a-killing me…

Well, my head’s full of questionsMy temperature’s rising fastWell, I’m looking for some answersBut I don’t know who to ask…

(Mixed up confusion, 1962, with apologies to Nobel Laureate Bob Dylan)

So while waiting for answers from EC,one person from EC suggested…

Page 24: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

24

Python 2.7.11

Page 25: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

25

• widely used programming language for general-purpose• created by Guido van Rossum and first released in 1991

Page 26: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

26

Python 2.7.11

must be 2.7.11

Page 27: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

27

Python 2.7.11

Page 28: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

28

Python 2.7.11

right-click

Page 29: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

29

Python 2.7.11

Page 30: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

30

Python 2.7.11

Page 31: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

31

Python 2.7.11

Page 32: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

32

Python 2.7.11

Page 33: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

33

Python 2.7.11

retrieve data fromyear range 2013-2016; the +1 is necessarymonth range 1-12; the +1 is necessary

Page 34: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

34

Python 2.7.11

Page 35: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

35

Python 2.7.11

output

Page 36: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

36

Python 2.7.11

If want to sort, etcneed to strip out (extraneous) station info repeated between each month / year

Page 37: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

37

Python 2.7.11: How long will it be supported?

If Python 2.7 converted to Python 3.6 (via 2to3.py)can (historical) climate data still be extracted from EC?

Page 38: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

38

Python 2.7.11: How long will it be supported?

email to EC:

IF I convert the script to Python 3.6,will the EC server(s) "understand" Python 3.6?

(Or is historical weather data only set-up for Python 2.7?)

Reply:…if EC is still using the version which uses the urllib2 library… (If yes)then no, a version of Python of 3.1 or higher will not work with this script

Reply#2:EC does not support this way of database extraction…

Page 39: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

39

for Daily (data)b/c .csv does not provide……multiple months or multiple years

Page 40: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

40

Cygwin and script

Page 41: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

41

EC instructions to install CygwinCygwin: Unix-like environment and command-line interface for Windows

Page 42: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

42

Cygwin and script

this includes the command line script!

Page 43: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

43

EC instructions to install CygwinCygwin: Unix-like environment and command-line interface for Windows

for year in `seq 2006 2008`;do for month in `seq 1 12`;do wget --content-disposition"http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=27226&Year=${year}&Month=${month}&Day=14&timeframe=1&submit= Download+Data" ;done;done

NOTE: spaces are important! Copy from EC as 1(one) continuous line

Page 44: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

44

Cygwin

Page 45: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

45

Cygwin

separate files for each month……bit of a pain?….

Page 46: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

46

…combine / merge multiple .csv (or .xls) NOTE: the following is for Excel 2016

Page 47: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

47

…combine / merge multiple .csv (or .xls)

Page 48: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

48

…combine / merge multiple .csv (or .xls)

Page 49: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

49

combined / merged files after Excel 2016 (obtained via Cygwin)

…bit of a pain?….

Page 50: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

50

another method: Octave

• programming language primarily intended for numerical computations• mostly compatible with Matlab• free open source• originally released 1988

Page 51: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

51

as of Nov21

courtesy Jay Brodeur, McMasterU

Page 52: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

52

Page 53: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

53

change what you want here… or….

Page 54: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

54

Page 55: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

55

paste code into OctaveEditor pane

…change script here…

Page 56: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

56

saved file name

Page 57: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

57

output…

separate years in one .csv…(but has not worked for me yet…)

Page 58: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

58

EnvironmentCanadaweather stationsas of 2012(not all active)

Page 59: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

59

EnvironmentCanadaweather stationsas of 2012(not all active)

Page 60: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

60

other climate data possibilities…using GIS

data interpolated to1 square kilometre grid

Version2: gridded raster climate data of minimum, mean, maximum temperature and precipitationfor 1970-2000 averagesby months Jan-Dec

Page 61: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

61

WorldClim.org raster data&EnvironmentCanadaweather stations

Page 62: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

62

WorldClimraster dataaverage August temperature1970-2000

Page 63: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

63

DayMetmuch more complicated……but possible…

Page 64: Utilising Cygwin, Python & Octave to obtain daily & hourly ... · PDF filedanielbm@uvic.ca 1 Utilising Cygwin, Python & Octave to obtain daily & hourly climate data for multiple months,

64

Summary

• Python 2.7 script• ‘simplest’ script but need to strip out station information when downloading multiple months,

years• long term support??

• Cygwin• separate .csv’s need to be combined / merged

• Octave• complex script• currently for me not compiling multiple months, years in one .csv

• WorldClim: 20 year averages; raster data for GIS

• DayMet: NetCDF files need to be converted to raster for GIS