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
ac1357d6
Commit
ac1357d6
authored
4 years ago
by
Tucker Gary Siegel
Browse files
Options
Downloads
Plain Diff
Merge branch '30_year_normals' into 'master'
added 30 year normals See merge request
!4
parents
e3230e29
8fa0e5f5
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
+92
-1
92 additions, 1 deletion
to_mongo.py
with
93 additions
and
1 deletion
README.md
+
1
−
0
View file @
ac1357d6
...
...
@@ -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
Go to
```/docs```
to view the Swagger generated API docs
#### API Endpoints
...
...
This diff is collapsed.
Click to expand it.
to_mongo.py
+
92
−
1
View file @
ac1357d6
...
...
@@ -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
(
"
mongodb+srv://gdd-server:u8i3icLAJXjZEhTs@cluster0.wdxf4.mongodb.net
"
)
db
=
client
[
"
gdd_database
"
]
...
...
@@ -80,10 +92,89 @@ 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
if
len
(
locs
)
!=
0
:
new_result
=
gdd
.
insert_many
(
locs
)
\ No newline at end of file
new_result
=
gdd
.
insert_many
(
locs
)
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