Commit 0d5ed633 authored by SAPONE Alann's avatar SAPONE Alann

New algos to add presets at runtime + new defaults + bug correction

parent ffc7da30
......@@ -47,8 +47,6 @@ import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.apache.log4j.Logger;
import org.cnrs.lam.dis.etc.configuration.ConfigFactory;
import org.cnrs.lam.dis.etc.dataimportexport.DataImporter;
......@@ -67,7 +65,6 @@ import org.json.JSONObject;
class DbInstaller {
private static Logger logger = Logger.getLogger(DbInstaller.class);
private static BlockingQueue<Thread> threadToWaitQueue = new ArrayBlockingQueue<Thread>(100);
public static void installDb(String dbDir) {
Connection connection = null;
......
1.24898403252389E+04 4.5646913847997E-22
1.48390871560965E+04 3.69306439738193E-22
1.95509409796914E+04 2.55786534654593E-22
2.51015534197874E+04 1.28015978842952E-22
2.90618564522374E+04 9.65083287159088E-23
3.19514828238111E+04 2.417340347864E-22
3.14055199530349E+04 2.55786534654593E-20
3.63604075580239E+04 2.0694414251272E-22
3.82898647525311E+04 2.63116217302494E-22
4.35734108310652E+04 9.65083287159088E-22
5.17692479786133E+04 3.25216189344876E-21
5.84072913037881E+04 5.6420373967039E-21
5.74092715057614E+04 5.33207295748675E-20
6.09789077040035E+04 7.91908900640278E-21
6.64668030550155E+04 9.25038667007794E-21
6.82075319826562E+04 3.20654388015905E-20
7.05996251575013E+04 4.31391459871965E-20
7.43459790583003E+04 4.37528666186614E-20
8.03415340166136E+04 1.49537062064636E-20
1.01388342663425E+05 1.51664456524066E-20
1.04043647460523E+05 5.48486599910097E-20
1.07692542116902E+05 5.11082693753952E-20
1.15378728467882E+05 1.45371377333112E-20
1.43116142780619E+05 1.35457812705556E-20
1.72991176422589E+05 1.19285961263829E-20
2.18309108577084E+05 1.08054920808152E-20
2.82713993555541E+05 1.09592168074265E-20
4.23882521377547E+05 1.39339419611296E-20
5.58477894940486E+05 1.67428196242449E-20
6.69266061373949E+05 2.86389725256297E-20
8.08973195108152E+05 4.6954947489462E-20
9.77843742830744E+05 6.77938911399052E-20
1.17182369496152E+06 8.03175021455648E-20
1.57075258977668E+06 7.17348903754886E-20
2.05175617190907E+06 4.37528666186614E-20
2.68005503627115E+06 2.22089478836388E-20
3.71842718477339E+06 7.91908900640278E-21
4.8154261908938E+06 2.987874424244E-21
5.8710066845208E+06 1.49537062064636E-21
9.0331313091409E+06 2.38343236058429E-22
\ No newline at end of file
......@@ -97,4 +97,14 @@
xUnit=Å
yUnit=erg/cm^2/s/Å/arcsec^2
dataType=FUNCTION
}
\ No newline at end of file
}
{
file=Galactic.dat
type=GALACTIC
name=Galactic
description=
xUnit=Å
yUnit=erg/cm^2/s/Å/arcsec^2
dataType=FUNCTION
}
<?xml version="1.0" encoding="UTF-8"?>
<observingParameters><info name="Demo - Obs Parameters - Int 1s" description=""/><dit value="1.0" unit="sec"/><exposureTime value="1.0" unit="sec"/><fixedParameter>EXPOSURE_TIME</fixedParameter><noExpo value="0"/><snr value="0.0" unit=""/><snrLambda value="0.0" unit="Å"/><timeSampleType>DIT</timeSampleType><spectralQuantumType>SPECTRAL_PIXEL</spectralQuantumType><extraBackgroundNoiseType>ONLY_CALCULATED_BACKGROUND_NOISE</extraBackgroundNoiseType><extraSignalType>ONLY_CALCULATED_SIGNAL</extraSignalType><extraBackgroundNoise value="0.0" unit="e⁻/s"/><extraSignal value="0.0" unit="e⁻/s"/><fixedSnrType>TOTAL</fixedSnrType></observingParameters>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<source>
<info name="BB-T10000K-MagJ20-Z0"
description=" BlackBody - Temp : 10000K - Mag AB J : 20 - redshift : 0" />
<magnitudeWavelength value="12500.0" unit="Å" />
<emissionLineWavelength value="0.0" unit="Å" />
<emissionLineFwhm value="0.0" unit="Å" />
<extendedSourceProfile>UNIFORM</extendedSourceProfile>
<extendedSourceRadius value="0.0" unit="arcsec" />
<magnitude value="20.0" />
<redshift value="0.0" />
<temperature value="10000.0" unit="K" />
<spatialDistributionType>POINT_SOURCE</spatialDistributionType>
<spectralDistributionType>BLACK_BODY</spectralDistributionType>
<emissionLineFlux value="0.0" unit="erg/cm^2/s" />
<extendedMagnitudeType>PEAK_VALUE</extendedMagnitudeType>
</source>
<?xml version="1.0" encoding="UTF-8"?>
<source>
<info name="BB-T5000k-MagJ20-Z0"
description="BlackBody - Temp : 5000K - Mag AB J : 20 - redshift : 0" />
<magnitudeWavelength value="12500.0" unit="Å" />
<emissionLineWavelength value="0.0" unit="Å" />
<emissionLineFwhm value="0.0" unit="Å" />
<extendedSourceProfile>UNIFORM</extendedSourceProfile>
<extendedSourceRadius value="0.0" unit="arcsec" />
<magnitude value="20.0" />
<redshift value="1.0" />
<temperature value="5000.0" unit="K" />
<spatialDistributionType>POINT_SOURCE</spatialDistributionType>
<spectralDistributionType>BLACK_BODY</spectralDistributionType>
<emissionLineFlux value="0.0" unit="erg/cm^2/s" />
<extendedMagnitudeType>PEAK_VALUE</extendedMagnitudeType>
</source>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<source>
<info name="BB-T5000K-MAGJ20-z1"
description="BlackBody - Temp : 5000K - Mag AB J : 20 - redshift : 1" />
<magnitudeWavelength value="12500.0" unit="Å" />
<emissionLineWavelength value="0.0" unit="Å" />
<emissionLineFwhm value="0.0" unit="Å" />
<extendedSourceProfile>UNIFORM</extendedSourceProfile>
<extendedSourceRadius value="0.0" unit="arcsec" />
<magnitude value="20.0" />
<redshift value="1.0" />
<temperature value="5000.0" unit="K" />
<spatialDistributionType>POINT_SOURCE</spatialDistributionType>
<spectralDistributionType>BLACK_BODY</spectralDistributionType>
<emissionLineFlux value="0.0" unit="erg/cm^2/s" />
<extendedMagnitudeType>PEAK_VALUE</extendedMagnitudeType>
</source>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<source>
<info name="Halpha SFR=40 z=0.8 " description="CFRS#03.125" />
<magnitudeWavelength value="0.0" unit="Å" />
<emissionLineWavelength value="6563.0" unit="Å" />
<emissionLineFwhm value="10.0" unit="Å" />
<extendedSourceProfile>UNIFORM</extendedSourceProfile>
<extendedSourceRadius value="0.0" unit="arcsec" />
<magnitude value="0.0" />
<redshift value="0.8" />
<temperature value="0.0" unit="K" />
<spatialDistributionType>POINT_SOURCE</spatialDistributionType>
<spectralDistributionType>EMISSION_LINE</spectralDistributionType>
<emissionLineFlux value="2.0E-16" unit="erg/cm^2/s" />
<extendedMagnitudeType>PEAK_VALUE</extendedMagnitudeType>
</source>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<source>
<info name="Halpha SFR=140 z=0.8" description="CFRS#03.1534" />
<magnitudeWavelength value="0.0" unit="Å" />
<emissionLineWavelength value="6563.0" unit="Å" />
<emissionLineFwhm value="6.3" unit="Å" />
<extendedSourceProfile>UNIFORM</extendedSourceProfile>
<extendedSourceRadius value="0.0" unit="arcsec" />
<magnitude value="0.0" />
<redshift value="0.8" />
<temperature value="0.0" unit="K" />
<spatialDistributionType>POINT_SOURCE</spatialDistributionType>
<spectralDistributionType>EMISSION_LINE</spectralDistributionType>
<emissionLineFlux value="7.0E-16" unit="erg/cm^2/s" />
<extendedMagnitudeType>PEAK_VALUE</extendedMagnitudeType>
</source>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<source>
<info name="Halpha SFR=400 z=1" description="CFRS#14.0600" />
<magnitudeWavelength value="0.0" unit="Å" />
<emissionLineWavelength value="6563.0" unit="Å" />
<emissionLineFwhm value="8.0" unit="Å" />
<extendedSourceProfile>UNIFORM</extendedSourceProfile>
<extendedSourceRadius value="0.0" unit="arcsec" />
<magnitude value="0.0" />
<redshift value="1.0" />
<temperature value="0.0" unit="K" />
<spatialDistributionType>POINT_SOURCE</spatialDistributionType>
<spectralDistributionType>EMISSION_LINE</spectralDistributionType>
<emissionLineFlux value="1.1E-15" unit="erg/cm^2/s" />
<extendedMagnitudeType>PEAK_VALUE</extendedMagnitudeType>
</source>
\ No newline at end of file
......@@ -236,6 +236,7 @@ public class DatasetInfoEntityJpaController {
cb.equal(from.get(DatasetInfoEntity_.namespace), info.getNamespace())),
cb.equal(from.get(DatasetInfoEntity_.type), type)));
TypedQuery<DatasetInfoEntity> query = em.createQuery(cq);
System.out.println(query.getResultList().size());
for (DatasetInfoEntity result : query.getResultList()) {
// The above query returns both the entries which have the same namespace
// and the ones which have null as namespace. Here we do another check
......
......@@ -3,7 +3,7 @@ CREATE TABLE ETC_INFO (
DB_VERSION INT NOT NULL -- The version of the database schema
);
INSERT INTO ETC_INFO VALUES (30);
INSERT INTO ETC_INFO VALUES (31);
-- The table defining the different sets of data that can be used in the datasets
CREATE TABLE DATASET (
......
......@@ -59,9 +59,12 @@ public class UIFactory {
frame = new EtcFrame();
}
frame.setInfoProvider(infoProvider);
frame.setVisible(true);
return frame;
}
public static void setFrameVisible(boolean visible) {
frame.setVisible(visible);
}
public static Messenger getMessenger() {
String uiMode = ConfigFactory.getConfig().getUiMode();
......
......@@ -123,6 +123,11 @@ public class EtcFrame extends javax.swing.JFrame implements org.cnrs.lam.dis.etc
private ImagesTabbedPane imagesTabbedPane = new ImagesTabbedPane();
private CommandHistoryPanel commandHistoryPanel = new CommandHistoryPanel();
private ChartsTabbedPane chartsTabbedPane = new ChartsTabbedPane();
private static EtcFrame instance;
public static EtcFrame getInstance() {
return instance;
}
public final static String DOCUMENTATION_URL = "https://cesam.lam.fr/Apps/ETC/documentation/";
......@@ -153,6 +158,8 @@ public class EtcFrame extends javax.swing.JFrame implements org.cnrs.lam.dis.etc
siteScrollPane.getVerticalScrollBar().setUnitIncrement(15);
sourceScrollPanel.getVerticalScrollBar().setUnitIncrement(15);
obsParamScrollPane.getVerticalScrollBar().setUnitIncrement(15);
instance = this;
}
public <T extends Number> void showImage(String title, Image<T> image) {
......
......@@ -48,6 +48,7 @@ import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import org.cnrs.lam.dis.etc.datamodel.ComponentType;
import org.cnrs.lam.dis.etc.ui.swing.generic.TableColumnResizer;
import org.javatuples.Triplet;
......
package org.cnrs.lam.dis.etc.ui.swing.importer;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import javax.swing.ProgressMonitor;
import javax.swing.SwingWorker;
import org.apache.log4j.Logger;
import org.cnrs.lam.dis.etc.configuration.ConfigFactory;
import org.cnrs.lam.dis.etc.datamodel.ComponentInfo;
import org.cnrs.lam.dis.etc.datamodel.ComponentType;
import org.cnrs.lam.dis.etc.ui.generic.InstrumentListenerHolder;
import org.cnrs.lam.dis.etc.ui.generic.ObsParamListenerHolder;
import org.cnrs.lam.dis.etc.ui.generic.SiteListenerHolder;
import org.cnrs.lam.dis.etc.ui.generic.SourceListenerHolder;
import org.cnrs.lam.dis.etc.ui.swing.DefaultMessageHandler;
import org.cnrs.lam.dis.etc.ui.swing.EtcFrame;
import org.cnrs.lam.dis.etc.ui.swing.MessengerHolder;
import org.javatuples.Pair;
import org.javatuples.Triplet;
public class FileImportWorker extends SwingWorker<Void, Pair<String, Integer>> {
private ProgressMonitor progressMonitor;
private List<String> errorMessageList = Collections.synchronizedList(new LinkedList<String>());
private List<Triplet<String, String, URL>> instrumentList;
private List<Triplet<String, String, URL>> siteList;
private List<Triplet<String, String, URL>> sourceList;
private List<Triplet<String, String, URL>> obsParamList;
private MultiImportTool importTool = null;
private volatile int totalSize = 0;
private int sizeDone = 0;
private ResourceBundle bundle = ResourceBundle.getBundle("org/cnrs/lam/dis/etc/ui/swing/messages");
private static Logger logger = Logger.getLogger(FileImportWorker.class);
private BlockingQueue<Thread> threadToWaitQueue = new ArrayBlockingQueue<Thread>(1);
public FileImportWorker(
MultiImportTool importTool,
ProgressMonitor progressMonitor,
List<Triplet<String, String, URL>> instrumentList,
List<Triplet<String, String, URL>> siteList,
List<Triplet<String, String, URL>> sourceList,
List<Triplet<String, String, URL>> obsParamList) {
this.importTool = importTool;
this.progressMonitor = progressMonitor;
if (this.progressMonitor == null) {
this.progressMonitor = new ProgressMonitor(
EtcFrame.getInstance(),
bundle.getString("MULTI_IMPORT_MESSAGE"),
" ", 0, 100
);
this.progressMonitor.setMillisToDecideToPopup(0);
this.progressMonitor.setMillisToPopup(0);
this.progressMonitor.setProgress(0);
}
this.instrumentList = instrumentList;
this.siteList = siteList;
this.sourceList = sourceList;
this.obsParamList = obsParamList;
}
@Override
protected Void doInBackground() throws Exception {
// We mute the MultiImportWindow
if (importTool != null)
importTool.setEnabled(false);
// We need to handle all the messages comming, so we set our own handler
EtcFrame etcFrame = EtcFrame.getInstance();
MessengerHolder.setHandler(new DefaultMessageHandler(etcFrame) {
private final ResourceBundle controllerBundle = ResourceBundle.getBundle("org/cnrs/lam/dis/etc/controller/messages");
// When we get the message that an action was started we need to
// wait for it to finish so we add its thread in the waiting queue
@Override
public void actionStarted(String message, Thread thread) {
boolean inTheQueue = false;
while (!inTheQueue) {
try {
threadToWaitQueue.put(thread);
inTheQueue = true;
} catch (InterruptedException ex) {
}
}
}
@Override
public void actionStoped(Thread thread) {
// We do nothing here
}
@Override
public void error(String message) {
errorMessageList.add(message);
}
@Override
public void warn(String message) {
errorMessageList.add(message);
}
@Override
public String decision(String message, List<String> options) {
return controllerBundle.getString("IGNORE_OPTION");
}
});
// Calculate the total size
totalSize += 2 * instrumentList.size();
totalSize += 2 * siteList.size();
totalSize += 2 * sourceList.size();
totalSize += 2 * obsParamList.size();
// Import all the components
importComponentsFromList(ComponentType.INSTRUMENT, instrumentList);
importComponentsFromList(ComponentType.SITE, siteList);
importComponentsFromList(ComponentType.SOURCE, sourceList);
importComponentsFromList(ComponentType.OBS_PARAM, obsParamList);
// Set the messenger back to the default
MessengerHolder.setDefaultHandler();
// We show any error messages
if (!errorMessageList.isEmpty()) {
StringBuilder errorMessage = new StringBuilder(bundle.getString("MULTI_IMPORT_ERROR"));
for (String error : errorMessageList) {
errorMessage.append(error);
errorMessage.append("\n");
}
MessengerHolder.getMessenger(EtcFrame.getInstance()).error(errorMessage.toString());
}
return null;
}
private void importComponentsFromList(ComponentType componentType, List<Triplet<String, String, URL>> componentList) {
for (Triplet<String, String, URL> triplet : componentList) {
// If the importing is canceled we return here
if (isCancelled())
return;
String name = triplet.getValue0();
String description = triplet.getValue1();
URL url = triplet.getValue2();
// Download the file
publish(new Pair<String, Integer>("Downloading " + name, sizeDone));
// We try to let other threads to run and then we check if we have been canceled
Thread.yield();
if (isCancelled()) {
return;
}
File downloadedFile = null;
try {
int bufSize = 8 * 1024;
BufferedInputStream urlStream = new BufferedInputStream(url.openStream(), bufSize);
File tempDir = new File(ConfigFactory.getConfig().getTempDir());
tempDir.mkdirs();
String fileName = url.getFile();
if (fileName.contains("/")) {
fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
}
downloadedFile = new File(tempDir, fileName);
downloadedFile.delete();
downloadedFile.createNewFile();
downloadedFile.deleteOnExit();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(downloadedFile), bufSize);
byte[] buffer = new byte[bufSize];
int read = -1;
while ((read = urlStream.read(buffer)) >= 0) {
out.write(buffer, 0, read);
}
out.flush();
urlStream.close();
out.close();
sizeDone++;
} catch (IOException ex) {
logger.error("Failed to create temporary file", ex);
errorMessageList.add("Failed to download " + url);
sizeDone += 2;
continue;
}
// If the importing is canceled we return here
if (isCancelled())
return;
// Now import the file
publish(new Pair<String, Integer>("Importing " + name, sizeDone));
// We try to let other threads to run and then we check if we have been canceled
Thread.yield();
if (isCancelled()) {
return;
}
ComponentInfo info = new ComponentInfo(name, description);
switch (componentType) {
case INSTRUMENT:
InstrumentListenerHolder.getInstrumentListener().importFromFile(downloadedFile, info);
break;
case SITE:
SiteListenerHolder.getSiteListener().importFromFile(downloadedFile, info);
break;
case SOURCE:
SourceListenerHolder.getSourceListener().importFromFile(downloadedFile, info);
break;
case OBS_PARAM:
ObsParamListenerHolder.getObsParamListener().importFromFile(downloadedFile, info);
break;
}
// The handler will start a new thread for doing the job. we wait till
// it will finish
Thread importingThread = null;
while (importingThread == null) {
try {
importingThread = threadToWaitQueue.take();
} catch (InterruptedException ex) {
}
}
while (importingThread.isAlive()) {
try {
importingThread.join();
} catch (InterruptedException ex) {
}
}
sizeDone++;
}
}
@Override
protected void process(List<Pair<String, Integer>> chunks) {
Pair<String, Integer> pair = chunks.get(chunks.size() -1);
if (pair.getValue0() != null) {
progressMonitor.setNote(pair.getValue0());
}
progressMonitor.setProgress((int)(pair.getValue1() * 100. / totalSize));
if (progressMonitor.isCanceled()) {
this.cancel(false);
}
}
@Override
protected void done() {
// We close the progress monitor and the multi import window
progressMonitor.setProgress(101);
if (importTool != null)
importTool.dispose();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment