Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gdd-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dawn
gdd-server
Commits
fe05857e
Commit
fe05857e
authored
4 years ago
by
tuckersiegel
Browse files
Options
Downloads
Patches
Plain Diff
added 30 year normals
parent
78fd75bc
No related branches found
No related tags found
1 merge request
!4
added 30 year normals
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+1
-0
1 addition, 0 deletions
README.md
to_mongo.py
+93
-2
93 additions, 2 deletions
to_mongo.py
with
94 additions
and
2 deletions
README.md
+
1
−
0
View file @
fe05857e
...
...
@@ -11,6 +11,7 @@ The data in mongodb has the following fields:
*
```year```
- Year of the data
*
```min_temps```
- Minimum daily temperature as an array. One element is one day
*
```max_temps```
- Maximum daily temperature as an array. One element is one day
*
```normal```
- Indicates whether the data is a 30 year normal or not
#### API Endpoints
*
```POST /api/:product/:year```
...
...
This diff is collapsed.
Click to expand it.
to_mongo.py
+
93
−
2
View file @
fe05857e
...
...
@@ -4,6 +4,18 @@ import tqdm
import
datetime
from
pymongo
import
MongoClient
def
is_leap_year
(
year
):
if
(
year
%
4
)
==
0
:
if
(
year
%
100
)
==
0
:
if
(
year
%
400
)
==
0
:
return
True
else
:
return
False
else
:
return
True
else
:
return
False
client
=
MongoClient
(
'
0.0.0.0
'
,
27017
)
db
=
client
[
"
gdd_database
"
]
...
...
@@ -21,12 +33,12 @@ coords = xr.open_dataset("coords.nc")
lat
=
coords
.
latitude
.
data
lon
=
coords
.
longitude
.
data
years
=
list
(
range
(
1981
,
1982
+
1
))
years
=
list
(
range
(
1981
,
2020
+
1
))
for
year
in
years
:
soy
=
np
.
datetime64
(
"
%s-01-01
"
%
year
)
print
(
year
)
data
=
xr
.
open_dataset
(
"
data/temps_
2019.nc
"
)
data
=
xr
.
open_dataset
(
"
data/temps_
%s.nc
"
%
year
)
x
=
np
.
where
(
~
np
.
isnan
(
np
.
nanmean
(
data
.
tmin
.
data
,
axis
=
0
)))
x
=
[(
a
,
b
)
for
a
,
b
in
zip
(
x
[
0
],
x
[
1
])]
...
...
@@ -66,8 +78,87 @@ for year in years:
t
[
"
min_temps
"
]
=
list
([
float
(
a
)
for
a
in
tmin_
])
t
[
"
max_temps
"
]
=
list
([
float
(
a
)
for
a
in
tmax_
])
t
[
"
_id
"
]
=
_id
t
[
"
normal
"
]
=
False
locs
.
append
(
t
)
count
+=
1
### 30 YEAR NORMALS ###
### Covers from 1981-2010 ###
single_year_min
=
np
.
zeros
((
365
,
621
,
1405
))
single_year_max
=
np
.
zeros
((
365
,
621
,
1405
))
single_year_min
[:]
=
np
.
nan
single_year_max
[:]
=
np
.
nan
for
year
in
range
(
1981
,
2010
+
1
):
print
(
year
)
data
=
xr
.
open_dataset
(
"
data/temps_%s.nc
"
%
year
)
tmins
=
data
.
tmin
.
data
tmaxs
=
data
.
tmax
.
data
if
is_leap_year
(
year
):
# extra day in leap year screws everything up
tmin_1
=
tmins
[:
59
]
tmin_2
=
tmins
[
60
:]
tmax_1
=
tmaxs
[:
59
]
tmin_2
=
tmaxs
[
60
:]
tmins
=
np
.
concatenate
([
tmin_1
,
tmin_2
],
axis
=
0
)
tmaxs
=
np
.
concatenate
([
tmin_1
,
tmin_2
],
axis
=
0
)
single_year_max
+=
tmaxs
/
30
single_year_min
+=
tmins
/
30
x
=
np
.
where
(
~
np
.
isnan
(
np
.
nanmean
(
single_year_max
,
axis
=
0
)))
x
=
[(
a
,
b
)
for
a
,
b
in
zip
(
x
[
0
],
x
[
1
])]
lat
=
lat
[::
-
1
]
tmins
=
single_year_min
tmaxs
=
single_year_max
locs
=
[]
count
=
0
for
i
in
tqdm
.
tqdm
(
x
):
if
len
(
locs
)
%
100
==
0
and
len
(
locs
)
!=
0
:
new_result
=
gdd
.
insert_many
(
locs
)
locs
=
[]
tmin_
=
tmins
[:,
i
[
0
],
i
[
1
]]
tmax_
=
tmaxs
[:,
i
[
0
],
i
[
1
]]
lat_
=
lat
[
i
[
0
]]
lon_
=
lon
[
i
[
1
]]
a
=
i
t
=
{}
_id
=
str
(
year
)
+
"
_
"
_id
+=
str
(
a
[
0
])
+
"
_
"
+
str
(
a
[
1
])
+
"
_
"
+
"
normal
"
t
[
"
location
"
]
=
{
"
type
"
:
"
Point
"
,
"
coordinates
"
:
[
float
(
lon_
),
float
(
lat_
)]}
t
[
"
prism_lat
"
]
=
int
(
a
[
0
])
t
[
"
prism_lon
"
]
=
int
(
a
[
1
])
t
[
"
last_date
"
]
=
0
#datetime.datetime.strptime(str(soy + np.timedelta64(len(tmin_) - 1, "D")) , "%Y-%m-%d")
t
[
"
year
"
]
=
0
t
[
"
min_temps
"
]
=
list
([
float
(
a
)
for
a
in
tmin_
])
t
[
"
max_temps
"
]
=
list
([
float
(
a
)
for
a
in
tmax_
])
t
[
"
_id
"
]
=
_id
t
[
"
normal
"
]
=
True
locs
.
append
(
t
)
count
+=
1
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment