Skip to content

Commit

Permalink
Merge pull request #174 from Plant-for-the-Planet-org/hotfix/refactor…
Browse files Browse the repository at this point in the history
…-earthengine-api

Hotfix: Refactor Earth Engine API Calls for Improved Asynchronous Handling
  • Loading branch information
dhakalaashish authored Apr 26, 2024
2 parents ccf9c64 + 3d5a47d commit e6e146d
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,36 @@ class GOES16GeoEventProviderClass implements GeoEventProviderClass {
const fromDateTime = (!lastRunDate || (currentDateTime.getTime() - lastRunDate.getTime()) > 2 * 3600 * 1000) ? twoHoursAgo : lastRunDate;

const images = ee.ImageCollection("NOAA/GOES/16/FDCF").filterDate(fromDateTime, currentDateTime);

// Fetch and process images here...
// The process includes fetching image IDs, processing them to extract fire data, etc.
// This is a simplified outline; integrate the logic from your initial example here.
const getImagesId = () => {
return new Promise((resolve, reject) => {
images.evaluate((imageCollection) => {
if (imageCollection && imageCollection.features) {
const imagesData = imageCollection.features.map(feature => feature.id);
resolve(imagesData);
} else {
logger('No features found in image collection', 'error');
reject(new Error("No features found"));
}
});
});
};
const getDateTimeInfo = (image) => {
return new Promise((resolve, reject) => {
ee.Date(image.get('system:time_start')).getInfo((info, error) => {
if (error) {
reject(error);
return;
}
resolve(info);
});
});
}
try {
const array_imagesId = await getImagesId() as string[];
for (const imageId of array_imagesId) {
const image = ee.Image(`${imageId}`)
// Get the datetime information from the image metadata
const datetimeInfo = await ee.Date(image.get('system:time_start')).getInfo();
const datetimeInfo = await getDateTimeInfo(image);
const datetime = new Date(datetimeInfo.value);


const temperatureImage = image.select('Temp');
const xMin = -142; // On station as GOES-E
const xMax = xMin + 135;
Expand Down Expand Up @@ -144,7 +149,7 @@ class GOES16GeoEventProviderClass implements GeoEventProviderClass {
};
} catch (error) {
console.error("Error fetching fire data:", error);
logger(`Error fetching fire data`, "error");
logger(`Error fetching fire data: ${error}`, "error");
}

// Normalize the fire data into GeoEvent format
Expand Down

0 comments on commit e6e146d

Please sign in to comment.