Plotting data from a deviated well

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
IanF
Newbie
Newbie
Posts: 20
Joined: Tue Jul 04, 2017 12:00 am

Plotting data from a deviated well

Post by IanF » Thu May 10, 2018 6:10 am

I wish to plot temperature data from a deviated well against measured depth, with vertical depth on the opposite axis. I have tried to attach a file of typical data but without success. Suffice to say that the measured depth / vertical depth relationship is not linear.
If the axis range and increment have been specified, it will be relatively easy to calculate the vertical depth at each measured depth increment (or vice versa), by an interpolation process (linear interpolation is usually fine) and write the axis label a the appropriate place. However, if the graph is on autorange and autoincrement, how do I find the positions at which there is a label on the primary independent axis?
If this or a similar question has been asked previously, a code example would be greatly appreciated.

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Plotting data from a deviated well

Post by Yeray » Wed May 16, 2018 10:26 am

Hello,

I'm not sure about what series type are you using to represent that information.
Also, I don't understand if you are getting problems loading the data or only showing the labels.
Could you please a simple example project we can run as-is to reproduce the problem here? Some screenshot could also help to understand what are you getting or failing to get.

Regarding the interpolation, note you can find a Line Interpolate example here.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

IanF
Newbie
Newbie
Posts: 20
Joined: Tue Jul 04, 2017 12:00 am

Re: Plotting data from a deviated well

Post by IanF » Fri May 18, 2018 6:05 am

Hi Yeray

Thanks for your reply. I didn't create a example project as I was hoping someone else may have come up with a solution.
I have attached an example project including data files. The base data is in DeviatedPT.csv, which contains the following fields:
Depth - measured depth down the deviated well
Temperature - measured at each depth
Pressure - measured at each depth
WHP - measured at each depth
Vertical Depth - calculated at each measured depth
Elevation - calculated at each measured depth.

I want to create a graph of Depth (on left axis) vs Temperature (top axis) and Pressure and WHP (bottom axis), with the corresponding Elevation displayed on the right axis.
The Elevation axis has to be a dummy axis without plotted against it - as the well is deviated, the relationship between Depth and Elevation is not linear. I have plotted Pressure against Depth and Elevation on the attached image, and you can see the two (blue) curves do not match.
DeviatedPT.jpg
DeviatedPT.jpg (173.1 KiB) Viewed 24647 times
So what I want to do is draw a Custom Elevation axis, showing major ticks and labels. There seem to be two options:
1. Draw evenly-spaced major ticks, corresponding to the major ticks on the Depth axis, and write the calculated elevation at each tick. The elevation calculations are no problem, but if the Depth axis is set to Automatic Scale, how do I find the Depth values at the major ticks?
2. Draw ticks at even elevation increments (say every 100 m). In this case, the tick marks will not be evenly spaced along the axis. I can calculate where each tick will be in relation to the minimum and maximum values on the Elevation axis, but is it easy to specify ticks at user-defined positions?

I look forward to your comments.
Regards
Errol
Attachments
DeviatedPT.zip
Zip file containing example project and data files.
(31.46 KiB) Downloaded 818 times

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Plotting data from a deviated well

Post by Yeray » Fri May 18, 2018 6:53 am

Hello,

Could you please check the attached project is correct? The .dpr references 'PT_Chart.pas' but the only .pas included is "formPTChart.pas", which is an empty form.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

IanF
Newbie
Newbie
Posts: 20
Joined: Tue Jul 04, 2017 12:00 am

Re: Plotting data from a deviated well

Post by IanF » Mon May 21, 2018 11:50 pm

Hi Yeray
Sorry about attaching the wrong example project. I am pretty sure this one will work.
Basically I want to plot all data sets against Depth on the Left Axis and then draw an axis on the Right Axis to represent Elevation.
I imagine it will be easiest to draw an axis with evenly-spaced tick marks and then "manually" write the value. Depth100m_VDepth_Elev.xlsx in the zip file gives the Elevation at each 100m Depth - I can calculate that.
If the Depth increment is known, I imagine it will be reasonably easy to write the elevation at each 100m Depth, although I would appreciate a bit of code to assist.
It is more of a problem if the Depth axis is using Automatic range and increment as I don't know how to find the Depth increments in this case.
Any assistance gratefully appreciated.
Regards
Errol
Attachments
DeviatedPT.zip
(80.57 KiB) Downloaded 811 times

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Plotting data from a deviated well

Post by Yeray » Thu May 24, 2018 7:37 am

Hello,

Now I believe I understand what are you trying to achieve. Thanks for the project.
Indeed, the options you have are those you described:
IanF wrote:1. Draw evenly-spaced major ticks, corresponding to the major ticks on the Depth axis, and write the calculated elevation at each tick. The elevation calculations are no problem, but if the Depth axis is set to Automatic Scale, how do I find the Depth values at the major ticks?
You could use OnGetAxisLabel event to modify the texts drawn for each label. Ie:

Code: Select all

procedure TfrmPTChart.DBChart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: string);
var tmp: Double;
begin
  if Sender = DBChart1.Axes.Right then
  begin
    tmp:=StrToFloatDef(LabelText, 0);
    // transform tmp value here
    LabelText:=FormatFloat(Sender.AxisValuesFormat, tmp);
  end;
end;
IanF wrote:2. Draw ticks at even elevation increments (say every 100 m). In this case, the tick marks will not be evenly spaced along the axis. I can calculate where each tick will be in relation to the minimum and maximum values on the Elevation axis, but is it easy to specify ticks at user-defined positions?
Yes, it's as easy as Clearing the Items array and add the desired labels with the Items.Add(Value, Text) function. Ie:

Code: Select all

  with DBChart1.Axes.Right do
  begin
    Items.Clear;
    i:=Round(Minimum);
    repeat
      Items.Add(i, IntToStr(i));  // adding custom label
      Inc(i, 100);
    until i>=Round(Maximum);
  end;
The second option allows more customization (ie, you can have a completely irregular increment if you want) but you have to handle the labels overlapping yourself.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

IanF
Newbie
Newbie
Posts: 20
Joined: Tue Jul 04, 2017 12:00 am

Re: Plotting data from a deviated well

Post by IanF » Thu May 31, 2018 6:57 am

Hi Yeray
Thanks for your help on this to date. Unfortunately, I am unable to create a Depth axis on the left and an Elevation axis on the right. I have attached a revised example project. When it runs, you will see the Depth axis on the left at 100m intervals, and a single value on the right. When you press the Draw Left Axis button, the left axis is replaced by the corresponding elevations at Depth increments of 100m, which is great. However, I would like the Depth axis on the left and the Elevation axis on the right, at the same time, and without another series being plotted (all series being plotted against depth).
Note that the function Elev calculates the elevation for any depth, using the Depth/Elevation relationship for the well.
I look forward to your suggestions.
Best regards
Errol
Attachments
DeviatedPT.zip
(71.72 KiB) Downloaded 793 times

IanF
Newbie
Newbie
Posts: 20
Joined: Tue Jul 04, 2017 12:00 am

Re: Plotting data from a deviated well

Post by IanF » Mon Jun 04, 2018 12:37 am

Hi Yeray
I am pleased to report that I have been able to create a Depth axis on the left and an Elevation axis on the right, by duplicating the series to plot on both axes. I have used CalcIncrement to get the left and right axis labels to line up, and the OnBeforeDrawAxes event to ensure the right axis draws correctly after scroll and zoom. I then hidden the duplicate series by setting them to 100% transparency. As the program counts series to assign symbols and line colours correctly to multiple data sets, I will have to skip the count for the duplicate series.
The example project is attached. I have two questions:
1. When I zoom in a number of times, the program freezes. Can you suggest why this might happen.
2. Is there any way to label the duplicate series with a Tag or similar, so it will be easy to not count these series when allocating symbols and colours to the visible series?
Best regards
Errol
Attachments
DeviatedPT.zip
(69.4 KiB) Downloaded 875 times

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Plotting data from a deviated well

Post by Yeray » Mon Jun 04, 2018 11:44 am

Hello Errol,

I think you could avoid using that hidden series by assigning both vertical axes to the first series and using OnGetAxisLabel event to format the right axis labels:

Code: Select all

procedure TfrmPTChart.FormShow(Sender: TObject);
//...
  //DrawRightAxis;

  Series4.Visible:=False;
  Series1.VertAxis:=aBothVertAxis;
end;

procedure TfrmPTChart.DBChart1BeforeDrawAxes(Sender: TObject);
begin
  //DrawRightAxis;
end;

procedure TfrmPTChart.DBChart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: string);
var tmp: Double;
begin
  if Sender = DBChart1.Axes.Right then
  begin
    tmp:=StrToFloatDef(ReplaceStr(LabelText, ThousandSeparator, ''), 0);
    tmp:=Round(Elev(tmp));
    LabelText:=FormatFloat(Sender.AxisValuesFormat, tmp);
  end;
end;
Regarding the hanging when zooming several times, you could set a limit at OnZoom or at OnMouseUp events.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

IanF
Newbie
Newbie
Posts: 20
Joined: Tue Jul 04, 2017 12:00 am

Re: Plotting data from a deviated well

Post by IanF » Mon Jun 25, 2018 6:37 am

Hello

Thank you for your suggestions. The graph of data from a deviated well, using both Depth and Elevation on the vertical axes is now working well - see enclosed project.
However, I have the following questions:

1. Is there a command to auto-synchronise two axes when a vertical axis is specified as aBothVertAxis, or do I have to manually synchronise the axis parameters as shown in procedure TfrmPTChart.SyncVertAxes?
2. I wish to be able to synchronise the grids of the two horizontal axes, as shown by clicking the "Synchronise dependent axes", using the SyncTopAxis procedure. This procedure works, but when implemented the program locks up after two or three zooms. Furthermore, when I uncheck, the top axis does not revert to automatic scaling.

I look forward to your comments

Regards

Errol
Attachments
DeviatedPT.zip
(66.99 KiB) Downloaded 836 times

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Plotting data from a deviated well

Post by Yeray » Wed Jun 27, 2018 7:53 am

Hello Errol,
IanF wrote:1. Is there a command to auto-synchronise two axes when a vertical axis is specified as aBothVertAxis, or do I have to manually synchronise the axis parameters as shown in procedure TfrmPTChart.SyncVertAxes?
The only property in your SyncVertAxes that seems to have a noticeable effect in your project is "Increment". I see you've set the Left Axis Increment to 100 at designtime so, if you don't do the same for the Right Axis, they look different.
IanF wrote:2. I wish to be able to synchronise the grids of the two horizontal axes, as shown by clicking the "Synchronise dependent axes", using the SyncTopAxis procedure. This procedure works, but when implemented the program locks up after two or three zooms.
When you add custom labels, at your SyncTopAxis method, you are incrementing the "i" variable rounding the "Increment". Note when the increment is less than 1, this is rounded to 0 so the "i" variable isn't incremented and you are inside an endless loop.
An option would be to change the "i" variable to a double and then avoid some roundings:

Code: Select all

    i:=BMin/BInc * BInc;
    repeat
      Tval := Round((i - BMin)/BDiff*TDiff + TMin);
      TPos := (i - Bmin)/BDiff*TDiff+TMin;
      Top.Items.Add(TPos, FloatToStr(Tval));  // adding custom label
      i:=i+BInc;
    until i>=BMax;
IanF wrote:Furthermore, when I uncheck, the top axis does not revert to automatic scaling.
Add this at your CheckBox1Click:

Code: Select all

DBChart1.Axes.Top.Items.Automatic:=True;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

IanF
Newbie
Newbie
Posts: 20
Joined: Tue Jul 04, 2017 12:00 am

Re: Plotting data from a deviated well

Post by IanF » Fri Jun 29, 2018 3:36 am

Good afternoon

Thank you for the most recent assistance - much appreciated. I should have realised that the locking up on zoom was an integer problem.

I have one more problem, that I am unable to reproduce in the test program. When I draw my graph, the horizontal grid lines slightly out of sync
UndoZoom.jpg
UndoZoom.jpg (130.97 KiB) Viewed 24445 times
. This only occurs if the left axis is set to Automatic scaling. When I scroll using the mouse wheel, the horizontal grid lines synchronize nicely
MouseWheelScroll.jpg
MouseWheelScroll.jpg (130.33 KiB) Viewed 24446 times
. However if I use mouse right-click to scroll the graph, the grid line become more unsynchronized.
RightClickScroll.jpg
RightClickScroll.jpg (107.31 KiB) Viewed 24446 times
Clearly I am not setting the Right Axis parameters correctly, but I have tried many options without success.

I would appreciate it if you could suggest some Right Axis settings I should specify to synchronize the grids.

Thanks and regards

Errol

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Plotting data from a deviated well

Post by Yeray » Fri Jun 29, 2018 10:57 am

Hello,

It's difficult to say what's going on without being able to reproduce and debug the problem.
I would debug the "GetAxisLabel" event, inside the "if Sender = DBChart1.Axes.Right then" condition to see if the "LabelText" has the same values from the Left Axis.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

IanF
Newbie
Newbie
Posts: 20
Joined: Tue Jul 04, 2017 12:00 am

Re: Plotting data from a deviated well

Post by IanF » Mon Jul 02, 2018 9:03 am

Hi Yeray
Thank you for your suggestions regarding the lack of synchronization of the left and right axes when I set VertAxis = aBothVertAxis. However, this has nothing to do with the OnGetAxisLabel event, as it occurs even when this event is turned off. The problem occurs only when LeftAxis.Automatic = True.
I find it difficult to understand why the two vertical axes are not automatically synchronized whenever VertAxis is set to aBothVertAxis, as I cannot see the purpose in having one vertical axis with a different range than the other one, when the series is being plotted against both axes. Relabelling an axis does not alter this observation - when I relabel a Depth axis to Elevation, I am stating that this is the Elevation of the corresponding Depth, but the two axes are essentially still synchronized.
However, given that the two axes need to be manually synchronized, I have tried various commands. For instance, as UndoZoom leaves the two axes slightly unsynchronized, I have tried various commands such as:

Code: Select all

procedure Tformmain.UndoZoom(Sender: TObject);
var
  AMin,AMax: double;
    if PBQuickGraphMain.IndependentLeft then
    begin
      QuickGraphChartMain.LeftAxis.CalcMinMax(AMin,AMax);
      QuickGraphChartMain.RightAxis.Minimum := AMin;
      QuickGraphChartMain.RightAxis.Maximum := AMax;
    end;
However, to no avail - the grid lines of the two vertical axes remain slightly unsynchronized, as shown in my previous post. However, mouse wheel scroll (with no defined event) causes the left and right grids to synchronize, which shows that synchronization is possible.
Clearly, I have some settings after UndoZoom that are causing the grids to become misaligned, but I cannot find these, however much I step through the code. I would appreciate any suggestions you might have, so I can get this working correctly.
Thanks and regards
Errol

IanF
Newbie
Newbie
Posts: 20
Joined: Tue Jul 04, 2017 12:00 am

Re: Plotting data from a deviated well

Post by IanF » Wed Jul 04, 2018 6:11 am

Hi Yeray

I am pleased to report that I have solved the problem with the two vertical axes not synchronizing when VertAxis is set to aBothVertAxes. I realised that there were additional series plotted on the Left Axis, and once I set the VertAxis of these series to aBothVertAxes, the error resolved itself.
Thanks for your assistance in this matter. I now understand significantly more of TeeChart.
Best regards
Errol

Post Reply