[R] Classification of wind events

Stefano Sofia @te|@no@@o||@ @end|ng |rom reg|one@m@rche@|t
Mon May 18 12:14:06 CEST 2020


Sorry for my fault.
I am very grateful for such code, which is extremely efficient. I would have never been able to reach these results.

In order to preserve the quality of this code, I dare to ask you a final question: once identified each single period in the column foehn1c, this period can be taken into consideration only if within it the mean of max_speed is higher than 8.0 (which is speed in m/s).
Could you please help me in this final step?

Thank you again for all your help
Stefano


         (oo)
--oOO--( )--OOo----------------
Stefano Sofia PhD
Civil Protection - Marche Region
Meteo Section
Snow Section
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona
Uff: 071 806 7743
E-mail: stefano.sofia using regione.marche.it
---Oo---------oO----------------

________________________________________
Da: Jeff Newmiller [jdnewmil using dcn.davis.ca.us]
Inviato: sabato 16 maggio 2020 21.04
A: Stefano Sofia; Jim Lemon; r-help mailing list
Oggetto: RE: [R] Classification of wind events

Please run your code before posting it... you forgot the quotes in your main_dir column.

first_day_POSIX <- as.POSIXct("2020-02-19-00-00", format="%Y-%m-%d-%H-%M")
last_day_POSIX <- as.POSIXct("2020-02-20-00-00", format="%Y-%m-%d-%H-%M")
mydf <- data.frame(data_POSIX=seq(first_day_POSIX, last_day_POSIX, by="10 min"))

mydf$main_dir <- c("WSW", "WSW", "SW", "SW", "W", "WSW", "WSW", "WSW", "W", "W", "SW", "WSW", "SSW", "S", "SW", "SW", "WSW", "WNW", "W", "WSW", "WSW", "SE", "SE", "SE", "NW", "NNE", "ENE", "SE", "NNW", "NW", "NW", "NW", "NW", "NW", "NW", "NE", "NW", "NW", "NW", "NW", "NW", "N", "WNW", "NW", "NNW", "NNW", "NW", "NW", "NW", "WNW", "ESE", "W", "WSW", "SW", "SW", "SW", "WSW", "SW", "S", "S", "SSW", "SW", "WSW", "WSW", "WSW", "WSW", "WSW", "WSW", "WSW", "SW", "WSW", "WSW", "WSW", "WSW", "SW", "SW", "WSW", "WSW", "WSW", "WSW", "WSW", "SW", "SW", "SW", "SW", "SW", "SW", "SW", "SW", "SW", "WSW", "WSW", "WSW", "WSW", "SW", "SW", "SW", "SW", "WSW", "SW", "SW", "SW", "SW", "SW", "WSW", "SW", "SW", "W", "WSW", "WSW", "SSW", "S", "WNW", "SW", "W", "WSW", "WSW", "SE", "SE", "SE", "NW", "NNE", "ENE", "SE", "NNW", "NW", "NW", "NW", "NW", "NW", "NW", "NE", "NW", "NW", "NW", "NW", "NW", "N", "WNW", "NW", "NNW", "NNW", "NW", "NW", "NW")

mydf$max_speed <- c(4.60, 4.60, 3.40, 3.10, 4.80, 4.20, 4.10, 4.50, 4.70, 4.30, 2.40, 2.30, 2.20, 2.10, 2.90, 2.80, 1.80, 2.70, 4.30, 3.30, 2.30, 2.30, 3.20, 3.20, 2.90, 2.30, 1.50, 1.80, 2.90, 2.40, 1.80, 2.40, 2.30, 2.60, 1.80, 2.30, 1.90, 2.20, 2.80, 2.40, 1.00, 1.10, 1.60, 2.30, 2.50, 3.30, 3.40, 3.20, 4.50, 3.90, 3.10, 2.40, 6.00, 7.80, 6.30, 7.80, 8.10, 6.10, 7.40, 9.50, 8.90, 9.10, 10.10, 10.50, 11.10, 10.10, 10.90, 11.30, 13.40, 13.50, 12.80, 11.50, 13.10, 13.50, 11.10, 10.50, 8.50, 10.10, 10.70, 13.60, 11.90, 14.90, 10.90, 10.90, 12.80, 12.10, 9.10, 8.30, 8.80, 7.40, 8.40, 10.30, 10.00, 7.00, 8.50, 8.40, 8.60, 6.70, 7.30, 6.20, 5.90, 5.90, 5.10, 5.80, 5.60, 6.50, 6.60, 11.70, 11.30, 8.70, 7.10, 6.90, 4.30, 3.80, 4.30, 3.30, 2.30, 2.30, 3.20, 3.20, 2.90, 2.30, 1.50, 1.80, 2.90, 2.40, 1.80, 2.40, 2.30, 2.60, 1.80, 2.30, 1.90, 2.20, 2.80, 2.40, 1.00, 1.10, 1.60, 2.30, 2.50, 3.30, 3.40, 3.20, 4.50)
# mark candidate rows
mydf$foehn1a <- mydf$main_dir %in% c( "WSW", "SW" )
# mark unstable conditions
mydf$foehn1b <- with( mydf
                    , cumsum( !foehn1a )
                    )
# find minimum length of foehn conditions
mydf$foehn1c <- ave( rep( 1, nrow( mydf ) )
                   , mydf$foehn1b
                   , FUN=function(v) 10 < length( v )
                   )
# find starts of foehns
mydf$foehn1d <- with( mydf
                    , 0 < diff( c( 0, foehn1c ) )
                    )
# identify foehns distinctly (multiple days)
mydf$foehn1e <- with( mydf
                    , ifelse( foehn1c
                            , cumsum( foehn1d )
                            , 0
                            )
                    )
mydf[ , c( 1, 2, 8 ) ]

On May 16, 2020 3:21:24 AM PDT, Stefano Sofia <stefano.sofia using regione.marche.it> wrote:
>Dear Jim and Jeff,
>thank you for your comments. You are right, it is quite difficult to
>detect this process through a single observation point, I am awre of
>it.
>I need to set up an automatic algorithm to filter 20 years of data, and
>I have to find an easy way to do it.
>I know quite well my automatic stations, the wind direction is very
>stable during these situations, and therefore I would like to start
>from it. (I should use also wind speed, relative humidity and
>temperature, but I will introduce them only once I will be able to
>manage the direction).
>In the case of the example below reported, I know that the directions
>of this particular automatic station must be only SW or WSW.
>
>My biggest problem, obviously, is to find the beginning and the end of
>each event, when there is a change in the main direction.
>Thinking about categorical data in general, is there a way to detect
>periods when one particular category is more frequent?
>
>Here I reproduce a real example 24 hours long, where these Foehn
>condition start between 09 and 10 and finish after 19:
>
>first_day_POSIX <- as.POSIXct("2020-02-19-00-00",
>format="%Y-%m-%d-%H-%M")
>last_day_POSIX <- as.POSIXct("2020-02-20-00-00",
>format="%Y-%m-%d-%H-%M")
>mydf <- data.frame(data_POSIX=seq(first_day_POSIX, last_day_POSIX,
>by="10 min"))
>
>mydf$main_dir <- c(WSW, WSW, SW, SW, W, WSW, WSW, WSW, W, W, SW, WSW,
>SSW, S, SW, SW, WSW, WNW, W, WSW, WSW, SE, SE, SE, NW, NNE, ENE, SE,
>NNW, NW, NW, NW, NW, NW, NW, NE, NW, NW, NW, NW, NW, N, WNW, NW, NNW,
>NNW, NW, NW, NW, WNW, ESE, W, WSW, SW, SW, SW, WSW, SW, S, S, SSW, SW,
>WSW, WSW, WSW, WSW, WSW, WSW, WSW, SW, WSW, WSW, WSW, WSW, SW, SW, WSW,
>WSW, WSW, WSW, WSW, SW, SW, SW, SW, SW, SW, SW, SW, SW, WSW, WSW, WSW,
>WSW, SW, SW, SW, SW, WSW, SW, SW, SW, SW, SW, WSW, SW, SW, W, WSW, WSW,
>SSW, S, WNW, SW, W, WSW, WSW, SE, SE, SE, NW, NNE, ENE, SE, NNW, NW,
>NW, NW, NW, NW, NW, NE, NW, NW, NW, NW, NW, N, WNW, NW, NNW, NNW, NW,
>NW, NW)
>
>mydf$max_speed <- c(4.60, 4.60, 3.40, 3.10, 4.80, 4.20, 4.10, 4.50,
>4.70, 4.30, 2.40, 2.30, 2.20, 2.10, 2.90, 2.80, 1.80, 2.70, 4.30, 3.30,
>2.30, 2.30, 3.20, 3.20, 2.90, 2.30, 1.50, 1.80, 2.90, 2.40, 1.80, 2.40,
>2.30, 2.60, 1.80, 2.30, 1.90, 2.20, 2.80, 2.40, 1.00, 1.10, 1.60, 2.30,
>2.50, 3.30, 3.40, 3.20, 4.50, 3.90, 3.10, 2.40, 6.00, 7.80, 6.30, 7.80,
>8.10, 6.10, 7.40, 9.50, 8.90, 9.10, 10.10, 10.50, 11.10, 10.10, 10.90,
>11.30, 13.40, 13.50, 12.80, 11.50, 13.10, 13.50, 11.10, 10.50, 8.50,
>10.10, 10.70, 13.60, 11.90, 14.90, 10.90, 10.90, 12.80, 12.10, 9.10,
>8.30, 8.80, 7.40, 8.40, 10.30, 10.00, 7.00, 8.50, 8.40, 8.60, 6.70,
>7.30, 6.20, 5.90, 5.90, 5.10, 5.80, 5.60, 6.50, 6.60, 11.70, 11.30,
>8.70, 7.10, 6.90, 4.30, 3.80, 4.30, 3.30, 2.30, 2.30, 3.20, 3.20, 2.90,
>2.30, 1.50, 1.80, 2.90, 2.40, 1.80, 2.40, 2.30, 2.60, 1.80, 2.30, 1.90,
>2.20, 2.80, 2.40, 1.00, 1.10, 1.60, 2.30, 2.50, 3.30, 3.40, 3.20, 4.50)
>
>
>Thank you for your attention
>Stefano
>
>
>         (oo)
>--oOO--( )--OOo----------------
>Stefano Sofia PhD
>Civil Protection - Marche Region
>Meteo Section
>Snow Section
>Via del Colle Ameno 5
>60126 Torrette di Ancona, Ancona
>Uff: 071 806 7743
>E-mail: stefano.sofia using regione.marche.it
>---Oo---------oO----------------
>
>________________________________________
>Da: Jim Lemon [drjimlemon using gmail.com]
>Inviato: mercoledì 13 maggio 2020 11.01
>A: Stefano Sofia; r-help mailing list
>Oggetto: Re: [R] Classification of wind events
>
>Hi Stefano,
>Given only one observation point you will find it difficult. If your
>automatic weather station is in the low area where the foehn wind is
>felt, it can only be distinguished from a dry katabatic wind if the
>upwind conditions are known. There is a similar but milder version of
>this in eastern Australia, but it is usually of the latter sort. There
>may be a way to measure turbulence above the peak of the high ground
>with radar or something, but I'm not familiar with that.
>
>Jim
>
>On Tue, May 12, 2020 at 6:13 PM Stefano Sofia
><stefano.sofia using regione.marche.it> wrote:
>>
>> Dear R list users,
>> I am aware that this question is not strictly related, at the present
>moment, to R code and it is more general. Please forgive me, but I need
>to share my thoughts with you.
>>
>> Foehn conditions on the southern slope of Alps happen with strong
>northerly flows that impact perpendicularly over the Apls. This
>situation triggers strong northerly leeward winds.
>> Given a single automatic weather station, I would like to identify
>these periods starting from wind direction and wind intensity data.
>Frequency of data is quarter of hour.
>> I would really find difficult to detect the moving windows of these
>events:
>> - I can't analyse data day by day;
>> - at the beginning and at the end of each event, when the process is
>not at full speed yet, the rotation is not always perfectly
>identifiable;
>> - I cannot claim in principle that the direction of each consecutive
>observation is costantly and strictly from the chosen direction.
>>
>> Does anybody have a clue on how to start to build this process in the
>right way?
>>
>> Thank you for your attention and your help
>> Stefano
>>
>>          (oo)
>> --oOO--( )--OOo----------------
>> Stefano Sofia PhD
>> Civil Protection - Marche Region
>> Meteo Section
>> Snow Section
>> Via del Colle Ameno 5
>> 60126 Torrette di Ancona, Ancona
>> Uff: 071 806 7743
>> E-mail: stefano.sofia using regione.marche.it
>> ---Oo---------oO----------------
>>
>> ________________________________
>>
>> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può
>contenere informazioni confidenziali, pertanto è destinato solo a
>persone autorizzate alla ricezione. I messaggi di posta elettronica per
>i client di Regione Marche possono contenere informazioni confidenziali
>e con privilegi legali. Se non si è il destinatario specificato, non
>leggere, copiare, inoltrare o archiviare questo messaggio. Se si è
>ricevuto questo messaggio per errore, inoltrarlo al mittente ed
>eliminarlo completamente dal sistema del proprio computer. Ai sensi
>dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità
>ed urgenza, la risposta al presente messaggio di posta elettronica può
>essere visionata da persone estranee al destinatario.
>> IMPORTANT NOTICE: This e-mail message is intended to be received only
>by persons entitled to receive the confidential information it may
>contain. E-mail messages to clients of Regione Marche may contain
>information that is confidential and legally privileged. Please do not
>read, copy, forward, or store this message unless you are an intended
>recipient of it. If you have received this message in error, please
>forward it to the sender and delete it completely from your computer
>system.
>>
>> --
>> Questo messaggio  stato analizzato da Libra ESVA ed  risultato non
>infetto.
>> This message was scanned by Libra ESVA and is believed to be clean.
>>
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>--
>
>Questo messaggio  stato analizzato con Libra ESVA ed  risultato non
>infetto.
>
>
>________________________________
>
>AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere
>informazioni confidenziali, pertanto è destinato solo a persone
>autorizzate alla ricezione. I messaggi di posta elettronica per i
>client di Regione Marche possono contenere informazioni confidenziali e
>con privilegi legali. Se non si è il destinatario specificato, non
>leggere, copiare, inoltrare o archiviare questo messaggio. Se si è
>ricevuto questo messaggio per errore, inoltrarlo al mittente ed
>eliminarlo completamente dal sistema del proprio computer. Ai sensi
>dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità
>ed urgenza, la risposta al presente messaggio di posta elettronica può
>essere visionata da persone estranee al destinatario.
>IMPORTANT NOTICE: This e-mail message is intended to be received only
>by persons entitled to receive the confidential information it may
>contain. E-mail messages to clients of Regione Marche may contain
>information that is confidential and legally privileged. Please do not
>read, copy, forward, or store this message unless you are an intended
>recipient of it. If you have received this message in error, please
>forward it to the sender and delete it completely from your computer
>system.
>
>-->
>Questo messaggio  stato analizzato da Libra ESVA ed  risultato non
>infetto.>
>This message was scanned by Libra ESVA and is believed to be clean.

--
Sent from my phone. Please excuse my brevity.

--

Questo messaggio  stato analizzato con Libra ESVA ed  risultato non infetto.


________________________________

AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.

--
Questo messaggio  stato analizzato da Libra ESVA ed  risultato non infetto.
This message was scanned by Libra ESVA and is believed to be clean.



More information about the R-help mailing list