Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: Refactor Earth Engine API Calls for Improved Asynchronous Handling #174

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading