diff --git a/controllers/gddAccumulatedController.js b/controllers/gddAccumulatedController.js
index 09e0c7ba7e862fb26fc6fd118641fbcdc7e63a3e..222f882f9c169383e2e3512daab8f696e776f62b 100644
--- a/controllers/gddAccumulatedController.js
+++ b/controllers/gddAccumulatedController.js
@@ -13,7 +13,7 @@ function send_response(message, gdds, data, res) {
     })
 }
 
-function find(collection, query, projection, t_base, res, product) {
+function find(collection, query, projection, t_base, res, product, current) {
     collection.findOne(query, projection).then(function(data) {
         var min_temps = data["min_temps"]
         var max_temps = data["max_temps"]
@@ -29,7 +29,17 @@ function find(collection, query, projection, t_base, res, product) {
             gdd_sum += gdd_value
             gdds.push(gdd_sum)
         }
-        send_response("Accumulated GDDs", gdds, data, res);
+        if (current) {
+            analog_year = data["analog_year"]
+        } else {
+            analog_year = -1
+        }
+            res.json({message: "Accumulated GDDs",
+                date: data["last_date"],
+                data: gdds,
+                analog_year: analog_year,
+                closest_lon: data["location"]["coordinates"][0],
+                closest_lat: data["location"]["coordinates"][1]});
     }, function(err) {
         res.status(500).send({"internal error": err})
     })
@@ -135,7 +145,8 @@ exports.accumulated_gdd = function (req, res) {
     if (year != new Date().getFullYear()) {
         find(gdd_collection, query, projection, t_base, res, product);
     } else {
-        find(gdd_current_collection, query, projection, t_base, res, product);
+        projection["analog_year"] = 1;
+        find(gdd_current_collection, query, projection, t_base, res, product, true);
     }
    
 };
diff --git a/controllers/gddController.js b/controllers/gddController.js
index 66a405946b6e7da16f65b4ea70630a7d7d2e577b..b37655f3204d8cea8f2efb919f2ca9c00dd5f82c 100644
--- a/controllers/gddController.js
+++ b/controllers/gddController.js
@@ -1,3 +1,5 @@
+const { response } = require('express');
+
 gdd_collection = require('../models/gdd.js');
 gdd_current_collection = require('../models/gdd_current.js');
 utils = require('../lib/utils');
@@ -5,16 +7,16 @@ utils = require('../lib/utils');
 
 
 function send_response(message, gdds, data, res) {
-    res.json({
+    return {
         message: message,
         date: data["last_date"],
         data: gdds,
         closest_lon: data["location"]["coordinates"][0],
         closest_lat: data["location"]["coordinates"][1]
-    })
+    };
 }
 
-function find(collection, query, projection, t_base, res, product) {
+function find(collection, query, projection, t_base, res, product, current) {
     collection.findOne(query, projection).then(function(data) {
         var min_temps = data["min_temps"]
         var max_temps = data["max_temps"]
@@ -28,7 +30,21 @@ function find(collection, query, projection, t_base, res, product) {
         
             gdds.push(gdd_value)
         }
-        send_response("GDDs", gdds, data, res);
+        // response = send_response("GDDs", gdds, data, res);
+        // if (current) {
+        //     response["analog_year"] = data["analog_year"];
+        // }
+        if (current) {
+            analog_year = data["analog_year"]
+        } else {
+            analog_year = -1
+        }
+            res.json({message: "GDDs",
+                date: data["last_date"],
+                data: gdds,
+                analog_year: analog_year,
+                closest_lon: data["location"]["coordinates"][0],
+                closest_lat: data["location"]["coordinates"][1]});
     }, function(err) {
         res.status(500).send({"internal error": err})
     })
@@ -104,7 +120,8 @@ exports.year_gdd = function (req, res) {
     if (year != new Date().getFullYear()) {
         find(gdd_collection, query, projection, t_base, res, product);
     } else {
-        find(gdd_current_collection, query, projection, t_base, res, product);
+        projection["analog_year"] = 1;
+        find(gdd_current_collection, query, projection, t_base, res, product, true);
     }
    
 };
\ No newline at end of file
diff --git a/models/gdd_current.js b/models/gdd_current.js
index 7658b97d224bb635fd811299bf9257c711756ccd..62edabe14ad6cd67b6862da3c319f3e2a880c724 100644
--- a/models/gdd_current.js
+++ b/models/gdd_current.js
@@ -20,6 +20,10 @@ var gddCurrentSchema = mongoose.Schema({
         type: Number,
         required: true
     },
+    analog_year: {
+        type: Number,
+        required: true
+    },
     last_date: {
         type: Date,
         default: Date.now
diff --git a/pull_data.py b/pull_data.py
index 08cbb5ed32218439da46fd943832780fef6b9c90..9d0078af8585da82698d33c80f75e28c151c21d4 100644
--- a/pull_data.py
+++ b/pull_data.py
@@ -28,6 +28,9 @@ gdd.drop()
 
 gdd = db["gdd_current"]
 
+
+gdd_base = db["gdd"]
+
 resp = gdd.create_index([ ("location", "2dsphere") ])
 resp = gdd.create_index([ ("year", 1) ])
 
@@ -136,6 +139,38 @@ for i in tqdm.tqdm(x):
     lat_ = lat[i[0]]
     lon_ = lon[i[1]]
 
+    query = {
+        "location": { 
+            "$near": {
+                "$geometry": {
+                    "type": "Point", 
+                    "coordinates": [float(lon_), float(lat_)]
+                },
+            },
+        },
+    }
+
+    proj = {
+        "min_temps": 1,
+        "max_temps": 1,
+        "year": 1
+    }
+
+    min_err = 10000000
+    analog_year = 1981
+    yearly_min_data = np.zeros((year - 1981, len(tmin_)))
+    yearly_max_data = np.zeros((year - 1981, len(tmin_)))
+    for loc_data in gdd_base.find(query, proj).limit(year - 1981):
+        yearly_min_data[loc_data["year"] - 1981] = np.array(loc_data["min_temps"][:len(tmin_)])
+        yearly_max_data[loc_data["year"] - 1981] = np.array(loc_data["max_temps"][:len(tmin_)])
+
+    l2_dist_min = np.mean((yearly_min_data - tmin_) ** 2, axis=1)
+    l2_dist_max = np.mean((yearly_max_data - tmax_) ** 2, axis=1)
+
+    l2_dist = (l2_dist_max + l2_dist_min) / 2
+
+    analog_year = np.argmin(l2_dist) + 1981
+
     a = i
 
     t = {}
@@ -147,6 +182,7 @@ for i in tqdm.tqdm(x):
     t["location"] = {"type": "Point", "coordinates": [float(lon_), float(lat_)]}
     t["prism_lat"] = int(a[0])
     t["prism_lon"] = int(a[1])
+    t["analog_year"] = int(analog_year)
     
     t["last_date"] = datetime.datetime.strptime(str(soy + np.timedelta64(len(tmin_) - 1, "D")) , "%Y-%m-%d")
     t["year"] = int(year)
diff --git a/swagger_definition.yaml b/swagger_definition.yaml
index 8bcc877a98f113baf60e870d24aeac2f8fa07a66..0456d5ee50287d1031473e7300748135e41be78b 100644
--- a/swagger_definition.yaml
+++ b/swagger_definition.yaml
@@ -78,6 +78,11 @@ paths:
                                     minimum: -125.0
                                     maximum: -66.5
                                     example: -76.94
+                                analog_year:
+                                      type: number
+                                      minimum: -1
+                                      maximum: 2020
+                                      example: 2005
             400:
                 description: Bad Request
                 content:
@@ -337,6 +342,11 @@ paths:
                                       minimum: -125.0
                                       maximum: -66.5
                                       example: -76.94
+                                  analog_year:
+                                      type: number
+                                      minimum: -1
+                                      maximum: 2020
+                                      example: 2005
               400:
                   description: Bad Request
                   content:
@@ -425,6 +435,7 @@ paths:
                                       minimum: -125.0
                                       maximum: -66.5
                                       example: -76.94
+                                  
               400:
                   description: Bad Request
                   content: