HDLC frame HCS and FCS - hdl-coder

I have an HDLC frame like blow and I want to calculate the HCS and FCS algorithm.
Its based on DLMS protocol noted in green book page 128.
Here is an example of this frame:
Ex.1:
Frame=`(7EA016030002002352A25EE6E700C401C10012000211927E)Hex`
HCS = `( 52A2 )Hex`
Data= `( 5EE6E700C401C100120002 )Hex`
FCS = `( 1192 )Hex`

FCS can be computed using the method in 8.5.3 and the lookup can be generated using the method in 8.5.4 of the Green Book 8.3.
HCS is calculated in the same way.

Related

Pie Chart with Labels and facet in altair: not able to proper render the value labels

Using the single chart example, I have a label for each piece of cake.
If I try to transform it in a faceted chart using this code
df=pd.read_csv("input.csv",keep_default_na=False)
base=alt.Chart(df).encode(
theta=alt.Theta(field="v", type="quantitative"),
color=alt.Color(field="k", type="nominal")
)
pie = base.mark_arc(outerRadius=100)
text = base.mark_text(radius=115,fill= "black").encode(alt.Text(field="v", type="quantitative", format=",.1f"))
alt.layer(pie, text, data=df).facet(column='label')
all the labels are all in the same wedge and then illegible (here the vega lite version vega lite version).
how to have a result similar to that of the single chart?
Thank you
f,n,k,v,label
1,3,0-5 %,99.7289972899729,Forest
1,4,5-10 %,0.27100271002710025,Forest
0,1,0-5 %,100.0,Non-Forest
254,5,0-5 %,99.0077177508269,unclassifiable
254,6,5-10 %,0.9922822491730982,unclassifiable
I must add:
stack=True as channel encoding option in the theta channel encoding;
and .resolve_scale( theta="independent" ) to the chart.
And it works (I learned this thanks to Mattijn van Hoek).
df=pd.read_csv("input.csv",keep_default_na=False)
base=alt.Chart(df).encode(
theta=alt.Theta(field="v", type="quantitative", stack=True),
color=alt.Color(field="k", type="nominal")
)
pie = base.mark_arc(outerRadius=100)
text = base.mark_text(radius=115,fill= "black").encode(alt.Text(field="v", type="quantitative", format=",.1f"))
alt.layer(pie, text, data=df).facet(column='label').resolve_scale(theta="independent")

Creating layout PDFs by iterating feature selection and setting extent

In ArcGIS Pro 2.4, I need to create a PDF page of a map layout where the map frame is zoomed to each row in a feature class. Each feature in this class is a polygon. I'm relatively new to ArcPy so I'm learning as I'm going.
So far I've been messing with arcpy.SearchCursor, to iterate the selection of the features. Inside the cursor, I need to use mf.camera.setExtent(mf.getLayerExtent(selectedfeature)) and mf.camera.scale *= 1.05 so the polygon shows its surroundings for context. Then I've been trying to export the layout (lyt) to a PDF somewhere. There are 700 of these polgyons (each labelled as a alphanumerical map page) so it's best to do this with arcpy.
import arcpy
aprx = arcpy.mp.ArcGISProject(r"G:\ArcGIS Projects\project.aprx")
m = aprx.listMaps("Map")[0]
lyr = m.listLayers("PLSS Quarter Sections*")[0]
lyt = aprx.listLayouts("Paper Maps*")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT", "Sewer Sections*")[0]
fc = "PLSS Quarter Sections"
fields = ['OBJECTID']
cursor = arcpy.SearchCursor(fc)
row = cursor.next()
for row in cursor:
mf.camera.setExtent(mf.getLayerExtent(row, True, False))
mf.camera.scale *= 1.05
lyt.exportToPDF(r"G:\ArcGIS Projects\output.pdf")
It should move the map frame inside the layout to the selected feature, zoom out, and save that layout to a PDF. All it does it give a TypeError: 1. How would I go about doing this?
After asking around, ArcGIS Pro has a feature called Map Series that lets you make a series of maps based off a certain layer. In my case, it created 700 maps with a single polygon framed in the map frame in my layout. It's also much easier than scripting it by hand.

Plotting data with arbitrary center and x axis positive in both directions

I’m writing a paper and I have data showing structural changes in my molecule. Those structural changes are inverting the d orbital arrangements.
To show a gradual inversion I’d like to plot a graphic showing the perfect structure (all bonds = 2.1) as the center of my x-axis and to the left what happens to the orbitals if I gradually change two bonds from 2.1 to 2.2. To the right the axis is, also, positive, starting from the center 2.1 and going to 2.2 (but showing what happens with a change to only one bond).
Here is a drawing to clarify my intention:
So far, the best that I could achieve is this:
plt.figure(figsize=(9, 8))
dxy = sns.stripplot(x="Bond", y="Energy(cm-1)", data=dfbd, jitter=False, dodge=False, size=44, marker="_", linewidth=2, hue="Orbital")
plt.ylabel("Energy (Eh)")
If you want to give it a try or have any insights on how to achieve this I'll be extremely grateful.
Here is the data in CSV:
,Type,Bond,Orbital,Energy(cm-1)
0,D4h,2.1,dyz,0.0
1,D4h,2.1,dyz,1.2
2,D4h,2.1,dxz,6.0
3,D4h,2.1,dx2-y2,6473.1
4,D4h,2.1,dz2,6491.1
5,D4h,2.12,dxz,0.0
6,D4h,2.12,dyz,62.9
7,D4h,2.12,dxy,84.3
8,D4h,2.12,dz2,6233.7
9,D4h,2.12,dx2-y2,6560.8
10,D4h,2.14,dxz,0.0
11,D4h,2.14,dyz,125.9
12,D4h,2.14,dxy,171.2
13,D4h,2.14,dz2,5992.8
14,D4h,2.14,dx2-y2,6650.5
15,D4h,2.16,dxz,0.0
16,D4h,2.16,dyz,184.7
17,D4h,2.16,dxy,254.8
18,D4h,2.16,dz2,5761.5
19,D4h,2.16,dx2-y2,6736.9
20,D4h,2.18,dxz,0.0
21,D4h,2.18,dyz,239.4
22,D4h,2.18,dxy,335.4
23,D4h,2.18,dz2,5539.6
24,D4h,2.18,dx2-y2,6820.6
25,D4h,2.2,dxz,0.0
26,D4h,2.2,dyz,290.4
27,D4h,2.2,dxy,413.0
28,D4h,2.2,dz2,5327.0
29,D4h,2.2,dx2-y2,6901.5
30,D4h*,2.1,dyz,0.0
31,D4h*,2.1,dyz,1.2
32,D4h*,2.1,dxz,6.0
33,D4h*,2.1,dx2-y2,6473.1
34,D4h*,2.1,dz2,6491.1
35,D4h*,2.12,dxz,0.0
36,D4h*,2.12,dyz,29.0
37,D4h*,2.12,dxy,39.1
38,D4h*,2.12,dz2,6359.1
39,D4h*,2.12,dx2-y2,6514.3
40,D4h*,2.14,dxz,0.0
41,D4h*,2.14,dyz,60.6
42,D4h*,2.14,dxy,82.5
43,D4h*,2.14,dz2,6239.0
44,D4h*,2.14,dx2-y2,6559.1
45,D4h*,2.16,dxz,0.0
46,D4h*,2.16,dyz,90.0
47,D4h*,2.16,dxy,124.3
48,D4h*,2.16,dz2,6123.8
49,D4h*,2.16,dx2-y2,6602.2
50,D4h*,2.18,dxz,0.0
51,D4h*,2.18,dyz,117.3
52,D4h*,2.18,dxy,164.5
53,D4h*,2.18,dz2,6013.3
54,D4h*,2.18,dx2-y2,6643.9
55,D4h*,2.2,dxz,0.0
56,D4h*,2.2,dyz,142.9
57,D4h*,2.2,dxy,203.2
58,D4h*,2.2,dz2,5907.6
59,D4h*,2.2,dx2-y2,6684.2
Following #ImportanceOfBeingErnest's comment, I would tend to go for the "fake axis" route, as it avoids mucking around with several axes, several labels, legends, etc...
df.loc[:,'fake_Bond'] = df.Bond
df.loc[df.Type=='D4h', 'fake_Bond'] = 2.0 + abs(df.loc[df.Type=='D4h', 'Bond'] - 2.2)
plt.figure(figsize=(9, 8))
dxy = sns.stripplot(x="fake_Bond", y="Energy(cm-1)", data=df, jitter=False, dodge=False, size=44, marker="_", linewidth=2, hue="Orbital")
plt.ylabel("Energy (Eh)")
dxy.set_xticklabels(np.concatenate([np.linspace(2.2,2.1,6),np.linspace(2.12,2.2,5)]))
dxy.set_xlabel("D4h $\longleftarrow$ Bond $\longrightarrow$ D4h*")

how to control transparency of ppp density plot

I am trying to use the layered methods to overlay few spatstat spatial objects. All these objects are for the same window. I have an im layer (density) from a ppp. I want to make this layer a bit transparent in order to have a better visibility of the other objects in the layered object.
How can I control the transparency of this density plot (im)? Is there something like alpha or transparency parameter for the plot.im ?
UPDATE:
library(spatstat)
pipes=simplenet
plot(pipes)
point_net = as.ppp(runifpoint(10, win = Window(pipes)))
point_surface = density(point_net)
plot(point_surface)
layers= layered(point_surface, point_net, pipes)
plot(layers)
Here , I have plotted 3 layers. As you can see the density plot has very dark blues and reds. Yes, I can plot lines and points with different colours to make them visible, but it would nice to do simple stacked line, point plots and add a little bit of transparency to the density (im) plots.
The purpose is just to avoid complex customized plot colours and to explain to colleagues.
thank you.
First the commands from the original post:
library(spatstat)
pipes=simplenet
point_net = as.ppp(runifpoint(10, win = Window(pipes)))
point_surface = density(point_net)
layers= layered(point_surface, point_net, pipes)
plot(layers)
You need to provide a different colourmap to plot.im. There are two
ways you can do this:
Plot each layer individually using add = TRUE for subsequent
layers and provide the colour map when you plot the im object.
Pass a list of plot arguments when you plot the layered object you
have created above.
I find the first option easier for illustration, so I will do that
first. The default colourmap of spatstat is the 29th Kovesi colour
sequence (?Kovesi for more details on these sequences):
def_col <- Kovesi$values[[29]]
head(def_col)
#> [1] "#000C7D" "#000D7E" "#000D80" "#000E81" "#000E83" "#000E85"
To add transparency you can use to.transparent with your choice of
fraction for more/less transparency:
def_col_trans <- to.transparent(def_col, fraction = 0.7)
head(def_col_trans)
#> [1] "#000C7DB3" "#000D7EB3" "#000D80B3" "#000E81B3" "#000E83B3" "#000E85B3"
Now you just need to use this as your colourmap:
plot(point_surface, col = def_col_trans)
plot(point_net, add = TRUE)
plot(pipes, add = TRUE)
To do it with the layered object you have to make a list of plot
argument lists (containing NULL if you don't have additional
arguments):
layer_args <- list(list(col = def_col_trans),
list(NULL),
list(NULL))
plot(layers, plotargs = layer_args)

How to encircle Invalid data in Excel?

I want to show a circle around only invalid data.
i have done the complete steps shown in this link
But this circle shown is very big and covers the entire cell.
I want a small circle only covering the data not the entire cell's width.
Data validation is a built in Excel functionality. It checks whole cell value.
So it is not possible, using Data validation, to accomplish what your trying.
It MAY BE POSSIBLE using VBA, shapes, events and (hard) parsing character rendering. In your place, I would be glad with this very big circles!!! :)
I agree with #LS_dev. See this MS Article about changing data validation for printing. Try modifying it to loop through all your data validation and change the width and height.
You can probably do it with this part of the code by changing the width and height:
If Not c.Validation.Value Then
Set o = ActiveSheet.Shapes.AddShape(msoShapeOval, _
c.Left - 2, c.Top - 2, c.Width + 4, c.Height + 4)
o.Fill.Visible = msoFalse
o.Line.ForeColor.SchemeColor = 10
o.Line.Weight = 1.25

Resources