Esempio n. 1
0
 def loadSeries(self, directory):
     """Handles loading a given series in a directory.
     Also changes the current working directory
     self.Param_Dict["Directory"]
     Parameters:
         directory: path of the series
     returns:
         ts: yt DataSetSeries object
     """
     GUILogger.info(f"{directory} is directory for series mode")
     self.Status_Dict["Dir"].setText(directory)
     self.Param_Dict["Directory"] = directory
     ok = self.askSeriesName()
     if ok:
         try:
             GUILogger.info(f"Loading series '{self.Param_Dict['Seriesname']}'...")
             ts = yt.load(directory + '/' + self.Param_Dict["Seriesname"])
             self.Param_Dict["Filename"] = ""
             self.Status_Dict["File"].setText(self.Param_Dict["Filename"])
             self.Param_Dict["isValidSeries"] = True
             self.Param_Dict["isValidFile"] = True
             return ts
         except YTOutputNotIdentified:
             sut.alertUser("Couldn't load this series. Please try again")
             # Ask the user to enter another series name.
             # If he cancels, pass.
             return self.loadSeries(directory)
     else:
         GUILogger.warning("Couldn't load series.")
         GUILogger.log(29, "Try replacing the last digits of your series with "
                       "questionmarks or import all files of the directory "
                       "by using *")
         return None
Esempio n. 2
0
 def setUpFile(self, testmode=""):
     """When the file is given, make it ready for evaluation by updating
     the fields for the axes and calculating their min and maxes.
     Parameters:
         testmode: argument given when called through the buttons to test
     """
     if self.Param_Dict["isValidFile"]:
         self.Param_Dict["SignalHandler"].changeEvalMode()
         self.Button_Dict["MakeLinePlot"].hide()
         GUILogger.info("Scanning file for relevant fields...")
         # Update Geometry and hide the widgets that would cause errors
         sut.updateGeometry(self.Param_Dict, self.CheckBox_Dict,
                            self.RadioDict_Dict, self.Edit_Dict,
                            self.Label_Dict)
         # Update the comboBoxes according to entries in field lists
         try:
             sut.updateFields(self.Param_Dict, self.ComboBox_Dict)
         except Exception:
             return
         sut.resetExtrema(self.Param_Dict, self.Edit_Dict,
                          self.Button_Dict, self.Label_Dict,
                          self.ComboBox_Dict, self)
         self.Param_Dict["SignalHandler"].getOtherUnitInput("Grid")
         self.Param_Dict["SignalHandler"].setPlotOptions()
         updateLabels(self.Param_Dict, self.Label_Dict)
         GUILogger.log(29, f"Loaded '{self.Param_Dict['Filename'].split('/')[-1]}'.")
         GUILogger.info("It is now ready for plotting.")
         sut.refreshWidgets(self.Edit_Dict, self.ComboBox_Dict)
Esempio n. 3
0
 def giveMultipleFeedback(self, success, directory):
     """Gives feedback on wether multiple plots were successful."""
     mode = self.Param_Dict["PlotMode"]
     if success:
         GUILogger.log(29, f"{mode} plots successful.")
         if directory != "":
             GUILogger.log(29, f"The pictures have been saved to <b>{directory}</b>.")
         cart = self.Param_Dict["Geometry"] == "cartesian"
         aligned = self.Param_Dict["NormVecMode"] == "Axis-Aligned"
         slcproj = mode in ["Slice", "Projection"]
         if cart and slcproj and aligned:
             self.Button_Dict["MakeLinePlot"].show()
Esempio n. 4
0
 def giveSingleFeedback(self, success):
     """Gives feedback on wether the plot was successful.
     Shows the MakeLinePlot button upon successful plotting if the
     conditions are met"""
     mode = self.Param_Dict["PlotMode"]
     if success:
         GUILogger.log(29, f"{mode} plot successful.")
         cart = self.Param_Dict["Geometry"] == "cartesian"
         aligned = self.Param_Dict["NormVecMode"] == "Axis-Aligned"
         slcproj = mode in ["Slice", "Projection"]
         if cart and slcproj and aligned:
             self.Button_Dict["MakeLinePlot"].show()
Esempio n. 5
0
def setUpWidgets(Param_Dict, CheckBox_Dict, Misc_Dict):
    """Formats the slider and spinner so it fits the time series given."""
    slider = Misc_Dict["SeriesSlider"]
    length = len(Param_Dict["DataSeries"])
    slider.setRange(0, length - 1)
    GUILogger.log(
        29,
        f"Loaded all {length} datasets of '{str(Param_Dict['Seriesname'])}'.")
    GUILogger.info("They are now ready for plotting.")
    slider.valueChanged.emit(0)
    slider.show()
    spinner = Misc_Dict["ProfileSpinner"]
    spinner.setMaximum(length)
    spinner.setValue(1)
    spinner.setDisabled(False)
Esempio n. 6
0
def setUpMovieFolder(Param_Dict):
    """Creates a folder for the movie pictures to be saved in."""
    directory = QW.QFileDialog.getExistingDirectory(
        None, "Select a directory "
        "to save the pictures in", Param_Dict["Directory"])
    if directory == "":
        GUILogger.warning(
            "Evaluation stopped. Please select a valid directory.")
        return False
    date = datetime.now().strftime("%d_%m_%Y_%H_%M_%S")
    plotMode = Param_Dict["PlotMode"]  # for the fstring
    directory = f"{directory}/{plotMode}plots_{date}"
    mkdir(directory)
    GUILogger.log(29, f"The pictures are being saved to <b>{directory}</b>.")
    return directory
Esempio n. 7
0
 def startLine(self):
     """Initiates LineDrawing in Canvas"""
     # Enables the information receival from plot
     GUILogger.info("Ready to draw a line on the plot.")
     GUILogger.log(29, "Just <b>press and release left click</b> on top of the plot.")
     toolbar = self.Param_Dict["CurrentPlotWindow"].toolbar
     toolbar._active = "ZOOM"  # This will set the cross
     toolbar._actions["pan"].setChecked(False)
     toolbar._actions["zoom"].setChecked(False)
     if toolbar._idPress is not None:
         toolbar._idPress = toolbar.canvas.mpl_disconnect(toolbar._idPress)
     if toolbar._idRelease is not None:
         toolbar._idRelease = toolbar.canvas.mpl_disconnect(toolbar._idRelease)
     toolbar.mode = ''
     self.Edit_Dict["LineUnit"].setText(self.Param_Dict["oldGridUnit"])
     self.Starter = self.Param_Dict["CurrentPlotWindow"].canvas.mpl_connect('button_press_event', self.lStartInput)
     self.Ender = self.Param_Dict["CurrentPlotWindow"].canvas.mpl_connect('button_release_event', self.lEndInput)
Esempio n. 8
0
 def lEndInput(self, event):
     """Handles the mouseButtonReleases and passes them to simul_utils"""
     sut.getCoordInput(self.Param_Dict, event, "end")
     self.Param_Dict["CurrentPlotWindow"].canvas.mpl_disconnect(self.cid)
     sut.shuffleCoords(self.Param_Dict)
     sut.changeToLinePlot(self.Param_Dict, self.Edit_Dict)
     self.RadioDict_Dict["1DOptions"]["Line"].setChecked(True)
     self.RadioDict_Dict["DimMode"]["1D"].setChecked(True)
     self.ComboBox_Dict["YAxis"].setCurrentText(self.Param_Dict["ZAxis"])
     self.Edit_Dict["YUnit"].setText(self.Param_Dict["ZUnit"])
     self.Edit_Dict["YMin"].setText(f"{self.Param_Dict['ZMin']:.3g}")
     self.Edit_Dict["YMax"].setText(f"{self.Param_Dict['ZMax']:.3g}")
     self.CheckBox_Dict["YLog"].setChecked(self.Param_Dict["ZLog"])
     self.Param_Dict["YLog"] = self.Param_Dict["ZLog"]
     self.Param_Dict["CurrentPlotWindow"].canvas.mpl_disconnect(self.Ender)
     GUILogger.log(29, "Line inputs have been updated. Press 'Create Plot' to make the line plot.")
     toolbar = self.Param_Dict["CurrentPlotWindow"].toolbar
     toolbar._active = None
Esempio n. 9
0
def createProfWithTimeForX(Param_Dict, worker):
    """Make a profile plot having the time as the x-Axis.
    Parameters:
        Param_Dict: For the fields and DataSets to be plotted.
    Returns:
        arr: list containing two YTArrays having the time as the first and the
             y-field as second entry
    """
    GUILogger.info("This may take some...time...")
    ts = Param_Dict["DataSeries"]
    timeMin = Param_Dict["XMin"]  # they should already be converted to xunit.
    timeMax = Param_Dict["XMax"]
    times = []
    datasets = []
    emitStatus(worker, "Gathering time data")
    for ds in ts:
        # use the times we have already calculated for each dataset
        time = Param_Dict["DataSetDict"][str(ds) + "Time"].to_value(Param_Dict["XUnit"])
        timecompare = float("{:.3g}".format(time))
        if timeMin <= timecompare <= timeMax:
            times.append(time)
            datasets.append(str(ds))
    GUILogger.log(29, "Iterating over the whole series from {:.3g} to {:.3g} {}..."
          .format(timeMin, timeMax, Param_Dict["XUnit"]))
    calcQuan = getCalcQuanName(Param_Dict)
    field = Param_Dict["YAxis"]
    calcQuanString = getCalcQuanString(Param_Dict)
    storage = {}
    i = 0
    length = len(times)
    if Param_Dict["YAxis"] in Param_Dict["NewDerFieldDict"].keys():
        for ds in ts:
            if str(ds) in datasets:
                try:
                    yResult = Param_Dict["DataSetDict"][str(ds) + field + calcQuan]
                except KeyError:
                    ad = ds.all_data()
                    yResult = eval(calcQuanString)
                    # save the plotpoints for later use
                    value = yt.YTQuantity(yResult, Param_Dict["YUnit"]).to_value(Param_Dict["FieldUnits"][field])
                    Param_Dict["DataSetDict"][str(ds) + field + calcQuan] = value
                storage[str(i)] = yResult  # this is kind of clunky, but this way we don't run into problems later
                i += 1
                progString = f"{i}/{length} data points calculated"
                emitStatus(worker, progString)
                if i % ceil(length/10) == 0:  # maximum of 10 updates
                    GUILogger.info(f"Progress: {progString}.")
    else:  # We want to use parallel iteration if possible
        yt.enable_parallelism(suppress_logging=True)
        newTS = yt.load(Param_Dict["Directory"] + "/" + Param_Dict["Seriesname"])
        for store, ds in newTS.piter(storage=storage):
            try:
                yResult = Param_Dict["DataSetDict"][str(ds) + field + calcQuan]
            except KeyError:
                ad = ds.all_data()  # This is needed for the following command
                yResult = eval(calcQuanString)
                # save the plotpoints for later use
                value = yt.YTQuantity(yResult, Param_Dict["YUnit"]).to_value(Param_Dict["FieldUnits"][field])
                Param_Dict["DataSetDict"][str(ds) + field + calcQuan] = value
            store.result = yResult
            i += 1
            progString = f"{i}/{length} data points calculated"
            emitStatus(worker, progString)
            if i % ceil(length/10) == 0:  # maximum of 10 updates
                GUILogger.info(f"Progress: {progString}.")
    labels = [field]
    # Convert the storage dictionary values to an array, so they can be
    # easily plotted
    arr_x = yt.YTArray(times, Param_Dict["XUnit"])
    arr_y = yt.YTArray(list(storage.values()), Param_Dict["YUnit"])
    arr = [arr_x, arr_y]
#    print(arr)
    return arr, labels
Esempio n. 10
0
def createMultipleProfiles(Param_Dict, worker):
    """Make a profile plot for each of the requested times and return them so
    they can be plotted.
    Parameters:
        Param_Dict: For the fields and DataSets to be plotted.
    Returns:
        arr: list containing YTArrays having the x-field as the first and the
             y-fields as second and following entries
        labels: the labels for the rows.
    """
    GUILogger.info("This may take some time.")
    onlyEvery = Param_Dict["ProfOfEvery"]
    if onlyEvery == 1:
        numString = ""
    else:
        suf = lambda n: "%d%s "%(n,{1:"st",2:"nd",3:"rd"}.get(n if n<20 else n%10,"th"))
        numString = suf(onlyEvery)
    GUILogger.log(29, "Creating a profile for every {}dataset of the series...".format(numString))
    # the user can input to only plot every nth file:
    yt.enable_parallelism(suppress_logging=True)
    storage = {}
    labels = []
    i = 0
    ts = Param_Dict["DataSeries"]
    length = ceil(len(ts)/onlyEvery)
    if Param_Dict["YAxis"] in Param_Dict["NewDerFieldDict"].keys():
        for ds in ts:
            if i % onlyEvery == 0:
                # Create a data container to hold the whole dataset.
                ad = ds.all_data()
                # Create a 1d profile of xfield vs. yfield:
                prof = yt.create_profile(ad, Param_Dict["XAxis"],
                                         fields=[Param_Dict["YAxis"]],
                                         weight_field=Param_Dict["WeightField"])
                # Add labels
                time = Param_Dict["DataSetDict"][str(ds) + "Time"]
                label = "{} at {:.3g} ".format(Param_Dict["YAxis"], time.value)
                label += str(time.units)
                labels.append(label)
                storage[str(i)] = prof[Param_Dict["YAxis"]]
                progString = f"{int(i/onlyEvery+1)}/{length} profiles done"
                emitStatus(worker, progString)
                if i % ceil(length/10) == 0:  # maximum of 10 updates
                    GUILogger.info(f"Progress: {progString}.")
            i += 1
    else:  # We want to use parallel iteration if possible
        ts = yt.load(Param_Dict["Directory"] + "/" + Param_Dict["Seriesname"])
        for store, ds in ts.piter(storage=storage):
            if i % onlyEvery == 0:
                ad = ds.all_data()
                prof = yt.create_profile(ad, Param_Dict["XAxis"],
                                         fields=[Param_Dict["YAxis"]],
                                         weight_field=Param_Dict["WeightField"])
                # Add labels
                time = Param_Dict["DataSetDict"][str(ds) + "Time"]
                label = "{} at {:.3g} ".format(Param_Dict["YAxis"], time.value)
                label += str(time.units)
                labels.append(label)
                store.result = prof[Param_Dict["YAxis"]]
                progString = f"{int(i/onlyEvery+1)}/{length} profiles done"
                emitStatus(worker, progString)
                GUILogger.info(f"Progress: {progString}.")
            i += 1
    # Convert the storage dictionary values to an array with x-axis as first
    # row and then the results of y-field as following rows.
    arr_x = prof.x
    arr = [arr_x]
    for arr_y in storage.values():
        if arr_y is not None:
            arr.append(arr_y)
    return arr, labels