Skip to content

Commit

Permalink
Grid file settings
Browse files Browse the repository at this point in the history
* Init settins

* Dialog for settings only when custom grid from GUI

* Add zams to settings

* Purge phases

* Add grid file settings to GUI

* Settings for altermodes
  • Loading branch information
Johaney-s authored Jun 6, 2021
1 parent 394aef9 commit 0a46acd
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 63 deletions.
4 changes: 4 additions & 0 deletions Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ If labels are provided:

points with the same label (in a continuous block of data) create a track. This way isochrones can be loaded.

After successfull parsing of the grid file, you can specify
which phase represents the ZAMS (this will help to estimate near-ZAMS points)
and choose which phases you want to exclude from the data.

Default grid data is extracted from [PARSEC STELLAR EVOLUTION CODE](https://people.sissa.it/~sbressan/parsec.html).

The **phase labels** in the default grid file are described [here](https://people.sissa.it/~sbressan/CAF09_V1.2S_M36_LT/readme.txt), the default grid in the StIFT uses these:
Expand Down
126 changes: 115 additions & 11 deletions src/main/java/GUI/FXMLLineChartController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

import backend.Data;
import backend.GridFileParser;
import backend.Settings;
import backend.objects.Star;
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.beans.property.ObjectProperty;
Expand All @@ -19,8 +24,19 @@
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
import javafx.util.Callback;

/**
* FXML Controller class
Expand All @@ -42,7 +58,6 @@ public void initialize(URL url, ResourceBundle rb) {
lineChart.setAnimated(false);
lineChart.setCreateSymbols(false);

//
NumberAxis xAxis = (NumberAxis)lineChart.getXAxis();
xAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(xAxis) {
@Override
Expand Down Expand Up @@ -93,13 +108,39 @@ private double getYMouseCoordinate() {

/**
* Takes input data file, extracts data and shows in graph
* @return true if successfull, false otherwise
* @param isDefault true if stream refers to default file (use predefined settings)
* @return true if successful, false otherwise
*/
public boolean showGraph(InputStream inStream) {
public boolean showGraph(InputStream inStream, boolean isDefault) {
try {
Data newData = GridFileParser.extract(inStream);
Settings newSettings = new Settings();

//manage settings
if (!isDefault) {
newSettings = manageSettings(newData);
if (newSettings == null) {
return false;
}
} else {
newSettings.setDefaultSettings();
}

newData.applySettings(newSettings);
Data.setCurrentData(newData);
lineChart.getData().clear();
addIsochronesToChart(newData.getGroupedData());

// add ZAMS track
if (newSettings.getPhaseZams() != null) {
XYChart.Series series = new XYChart.Series();
ArrayList<Star> track = Data.getCurrentData().getZAMS().getTrack();
for (int i = 0; i < track.size(); i++) {
//also need to invert x-axis and this solution sucks, but FIXME later
series.getData().add(new XYChart.Data(-track.get(i).getTemperature(), track.get(i).getLuminosity()));
}
lineChart.getData().add(series);
}
} catch (IOException ex) {
mainController.showAlert("Error while parsing grid data", ex.getMessage(), Alert.AlertType.ERROR);
return false;
Expand All @@ -108,10 +149,10 @@ public boolean showGraph(InputStream inStream) {
return true;
}

public boolean showGraph(File file) {
public boolean showGraph(File file, boolean isDefault) {
try {
InputStream inStream = new FileInputStream(file);
return showGraph(inStream);
return showGraph(inStream, isDefault);
} catch (FileNotFoundException ex) {
mainController.showAlert("File not found", ex.getMessage(), Alert.AlertType.ERROR);
return false;
Expand Down Expand Up @@ -158,15 +199,78 @@ public void run() {
th.setDaemon(true);
th.start();
}
}


/**
* Evoke dialog to specify custom settings
*/
private Settings manageSettings(Data loadedData) {
Dialog<Settings> dialog = new Dialog<>();
dialog.setTitle("Settings");
dialog.setHeaderText("Please specify the settings for the file you are uploading.");

Label label1 = new Label("ZAMS phase is: ");
Label label2 = new Label("Include phases: ");

//ZAMS
XYChart.Series series = new XYChart.Series();
ArrayList<Star> track = GridFileParser.getCurrentData().getZAMS().getTrack();
for (int i = 0; i < track.size(); i++) {
//also need to invert x-axis and this solution sucks, but FIXME later
series.getData().add(new XYChart.Data(-track.get(i).getTemperature(), track.get(i).getLuminosity()));
ChoiceBox choiceBox = new ChoiceBox();
choiceBox.getItems().add("-");
choiceBox.setValue("-");
choiceBox.getItems().addAll(loadedData.getCurrentPhases());

//Phases
List<CheckBox> phaseBoxes = new ArrayList<>();
List<Short> availablePhases = new ArrayList<>(loadedData.getCurrentPhases());
GridPane allowedPhasesPane = new GridPane();
availablePhases.sort(Comparator.naturalOrder());
if (Data.getCurrentData().getCurrentPhases().size() > 12) {
allowedPhasesPane.add(new Label("Too many"), 0, 0);
allowedPhasesPane.add(new Label("phases!"), 0, 1);
} else {
for (int i = 0; i < availablePhases.size(); i++) {
CheckBox checkBox = new CheckBox(availablePhases.get(i).toString());
phaseBoxes.add(checkBox);
allowedPhasesPane.add(checkBox, i % 3, i / 3);
checkBox.setSelected(true);
}
}
lineChart.getData().add(series);

GridPane grid = new GridPane();
grid.add(label1, 1, 1);
grid.add(choiceBox, 2, 1);
grid.add(label2, 1, 2);
grid.add(allowedPhasesPane, 2, 2);
dialog.getDialogPane().setContent(grid);

ButtonType buttonTypeOk = new ButtonType("Upload file", ButtonBar.ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().add(buttonTypeOk);

dialog.setResultConverter(new Callback<ButtonType, Settings>() {
@Override
public Settings call(ButtonType b) {
if (b==buttonTypeOk) {
HashSet<Short> selectedPhases = new HashSet<>();
for (CheckBox checkBox : phaseBoxes) {
if (checkBox.isSelected()) { selectedPhases.add(Short.parseShort(checkBox.getText())); }
}
Short zams = null;
if (choiceBox.getValue() != "-") {
zams = Short.parseShort(choiceBox.getValue().toString());
}
return new Settings(selectedPhases, zams, false);
}
return null;
}
});

Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image(this.getClass().getResource("/settings.png").toString()));

dialog.getDialogPane().getChildren().stream().filter(node -> node instanceof Label).forEach(node
-> ((Label)node).setMinHeight(Region.USE_PREF_SIZE)); //fix for broken linux dialogues
Optional<Settings> result = dialog.showAndWait();
return result.orElse(null);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/GUI/FXMLMainController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package GUI;

import backend.GridFileParser;
import backend.Data;
import backend.objects.ResultStar;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -79,7 +79,7 @@ public void initialize(URL url, ResourceBundle rb) {

lineChartController.setMainController(this);
InputStream inStream = getClass().getResourceAsStream("/Data.txt");
lineChartController.showGraph(inStream);
lineChartController.showGraph(inStream, true);
fillPhaseBoxes();
tableViewController.getTableModel().reset();
tableViewController.setLoadingController(loadingController);
Expand Down Expand Up @@ -134,7 +134,7 @@ public void uploadNewGridItemAction() {

File file = fileChooser.showOpenDialog(vBox.getScene().getWindow());
if (file != null) {
if (lineChartController.showGraph(file)) {
if (lineChartController.showGraph(file, false)) {
tableViewController.reset();
fillPhaseBoxes();
showAlert("Upload new grid", "New grid uploaded successfully.", AlertType.INFORMATION);
Expand Down Expand Up @@ -179,7 +179,7 @@ public void resetGridItemAction() {
AlertType.CONFIRMATION);
if (alert.getResult() != null && alert.getResult().equals(ButtonType.OK)) {
InputStream inStream = getClass().getResourceAsStream("/Data.txt");
lineChartController.showGraph(inStream);
lineChartController.showGraph(inStream, true);
tableViewController.reset();
fillPhaseBoxes();
showAlert("Reset grid", "Grid successfully reset to default.", AlertType.INFORMATION);
Expand Down Expand Up @@ -252,9 +252,9 @@ public void goButtonAction() {
private void fillPhaseBoxes() {
phasePane.getChildren().clear();
allCheckBoxes.clear();
List<Short> phasesValues = new ArrayList<>(GridFileParser.getCurrentData().getCurrentPhases());
List<Short> phasesValues = new ArrayList<>(Data.getCurrentData().getCurrentPhases());
phasesValues.sort(Comparator.naturalOrder());
if (GridFileParser.getCurrentData().getCurrentPhases().size() > 12) {
if (Data.getCurrentData().getCurrentPhases().size() > 12) {
phasePane.add(new Label("Not"), 0, 0);
phasePane.add(new Label("available"), 0, 1);
} else {
Expand Down Expand Up @@ -330,7 +330,7 @@ public void manageInput(double x, double y, double temp_unc, double lum_unc, sho
}

Runnable runnable = () -> {
ResultStar result = GridFileParser.getCurrentData().estimate(x, y, temp_unc, lum_unc, includeDeviation, rounding, ignoredPhases);
ResultStar result = Data.getCurrentData().estimate(x, y, temp_unc, lum_unc, includeDeviation, rounding, ignoredPhases);
tableViewController.handleNewResult(result);
if (executor.getQueue().size() > 0) {
Platform.runLater(() -> {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/GUI/FastMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FastMode {
public static void main(String[] args) {
Data data;
File inputFile;
File gridFile = null;
File gridFile;
File exportFile;
System.out.println("========= StIFT fast mode =========");

Expand Down Expand Up @@ -40,6 +40,14 @@ public static void main(String[] args) {
System.out.println("Grid file: default (PARSEC + COLIBRI)");
}
data = GridFileParser.extract(is);
Settings settings = new Settings();
if (gridFile == null) {
settings.setDefaultSettings();
} else {
settings = new Settings(data.getCurrentPhases(), null, false);
}
data.applySettings(settings);
Data.setCurrentData(data);
System.out.println("Export file: " + exportFile);

System.out.println("Total number of isochrones: " + data.getGroupedData().size());
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/GUI/TextOnly.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public static void main(String[] args) {
System.out.println("Grid file: default (PARSEC + COLIBRI)");
}
data = GridFileParser.extract(is);
Settings settings = new Settings();
if (args.length == 6 || args.length == 4) {
settings.setDefaultSettings();
} else {
settings = new Settings(data.getCurrentPhases(), null, false);
}
data.applySettings(settings);
Data.setCurrentData(data);

System.out.println("Total number of isochrones: " + data.getGroupedData().size());
System.out.printf("Input:%n%.4f\t%.4f uncertainties: %.4f\t%.4f%n", x, y, x_unc, y_unc);
Expand Down
Loading

0 comments on commit 0a46acd

Please sign in to comment.