-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReadWriteSurface.py
109 lines (72 loc) · 2.86 KB
/
ReadWriteSurface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
# coding: utf-8
# This is the current version.
#
# Running with an ERDDAP URL was many time slower to load.
#
# This version does each plot individually and composes them in a GridSpec panel.
# In[77]:
import pandas as pd
import utility as u
import numpy as np
import datetime
import colorcet as cc
# In[78]:
df = pd.read_csv('latest_surface.csv', skiprows=[1], low_memory=False)
df.sort_values(['time','observation_depth'], ascending=False, inplace=True)
# In[79]:
# Remove any row that has no surface observation for the 7 surface variables we are plotting.
surface_cols = ('latitude',
'longitude',
'time',
'observation_depth',
'platform_type',
'platform_code',
'sst',
'slp',
'atmp',
'winddir',
'windspd',
'dewpoint',
'clouds')
# Some platforms report ztmp with observation_depth = 0.0 which is really sst.
# So to get all surface obs you have to segment by platform type
surface_platforms = ['TROPICAL MOORED BUOYS',
'C-MAN WEATHER STATIONS',
'DRIFTING BUOYS (GENERIC)',
'ICE BUOYS',
'MOORED BUOYS (GENERIC)',
'RESEARCH',
'SHIPS (GENERIC)',
'SHORE AND BOTTOM STATIONS (GENERIC)',
'TIDE GAUGE STATIONS (GENERIC)',
'TSUNAMI WARNING STATIONS',
'UNKNOWN',
'UNMANNED SURFACE VEHICLE',
'VOLUNTEER OBSERVING SHIPS',
'VOLUNTEER OBSERVING SHIPS (GENERIC)',
'VOSCLIM',
'WEATHER AND OCEAN OBS',
'WEATHER BUOYS',
'WEATHER OBS']
# Removes rows with other platform types
surface = df[df.platform_type.isin(surface_platforms)]
# Removes columns that are not metdadata or a desired surface variable
surface = surface.loc[:, surface_cols]
# Removes any row that does not have at least 1 surface observation that is not NaN
surface.dropna(subset=['sst', 'slp', 'atmp', 'winddir', 'windspd', 'dewpoint', 'clouds'], how='all', inplace=True)
# In[80]:
# In[81]:
surface_max = surface.drop_duplicates(['platform_code'])
# In[82]:
surface_locs = surface_max.loc[:,('latitude', 'longitude', 'platform_type', 'platform_code')]
surface_locs.sort_values(['platform_type'], inplace=True)
# In[83]:
# Make time the index for the surface data since all plots are timeseries.
surface['time_val'] = surface['time']
surface.loc[:, 'time'] = pd.to_datetime(surface['time'])
surface.set_index('time', inplace=True)
# In[84]:
# In[85]:
surface_locs.to_pickle('surface_locations_latest.pkl')
surface.to_pickle('surface_data_latest.pkl')