AstroFabry
New member
Hi guys.
I'm trying to find a proper way to clone an ImageWindow but I'm stuck with FITS keywords that do not want to get copied ...
Here is my code (partially copied from other scripts and partially modified):
Does anyone know how to do it properly ?
Thank you very much for your help !
AstroFabry
I'm trying to find a proper way to clone an ImageWindow but I'm stuck with FITS keywords that do not want to get copied ...
Here is my code (partially copied from other scripts and partially modified):
JavaScript:
this.cloneProperties = function (oldView, newView) {
try {
console.warningln("Cloning properties from " + oldView.id + " to " + newView.id);
let oldProperties = [];
for (let idx = 0; idx < oldView.properties.length; ++idx) {
oldProperties.push([oldView.properties[idx], oldView.propertyValue(oldView.properties[idx]), oldView.propertyAttributes((oldView.properties[idx]))]);
}
newView.beginProcess();
for (let idx = 0; idx < oldProperties.length; ++idx) {
try {
newView.setPropertyValue(oldProperties[idx][0], oldProperties[idx][1]);
newView.setPropertyAttributes(oldProperties[idx][0], oldProperties[idx][2]);
} catch (e) {
this.logger.error(e.message);
}
}
// THIS PART DOESN'T WORK - BEGIN
for (let idx = 0; idx < oldView.window.keywords.length; ++idx)
{
newView.window.keywords.push(new FITSKeyword(oldView.window.keywords[idx]));
}
// THIS PART DOESN'T WORK - END
newView.endProcess();
} catch (e) {
this.logger.error(e.message);
};
};
this.cloneView = function (view, newId) {
try {
let newWindow = new ImageWindow(1, 1, 1, view.window.bitsPerSample, view.window.isFloatSample, view.image.colorSpace != ColorSpace_Gray, newId);
newWindow.mainView.beginProcess(UndoFlag_NoSwapFile);
newWindow.mainView.image.assign(view.image);
newWindow.mainView.endProcess();
this.cloneProperties(view, newWindow.mainView);
newWindow.mainView.stf = view.stf;
newWindow.show();
newWindow.zoomToFit();
return newWindow.mainView;
} catch (e) {
this.logger.error(e.message);
};
return null;
};
Does anyone know how to do it properly ?
Thank you very much for your help !
AstroFabry
Last edited: