why do we use ee.number().pow().int in Cloud masking using Google earth engine - libgee

I didn't understand why we use raise number 2 with power 3 for accessing cloud bit mask
and what exactly means setting flag to 0 while performing bitwiseAnd operation
var maskL8SR = function(image) {
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = ee.Number(2).pow(3).int();
var cloudsBitMask = ee.Number(2).pow(5).int();
// Get the QA band.
var qa = image.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).and(
qa.bitwiseAnd(cloudsBitMask).eq(0));
return image

Related

Standard deviation for categories

Hi I have desperately been trying to work this out and have referred to several posts but am still not getting the correct answer!
I have a bunch of providers of different provider type. I calculate an average cost change for each provider (from more granular payment data). I then want to find the standard deviation of these provider level changes for the difference provider type.
This is where I've got up to with the dax - this gives the same standard deviation across all provider types rather than the required output.
group_test =
var tab1 = SUMMARIZECOLUMNS(ProvData[Provider Type],ProvData[Provider Code], "prov_avg",AVERAGEX(core_data, sum(PayData[Payment1])-sum(PayData[Payment2]))/SUM(PayData[Payment1]))
var sd_type = SELECTCOLUMNS(SUMMARIZE(tab1,[Provider Type],[Provider Code], "test", STDEVX.S(tab1,[prov_avg])), "sd_type", [test])
var tab2 = ADDCOLUMNS(tab1, "sd_type", sd_type)
return tab2
I want my final table to look like this
Provider Code
Provider type
Prov_avg
sd_type
1
a
x
sd for a
2
a
y
sd for a
3
b
z
sd for b
Thanks in advance for any help
Add a column to your table:
stdColumn =
var prov_Code = ProvData[Provider Code]
var prov_type = ProvData[Provider Type]
var stdValue = CALCULATE (STDEV.S([prov_avg]), FILTER(prov_Code = ProvData[Provider Code] && prov_type = ProvData[Provider Type]))
return stdValue
So what we do is to calculate the stdev based on the filter given on Code & Type

Calculate the difference between 2 rows in PowerBI using DAX

I'm trying to complete something which should be quite simple but for the life of me, I can't work it out.
I'm trying to calculate the difference between 2 rows that share the same 'Scan type'.
I have attached a photo showing sample data from production. We run a scan and depending on the results of the scan, it's assigned a color.
I want to find the difference in Scan IDs between each Red scan.
Using the attached Photo of Sample data, I would expect a difference of 0 for id 3. A difference of 1 for id 4 and a difference of 10 for id 14.
I have (poorly) written something that works based on the maximum value from the scan id.
I have also tried following a few posts to see if I can get it to work..
var _curid= MAX(table1[scanid])
var _curclueid = MAX(table1[scanid])
var _calc =CALCULATE(SUM(TABLE1[scanid],FILTER(ALLSELECTED(table1[scanid]),table1[scanid]))
return if(_curid-_calc=curid,0,_curid-_calc)
Edit;
Forgot to mention I have checked threads;
57699052
61464745
56703516
57710425
Try the following DAX and if it helps then accept it as the answer.
Create a calculated column that returns the ID where the colour is Red as follows:
Column = IF('Table'[Colour] = "Red", 'Table'[ID])
Create another column as following:
Column 2 =
VAR Colr = 'Table'[Colour]
VAR SCAN = 'Table'[Scan ID]
VAR Prev_ID =
CALCULATE(MAX('Table'[Column 2]),
FILTER('Table', 'Table'[Colour] = Colr && 'Table'[Scan ID] < SCAN))
RETURN
'Table'[Column] - Prev_ID
Output:
EDIT:-
If you want your first value(ID3) to be 0 then relace the RETURN line with the following line:
IF(ISBLANK(Prev_ID) && 'Table'[Colour] = "Red", 0, 'Table'[Column] - Prev_ID )
This will give you the following result:

Cell formating based on other cell value google sheets

I have 2 sheets the first one is Orders and second one is the ShippingDoc.
At Shipping doc, I have Cell C2. In that cell I choose/write ID from range of A7:A from Orders.
Is there a way if I choose example ID 1 at C2 then automatically A7 at Orders to change background to green. Also if I change the ID to 2 the A8 to be green and to not delete the A7 color.
There is a better way of achieving this using Apps Script. Go to tools->Script editor and there use the following code (explained on the comments in the code):
// Update everytime the value on C2 changes
function onEdit() {
var spreadsheet = SpreadsheetApp.getActive();
// Get C2 value
var C2value = spreadsheet.getSheetByName("ShippingDoc").getRange('C2').getValue();
// If input value is higher than 0
if(C2value>0){
// Ofset to set the background after A7
var number = C2value+6;
// Set background color of appropiate cell
spreadsheet.getSheetByName("Orders").getRange('A'+number+'').setBackground('green');
}
}
Check out more information about how to do amazing things in sheets with simple scripts HERE
I hope this has helped you. Let me know if you need anything or if you did not understand something.
try:
=(REGEXMATCH(""&INDIRECT("ShippingDoc!C2"), ""&A1))*(A1<>"")

How to write CouchDB view to get currently active servers given start timestamp and end timestamp of each server?

I have set of documents which has the server name, with the start timestamp and end timestamp of that server. eg.
[
{
serverName: "Houston",
startTimestamp: "2018/03/07 17:52:13 +000",
endTimestamp: "2018/03/07 18:50:10 +000"
},
{
serverName: "Canberra",
startTimestamp: "2018/03/07 18:48:09 +000",
endTimestamp: "2018/03/07 20:10:00 +000"
},
{
serverName: "Melbourne",
startTimestamp: "2018/03/08 01:43:13 +000",
endTimestamp: "2018/03/08 12:09:10 +000"
}
]
With this data, given a Timestamp I need to get the list of active servers at that point of time.
For example. for TS="2018/03/07 18:50:00 +000" from the above data the list of active servers are ["Huston", "Canberra"]
Is it possible to achieve this using only CouchDB views. If so how to go about it?
Note: Initially I tried the following approach. In the map function I emit two documents
1 with key=doc.startTimestsamp and value={"station_add": doc.station}
1 with key=doc.startEndtsamp and value={"station_rem": doc.station}
My intention was to iterate through these in the reduce function adding stations present in "station_add" and removing stations in "stations_rem". But I found that CouchDB does not mention anything about the ordering of values in the reduce function.
If you can live with fixed periods and don't mind the extra disk space that might be needed for the view results, you can create a view of active servers per hour, for example.
Iterate over the periods between start and end and emit the time that each server was online during this period:
function(doc) {
var start = new Date(doc.startTimestamp).getTime()
var end = new Date(doc.endTimestamp).getTime()
var msPerPeriod = 60*60*1000
var msOfflineInFirstPeriod = start % msPerPeriod
var firstPeriod = start - msOfflineInFirstPeriod
var msOnlineInLastPeriod = end % msPerPeriod
var lastPeriod = end - msOnlineInLastPeriod
if (firstPeriod === lastPeriod) {
// The server was only online within one period.
emit([new Date(firstPeriod), doc.serverName], [1, msOnlineInLastPeriod - msOfflineInFirstPeriod])
} else {
// The server was online over multiple periods.
emit([new Date(firstPeriod), doc.serverName], [1,msPerPeriod - msOfflineInFirstPeriod])
for (var period = firstPeriod + msPerPeriod; period < lastPeriod; period += msPerPeriod) {
emit([new Date(period), doc.serverName], [1, msPerPeriod])
}
emit([new Date(lastPeriod), doc.serverName], [1,msOnlineInLastPeriod])
}
}
If you want the total without the server names, just add a reduce function with the built-in shortcut _sum. You'll get the number of servers online during the period as the first number and the milliseconds that the servers were online in that period as the second number.
You can play with the view if you emit the year, month and day as the first keys. Then you can use the group_level at query time to get a finer or more coarse overview.
Bear in mind that this view might get large on disk, as each row has to be stored, and also the intermediate results for each group level are stored. So you shouldn't set the period duration too small – emitting a row for each second would take a lot of disk space, for example.

limit the Y-axis character in google visulaization combo graph to given limit

Hi,
Is there any way to limit the Y-axis character in google visulaization combo graph to given limit and then ...
By Default it is doing when more then 22 character. But I want to reduce it to given character.
Attached is the screen shot
I assume you meant X-axis, not Y-axis, given your screen shot. There is a quick-and-dirty approach that truncates the displayed strings to 22 characters, but this will affect the tooltips as well as the axis labels:
for (var i = 0; i < data.getNumberOfRows(); i++) {
// assumes column 0 is your labels
var label = data.getValue(i, 0);
label = label.substring(0, 22);
data.setFormattedValue(i, 0, label);
}
If you just want to affect the axis labels, there are different approaches you can take, and which one you take depends on what you want to achieve by truncating the labels. What is it that you want to achieve?