Author: echatellier Date: 2015-04-16 16:43:41 +0000 (Thu, 16 Apr 2015) New Revision: 352 Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/352 Log: Add Lbar and recruitment exports Added: trunk/exports/Lbar.java trunk/exports/Recruitment.java trunk/sensitivityexports/SensitivityLbarJanvierY1.java trunk/sensitivityexports/SensitivityRecruitmentY1.java Modified: trunk/scripts/ResultName.java trunk/scripts/SiMatrix.java trunk/scripts/SiMatrixEffortByCell.java trunk/simulators/DefaultSimulator.java Added: trunk/exports/Lbar.java =================================================================== --- trunk/exports/Lbar.java (rev 0) +++ trunk/exports/Lbar.java 2015-04-16 16:43:41 UTC (rev 352) @@ -0,0 +1,90 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2015 Ifremer, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package exports; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.Writer; + +import org.nuiton.math.matrix.*; + +import scripts.ResultName; + +import fr.ifremer.isisfish.entities.*; +import fr.ifremer.isisfish.export.Export; +import fr.ifremer.isisfish.types.TimeStep; +import fr.ifremer.isisfish.datastore.SimulationStorage; + +/** + * Population mean length. + * + * Created: 03/2015 + * + * @author lgasche <anonymous@labs.libre-entreprise.org> + * @version $Revision$ + */ +public class Lbar implements Export { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory.getLog(Lbar.class); + + protected String[] necessaryResult = { + ResultName.MATRIX_LBAR + }; + + @Override + public String[] getNecessaryResult() { + return this.necessaryResult; + } + + @Override + public String getExportFilename() { + return "Lbar"; + } + + @Override + public String getExtensionFilename() { + return ".csv"; + } + + @Override + public String getDescription() { + return "Exporte les longueurs moyennes par pop par zone en tableau avec des lignes pop;zone;date;longueur."; + } + + @Override + public void export(SimulationStorage simulation, Writer out) throws Exception { + for (Population pop : simulation.getParameter().getPopulations()) { + MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_LBAR); + for (MatrixIterator i = mat.iterator(); i.hasNext();) { + i.next(); + Object[] sems = i.getSemanticsCoordinates(); + TimeStep step = (TimeStep) sems[0]; + Zone zone = (Zone) sems[1]; + + double val = i.getValue(); + out.write(pop.getName() + ";" + zone.getName() + ";" + step.getStep() + ";" + val + "\n"); + } + } + } +} Property changes on: trunk/exports/Lbar.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/exports/Recruitment.java =================================================================== --- trunk/exports/Recruitment.java (rev 0) +++ trunk/exports/Recruitment.java 2015-04-16 16:43:41 UTC (rev 352) @@ -0,0 +1,89 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2015 Ifremer, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package exports; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.Writer; + +import org.nuiton.math.matrix.*; + +import scripts.ResultName; + +import fr.ifremer.isisfish.entities.*; +import fr.ifremer.isisfish.export.Export; +import fr.ifremer.isisfish.types.TimeStep; +import fr.ifremer.isisfish.datastore.SimulationStorage; + +/** + * Recruitment. + * + * Created: 03/2015 + * + * @author lgasche <anonymous@labs.libre-entreprise.org> + * @version $Revision$ + */ +public class Recruitment implements Export { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory.getLog(Recruitment.class); + + protected String[] necessaryResult = { + ResultName.MATRIX_RECRUITMENT + }; + + @Override + public String[] getNecessaryResult() { + return this.necessaryResult; + } + + @Override + public String getExportFilename() { + return "Recruitment"; + } + + @Override + public String getExtensionFilename() { + return ".csv"; + } + + @Override + public String getDescription() { + return "Exporte le recrutement par pop par en tableau avec des lignes pop;date;recrutement."; + } + + @Override + public void export(SimulationStorage simulation, Writer out) throws Exception { + for (Population pop : simulation.getParameter().getPopulations()) { + MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_RECRUITMENT); + for (MatrixIterator i = mat.iterator(); i.hasNext();) { + i.next(); + Object[] sems = i.getSemanticsCoordinates(); + TimeStep step = (TimeStep) sems[0]; + + double val = i.getValue(); + out.write(pop.getName() + ";" + step.getStep() + ";" + val + "\n"); + } + } + } +} Property changes on: trunk/exports/Recruitment.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/scripts/ResultName.java =================================================================== --- trunk/scripts/ResultName.java 2014-12-22 10:19:18 UTC (rev 351) +++ trunk/scripts/ResultName.java 2015-04-16 16:43:41 UTC (rev 352) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2014 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin + * Copyright (C) 2006 - 2015 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -112,7 +112,7 @@ * Dimension 4 : Group * Dimension 5 : Zone * - * N'est calculé que si l'effort est calculé par cellule et non par zone. + * N'est calcule que si l'effort est calcule par cellule et non par zone. * @see simulators.SimulatorEffortByCell */ @Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZoneMet") @@ -137,7 +137,7 @@ * Dimension 4 : Group * Dimension 5 : Zone * - * N'est calculé que si l'effort est calculé par cellule et non par zone. + * N'est calcule que si l'effort est calcule par cellule et non par zone. * @see simulators.SimulatorEffortByCell */ @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZoneMet") @@ -188,6 +188,21 @@ */ @Doc(value = "do the doc of Result matrixAbundance") static final public String MATRIX_ABUNDANCE = n("matrixAbundance"); + + /** + * Matrix with two dimensions + * Dimension 1 : TimeStep + * Dimension 2 : Zone (semantics : Dimension 1) + */ + @Doc(value = "do the doc of Result matrixLbar") + static final public String MATRIX_LBAR = n("matrixLbar"); + + /** + * Matrix with one dimension + * Dimension 1 : TimeStep + */ + @Doc(value = "do the doc of Result matrixRecruitment") + static final public String MATRIX_RECRUITMENT = n("matrixRecruitment"); /** * Matrix with three dimensions Modified: trunk/scripts/SiMatrix.java =================================================================== --- trunk/scripts/SiMatrix.java 2014-12-22 10:19:18 UTC (rev 351) +++ trunk/scripts/SiMatrix.java 2015-04-16 16:43:41 UTC (rev 352) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2014 Ifremer, Code Lutin, Benjamin Poussin + * Copyright (C) 2006 - 2015 Ifremer, Code Lutin, Benjamin Poussin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -273,7 +273,6 @@ * @param N l'abondance sous forme de matrice 2D [class x zone] * @param pop * @param step - * @param matrixCatchRatePerStrategyMet * @return * @throws TopiaException * @throws IsisFishException @@ -306,7 +305,6 @@ * * @param pop * @param step - * @param matrixFishingMortality * @return * @throws TopiaException * @throws IsisFishException @@ -894,7 +892,6 @@ * @param N * @param pop * @param step - * @param matrixFishingMortality * @return * @throws IsisFishException * @throws TopiaException @@ -1289,4 +1286,76 @@ return result; } + + /** + * Permet de calculer la longueur moyenne (Lbar) d'une population. + * + * @param step + * @param pop + * @param N + * @return + */ + public MatrixND Lbar(TimeStep step, Population pop, MatrixND N) throws TopiaException { + MatrixND LbarMatrix = N.copy(); + LbarMatrix.setName(ResultName.MATRIX_LBAR); + //log.info("Lbar_1 = " + LbarMatrix); + + List<PopulationGroup> groups = pop.getPopulationGroup(); + List<Zone> zones = pop.getPopulationZone(); + + // On multiplie l'abondance de chaque groupe par la taille de ce groupe + + // On somme sur les groupes + + // On utilise divise la valeur obtenue par l'abondance totale + + for (PopulationGroup group : groups) { + for (Zone zn : zones) { + LbarMatrix.setValue(group, zn, LbarMatrix.getValue(group, zn) * group.getLength()); + } + } + + LbarMatrix = LbarMatrix.sumOverDim(0); // Somme sur les groupes + LbarMatrix = LbarMatrix.reduce(); + //log.info("LbarMatrix_2 = " + LbarMatrix); + + MatrixND matAB = N.copy(); + matAB = matAB.sumOverDim(0); + matAB = matAB.reduce(); + //log.info("matAB = " + matAB); + + for (Zone zn : zones) { + LbarMatrix.setValue(zn, LbarMatrix.getValue(zn) / matAB.getValue(zn)); + } + + //log.info("LbarMatrix_3 = " + LbarMatrix); + + return LbarMatrix; + } + + /** + * Permet de sortir le recrutement par pas de temps. + * @param step + * @param pop + * @return + */ + public MatrixND Recruitment(TimeStep step, Population pop) throws TopiaException { + + List<Population> populations = Collections.singletonList(pop); + + MatrixND RecruitmentMatrix = MatrixFactory.getInstance().create( + ResultName.MATRIX_RECRUITMENT, + new List[]{populations}, // + new String[]{n("Population")}); + + //log.info("Recruitment_1 = " + RecruitmentMatrix); + + // Pour chaque pas de temps on recupere le recrutement + + RecruitmentMatrix.setValue(pop, context.getPopulationMonitor().getRecruitment(step, pop).sumAll()); + + //log.info("RecruitmentMatrix_2 = " + RecruitmentMatrix); + + return RecruitmentMatrix; + } } Modified: trunk/scripts/SiMatrixEffortByCell.java =================================================================== --- trunk/scripts/SiMatrixEffortByCell.java 2014-12-22 10:19:18 UTC (rev 351) +++ trunk/scripts/SiMatrixEffortByCell.java 2015-04-16 16:43:41 UTC (rev 352) @@ -1,3 +1,24 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2015 Ifremer, Code Lutin, Benjamin Poussin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ package scripts; import static org.nuiton.i18n.I18n.n; @@ -28,8 +49,6 @@ import org.nuiton.math.matrix.MatrixND; import org.nuiton.topia.TopiaException; -import static org.nuiton.i18n.I18n.n; - /** * * @author poussin @@ -498,9 +517,7 @@ * metier * * @param step - * @param matrixFishingMortality - * @param group - * @param zone + * @param matrixFishingMortalityPerCell * @return */ protected MatrixND totalFishingMortalityPerCell(TimeStep step, Added: trunk/sensitivityexports/SensitivityLbarJanvierY1.java =================================================================== --- trunk/sensitivityexports/SensitivityLbarJanvierY1.java (rev 0) +++ trunk/sensitivityexports/SensitivityLbarJanvierY1.java 2015-04-16 16:43:41 UTC (rev 352) @@ -0,0 +1,88 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2015 Ifremer, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * #L% + */ +package sensitivityexports; + +import java.io.Writer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixND; + +import scripts.ResultName; +import fr.ifremer.isisfish.datastore.ResultStorage; +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.entities.Population; +import fr.ifremer.isisfish.export.SensitivityExport; +import fr.ifremer.isisfish.types.TimeStep; +import fr.ifremer.isisfish.util.Doc; + +public class SensitivityLbarJanvierY1 implements SensitivityExport { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory.getLog(SensitivityLbarJanvierY1.class); + + protected String[] necessaryResult = { ResultName.MATRIX_LBAR }; + + @Doc("Population") + public Population param_pop; + + @Override + public void export(SimulationStorage simulation, Writer out) + throws Exception { + ResultStorage resultStorage = simulation.getResultStorage(); + TimeStep lastStep = resultStorage.getLastStep(); + TimeStep janvierLastYear = new TimeStep(12 * lastStep.getYear()); + double lbar = 0.0; + for (Population pop : simulation.getParameter().getPopulations()) { + if (pop.getName().equals(param_pop.getName())) { + + //Get the lbar of the last time step + MatrixND matlastJan = resultStorage.getMatrix(janvierLastYear, pop, + ResultName.MATRIX_LBAR); + MatrixND meanLastJan = matlastJan.meanOverDim(0); // moyenne sur les zones + lbar = meanLastJan.sumAll(); // On somme tout mais en fait il n'y a plus qu'une valeur dans la matrice; permet d'avoir un double + } + } + out.write(Double.toString(lbar)); + } + + @Override + public String getDescription() { + return "lbar for January of the last year. lbar is the mean lbar over zones"; + } + + @Override + public String getExportFilename() { + return "SensitivityLbarJanvierY1_" + param_pop.getName(); + } + + @Override + public String getExtensionFilename() { + return ".csv"; + } + + @Override + public String[] getNecessaryResult() { + return this.necessaryResult; + } + +} Property changes on: trunk/sensitivityexports/SensitivityLbarJanvierY1.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/sensitivityexports/SensitivityRecruitmentY1.java =================================================================== --- trunk/sensitivityexports/SensitivityRecruitmentY1.java (rev 0) +++ trunk/sensitivityexports/SensitivityRecruitmentY1.java 2015-04-16 16:43:41 UTC (rev 352) @@ -0,0 +1,94 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2015 Ifremer, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package sensitivityexports; + +import java.io.Writer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixND; + +import scripts.ResultName; +import fr.ifremer.isisfish.datastore.ResultStorage; +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.entities.Population; +import fr.ifremer.isisfish.export.SensitivityExport; +import fr.ifremer.isisfish.types.TimeStep; +import fr.ifremer.isisfish.util.Doc; + +public class SensitivityRecruitmentY1 implements SensitivityExport { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory.getLog(SensitivityRecruitmentY1.class); + + protected String[] necessaryResult = { + ResultName.MATRIX_RECRUITMENT + }; + + @Doc("Population") + public Population param_pop; + + @Override + public void export(SimulationStorage simulation, Writer out) + throws Exception { + ResultStorage resultStorage = simulation.getResultStorage(); + TimeStep lastStep = resultStorage.getLastStep(); + double recruitment = 0.0; + + for (Population pop : simulation.getParameter().getPopulations()) { + if (pop.getName().equals(param_pop.getName())) { + for (int i = 0; i < 12; i++) { + + //Get the recruitment of each month of the last year + MatrixND matlastdate = resultStorage.getMatrix( + new TimeStep(lastStep.getStep() - i), + pop, + ResultName.MATRIX_RECRUITMENT); + recruitment += matlastdate.sumAll(); + } + } + } + + out.write(Double.toString(recruitment)); + } + + @Override + public String getDescription() { + return "Total recruitment for the last year for the population."; + } + + @Override + public String getExportFilename() { + return "SensitivityRecruitmentY1_" + param_pop.getName(); + } + + @Override + public String getExtensionFilename() { + return ".csv"; + } + + @Override + public String[] getNecessaryResult() { + return this.necessaryResult; + } + +} Property changes on: trunk/sensitivityexports/SensitivityRecruitmentY1.java ___________________________________________________________________ Added: svn:eol-style + native Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/simulators/DefaultSimulator.java =================================================================== --- trunk/simulators/DefaultSimulator.java 2014-12-22 10:19:18 UTC (rev 351) +++ trunk/simulators/DefaultSimulator.java 2015-04-16 16:43:41 UTC (rev 352) @@ -1,9 +1,8 @@ - /* * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2014 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2006 - 2015 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -457,6 +456,16 @@ resManager.addResult(step, pop, biomassBM); } + if (resManager.isEnabled(ResultName.MATRIX_LBAR)) { + MatrixND Lbar = siMatrix.Lbar(step, pop, N); + resManager.addResult(step, pop, Lbar); + } + + if (resManager.isEnabled(ResultName.MATRIX_RECRUITMENT)) { + MatrixND Recruitment = siMatrix.Recruitment(step, pop); + resManager.addResult(step, pop, Recruitment); + } + MatrixND abundance; // compute fishing matrix only if there are one or more strategy if (siMatrix.getStrategies(step).size() > 0) {