Saturday, February 6, 2021

Installing Python 3.9.1 and psycopg2 on Big Sur 11.1 - Apple M1

 I recently purchased my first Mac.  It is a MacBook Pro 13" M1, great little machine with lots of power.  The work I do is Python, ansible, and other miscellaneous development projects connecting to databases, lately PostgreSQL. I do use a laptop for photography work as well.  The first steps were getting the development environment up and running.  Microsoft VS Code went in smoothly and synced everything once connected to my Microsoft account.

Next was installing Python.  This was interesting as I wanted at least Python 3.8+ and for the M1 it seemed that 3.9.1 was the first real supported release.  The M1 with Big Sur comes with Python 2.7 and you do not want to replace it.

I found two ways to install Python 3.9, one using pyenv and one using brew. I did find that you do not want to mix the two.  I removed both and tired just pyenv by itself and got lots of errors with matplotlib, pandas, and psycopg2.  Most of the solutions I found did not seem to help and maybe I did not do the right things.  So I removed the pyenv install and went the brew install of Python 3.9.1 and here are the steps I used to get them the modules I wanted installed and working.

First installing Python 3.9.1

First thing I noticed with this installation is that everything ends up in /opt/homebrew and you will need to add directories to your path.

In my case homebrew was installed in /opt/homebrew by default. I followed the instructions on the Brew Homepage. Update your .zshrc to update the PATH on terminal startup.

export PATH="/opt/homebrew/bin:$PATH" 
Next install openssl and Python 3.9

$ brew install openssl
$ brew install python@3.9

I had number of modules that had issues getting installed, particularly dependencies for matplotlib and the next steps got numpy, pandas, and matplotlib installed without issues.

$ brew install openblas

$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install cython --no-use-pep517

$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install numpy --no-use-pep517

$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install pandas --no-use-pep517

$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install pybind11 --no-use-pep517

$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install scipy --no-use-pep517

$ brew install libjpeg zlib

$ python3 -m pip install pillow

$ python3 -m pip install matplotlib

Next I installed PostgreSQL 12.5
$ brew install postgresql@12
export PATH="/opt/homebrew/opt/postgresql@12/bin:$PATH" 

Validate pip3 is being used from /opt/homebrew/bin/pip3
$ which pip3
Next set the following flags to install psycopg2-binary
export LDFLAGS="-L/opt/homebrew/opt/openssl/lib"
export CPPFLAGS="-L/opt/homebrew/opt/openssl/include"

Install psycopg2-binary using pip3
$ pip3 install psycopg2-binary

I found that I needed to ensure the python script has at the top a call to use python3
#!/usr/bin/env python3

Monday, February 22, 2016

Ham Radio: Digital Mode JT-65 and JT-9

Amateur Radio is another one of my hobbies.  In January I found this new Digital Mode called JT-65, so far I have used it on 10 meters through 40 meters and listened on 6 meters and 80 meters.  What is really neat about this mode is less power is more.  10 watts on 20 meters I worked Reunion Island from Longview, Washington and based on the signal report I could have probably used even less.

I won't go into what JT-65 is, but since you can read tons about it here.  WSJT stands for "Weak Signal Communication by K1JT."  The mode is used for EME (Earth-Moon-Earth) communications, meteor scatter and HF/LF communications.  
The JT-65 QSO is very short but very long.  You can only send 13 characters, uppercase A-Z, 0-9, slash(/), hyphen(-) and the space character.  Each side of the QSO takes 1 minute.  Yes! 1 minute so a standard QSO, from QSO to sign-off is 6 minutes.  Typically you will see something like:

CQ N7DQ CN86             <-- basic call for a QSO with grid square
N7DQ KG7EYC CN86    <-- Please talk to me
KG7EYC N7DQ -01        <-- Signal report for KG7EYC from N7DQ
N7DQ KG7EYC R-01      <-- Acknowledge signal report and send a signal report
KG7EYC N7DQ 73          <-- Thank you for the QSO
N7DQ KG7EYC 73          <-- Thank you for the QSO 

Remember this is one minute for each phase of the QSO, well actually, 47 seconds sending the transmission and 13 seconds of listening, deciding what to do next. Look at the list of stations, decide which one you want to talk with, and click on the call and ensure you have transmit enabled.

You can hear JT-65 on multiple HF and even VHF frequencies.  The sound reminds me of music from a child's music box.  This link provides a list of those frequencies and recommendations on Good Operating Procedures.  

Now your are thinking how do I try this mode out.  First I am assuming you already are doing some form of digital communication from your computer through your radio such as RTTY or PSK31.  If not, you will want to get a link between your computer and radio using something like a SignaLink USB or checkout and see if your radio can connect directly to your computer via a cable and do digital modes.  You should need a simple cable that you should be able to purchase from your radio manufacture or the place you bought the radio.

One other connection you might want to setup is Rig Control, this way you can use your computer to control your radio.  Again, the cable should be available via your radio manufacture or your radio vendor.  Search on Google for your radio and rig control or CAT, for example,  "Yaesu FT-897 CAT" or "Kenwood TS-850 Rig Control" and you should find something to point you in the right direction.

Now for the process to set things up. Your computer clock must be accurate to within a second or two.  From my experience with Windows 7, 8, and 10, Windows only updates the clock about once a day and for some laptops the time drift can be big.  First download Dimension4.  It is a basic install, accept the defaults, once installed start it up and configure it to start on Windows startup.  I have found that if you put your computer to sleep, having this running will help with time drift issues.

Next, download WSJT-x (1.6). During the install it will ask some basic questions.  There is a question about using, I recommend you take the default. While you run WSJT-x, it will report what stations you hear and the signal report you would give them.  You can later change this to if you want and if you want to see a map of connection  go here. What is cool about this is you will see how far your signal can go around the world.

Image from spots:

Image from spots on a map:

Finally, download JT Alert  - make sure you get the supporting applications as well. Install in the order downloaded.  JT Alert provides an interface to some logs and helps you track needed contacts for state, country or grid.

Basic quick start:
Start WSJT-x, go to File->Settings. Fill out the first tab with your information.  

Next if you have a rig control cable, go to the rig tab and configure it for your radio, 

next go to the audio tab and setup the connection to your sound card interface. 

There are some other options that are beyond this simple article and you will some good setup directions out there.  Read some of the docs for WSJT-x on setting things up, basically about 15 minutes, maybe 30 minutes or if you don't skim an hour.  This mode and setup is easy, follow the quick guides and get on the air.

Now make sure you started Dimension4, ensure it syncs your computer clock and is set to startup on booting the computer. Start WSJT-x followed by JT Alert. Set your radio to the recommended frequencies in WSJT-x and listen, let the program decode.

Focus on JT-65 not JT-9 at this time. Make sure you set your radio output power to no more than 10 watts, yes that is right 10 watts. More than that you will be splattering the band with noise and causing interference for other stations.  If you are getting lots of -01 reports, you might consider decreasing your power.  There is a site that will help you do a signal report and power comparison called dBCalc: Signal Power & dB Comparison.  One other reason to keep the power low is that this mode is full key down during the entire communication.  If you are using more than 50 watts or 100 watts, you could have some issues with your finals life span.

What I find interesting and cool is how well, WSJT-x pulls signals from the noise, here is an image of a station calling from Japan and for me is right in some noise either caused by propagation conditions, antenna issues, computer noise, radio noise or interference.  You can even have signals that are crossed over each other see both QSOs. Though if two transmitting signals are exactly on each other you may not decode either and the music is not good.

Go out to Youtube and do a search for WJST-x and find a couple of videos about operating in this mode -- probably should have told you this first but we are amateur radio operators and we try stuff before reading everything.

There are several other programs that do JT-65/JT-9 but I have found that I like the way WSJT-x works by keeping things simple.  I have downloaded and used the programs and they have some pretty neat features as well.  Here is a list of the other programs.  JT Alert will interface to each of them as well, so you may need to reinstall JT Alert to configure it to see these programs.

JT65-HF-Comfort by DL3VCO

JT65-HF HB9HQX Edition

JT65-HF by W6CQZ looks like it is no longer available and the project is abandoned.

Hope you give this mode a try and you should see me out on the air at some point.

73 de Mike - N7DQ

Sunday, April 7, 2013

So Consumer Beware!

 Early mid-week last week, I get a call about doing a survey out of Fort Collins, Colorado on energy efficiency.  Nice survey and took only 5 minutes like they said and had some good questions.  Well, if you give them your address, you are entered to win a gas card of anywhere from $25 to $100.  Guess what we won a $40 gas card.

Now hold on.  They deliver the gas card but ask that you give them an opinion on a piece of energy efficient equipment, and only an opinion nothing is being sold, and you then get your gas card after the person spends an hour getting your opinion.

Well, I say okay.  The guy shows up and first thing he says is out of these prizes which one would you take in addition to the gas card.  I say, "None."  They all looked cool but were all cheap, probably everything only about $50.

Next thing is he is trying to sell a air cleaner, a super special air filter and ultimately even a super cool vacuum cleaner.  Nothing about just asking our opinion, everything was for sell.  And supposedly the company only did surveys.    I did find out that if we did buy the special air filter we would have had to call a number to day we were getting it and they would send one of the prizes the guy mentioned at first.

Well we wasted one hour of time our time to get a $40 gas card and fortunately were smart enough not to buy anything.  We never asked the price of anything but we figured it would be expensive.  We did get the $40 gas card.

The gas card is ridiculous. You have to get your gas and receipt, send the receipt in with the card filled out and get back four $10 coupons that you can only use one a month over four months.  It takes at least 10 weeks to get the coupons back. I will see if we really get the coupons but I don't expect much for the effort.

From what I can tell the entire deal was a scam.  We were pretty careful not to buy anything and not to show the person around the house or leave anything expensive out.  Based on all this I think everyone they called won a gas card of some value.

So beware if you get a call for a survey and then an offer of a prize at the end of it and they tell you they will deliver it to you. Oh! And they just want an hour of your time for your opinion on a piece of equipment.  Run away, say NO! This is a total scam.    ----   Remember the old adage, if it is too good to be true it is probably a scam.