-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsunrise_map.py
70 lines (60 loc) · 2.25 KB
/
sunrise_map.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
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 9 10:33:38 2019
@author: [email protected]
"""
import numpy as np
from sunrise import terminator as ter
from datetime import datetime
import matplotlib.pyplot as plt
from skimage import measure
from cartomap import geogmap as gm
def get_terminator(time, alt_km=0,
glon=None, glat=None,
return_sza=False):
if glon is None and glat is None:
glon, glat = np.meshgrid(np.arange(-180,180,1), np.arange(-90,91,.2))
if time is None:
time = datetime.now()
else:
assert isinstance(time, datetime)
sza_2d = ter.get_sza(time, glon, glat, alt_km=alt_km) - 90
terminator = np.squeeze(np.array(measure.find_contours(sza_2d, 0)))
if len(terminator.shape) == 2:
x = terminator[:,1] - 180
y = terminator[:,0] - 90
elif (len(terminator.shape) == 1) and (terminator.shape[0] > 1):
x = []
y = []
for i, t in enumerate(terminator):
x.append(t[:,1] - 180)
y.append(t[:,0] - 90)
if return_sza:
return sza_2d
else:
return x, y
date = datetime(2017,8,21,23)
alt_km = 0
glon, glat = np.meshgrid(np.arange(-180, 180.1, 1),
np.arange(-90, 90.1, 1))
sza = get_terminator(time=date, alt_km = alt_km, glon=glon, glat = glat, return_sza=True)
terminator = np.squeeze(np.array(measure.find_contours(sza, 0)))
x,y = get_terminator(time=date, alt_km = alt_km, glon=glon, glat = glat)
if isinstance(x, list):
plt.figure()
im = plt.pcolormesh(glon, glat, sza, cmap='bwr', vmin=-80, vmax=80)
for i in range(len(x)):
plt.plot(x[i], y[i], '--g', lw=4)
plt.colorbar(im)
else:
plt.figure()
im = plt.pcolormesh(glon, glat, sza, cmap='bwr', vmin=-80, vmax=80)
plt.plot(x, y, '--g', lw=4)
plt.colorbar(im)
fig, ax = gm.plotCartoMap(projection='plate',lon0=-50,
title="{}, Terminators H=[0,150] km".format(date),
lonlim=[-140,0], latlim=[-90,90],
meridians = np.arange(-180,180.1,40),
parallels = np.arange(-80,80.1,20),
date=date,
terminator=True, terminator_altkm=[0,150])