Project

General

Profile

Corot » History » Version 11

Version 10 (Anonymous, 05/06/2012 16:37) → Version 11/28 (Anonymous, 05/06/2012 17:12)

h1. Corot

h2. [[Scripts Scripts de création des imagettes]] imagettes

Premièrement, récupérer la liste des corotid à traiter. On peut séparer par run_code pour faire tourner le script moins longtemps et faire moins chauffer le corot-lightcurve et son repertoire 'temp'.


On récupère donc les corotid depuis pgadmin3 (exemple pour SRa05 et EN2_STAR_CHR : select distinct corotid from exo_n2_view where run_code like 'SRa05%' and en2_star_mon; )

Puis avec emacs on rajoute le début de l'url : http://idoc-corot-lightcurve.ias.u-psud.fr/rest/tempo/basic/N2/SRa05/ (dans un fichier, par exemple "links.txt")

On utilise tempo qui pointe vers les data privés mais sans authentification (ligne à décommenter dans spring-config.xml sur idc-appli2 : /usr/local/tomcat_corot/webapps/corot-lightcurve/WEB-INF/conf)

Puis on exécute le script perl qui va générer les *.png dans /usr/local/tomcat_corot/webapps/corot-lightcurve/temp/ :

<pre><code class="java">

#!/usr/bin/perl
open READ, "< links.txt";
while (<READ>)
{
chomp;
system("curl $_ | grep \"alt=\\\"Light curve for corot id\" >> adr_img.txt");
}

</code></pre>

On obtient une ligne par imagette générée.

<img src="http://idoc-corot-lightcurve.ias.u-psud.fr/temp/lightcurve_8653845841090318133.png" alt="Light curve for corot id : 223925326 (run SRa05)" />

Il faut ensuite copier les imagettes en local et les renommer : D'abord éditer avec Emacs (avec des replace string) pour obtenir :

http://idoc-corot-lightcurve.ias.u-psud.fr/temp/lightcurve_8653845841090318133.png > img_exo_223925326_SRa05.png

Puis lancer le 2eme script perl :

<pre><code class="java">

#!/usr/bin/perl
open READ, "< adr_img.txt";
while (<READ>)
{
chomp;
system("curl $_");
}

</code></pre>

h2. Gestion des imagettes dans le Detail

Dans le fichier : /usr/local/Sitools2_Corot/workspace/client-user/js/components/viewDataDetail/viewDataDetail.js
Ligne 102 : collapsed : false

h2. Export VOTABLE

Dans contextMenu.js (client) :

<pre><code class="javascript">
// ligne 864 fichier version 0.9.1
// on test que l'utilisateur ne selectionne pas CHR et MON en meme temps + qu'il n'a pas pris de WINDESC et d'IMAG
if((request.search("EN2_STAR_CHR")!=-1 && request.search("EN2_STAR_MON")!=-1) || request.search("EN2_WIN")!=-1 || request.search("EN2_STAR_IMAG")!=-1){
// si oui on l'averti que ce n'est pas possible et on ne lance pas le VOTable
Ext.Msg.alert("WARNING !", "DONT SELECT WINDESCRIPTOR OR IMAG" + "<br/>" + " ALSO DONT PICK EN2_STAR_MON AND EN2_STAR_CHR AT THE SAME TIME PLEASE !!!");

}else{
// sinon on lance exportVOTable


url += "?1=1" + request;
if (!Ext.isEmpty(limit)) {
url += "&limit=" + limit;
}
if (! Ext.isEmpty(userParameters)) {
Ext.iterate(userParameters, function (key, value) {
url += "&" + key + "=" + value;
});
}

// If Get => the Resource MUST be synchrone and then send a representation
if (method == "GET") {
window.open(url);
Ext.getBody().unmask();
return;
} else {
this._executeRequestForResource(url, method);
}
}

</code></pre>

Puis dans ExportVORessource.java :

<pre><code class="java">
// ligne 192
// Execute request to know which value are selected
String primkey="";
Integer type=0;
try {
primkey = databaseRequest.getRequestAsString(); //.getSelectedPrimaryKey();
boolean found = primkey.contains("AN2");
if(found){
System.out.println("J'ai trouvé AN2 !!!\n");
type=1;
}else{
//System.out.println("AN2 non trouvé !!!\n");
if((primkey.contains("EN2_STAR_CHR") && primkey.contains("EN2_STAR_MON")) || primkey.contains("EN2_WIN") || primkey.contains("EN2_STAR_IMAG")){
System.out.println("Error j'ai trouvé CHR et MON !!!\n");
}else{
if(primkey.contains("EN2_STAR_CHR")){
System.out.println("J'ai trouvé CHR !!!\n");
type = 2;
} else{
if(primkey.contains("EN2_STAR_MON")){
System.out.println("J'ai trouvé MON !!!\n");
type = 3;
}
}
}
}
System.out.println("Type vaux : " + type);
} catch (SitoolsException ex) {
Logger.getLogger(ExportVOResource.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("primkey : " + primkey); // astero et AN2_STAR dans la requete !!!

[ ........ ]

// ligne 246
String template_name = "";
if (type==1)
template_name = "template_astero.ftl";
else if (type==2)
template_name = "template_exo_chr.ftl";
else if (type==3)
template_name = "template_exo_mon.ftl";


System.out.println("j'envoie le template : " + template_name);

//Return the response
if (type!=0)
return new VOTableRepresentation(dataModel, template_name);
else
return null;
</code></pre>

Les templates.ftl doivent être dans le folder de VOTableRepresentation.java et doivent être bien définis.

Exemple : Pour EN2_STAR_MON, template_exo_mon.ftl

<pre><code class="XML">

<?xml version="1.0" encoding="UTF-8"?>
<VOTABLE version="1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ivoa.net/xml/VOTable/v1.2"
xmlns="http://www.ivoa.net/xml/VOTable/v1.2">
<!--
! VOTable written by MHUSSON@IAS version 0.1 (mhusson@ias.u-psud.fr)
! at 2012-03-30
! Best use with TOPCAT 3.9 or higher version
!-->
<RESOURCE name="COROT N2 EN2MON">
<DESCRIPTION>COROT N2 PUBLIC DATA VOTABLE STREAM FORMAT</DESCRIPTION>
<PARAM name="COROT VERSION" datatype="char" arraysize="*" value="N2">
<DESCRIPTION>COROT N2 FITS STREAM</DESCRIPTION>
</PARAM>
<INFO name="SITOOLS2 COROT PROJECT" value="http://idoc-corotn2-public-v2.ias.u-psud.fr">
VOTABLE generated with SItools2 COROT and exportVO Ressource (J-C.Malapert@CNES, M.Husson@IAS)
</INFO>
<TABLE ID="reference">
<FIELD ID="date" arraysize="23" datatype="char" name="DATE" unit="yyyy-mm-jjThh:mi:ss"/>
<FIELD ID="datejd" datatype="double" name="DATEJD" unit="COROT JULIAN DAY"/>
<FIELD ID="datehel" datatype="double" name="DATEHEL" unit="COROT JULIAN DAY"/>
<FIELD ID="status" datatype="int" name="STATUS"/>
<FIELD ID="whiteflux" datatype="float" name="WHITEFLUX" unit="ELECTRONS"/>
<FIELD ID="whitefluxdev" datatype="float" name="WHITEFLUXDEV" unit="ELECTRONS"/>
<FIELD ID="bg" datatype="float" name="BG" unit="ELECTRONS PER PIXEL"/>
<FIELD ID="correc" datatype="float" name="CORREC" unit="ELECTRONS"/>
</TABLE>
<#list rows as row>
<TABLE ref="reference" name="${row["file"]}">
<PARAM name="COROT ID" value="${row["corotid"]}"/>
<PARAM name="COROT RUN" value="${row["run_code"]}"/>
<DATA>
<FITS extnum="1">
<STREAM actuate="onRequest" href="${row["download"]}"/>
</FITS>
</DATA>
</TABLE>
</#list>
</RESOURCE>
</VOTABLE>

</code></pre>

h2. Les composants de formulaire :

Le Date Begin-end : qui permet de faire une requête sur deux colonnes différentes, "date de début" et "date de fin". On récupère ainsi les observations dont la date de début est intervenu après "date de début" et dont la fin est intervenu avant la "date de fin".

Le code javascript correspondant :

Partie ADMIN :

<pre><code class="javascript">

/*global Ext, sitools, ID, i18n, document, showResponse, alertFailure, LOCALE, ImageChooser,
showHelp*/
Ext.namespace('sitools.component.forms.multiParam');

sitools.component.forms.multiParam.DateBeginEnd = Ext.extend(sitools.component.forms.multiParam.abstractForm, {
height : 250,
id : 'sitools.component.forms.definitionId',
initComponent : function () {
this.winPropComponent.specificHeight = 350;
this.winPropComponent.specificWidth = 400;
sitools.component.forms.multiParam.DateBeginEnd.superclass.initComponent.call(this);



/*
* Build all the Columns mapping for the configuration,
* this object needs three columns
*/
var labels = ['DATE FROM', 'DATE TO'];
for (var i = 1; i <= 2; i++) {
this['mapParam' + i] = new Ext.form.ComboBox({
fieldLabel : labels[i - 1],
triggerAction : 'all',
name : "PARAM" + i,
specificType : "mapParam",
columnIndex : i,
lazyRender : true,
mode : 'local',
store : this.storeColumn,
valueField : 'columnAlias',
displayField : 'header',
anchor : '100%',
allowBlank : false

});

if (this.action == "modify") {
Ext.apply(this['mapParam' + i], {
value : this.selectedRecord.data.code[i - 1]
});
}

this.insert(i, this['mapParam' + i]);
}

this.componentDefaultValue1 = new Ext.form.DateField({
fieldLabel : i18n.get('label.defaultValue') + ' (DATE FROM)',
name : 'componentDefaultValue1',
anchor : '100%',
format : DEFAULT_DATE_FORMAT
});
this.componentDefaultValue2 = new Ext.form.DateField({
fieldLabel : i18n.get('label.defaultValue') + ' (DATE TO)',
name : 'componentDefaultValue2',
anchor : '100%',
format : DEFAULT_DATE_FORMAT
});

this.add(this.componentDefaultValue1);
this.add(this.componentDefaultValue2);


},
onRender : function () {
sitools.component.forms.multiParam.DateBeginEnd.superclass.onRender.apply(this, arguments);
if (this.action == 'modify') {
if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) {
if (Ext.isString(this.selectedRecord.data.defaultValues[0])) {
this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0].split('T')[0]);
}
else {
this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0].split('T')[0]);
}
if (Ext.isString(this.selectedRecord.data.defaultValues[1])) {
this.componentDefaultValue2.setValue(this.selectedRecord.data.defaultValues[1].split('T')[0]);
}
else {
this.componentDefaultValue2.setValue(this.selectedRecord.data.defaultValues[1].split('T')[0]);
}
}
}
},
afterRender : function () {
sitools.component.forms.multiParam.DateBeginEnd.superclass.afterRender.apply(this, arguments);
if (this.action == 'modify') {
if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) {
this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0]);
this.componentDefaultValue2.setValue(this.selectedRecord.data.defaultValues[1]);

}
}

},

_onValidate : function (action, gridFormComponents) {
var f = this.getForm();
if (!f.isValid()) {
Ext.Msg.alert(i18n.get('label.error'), i18n.get('warning.invalidForm'));
return false;
}
var defaultValue1 = Ext.isEmpty(f.findField('componentDefaultValue1')) ? "" : f.findField('componentDefaultValue1').getValue();
var defaultValue2 = Ext.isEmpty(f.findField('componentDefaultValue2')) ? "" : f.findField('componentDefaultValue2').getValue();

var columnObjects = this.find('specificType', 'mapParam');
var code = [];
Ext.each(columnObjects, function (columnObject) {
code.push(columnObject.getValue());
});

if (action == 'modify') {
var rec = gridFormComponents.getSelectionModel().getSelected();

var labelParam1 = Ext.isEmpty(f.findField('LABEL_PARAM1')) ? "" : f.findField('LABEL_PARAM1').getValue();
var css = Ext.isEmpty(f.findField('CSS')) ? "" : f.findField('CSS').getValue();

rec.set('label', labelParam1);
rec.set('code', code);
rec.set('css', css);
rec.set('componentDefaultHeight', f.findField('componentDefaultHeight').getValue());
rec.set('componentDefaultWidth', f.findField('componentDefaultWidth').getValue());

rec.set('defaultValues', [ defaultValue1, defaultValue2]);
} else {
var formComponentsStore = gridFormComponents.getStore();

// Génération de l'id
var lastId = 0;
var greatY = 0;
formComponentsStore.each(function (component) {
if (component.data.id > lastId) {
lastId = parseInt(component.data.id, 10);
}
if (component.data.ypos > greatY) {
greatY = parseInt(component.data.ypos, 10) + parseInt(component.data.height, 10);
}

});
var componentId = lastId + 1;
componentId = componentId.toString();
var componentYpos = greatY + 10;

formComponentsStore.add(new Ext.data.Record({
label : f.findField('LABEL_PARAM1').getValue(),
type : this.ctype,
code : code,
width : f.findField('componentDefaultWidth').getValue(),
height : f.findField('componentDefaultHeight').getValue(),
id : componentId,
ypos : componentYpos,
css : f.findField('CSS').getValue(),
jsAdminObject : this.jsAdminObject,
jsUserObject : this.jsUserObject,
defaultValues : [ defaultValue1, defaultValue2 ]
}));
}
return true;
}

});

</code></pre>

partie CLIENT :

<pre><code class="javascript">
/***************************************
* Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
*
* This file is part of SITools2.
*
* SITools2 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.
*
* SITools2 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 SITools2. If not, see <http://www.gnu.org/licenses/>.
***************************************/
/*global Ext, sitools*/
Ext.ns('sitools.component.users.SubSelectionParameters.SingleSelection');

sitools.component.users.SubSelectionParameters.SingleSelection.DateBeginEnd = Ext.extend(Ext.Container, {

initComponent : function () {
this.fieldFrom = new Ext.form.DateField({
allowBlank : true,
format : DEFAULT_DATE_FORMAT,
width : 165,
height : this.height,
value : new Date(this.defaultValues[0]).format(DEFAULT_DATE_FORMAT)
});
this.fieldTo = new Ext.form.DateField({
allowBlank : true,
format : DEFAULT_DATE_FORMAT,
width : 165,
height : this.height,
value : new Date(this.defaultValues[1]).format(DEFAULT_DATE_FORMAT)
});
Ext.apply(this, {
layout : 'table',
columns : 2, /* 3*/
fieldLabel : this.label,
stype : "sitoolsFormContainer",

items : [ new Ext.Container({
border : false,
html : this.label + " : ",
width : "150"
}), this.fieldFrom, new Ext.Container({
border : false,
html : '&nbsp;'
}), this.fieldTo ]
});
sitools.component.users.SubSelectionParameters.SingleSelection.DateBeginEnd.superclass.initComponent.apply(
this, arguments);
},

/**
* The code of the parameter to notify changed event.
*/
code : null,

/**
* The left bound of the period.
*/
fieldFrom : null,

/**
* The right bound of the period.
*/
fieldTo : null,

notifyValueSelected : function () {
this.parent.notifyValueChanged(this.code);
},

isValueDefined : function () {
if (this.fieldFrom.getValue() && this.fieldTo.getValue()) {
return true;
} else {
return false;
}
},

getSelectedValue : function () {
return {
from : this.fieldFrom.getValue(),
to : this.fieldTo.getValue()
};
},

getParameterValue : function () {
var value = this.getSelectedValue();
if (Ext.isEmpty(value) || Ext.isEmpty(value.from) || Ext.isEmpty(value.to)) {
return null;
}
return this.type + "|" + this.code + "|" + value.from.format('Y-m-d') + "|" + value.to.format('Y-m-d') ;
}
});
</code></pre>

Code JAVA à inclure dans *workspace/fr.cnes.sitools.extensions/src/fr/cnes/sitools/filter* et référencer la classe dans le fichier *fr.cnes.sitools.filter.FilterHelper*

<pre><code class="java">
/*******************************************************************************
* Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
*
* This file is part of SITools2.
*
* SITools2 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.
*
* SITools2 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 SITools2. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package fr.cnes.sitools.filter.basic;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import org.restlet.Request;
import org.restlet.data.Form;
import org.restlet.ext.wadl.ParameterInfo;
import org.restlet.ext.wadl.ParameterStyle;

import fr.cnes.sitools.common.validator.ConstraintViolation;
import fr.cnes.sitools.common.validator.Validator;
import fr.cnes.sitools.dataset.DataSetApplication;
import fr.cnes.sitools.dataset.filter.business.AbstractFilter;
import fr.cnes.sitools.dataset.model.Column;
import fr.cnes.sitools.dataset.model.DataSet;
import fr.cnes.sitools.dataset.model.Operator;
import fr.cnes.sitools.dataset.model.Predicat;
import fr.cnes.sitools.util.SQLUtils;

/**
* Filter defined for Date Between Component
*
*
* @author d.arpin
* <a href="https://sourceforge.net/tracker/?func=detail&atid=2158259&aid=3411383&group_id=531341">[3411383]</a><br/>
* 2011/09/19 d.arpin {add quotes arround date Value}
*/
public final class DateBeginEndFilter extends AbstractFilter {
/**
* The index of TYPE
*/
private static final int TYPE = 0;
/**
* The index of COLUMN
*/
private static final int COLUMN = 1;
/**
* The index of Values
*/
private static final int VALUES = 2;

/** The TEMPLATE_PARAM */
private static final String TEMPLATE_PARAM = "p[#]";
/**
* the values from to
*/
private String[] values;

/**
* The list of component that uses this filter
*/
private enum TYPE_COMPONENT {
/** DefaultType */
DATE_BEGIN_END
}

/**
* Default constructor
*/
public DateBeginEndFilter() {

super();
this.setName("DateBeginEndFilter");
this.setDescription("Required when using Date Between Components between 2 columns");

this.setAuthor("HUSSON@IAS");
this.setClassAuthor("HUSSON@IAS");
this.setClassOwner("IAS");
this.setVersion("0.1");
this.setDefaultFilter(true);

HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>();

ParameterInfo paramInfo;
paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY,
"DATE_BEGIN_END|columnFrom,columnTo|valueFrom|valueTo");
rpd.put("0", paramInfo);
this.setRequestParamsDescription(rpd);
//

}

@Override
public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception {
// Get the dataset
DataSetApplication dsApplication = null;
DataSet ds = null;

Form params = request.getResourceRef().getQueryAsForm();
boolean filterExists = true;
int i = 0;
// Build predicat for filters param
while (filterExists) {
String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++));
String formParam = params.getFirstValue(index);
if (formParam != null) {
String[] parameters = formParam.split("\\|");
TYPE_COMPONENT[] types = TYPE_COMPONENT.values();
Boolean trouve = false;
for (TYPE_COMPONENT typeCmp : types) {
if (typeCmp.name().equals(parameters[TYPE])) {
trouve = true;
}
}
if (trouve) {
if (dsApplication == null) {
dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication");
ds = dsApplication.getDataSet();
}
String columnfrom = null;
String columnto = null;
if (parameters.length >= VALUES) {
columnfrom = parameters[COLUMN].split(",")[0];
columnto = parameters[COLUMN].split(",")[1];

Column colfrom = ds.findByColumnAlias(columnfrom);
Column colto = ds.findByColumnAlias(columnto);

if (colfrom != null && colfrom.getFilter() != null && colfrom.getFilter() && checkValues(parameters) && colto != null && colto.getFilter() != null && colto.getFilter()) {
// escape the values to avoid SQL injection
String valuefrom = "'" + SQLUtils.escapeString(values[0]) + "'";
String valueto = "'" + SQLUtils.escapeString(values[1]) + "'";

Predicat predicat = new Predicat();
predicat.setLeftAttribute(colfrom);
predicat.setNbOpenedParanthesis(1);
predicat.setNbClosedParanthesis(0);
predicat.setCompareOperator(Operator.GTE.value());
predicat.setRightValue(valuefrom);
predicats.add(predicat);
predicat = new Predicat();
predicat.setLeftAttribute(colto);
predicat.setNbOpenedParanthesis(0);
predicat.setNbClosedParanthesis(1);
predicat.setCompareOperator(Operator.LTE.value());
predicat.setRightValue(valueto);
predicats.add(predicat);
}

}
}
}

else {
filterExists = false;
}
}

return predicats;
}

/**
* Check values of the form
*
* @param parameters
* the parameters of the filter
* @return true if values agree
*/
private boolean checkValues(String[] parameters) {
values = Arrays.copyOfRange(parameters, VALUES, parameters.length);
if (values.length == 2) {
return true;
}
return false;
}

/**
* Gets the validator for this Filter
*
* @return the validator for the filter
*/
@Override
public Validator<AbstractFilter> getValidator() {
return new Validator<AbstractFilter>() {
@Override
public Set<ConstraintViolation> validate(AbstractFilter item) {
return null;
}
};
}

}
</code></pre>